Analysis of Uninformed Search Methods Slides adapted from

  • Slides: 44
Download presentation
Analysis of Uninformed Search Methods Slides adapted from: 6. 034 Tomas Lozano Perez, Russell

Analysis of Uninformed Search Methods Slides adapted from: 6. 034 Tomas Lozano Perez, Russell and Norvig AIMA Brian C. Williams 16. 410 -13 Sep 21 st, 2004 Brian Williams, Fall 04 1

Assignments • Remember: Problem Set #2: Simple Scheme and Search due Monday, September 27

Assignments • Remember: Problem Set #2: Simple Scheme and Search due Monday, September 27 th, 2004. • Reading: – Uninformed search: more of AIMA Ch. 3 Brian Williams, Fall 04 2

Outline • Recap • Analysis – Depth-first search – Breadth-first search • Iterative deepening

Outline • Recap • Analysis – Depth-first search – Breadth-first search • Iterative deepening Brian Williams, Fall 04 3

Complex missions must carefully: • Plan complex sequences of actions • Schedule tight resources

Complex missions must carefully: • Plan complex sequences of actions • Schedule tight resources • Monitor and diagnose behavior • Repair or reconfigure hardware. ð Most AI problems, like these, may be formulated as state space search. Brian Williams, Fall 04 4

Problem Solving: Formulate Graph and Find Paths • Formulate Goal • Formulate Problem –

Problem Solving: Formulate Graph and Find Paths • Formulate Goal • Formulate Problem – States – Operators • Generate Solution Goose Grain Astronaut Fox Astronaut Goose Grain Fox Astronaut Goose Fox Grain Fox Astronaut Goose – Sequence of states Goose Grain Fox Astronaut Goose Fox Astronaut Grain Brian Williams, Fall 04 Astronaut Grain Fox Goose Fox Astronaut Goose Grain Astronaut Fox Astronaut Goose Grain Fox Goose Astronaut Fox Grain Astronaut Goose Fox Grain Goose Grain Fox Astronaut Grain Goose Fox 5

Elements of Algorithm Design Description: (last Wednesday) – stylized pseudo code, sufficient to analyze

Elements of Algorithm Design Description: (last Wednesday) – stylized pseudo code, sufficient to analyze and implement the algorithm – Implementation (last Monday). Brian Williams, Fall 04 6

Depth First Search (DFS) S A D C Depth-first: B C D G G

Depth First Search (DFS) S A D C Depth-first: B C D G G C Add path extensions to front of Q Pick first element of Q G Breadth First Search (BFS) S A D C C G Breadth-first: B D C G G Brian Williams, Fall 04 Add path extensions to back of Q Pick first element of Q 7

Issue: Starting at S and moving top to bottom, will depth-first search ever reach

Issue: Starting at S and moving top to bottom, will depth-first search ever reach G? C G A D S B Brian Williams, Fall 04 8

Depth-First Effort can be wasted in more mild cases 3 C Q 1 (S)

Depth-First Effort can be wasted in more mild cases 3 C Q 1 (S) 2 (A S) (B S) 3 (C A S) (D A S) (B S) 4 (D A S) (B S) 5 (C D A S)(G D A S) (B S) 6 How (Gmuch D A S)(B S) wasted 2 A 1 G 4 D S B • C visited multiple times • Multiple paths to C, D & G effort can be incurred in the worst case? Brian Williams, Fall 04 9

How Do We Avoid Repeat Visits? Idea: • Keep track of nodes already visited.

How Do We Avoid Repeat Visits? Idea: • Keep track of nodes already visited. • Do not place visited nodes on Q. Does this maintain correctness? • Any goal reachable from a node that was visited a second time would be reachable from that node the first time. Does it always improve efficiency? • Visits only a subset of the original paths, such that Fall 04 each node appears Brian at. Williams, most once at the head of a 10

How Do We Modify Simple Search Algorithm Let Q be a list of partial

How Do We Modify Simple Search Algorithm Let Q be a list of partial paths, Let S be the start node and Let G be the Goal node. 1. Initialize Q with partial path (S) as only entry; 2. If Q is empty, fail. Else, pick some partial path N from Q 3. If head(N) = G, return N reached!) (goal 4. Else a) Remove N from Q b) Find all children of head(N) and create all the one-step extensions of N to each child. Brian Williams, Fall 04 c) Add to Q all the extended paths; 11

Simple Search Algorithm Let Q be a list of partial paths, Let S be

Simple Search Algorithm Let Q be a list of partial paths, Let S be the start node and Let G be the Goal node. 1. Initialize Q with partial path (S) as only entry; set Visited = ( ) 2. If Q is empty, fail. Else, pick some partial path N from Q 3. If head(N) = G, return N reached!) (goal 4. Else a) Remove N from Q b) Find all children of head(N) not in Visited and create all the one-step extensions of N to each Brian Williams, Fall 04 child. 12

Note: Testing for the Goal • Algorithm stops (in step 3) when head(N) =

Note: Testing for the Goal • Algorithm stops (in step 3) when head(N) = G. • Could have performed test in step 6, as each extended path is added to Q. • But, performing test in step 6 will be incorrect for optimal search, discussed later. ð We chose step 3 to maintain uniformity with these future searches. Brian Williams, Fall 04 13

Outline • Analysis – Depth-first search – Breadth-first search • Iterative deepening Brian Williams,

Outline • Analysis – Depth-first search – Breadth-first search • Iterative deepening Brian Williams, Fall 04 14

Elements of Algorithm Design Description: (last Wednesday) – stylized pseudo code, sufficient to analyze

Elements of Algorithm Design Description: (last Wednesday) – stylized pseudo code, sufficient to analyze and implement the algorithm – Implementation (last Monday). Analysis: (today) • Soundness: – when a solution is returned, is it guaranteed to be correct? • Completeness: – is the algorithm guaranteed to find a solution when there is one? • Time complexity: – how long does it take to find a solution? • Space complexity: – how much memory does it need to perform search? Brian Williams, Fall 04 15

Characterizing Search Algorithms b=3 Level 0 d=1 m=2 Level 1 Level 2 b =

Characterizing Search Algorithms b=3 Level 0 d=1 m=2 Level 1 Level 2 b = maximum branching factor, number of children d = depth of the shallowest goal node m = maximum length of any path in the state space Brian Williams, Fall 04 16

Cost and Performance Which is better, depth-first or breadth-first? C S A B G

Cost and Performance Which is better, depth-first or breadth-first? C S A B G A D C C D G C G G S D B Search Method Worst Time Worst Space Shortest Path? Guaranteed to find path? Depth-first Breadth-first Worst case time is proportional to number of nodes visited Worst case space is proportional to maximal length of Q Brian Williams, Fall 04 17

Worst Case Time for Depth-first Worst case time T is proportional to number of

Worst Case Time for Depth-first Worst case time T is proportional to number of nodes visited Level 0 1 b*1 Level 1 b*b. . . b*bm-1 Level 2 Level m Tdfs = [bm + … b + 1]*cdfs b * Tdfs = [bm+1 + bm + … b]*cdfs [b – 1] * Tdfs = [bm+1 – 1]*cdfs where cdfs is time per node Solve recurrence Tdfs = [bm+1 – 1] / [b – 1] *cdfs Brian Williams, Fall 04 18

Cost Using Order Notation Worst case time T is proportional to number of nodes

Cost Using Order Notation Worst case time T is proportional to number of nodes visited Level 0 1 b*1 Level 1 b*b. . . b*bm-1 Level 2 Order Notation • T = O(e) if T ≤ c * e for some constant c Tdfs = [bm+1 – 1] / [b – 1] *cdfs = O(bm+1) ~ O(bm) for large b Brian Williams, Fall 04 19

Cost and Performance Which is better, depth-first or breadth-first? C S A B G

Cost and Performance Which is better, depth-first or breadth-first? C S A B G A D C C D G C G G S D B Search Method Worst Time Depth-first ~ bm Worst Space Shortest Path? Guaranteed to find path? Breadth-first Worst case time is proportional to number of nodes visited Worst case space is proportional to maximal length of Q Brian Williams, Fall 04 20

Worst Case Space for Depth-first Worst case space Sdfs is proportional to maximal length

Worst Case Space for Depth-first Worst case space Sdfs is proportional to maximal length of Q Level 0 Level 1 Level m Brian Williams, Fall 04 21

Worst Case Space for Depth-first Worst case space Sdfs is proportional to maximal length

Worst Case Space for Depth-first Worst case space Sdfs is proportional to maximal length of Q Level 0 Level 1 b-1 Level m b-1. . . b • If a node is queued its parent and siblings have been queued, and its parent dequeued. è Sdfs ≥ [(b-1)*m+1] *cdfs where cdfs is space per node The children of at most one sibling is expanded at each level. è Sdfs = [(b-1)*m+1] *cdfs • Sdfs = O(b*m) Brian Williams, Fall 04 22

Cost and Performance Which is better, depth-first or breadth-first? C S A B G

Cost and Performance Which is better, depth-first or breadth-first? C S A B G A D C C D G C G G S D B Search Method Worst Time Worst Space Depth-first ~bm b*m Shortest Path? Guaranteed to find path? Breadth-first Worst case time is proportional to number of nodes visited Worst case space is proportional to maximal length of Q Brian Williams, Fall 04 23

Cost and Performance Which is better, depth-first or breadth-first? C S A B G

Cost and Performance Which is better, depth-first or breadth-first? C S A B G A D C C D G C G S G D B Search Method Worst Time Worst Space Shortest Path? Depth-first ~bm b*m No Guaranteed to find path? Breadth-first Worst case time is proportional to number of nodes visited Worst case space is proportional to maximal length of Q Brian Williams, Fall 04 24

Cost and Performance Which is better, depth-first or breadth-first? C S A B G

Cost and Performance Which is better, depth-first or breadth-first? C S A B G A D C C D G C G D S G B Search Method Depth-first Worst Time Worst Space Shortest Path? ~bm b*m No Guaranteed to find path? Yes for finite graph Breadth-first Worst case time is proportional to number of nodes visited Worst case space is proportional to maximal length of Q Brian Williams, Fall 04 25

Cost and Performance Which is better, depth-first or breadth-first? C S A B G

Cost and Performance Which is better, depth-first or breadth-first? C S A B G A D C D G S C G C D G B Search Method Depth-first Worst Time Worst Space Shortest Path? ~bm b*m No Guaranteed to find path? Yes for finite graph Breadth-first Worst case time is proportional to number of nodes visited Worst case space is proportional to maximal length of Q Brian Williams, Fall 04 26

Worst Case Time for Breadth-first Worst case time T is proportional to number of

Worst Case Time for Breadth-first Worst case time T is proportional to number of nodes visited Level 0 Level 1 Level d+1 Level m . . . Consider case where solution is at level d: Brian Williams, Fall 04 27

Worst Case Time for Breadth-first Worst case time T is proportional to number of

Worst Case Time for Breadth-first Worst case time T is proportional to number of nodes visited Level 0 1 Level 1 b. . . Level d+1 Level m bd bd+1 - b. . . Consider case where solution is at level d: Tbfs = [bd+1 + bd + … b + 1 - b]*cbfs ~ O(bd+1) Brian Williams, Fall 04 for large b 28

Cost and Performance Which is better, depth-first or breadth-first? C S A B G

Cost and Performance Which is better, depth-first or breadth-first? C S A B G A D C D G S C G C D G B Search Method Depth-first Worst Time Worst Space Shortest Path? ~bm b*m No Guaranteed to find path? Yes for finite graph Breadth-first ~bd+1 Worst case time is proportional to number of nodes visited Worst case space is proportional to maximal length of Q Brian Williams, Fall 04 29

Worst Case Space for Breadth-first Worst case space Sdfs is proportional to maximal length

Worst Case Space for Breadth-first Worst case space Sdfs is proportional to maximal length of Q Level 0 Level 1 Level d+1 Brian Williams, Fall 04 30

Worst Case Space for Breadth-first Worst case space Sdfs is proportional to maximal length

Worst Case Space for Breadth-first Worst case space Sdfs is proportional to maximal length of Q Level 0 1 Level 1 b. . . Level d bd Level d+1 bd+1 - b Sbfs = [bd+1 - b + 1]*cbfs = O(bd+1) Brian Williams, Fall 04 31

Cost and Performance Which is better, depth-first or breadth-first? C S A B G

Cost and Performance Which is better, depth-first or breadth-first? C S A B G A D C D G S C G C D G B Search Method Depth-first Worst Time Worst Space Shortest Path? ~bm b*m No Guaranteed to find path? Yes for finite graph Breadth-first ~bd+1 Worst case time is proportional to number of nodes visited Worst case space is proportional to maximal length of Q Brian Williams, Fall 04 32

Breadth-first Finds Shortest Path Nodes visited earlier can’t include G Level 0 First reached

Breadth-first Finds Shortest Path Nodes visited earlier can’t include G Level 0 First reached Level 1 Level d+1 G G Assuming each edge is length 1, other paths to G must be at least as long as first found Brian Williams, Fall 04 33

Cost and Performance Which is better, depth-first or breadth-first? C S A B G

Cost and Performance Which is better, depth-first or breadth-first? C S A B G A D C D G S C G C D G B Search Method Depth-first Worst Time Worst Space Shortest Path? ~bm b*m No Guaranteed to find path? Yes for finite graph Breadth-first Yes unit d+1 bd+1 Worst case~b time is proportional to number of nodes visited lngth Worst case space is proportional to maximal length of Q Brian Williams, Fall 04 34

Cost and Performance Which is better, depth-first or breadth-first? C S A B G

Cost and Performance Which is better, depth-first or breadth-first? C S A B G A D C D G S C G C D G B Search Method Depth-first Worst Time Worst Space Shortest Path? ~bm b*m No Guaranteed to find path? Yes for finite graph Breadth-first Yes unit d+1 bd+1 Worst case~b time is proportional to number. Yes of nodes visited lngth Worst case space is proportional to maximal length of Q Brian Williams, Fall 04 35

The Worst of The Worst Which is better, depth-first or breadth-first? S A D

The Worst of The Worst Which is better, depth-first or breadth-first? S A D C C B C D G C G A S G G D B • Assume d = m in the worst case, and call both m. • Take the conservative estimate: bm + … 1 = O(bm+1) Search Method Depth-first Worst Time Worst Space Shortest Path? bm+1 b*m No Guaranteed to find path? Yes for finite graph Breadth-first bm+1 bm Yes unit lngth Yes Worst case time is proportional to number of nodes visited Worst case space is proportional to maximal length of Q Brian Williams, Fall 04 36

For best first search, which runs out first – time or memory? Growth for

For best first search, which runs out first – time or memory? Growth for Best First Search b = 10; 10, 000 nodes/sec; 1000 bytes/node Depth Nodes Time Memory 2 1, 100 . 11 seconds 1 megabyte 4 111, 100 11 seconds 106 megabytes 6 107 19 minutes 10 gigabytes 8 109 31 hours 1 terabyte 10 1011 129 days 101 terabytes 12 1013 35 years 10 petabytes 14 1015 3, 523 years 1 exabyte Brian Williams, Fall 04 37

How Do We Get The Best of Both Worlds? C S A B G

How Do We Get The Best of Both Worlds? C S A B G A D C D G S C G C D G B Search Method Depth-first Worst Time Worst Space Shortest Path? ~bm b*m No Guaranteed to find path? Yes for finite graph Breadth-first Yes unit d+1 bd+1 Worst case~b time is proportional to number. Yes of nodes visited lngth Worst case space is proportional to maximal length of Q Brian Williams, Fall 04 38

Outline • Analysis • Iterative deepening Brian Williams, Fall 04 39

Outline • Analysis • Iterative deepening Brian Williams, Fall 04 39

Iterative Deepening (IDS) Idea: • Explore tree in breadth-first order, using depth-first search. è

Iterative Deepening (IDS) Idea: • Explore tree in breadth-first order, using depth-first search. è Search tree to depth 1, …. Level 0 S Level 1 A Level 2 Level 3 D C B C G D C Brian Williams, Fall 04 G G 40

Iterative Deepening (IDS) Idea: • Explore tree in breadth-first order, using depth-first search. è

Iterative Deepening (IDS) Idea: • Explore tree in breadth-first order, using depth-first search. è Search tree to depth 1, then 2, …. Level 0 S Level 1 A Level 2 Level 3 D C B C G D C Brian Williams, Fall 04 G G 41

Iterative Deepening (IDS) Idea: • Explore tree in breadth-first order, using depth-first search. è

Iterative Deepening (IDS) Idea: • Explore tree in breadth-first order, using depth-first search. è Search tree to depth 1, then 2, then 3…. Level 0 S Level 1 A Level 2 Level 3 D C B C G D C Brian Williams, Fall 04 G G 42

Speed of Iterative Deepening Level 0 Level 1 A Level 2 Level d d+1

Speed of Iterative Deepening Level 0 Level 1 A Level 2 Level d d+1 S D C B C G D C G G d*b. . . 2*bd-1 1*bd Compare speed of BFS vs IDS: • Tbfs = 1+b + b 2 +. . . bd + (bd+1 – b) = O(bd+2) • Tids = (d + 1)1 + (d)b + (d - 1)b 2 +. . . bd = O(bd+1) è Iterative deepening performs better than breadth-first! Brian Williams, Fall 04 43

Summary • Most problem solving tasks may be encoded as state space search. •

Summary • Most problem solving tasks may be encoded as state space search. • Basic data structures for search are graphs and search trees. • Depth-first and breadth-first search may be framed, among others, as instances of a generic search strategy. • Cycle detection is required to achieve efficiency and completeness. • Complexity analysis shows that breadth-first is preferred in terms of optimality and time, while depth-first is preferred in terms of space. • Iterative deepening draws the best from depth-first and breadth-first search. Brian Williams, Fall 04 44