ics-270a: notes 3: 1 lecture 3: uninformed search ics 270a winter 2003

32
ICS-270a: Notes 3: 1 Lecture 3: Uninformed Search ICS 270a Winter 2003

Upload: sydney-george

Post on 14-Jan-2016

218 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: ICS-270a: Notes 3: 1 Lecture 3: Uninformed Search ICS 270a Winter 2003

ICS-270a: Notes 3: 1

Lecture 3: Uninformed Search

ICS 270a Winter 2003

Page 2: ICS-270a: Notes 3: 1 Lecture 3: Uninformed Search ICS 270a Winter 2003

ICS-270a: Notes 3: 2

Summary

• Uninformed Blind search

– Breadth-first

– uniform first

– depth-first

– Iterative deepening depth-first

– Bidirectional

– Branch and Bound

• Informed Heuristic search (next class)

– Greedy search, hill climbing, Heuristics

• Important concepts:

– Completeness

– Time complexity

– Space complexity

– Quality of solution

Page 3: ICS-270a: Notes 3: 1 Lecture 3: Uninformed Search ICS 270a Winter 2003

ICS-270a: Notes 3: 3

Graph and Tree notations

Page 4: ICS-270a: Notes 3: 1 Lecture 3: Uninformed Search ICS 270a Winter 2003

ICS-270a: Notes 3: 4

Search Tree Notation• Branching degree, b

– b is the number of children of a node• Depth of a node, d

– number of branches from root to a node

• Arc weight, Cost of a path• n n’ , n parent node of n’, a child

node• Node generation• Node expansion• Search policy:

– determines the order of nodes expansion

• Two kinds of nodes in the tree– Open Nodes (Fringe)

• nodes which are not expanded (i.e., the leaves of the tree)

– Closed Nodes• nodes which have already been

expanded (internal nodes)

d = Depth

0

1

2

b=2S

G

Page 5: ICS-270a: Notes 3: 1 Lecture 3: Uninformed Search ICS 270a Winter 2003

ICS-270a: Notes 3: 5

Example: Map Navigation

S G

A B

D E

C

F

S = start, G = goal, other nodes = intermediate states, links = legal transitions

Page 6: ICS-270a: Notes 3: 1 Lecture 3: Uninformed Search ICS 270a Winter 2003

ICS-270a: Notes 3: 6

Example of a Search Tree

S

A D

B D

C E

E

Note: this is the search tree at some particular point in in the search.

Page 7: ICS-270a: Notes 3: 1 Lecture 3: Uninformed Search ICS 270a Winter 2003

ICS-270a: Notes 3: 7

Search Method 1: Breadth First Search

S

A D

BD

C E E

E

B F

A

B

(Use the simple heuristic of not generating a child node if that node is a parent to avoid “obvious” loops: this clearly does not avoid all loops and there are other ways to do this)

S S

Page 8: ICS-270a: Notes 3: 1 Lecture 3: Uninformed Search ICS 270a Winter 2003

ICS-270a: Notes 3: 8

Breadth-First Search

Page 9: ICS-270a: Notes 3: 1 Lecture 3: Uninformed Search ICS 270a Winter 2003

ICS-270a: Notes 3: 9

Breadth-First-Search (*)

1. Put the start node s on OPEN

2. If OPEN is empty exit with failure.

3. Remove the first node n from OPEN and place it on CLOSED.

4. If n is a goal node, exit successfully with the solution obtained by tracing back

pointers from n to s.

5. Otherwise, expand n, generating all its successors attach to them pointers

back to n, and put them at the end of OPEN in some order.

6. Go to step 2.

For Shortest path or uniform cost:

5’ Otherwise, expand n, generating all its successors attach to them pointers

back to n, and put them in OPEN in order of shortest cost path.

* This simplified version does not check for loops

Page 10: ICS-270a: Notes 3: 1 Lecture 3: Uninformed Search ICS 270a Winter 2003

ICS-270a: Notes 3: 10

What is the Complexity of Breadth-First Search?

• Time Complexity

– assume (worst case) that there is 1 goal leaf at the RHS

– so BFS will expand all nodes

= 1 + b + b2+ ......... + bd

= O (bd)

• Space Complexity

– how many nodes can be in the queue (worst-case)?

– at depth d-1 there are bd unexpanded nodes in the Q = O (bd)

d=0

d=1

d=2

d=0

d=1

d=2G

G

Page 11: ICS-270a: Notes 3: 1 Lecture 3: Uninformed Search ICS 270a Winter 2003

ICS-270a: Notes 3: 11

Examples of Time and Memory Requirements for Breadth-First Search

Depth of NodesSolution Expanded Time Memory

0 1 1 millisecond 100 bytes

2 111 0.1 seconds 11 kbytes

4 11,111 11 seconds 1 megabyte

8 108 31 hours 11 giabytes

12 1012 35 years 111 terabytes

Assuming b=10, 1000 nodes/sec, 100 bytes/node

Page 12: ICS-270a: Notes 3: 1 Lecture 3: Uninformed Search ICS 270a Winter 2003

ICS-270a: Notes 3: 13

Breadth-First Search (BFS) Properties

• Solution Length: optimal

• Generates every node just once

• Search Time: O(Bd)

• Memory Required: O(Bd)

• Drawback: require exponential space

1

3

7

15141312111098

4 5 6

2

Page 13: ICS-270a: Notes 3: 1 Lecture 3: Uninformed Search ICS 270a Winter 2003

ICS-270a: Notes 3: 14

Search Method 2: Depth First Search (DFS)

S

A

B

D

C E

D

D

F

G

Here, to avoid repeated states assume we don’t expand any child node which appears already in the path from the root S to the parent. (Again, one could use other strategies)

Page 14: ICS-270a: Notes 3: 1 Lecture 3: Uninformed Search ICS 270a Winter 2003

ICS-270a: Notes 3: 15

Depth-First Search

Page 15: ICS-270a: Notes 3: 1 Lecture 3: Uninformed Search ICS 270a Winter 2003

ICS-270a: Notes 3: 16

Page 16: ICS-270a: Notes 3: 1 Lecture 3: Uninformed Search ICS 270a Winter 2003

ICS-270a: Notes 3: 17

Depth-First-Search (*)

1. Put the start node s on OPEN

2. If OPEN is empty exit with failure.

3. Remove the first node n from OPEN and place it on CLOSED.

4. If n is a goal node, exit successfully with the solution obtained by

tracing back pointers from n to s.

5. Otherwise, expand n, generating all its successors attach to them

pointers back to n, and put them at the top of OPEN in some order.

6. Go to step 2.

Page 17: ICS-270a: Notes 3: 1 Lecture 3: Uninformed Search ICS 270a Winter 2003

ICS-270a: Notes 3: 18

What is the Complexity of Depth-First Search?

• Time Complexity

– assume (worst case) that there is 1 goal leaf at the RHS

– so DFS will expand all nodes

=1 + b + b2+ ......... + bd = O (bd)

• Space Complexity

– how many nodes can be in the queue (worst-case)?

– at depth l < d we have b-1 nodes

– at depth d we have b nodes

– total = (d-1)*(b-1) + b = O(bd)

d=0

d=1

d=2G

d=0

d=1

d=2

d=3

d=4

Page 18: ICS-270a: Notes 3: 1 Lecture 3: Uninformed Search ICS 270a Winter 2003

ICS-270a: Notes 3: 19

Techniques for Avoiding Repeated States

• Method 1

– do not create paths containing cycles (loops)

• Method 2

– never generate a state generated before

• must keep track of all possible states (uses a lot of memory)

• e.g., 8-puzzle problem, we have 9! = 362,880 states

• Method 1 is most practical, work well on most problems

S

B

C

S

B C

SC B S

State SpaceExample of a Search Tree

Page 19: ICS-270a: Notes 3: 1 Lecture 3: Uninformed Search ICS 270a Winter 2003

ICS-270a: Notes 3: 20

Example, diamond networks

Page 20: ICS-270a: Notes 3: 1 Lecture 3: Uninformed Search ICS 270a Winter 2003

ICS-270a: Notes 3: 21

Depth-First Search (DFS) Properties

• Non-optimal solution path

• Incomplete unless there is a depth bound

• Reexpansion of nodes,

• Exponential time

• Linear space

Page 21: ICS-270a: Notes 3: 1 Lecture 3: Uninformed Search ICS 270a Winter 2003

ICS-270a: Notes 3: 22

Comparing DFS and BFS

• Same worst-case time Complexity, but

– In the worst-case BFS is always better than DFS

– Sometime, on the average DFS is better if:

• many goals, no loops and no infinite paths

• BFS is much worse memory-wise

• DFS is linear space

• BFS may store the whole search space.

• In general

• BFS is better if goal is not deep, if infinite paths, if many loops, if small search space

• DFS is better if many goals, not many loops,

• DFS is much better in terms of memory

Page 22: ICS-270a: Notes 3: 1 Lecture 3: Uninformed Search ICS 270a Winter 2003

ICS-270a: Notes 3: 24

Iterative Deepening (DFS)

• Every iteration is a DFS with a depth cutoff.

Iterative deepening (ID)1. i = 1

2. While no solution, do

3. DFS from initial state S0 with cutoff i

4. If found goal, stop and return solution, else, increment cutoff

Comments:• ID implements BFS with DFS• Only one path in memory• BFS at step i may need to keep 2i nodes in OPEN

Page 23: ICS-270a: Notes 3: 1 Lecture 3: Uninformed Search ICS 270a Winter 2003

ICS-270a: Notes 3: 25

Iterative deepening search

Page 24: ICS-270a: Notes 3: 1 Lecture 3: Uninformed Search ICS 270a Winter 2003

ICS-270a: Notes 3: 26

Comments on Iterative Deepening Search

• Complexity– Space complexity = O(bd)

• (since its like depth first search run different times)– Time Complexity

• 1 + (1+b) + (1 +b+b2) + .......(1 +b+....bd) • = O(bd)

(i.e., asymptotically the same as BFS or DFS in the the worst case)

• The overhead in repeated searching of the same subtrees is small relative to the overall time

– e.g., for b=10, only takes about 11% more time than DFS

• A useful practical method– combines

• guarantee of finding an optimal solution if one exists (as in BFS)• space efficiency, O(bd) of DFS• But still has problems with loops like DFS

Page 25: ICS-270a: Notes 3: 1 Lecture 3: Uninformed Search ICS 270a Winter 2003

ICS-270a: Notes 3: 27

Iterative Deepening (DFS)

• Time:

2)1(

22

11

11)()(

b

nbnn

jb

jb bonT

BFS time is O(bn) B is the branching degree ID is asymptotically like BFS For b=10 d=5 d=cut-off DFS = 1+10+100,…,=111,111 IDS = 123,456 Ratio is

?

b

Page 26: ICS-270a: Notes 3: 1 Lecture 3: Uninformed Search ICS 270a Winter 2003

ICS-270a: Notes 3: 28

Bidirectional Search

• Idea

– simultaneously search forward from S and backwards from G

– stop when both “meet in the middle”

– need to keep track of the intersection of 2 open sets of nodes

• What does searching backwards from G mean

– need a way to specify the predecessors of G

• this can be difficult,

• e.g., predecessors of checkmate in chess?

– what if there are multiple goal states?

– what if there is only a goal test, no explicit list?

• Complexity

– time complexity is best: O(2 b(d/2)) = O(b (d/2)), worst: O(bd+1)

– memory complexity is the same

Page 27: ICS-270a: Notes 3: 1 Lecture 3: Uninformed Search ICS 270a Winter 2003

ICS-270a: Notes 3: 29

Bi-Directional Search

Page 28: ICS-270a: Notes 3: 1 Lecture 3: Uninformed Search ICS 270a Winter 2003

ICS-270a: Notes 3: 30

Bi-Directional Search (continued)

Page 29: ICS-270a: Notes 3: 1 Lecture 3: Uninformed Search ICS 270a Winter 2003

ICS-270a: Notes 3: 31

Uniform Cost Search

• Expand lowest-cost OPEN node (g(n))

• In BFS g(n) = depth(n)

Requirement g(successor)(n)) g(n)

Page 30: ICS-270a: Notes 3: 1 Lecture 3: Uninformed Search ICS 270a Winter 2003

ICS-270a: Notes 3: 32

Uniform cost search 1. Put the start node s on OPEN

2. If OPEN is empty exit with failure.

3. Remove the first node n from OPEN and place it on CLOSED.

4. If n is a goal node, exit successfully with the solution obtained by

tracing back pointers from n to s.

5. Otherwise, expand n, generating all its successors attach to them

pointers back to n, and put them at the end of OPEN in order of

shortest cost

6. Go to step 2.

DFS Branch and Bound

At step 4: compute the cost of the solution found and update the upper bound U.At step 4: compute the cost of the solution found and update the upper bound U. at step 5:at step 5: expand n, generating all its successors attach to them pointers back to n, and put in OPEN in order of shortest cost. Compute cost of paretial path to node and prune if larger than U...

Page 31: ICS-270a: Notes 3: 1 Lecture 3: Uninformed Search ICS 270a Winter 2003

ICS-270a: Notes 3: 33

Comparison of Algorithms

Page 32: ICS-270a: Notes 3: 1 Lecture 3: Uninformed Search ICS 270a Winter 2003

ICS-270a: Notes 3: 34

Summary• A review of search

– a search space consists of states and operators: it is a graph– a search tree represents a particular exploration of search space

• There are various strategies for “uninformed search”– breadth-first– depth-first– iterative deepening– bidirectional search– Uniform cost search– Depth-first branch and bound

• Repeated states can lead to infinitely large search trees– we looked at methods for for detecting repeated states

• All of the search techniques so far are “blind” in that they do not look at how far away the goal may be: next we will look at informed or heuristic search, which directly tries to minimize the distance to the goal. Example we saw: greedy search