Uninformed Search Lecture 4 Introduction to Artificial Intelligence - - PDF document

uninformed search
SMART_READER_LITE
LIVE PREVIEW

Uninformed Search Lecture 4 Introduction to Artificial Intelligence - - PDF document

Uninformed Search Lecture 4 Introduction to Artificial Intelligence Introduction to Artificial Intelligence Hadi Moradi moradi@usc.edu 1 Remember: Implementation of search algorithms Function General-Search(problem, Queuing-Fn) returns a


slide-1
SLIDE 1

1

Uninformed Search

Lecture 4 Introduction to Artificial Intelligence

1

Introduction to Artificial Intelligence Hadi Moradi moradi@usc.edu

Remember: Implementation of search algorithms

Function General Search(problem Queuing Fn) returns a Function General-Search(problem, Queuing-Fn) returns a

solution, or failure nodes make-queue(make-node(initial-state[problem]))

loop do if nodes is empty then return failure

node Remove-Front(nodes)

2

( )

if Goal-Test[problem] applied to State(node) succeeds then return node

nodes Queuing-Fn(nodes, Expand(node, Operators[problem]))

end

slide-2
SLIDE 2

2

Remember: Implementation of search algorithms

Q i F ( l t ) i

i

Queuing-Fn(queue, elements) is a queuing

function that inserts a set of elements into the queue and determines the order of node expansion. Varieties of the queuing function produce varieties of the search algorithm.

3

Encapsulating state information in nodes

4

slide-3
SLIDE 3

3

Evaluation of search strategies

Search algorithms are commonly evaluated Search algorithms are commonly evaluated

according to the following four criteria:

Completeness: does it always find a solution

if one exists?

Time complexity: how long does it take as

function of num of nodes?

5

function of num. of nodes?

Space complexity: how much memory does

it require?

Optimality: does it guarantee the least-cost

solution?

Evaluation of search strategies

Time and space comple it a e meas ed

Time and space complexity are measured

in terms of:

b – max branching factor of the search tree d – depth of the least-cost solution m – max depth of the search tree (may be

6

p ( y infinity)

slide-4
SLIDE 4

4

Note: Approximations

  • In our complexity analysis, we do not take the built-in loop-

p y y , p detection into account. The results only ‘formally’ apply to the

variants of our algorithms WITHOUT loop-checks.

Studying the effect of the loop-checking

7

Studying the effect of the loop-checking

  • n the complexity is hard:
  • verhead of the checking MAY or MAY NOT

be compensated by the reduction of the size

  • f the tree.

http://www.cs.kuleuven.ac.be/~ dannyd/FAI/

Note: Approximations

Also: our analysis DOES NOT take the

length (space) of representing paths into account !!

8

slide-5
SLIDE 5

5

Uninformed search strategies

Use only information available in the Use only information available in the problem formulation

Breadth-first Uniform-cost

9

Uniform-cost Depth-first Depth-limited Iterative deepening

Breadth-first search

Move

downwards level by

S A D B D A E

10

, level by level, until goal is reached.

C E E B B F D F B F C E A C G G G G G F C

slide-6
SLIDE 6

6

Example: Traveling from Arad To Bucharest

11

Breadth-first search

12

slide-7
SLIDE 7

7

Breadth-first search

13

Breadth-first search

14

slide-8
SLIDE 8

8

Properties of breadth-first search

Search algorithms are commonly evaluated

according to the following four criteria:

Completeness: Time complexity: 15

Time complexity:

Space complexity: Optimality:

Uniform-cost search

So, the queueing function keeps the node list sorted by increasing path

16

cost, and we expand the first unexpanded node (hence with smallest path cost)

A refinement of the breadth-first strategy: Breadth-first = uniform-cost with path cost = node depth

slide-9
SLIDE 9

9

Romania with step costs in km

17

Uniform-cost search

18

slide-10
SLIDE 10

10

Uniform-cost search

19

Uniform-cost search

20

slide-11
SLIDE 11

11

Properties of uniform-cost search

Completeness:

?

Completeness:

?

Time complexity:

?

Space complexity:

?

Optimality:

?

21

Implementation of uniform- cost search

Initialize Queue with root node (built from start

Q ( state)

Repeat until Queue is empty/node 1 has Goal state:

Remove first node from front of Queue Expand node (find its children) Reject those children that have already been considered, 22

to avoid loops

Add remaining children to Queue, in a way that keeps

entire queue sorted by increasing path cost

If Goal was reached, return success, otherwise

failure

slide-12
SLIDE 12

12

Caution!

Uniform-cost search

S A C

1 5

5 5 1

Uniform cost search not optimal if it is terminated when any node in the queue has goal state

100 100

D

5

10 10

E

5

15 15

A C B

1

2

23

state.

G

5

F

5

20 20

  • Uniform cost returns the

path with cost 102 (if any goal node is considered a solution), while there is a path with cost 25.

Question:

S A C

1 5 1

Do we have the

previous problem in this example?

100 100

D

5

E

5

A C B

1 1

24

G

5

F

5

slide-13
SLIDE 13

13

Note: Loop Detection

In class we saw that the search may fail In class, we saw that the search may fail

  • r be sub-optimal if:
  • no loop detection: then algorithm runs

into infinite cycles (A -> B -> A -> B -> …)

25

(A > B > A > B > …)

  • not queueing-up a node that has a state

which we have already visited:

may yield suboptimal solution

Note: Loop Detection

  • simply avoiding to go back to our parent:

simply avoiding to go back to our parent: looks promising, but we have not proven that it works Solution?

26

I s that enough??

slide-14
SLIDE 14

14

Example

From: http://www.csee.umbc.edu/471/current/notes/uninformed-search/

27

G

Breadth-First Search Solution

From: http://www.csee.umbc.edu/471/current/notes/uninformed-search/

28

slide-15
SLIDE 15

15

Uniform-Cost Search Solution

From: http://www.csee.umbc.edu/471/current/notes/uninformed-search/

29

Note: Queuing in Uniform- Cost Search

Problem: wasting (but not incorrect) to queue-up th d ith G three nodes with G:

  • Although different paths, but for sure that the one with

smallest path cost (9 in the example) is the first one in the queue.

Solution: refine the queuing function by:

30

I s that it??

slide-16
SLIDE 16

16

A Clean Robust Algorithm

Function UniformCost-Search(problem, Queuing-Fn) returns a solution, or failure

  • pen make-queue(make-node(initial-state[problem]))

closed [empty] loop do if open is empty then return failure currnode Remove-Front(open) if Goal-Test[problem] applied to State(currnode) then return currnode children Expand(currnode, Operators[problem])

31

while children not empty [… see next slide …] end closed Insert(closed, currnode)

  • pen Sort-By-PathCost(open)

end

A Clean Robust Algorithm

[… see previous slide …] children Expand(currnode, Operators[problem]) while children not empty child Remove-Front(children) if no node in open or closed has child’s state

  • pen Queuing-Fn(open, child)

else if there exists node in open that has child’s state if PathCost(child) < PathCost(node)

  • pen Delete-Node(open, node)
  • pen Queuing-Fn(open, child)

32

p g ( p ) else if there exists node in closed that has child’s state if PathCost(child) < PathCost(node) closed Delete-Node(closed, node)

  • pen Queuing-Fn(open, child)

end [… see previous slide …]

slide-17
SLIDE 17

17

Example

S

1 5

# State Depth Cost Parent 1 S

  • 100

100

D

5

E

5

A C

5

B

1 1

1 S

33

G

5

E F

5

Example

S

1

# State Depth Cost Parent 1 S

  • 100

100

D

5

E

5

S A C

1 5

B

1 1

S 2 A 1 1 1 3 C 1 5 1 Black = open queue Grey = closed queue

34

G

100 100 5

E F

5

Insert expanded nodes Such as to keep open queue sorted # : The step in which the node expanded

slide-18
SLIDE 18

18

Example

S

1 5

# State Depth Cost Parent 1 S

  • 100

100

D

5

E

5

S A C

5

B

1 1

1 S 2 A 1 1 1 4 B 2 2 2 3 C 1 5 1 Node 2 has 2 successors: one with state B and one with state S.

35

G

100 100 5

E F

5

We have node # 1 in closed with state S; but its path cost 0 is smaller than the path cost obtained by expanding from A to S. So we do not queue-up the successor of node 2 that has state S.

Example

S

1 5

# State Depth Cost Parent 1 S

  • 100

100

D

5

E

5

S A C

5

B

1 1

S 2 A 1 1 1 4 B 2 2 2 5 C 3 3 4 6 G 3 102 4 Node 4 has a successor with state C and Cost smaller than node # 3 in open that Also had state C; so we update open

36

G

100 100 5

E F

5

Also had state C; so we update open To reflect the shortest path.

slide-19
SLIDE 19

19

Example

S

1 5

# State Depth Cost Parent 1 S

  • 100

100

D

5

E

5

S A C

5

B

1 1

1 S 2 A 1 1 1 4 B 2 2 2 5 C 3 3 4 7 D 4 8 5 6 G 3 102 4

37

G

100 100 5

E F

5

Example

S

1 5

# State Depth Cost Parent 1 S

  • 100

100

D

5

E

5

S A C

5

B

1 1

S 2 A 1 1 1 4 B 2 2 2 5 C 3 3 4 7 D 4 8 5 8 E 5 13 7 6 G 3 102 4

38

G

100 100 5

E F

5

slide-20
SLIDE 20

20

Example

S

1 5

# State Depth Cost Parent 1 S

  • 100

100

D

5

E

5

S A C

5

B

1 1

1 S 2 A 1 1 1 4 B 2 2 2 5 C 3 3 4 7 D 4 8 5 8 E 5 13 7 9 F 6 18 8 6 G 3 102 4

39

G

100 100 5

E F

5

Example

S

1 5

# State Depth Cost Parent 1 S

  • 100

100

D

5

E

5

S A C

5

B

1 1

S 2 A 1 1 1 4 B 2 2 2 5 C 3 3 4 7 D 4 8 5 8 E 5 13 7 9 F 6 18 8 10 G 7 23 9 6 G 3 102 4

40

G

100 100 5

E F

5

6 G 3 102 4

slide-21
SLIDE 21

21

Example

S

1 5

# State Depth Cost Parent 1 S

  • 100

100

D

5

E

5

S A C

5

B

1 1

1 S 2 A 1 1 1 4 B 2 2 2 5 C 3 3 4 7 D 4 8 5 8 E 5 13 7 9 F 6 18 8 10 G 7 23 9 6 G 3 102 4

41

G

100 100 5

E F

5

6 G 3 102 4

Goal reached

More examples…

See the great demos at:

42

http://pages.pomona.edu/~ jbm04747/courses/spring20 01/cs151/Search/Strategies.html

slide-22
SLIDE 22

22

Depth-first search

B S S A

43

C E D F G

Romania with step costs in km

44

slide-23
SLIDE 23

23

Depth-first search

45

Depth-first search

46

slide-24
SLIDE 24

24

Depth-first search

47

Properties of depth-first search

  • Completeness:

? p

  • Time complexity:

?

  • Space complexity:

?

  • Optimality:

? Remember:

48

Remember: b = branching factor m = max depth of search tree

slide-25
SLIDE 25

25

Avoiding repeated states

In increasing order of effectiveness and In increasing order of effectiveness and computational overhead:

  • 1. do not return to state we come from,

i.e., expand function will skip possible

49

i.e., expand function will skip possible successors that are in same state as node’s parent.

Avoiding repeated states

2 do not create paths with cycles i e

  • 2. do not create paths with cycles, i.e.,

expand function will skip possible successors that are in same state as any

  • f node’s ancestors.
  • 3. do not generate any state that was ever

50

g y generated before, by keeping track (in memory) of every state generated, unless the cost of reaching that state is lower than last time we reached it.

slide-26
SLIDE 26

26

Examples: Avoiding repeated states

Assembly Assembly example

51