Problem Solving as State Space Search Brian C. Williams 16.410-13 Sept 13th, 2010 Slides adapted from: 6.034 Tomas Lozano Perez, Russell and Norvig AIMA Brian Williams, Fall 10 1 Assignments • Remember: Problem Set #1: Java warm up Out last Wednesday, Due this Wednesday, September 15th • Reading: – Today: Solving problems through search [AIMA] Ch. 3.1-4 – Wednesday: Asymptotic Analysis Lecture 2 Notes of 6.046J; Recurrences, Lecture 12 Notes of 6.042J. Brian Williams, Fall 10 2 1 Recap - Course Objectives 1. Understand the major types of agents and architectures: – goal-directed vs utility-based – deliberative vs reactive – model-based vs model-free 2. Learn the modeling and algorithmic building blocks for creating agents: – Model problem in an appropriate formal representation. – Specify, analyze, apply and implement reasoning algorithms to solve the problem formulations. Brian Williams, Fall 10 3 Recap – Agent Architectures Mission Goals Map Plan Locate in World Monitor & Diagnosis Execute Plan Routes Maneuver and Track Functions: Robust, coordinated operation + mobility It Begins with State Space Search! Brian Williams, Fall 10 4 2 Problem Solving as State Space Search • Problem Formulation (Modeling) – Problem solving as state space search • Formal Representation – Graphs and search trees • Reasoning Algorithms – Depth and breadth-first search Brian Williams, Fall 10 5 Most Agent Building Block Implementations Use Search Robust Operations: • Activity Planning • Diagnosis • Repair • Scheduling • Resource Allocation Mobility: • Path Planning • Localization • Map Building • Control Trajectory Design Brian Williams, Fall 10 6 3 Example: Outpost Logistics Planning Brian Williams, Fall 10 7 Image produced for NASA by John Frassanito and Associates. Can the astronaut get its supplies safely across a Lunar crevasse? Astronaut Goose Grain Fox • Astronaut + 1 item allowed in the rover. • Goose alone eats Grain • Fox alone eats Goose Rover Early AI: What are the universal problem solving methods? Simple Trivial Brian Williams, Fall 10 8 4 Problem Solving as State Space Search • Formulate Goal – State • Astronaut, Fox, Goose & Grain below crevasse. • Formulate Problem – States • Astronaut, Fox, Goose & Grain above or below the crevasse. – Operators • Move: Astronaut drives rover and 1 or 0 items to other side of crevasse. – Initial State • Astronaut, Fox, Goose & Grain above crevasse. • Generate Solution – Sequence of Operators (or States) • Move(goose,astronaut), Move(astronaut), . . . Brian Williams, Fall 10 9 Goose Grain Astronaut Fox Astronaut Goose Grain Fox Grain Fox Astronaut Goose Grain Fox Astronaut Goose Goose Grain Fox Astronaut Goose Fox Astronaut Grain Brian Williams, Fall 10 10 5 Goose Grain Grain Astronaut Fox Astronaut Goose Grain Fox Astronaut Goose Fox Grain Fox Astronaut Goose Goose Grain Fox Goose Fox Astronaut Astronaut Grain Goose Grain Astronaut Goose Grain Fox Astronaut Fox Grain Fox Goose Fox Astronaut Grain Goose Grain Goose Astronaut Fox Grain Astronaut Goose Grain Fox Grain Fox Astronaut Goose Fox Astronaut Grain Fox Goose Fox Astronaut Goose Grain Goose Grain Fox Astronaut Goose Astronaut Grain Astronaut Grain Goose Brian Williams, Fall 10 Grain Astronaut Goose Fox Astronaut Goose Goose Grain Fox Goose Astronaut Astronaut Fox Fox Astronaut Grain Fox Grain Astronaut Fox Astronaut Goose Grain Goose Fox 11 Astronaut Astronaut Fox Goose Grain Fox Goose Astronaut Fox Grain Astronaut Goose Fox Astronaut Grain Goose Brian Williams, Fall 10 Grain Goose Grain Fox Astronaut Goose Grain Fox Astronaut Goose Grain Fox Astronaut Grain Goose Fox 12 6 Formulation Example: 8-Puzzle 5 4 1 6 1 8 8 7 3 2 7 Start 2 3 4 6 5 Goal • States: integer location for each tile AND …?? • Operators: move empty square up, down, left, right • Initial and as shown above Goal States: Brian Williams, Fall 10 13 Languages for Expressing States and Operators for Complex Tasks • Swaggert & Lovell assemble emergency rig for Apollo 13 lithium hydroxide unit. Image source: NASA. Brian Williams, Fall 10 14 7 Example: STRIPS Planning Language Initial state: (and (hose a) (clamp b) (hydroxide-unit c) (on-table a) (on-table b) (on-table c) (clear a) (clear b) (clear c) (empty arm)) Operators precondition: (and (clear hose) (on-table hose) (empty arm)) pickup hose effect: (and (not (clear hose)) (not (on-table hose)) (not (empty arm)) (holding arm hose))) goal (partial state): (and (connected a b) (connected b c))) Brian Williams, Fall 10 15 Problem: Find a Route from home to MIT States? Operators?, Initial and Goal State? 16 © MapQuest, Navigation Technologies. All rights reserved. This content is excluded from our Creative Commons license. For more information, see http://ocw.mit.edu/fairuse. 8 Problem: Compensating for Error Online 1 2 8 7 3 4 6 5 • Policy, π(v) → e, dictates how to act in all states. • Policy π corresponds to a shortest path tree from all vertices to the destination. Brian Williams, Fall 09 17 How do we Map Path Planning to State Space Search? Start position Vehicle translates, but no rotation Goal position 18 9 1. Create Configuration Space Start position Vehicle translates, but no rotation Idea: Transform to equivalent problem of navigating a point. Goal position 19 2. Map From Continuous Problem to Graph Search: Create Visibility Graph Start position Goal position 20 10 2. Map From Continuous Problem to Graph Search: Create Visibility Graph Start position Goal position 21 3. Find Shortest Path (e.g., A*) Start position Goal position 22 11 Resulting Solution Start position Goal position 23 A Visibility Graph is a Kind of Roadmap Start position What are the strengths / weaknesses of roadmaps? What are some other types of roadmaps? Goal position 24 12 Voronoi Diagrams Lines equidistant from CSpace obstacles 25 Roadmaps: Approximate Fixed Cell Brian Williams, Fall 03 26 13 Roadmaps: Approximate Fixed Cell Brian Williams, Fall 03 27 Roadmaps: Approximate Variable Cell Brian Williams, Fall 03 28 14 Roadmaps: Exact Cell Decomposition Brian Williams, Fall 03 29 How do we handle large state spaces? Start position RRT, Ta RRT, Tb Goal position Rapid exploring Random Trees Brian Williams, Fall 03 30 15 Problem Solving as State Space Search • Problem Formulation (Modeling) – Problem solving as state space search • Formal Representation – Graphs and search trees • Reasoning Algorithms – Depth and breadth-first search Brian Williams, Fall 10 31 Problem Formulation: A Graph Operator State Edge Vertex t h Head Vertex of Edge Tail Vertex of Edge neighbors (adjacent) Undirected Graph Directed Graph (two-way streets) (one-way streets) Brian Williams, Fall 10 32 16 Problem Formulation: A Graph In Degree (2) Degree (3) b b Out Degree (1) Undirected Graph Directed Graph (two-way streets) (one-way streets) Brian Williams, Fall 10 33 Problem Formulation: A Graph Strongly connected graph Directed path between all vertices. Connected graph Path between all vertices. Complete graph All vertices are adjacent. b b a a c d Directed Graph (one-way streets) c e d e Sub graph Subset of vertices edges between vertices in Subset Clique A complete subgraph (All vertices are adjacent). Brian Williams, Fall 10 Undirected Graph (two-way streets) 34 17 Specifying a Graph: G = <V, E> Notation: <a, b, … n> an ordered list of elements a, b … {a, b, … n} an unordered set of distinguished elements. Vertices V = {a, b, c, d, e} b a c Edges E = {<a, b>, <a, c>, <b, e>, <c, b>, <c,d>, <e, d>} e d Brian Williams, Fall 10 35 Examples of Graphs Boston San Fran Roadmap Wash DC LA Dallas B Planning Actions Put B on C (graph of possible states of the world) C A C A B Put C on A Put C on A A B C A C Put C on B A B Brian Williams, Fall 10 Put A on C C B 36 18 Formalizing State Space Search Input: A search problem S = <g, S, G> where • graph g = <V, E>, • start vertex S in V, and • goal vertex G in V. Output: A simple path P = <S, v2, … G> in g from S to G. C G A D S Brian Williams, Fall 10 B 37 Simple Paths of Graph g = <V, E> C G A <S, A, D, C> D S start end B A (directed) path P of graph g is a sequence of vertices <v1, … vn> in V such that each successive pair <vi,vi+1> is a (directed) edge in E A simple path is a path that has no cycles. A cycle is a subpath where start = end (i.e., repeated vertices). Brian Williams, Fall 10 38 19 A Problem Solver Searches through all Simple Paths S C A G A D D C S G B Brian Williams, Fall 10 39 A Search Tree Denotes All Simple Paths S C A B G A D D S C C G D C G G B Enumeration is: • Complete • Systematic • Sound Brian Williams, Fall 10 40 20 Search Trees think of a tree as a “family” tree A tree T is a directed graph, such that • there exists exactly one undirected path between any pair of vertices. • In degree of each vertex is 1 Brian Williams, Fall 10 41 Search Trees Node (Vertex) Root Branch (Edge) Leaf think of a tree as a “family” tree Brian Williams, Fall 10 42 21 Search Trees Parent Siblings Child think of a tree as a “family” tree Brian Williams, Fall 10 43 Search Trees Ancestors think of a tree as a “family” tree Brian Williams, Fall 10 44 22 Search Trees Descendants think of a tree as a “family” tree Brian Williams, Fall 10 45 Problem Solving as State Space Search • Problem Formulation (Modeling) – Problem solving as state space search • Formal Representation – Graphs and search trees • Reasoning Algorithms – Depth and breadth-first search Brian Williams, Fall 10 46 23 Classes of Search Blind Depth-First Systematic exploration of whole tree (uninformed) Breadth-First until the goal is found. Iterative-Deepening Optimal A* Use path “length” measure. Find (informed) Branch&Bound “shortest” path. Heuristic Hill-Climbing Use heuristic measure of goodness (informed) Best-First of a node. Beam Brian Williams, Fall 10 47 Depth First Search (DFS) Local Rule: After visiting node… • Visit its children before its siblings • Visit its children left to right 1 S 2 A 3 4 C 6 D 5 G 7 B 11 8 C D 9 C Brian Williams, Fall 10 G G 10 48 24 Breadth First Search (BFS) Local Rule: After visiting node… • Visit its siblings, before its children • Visit its children left to right 1 S 2 A 4 8 C 5 D 9 G 3 B 7 6 C D 10 C G G 11 Brian Williams, Fall 10 49 Elements of Algorithm Design Algorithm Description: (Today) – stylized pseudo code, sufficient to analyze and implement the algorithm (implementation next Wednesday). Algorithm Analysis: (Wednesday & Monday) • Time complexity: – how long does it take to find a solution? • Space complexity: – how much memory does it need to perform search? • 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? Brian Williams, Fall 10 50 25 Problem Solving as State Space Search • Problem Formulation (Modeling) • Formal Representation • Reasoning Algorithms – A generic search algorithm description – Depth-first search example – Handling cycles – Breadth-first search example Brian Williams, Fall 10 51 Solve <g = <V, E>, S, G> using State Space Search Search States: • All simple paths <S, …v> in g starting at S Initial State: • <S> Operator: • Extend a path <S, … v> to <S, … v, u> for each <v, u> in E – call u a child of v Goal: • A simple path <S, …, G> in g Brian Williams, Fall 10 52 26 Solve <g = <V, E>, S, G> using State Space Search How do we maintain the search state? • An ordering on partial paths yet to be expanded (called a queue Q). How do we perform search? • Repeatedly: 1. Select next partial path from Q. 2. Expand it. 3. Add expansions to Q. C • Terminate when goal G is found. S A D B C D G C G G Brian Williams, Fall 10 53 Simple Search Algorithm: Preliminaries • A partial path from S to D is listed in reverse order, • e.g., <D, A, S> • The head of a partial path is its most recent visited node, • e.g., D. S A • The Q is a list of partial paths, • e.g. (<D, A, S>, <C, A, S> …>. D C Brian Williams, Fall 10 B C G D C G G 54 27 Simple Search Algorithm Let Q be a list of partial paths, S be the Start node and G be the Goal node. 1. Initialize Q with partial path <S> 2. If Q is empty, fail. Else, pick a partial path N from Q 3. If head(N) = G, return N (goal reached!) 4. Else: a) Remove N from Q b) Find all children of head(N) and create a one-step extension of N to each child c) Add all extended paths to Q d) Go to step 2 Brian Williams, Fall 10 55 Problem Solving as State Space Search • Problem Formulation (Modeling) • Formal Representation • Reasoning Algorithms – A generic search algorithm description – Depth-first search example – Handling cycles – Breadth-first search example Brian Williams, Fall 10 56 28 Depth First Search (DFS) Idea: After visiting node • Visit its children left to right (or top to bottom) • Visit its children before its siblings 1 S 2 A 3 4 C 6 D 5 7 B 11 8 C G D 9 C G G 10 Assume we remove the first element of Q, Where to Q do we add the path extensions? Brian Williams, Fall 10 57 Simple Search Algorithm Let Q be a list of partial paths, S be the start node and G be the Goal node. 1. Initialize Q with partial path <S> 2. If Q is empty, fail. Else, pick a partial path N from Q 3. If head(N) = G, return N (goal reached!) 4. Else: a) Remove N from Q b) Find all children of head(N) and create a one-step extension of N to each child c) Add all extended paths to Q d) Go to step 2 Brian Williams, Fall 10 58 29 Depth-First Pick first element of Q; Add path extensions to front of Q C Q 1 (S) G A 2 D 1 3 S 4 B 5 Brian Williams, Fall 10 59 Simple Search Algorithm Let Q be a list of partial paths, S be the Start node and G be the Goal node. 1. Initialize Q with partial path <S> 2. If Q is empty, fail. Else, pick a partial path N from Q 3. If head(N) = G, return N (goal reached!) 4. Else: a) Remove N from Q b) Find all children of head(N) and create a one-step extension of N to each child c) Add all extended paths to Q d) Go to step 2 Brian Williams, Fall 10 60 30 Depth-First Pick first element of Q; Add path extensions to front of Q C Q 1 (S) G A 2 D 1 3 S 4 B 5 Brian Williams, Fall 10 61 Depth-First Pick first element of Q; Add path extensions to front of Q C Q 1 (S) 2 (A S) G A D 1 3 S 4 B 5 Added paths in blue Brian Williams, Fall 10 62 31 Depth-First Pick first element of Q; Add path extensions to front of Q C Q 1 (S) 2 (A S) (B S) G A D 1 3 S 4 B 5 Added paths in blue Brian Williams, Fall 10 63 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> 2. If Q is empty, fail. Else, pick a partial path N from Q 3. If head(N) = G, return N (goal reached!) 4. Else: a) Remove N from Q b) Find all children of head(N) and create a one-step extension of N to each child c) Add all extended paths to Q d) Go to step 2 Brian Williams, Fall 10 64 32 Depth-First Pick first element of Q; Add path extensions to front of Q C Q 1 (S) 2 (A S) (B S) 2 G A D 1 3 S 4 B 5 Added paths in blue Brian Williams, Fall 10 65 Depth-First Pick first element of Q; Add path extensions to front of Q C Q 1 (S) 2 (A S) (B S) 3 (C A S) (D A S) (B S) 2 G A D 1 S 4 B 5 Added paths in blue Brian Williams, Fall 10 66 33 Depth-First Pick first element of Q; Add path extensions to front of Q 3 C Q 1 (S) 2 (A S) (B S) 3 (C A S) (D A S) (B S) 2 G A D 1 S 4 B 5 Added paths in blue Brian Williams, Fall 10 67 Depth-First Pick first element of Q; Add path extensions to front of Q 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) 2 G A D 1 S B 5 Added paths in blue Brian Williams, Fall 10 68 34 Depth-First Pick first element of Q; Add path extensions to front of Q 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) 2 G A 4 D 1 S B 5 Added paths in blue Brian Williams, Fall 10 69 Depth-First Pick first element of Q; Add path extensions to front of Q 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) 2 G A 4 D 1 S B Brian Williams, Fall 10 70 35 Depth-First Pick first element of Q; Add path extensions to front of Q 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) 2 G A 4 D 1 S B Brian Williams, Fall 10 71 Depth-First Pick first element of Q; Add path extensions to front of Q 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 (G D A S)(B S) 2 G A 4 D 1 S B Brian Williams, Fall 10 72 36 Depth-First Pick first element of Q; Add path extensions to front of Q 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 (G D A S)(B S) 2 G A 4 D 1 S B Brian Williams, Fall 10 73 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> 2. If Q is empty, fail. Else, pick a partial path N from Q 3. If head(N) = G, return N (goal reached!) 4. Else: a) Remove N from Q b) Find all children of head(N) and create a one-step extension of N to each child c) Add all extended paths to Q d) Go to step 2 Brian Williams, Fall 10 74 37 Problem Solving as State Space Search • Problem Formulation (Modeling) • Formal Representation • Reasoning Algorithms – A generic search algorithm description – Depth-first search example – Handling cycles – Breadth-first search example Brian Williams, Fall 10 75 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 10 76 38 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 (G D A S)(B S) 2 G A 4 D 1 S B • C visited multiple times • Multiple paths to C, D & G How much wasted effort can be incurred in the worst case? Brian Williams, Fall 10 77 How Do We Avoid Repeat Visits? Idea: • Keep track of nodes already visited. • Do not place expanded path on Q if head is a visited node. 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 this always improve efficiency? • Visits only a subset of the original paths, such that each node appears at most once at the head of a visited path. Brian Williams, Fall 10 78 39 How Do We Modify The 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 (goal reached!) 4. Else a) Remove N from Q b) Find all children of head(N) and create a one-step extension of N to each child c) Add to Q all the extended paths d) Go to step 2 Brian Williams, Fall 10 79 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 (goal reached!) 4. Else a) Remove N from Q b) Find all children of head(N) not in Visited and create a one-step extension of N to each child c) Add to Q all the extended paths d) Add children of head(N) to Visited e) Go to step 2 Brian Williams, Fall 10 80 40 Testing for the Goal • This algorithm stops (in step 3) when head(N) = G. • We could have performed this test in step 6 as each extended path is added to Q. This would catch termination earlier and be perfectly correct for all the searches we have covered so far. • However, performing the test in step 6 will be incorrect for the optimal search algorithms that we look at later. We have chosen to leave the test in step 3 to maintain uniformity with these future searches. Brian Williams, Fall 10 81 Problem Solving as State Space Search • Problem Formulation (modeling) • Formal Representation • Reasoning Algorithms – A generic search algorithm description – Depth-first search example – Handling cycles – Breadth-first search example Brian Williams, Fall 10 82 41 Breadth First Search (BFS) Idea: After visiting node • Visit its children left to right • Visit its siblings, before its children 1 S 2 A 4 8 C 5 D 9 3 B 7 6 C D 10 G C G 11 G Assume we remove the first element of Q, Where to Q do we add the path extensions? Brian Williams, Fall 10 83 Breadth-First with Visited List Pick first element of Q; Add path extensions to end of Q 1 Q Visited (S) S C 2 G A 3 D 1 S 4 B 5 6 Brian Williams, Fall 10 84 42 Breadth-First with Visited List Pick first element of Q; Add path extensions to end of Q 1 Q Visited (S) S C 2 G A 3 D 1 S 4 B 5 6 Brian Williams, Fall 10 85 Breadth-First with Visited List Pick first element of Q; Add path extensions to end of Q Q Visited 1 (S) S 2 (A S) (B S) A,B,S 3 C G A D 1 S 4 B 5 6 Brian Williams, Fall 10 86 43 Breadth-First with Visited List Pick first element of Q; Add path extensions to end of Q Q Visited 1 (S) S 2 (A S) (B S) A,B,S 3 C 2 G A D 1 S 4 B 5 6 Brian Williams, Fall 10 87 Breadth-First with Visited List Pick first element of Q; Add path extensions to end of Q Q Visited 1 (S) S 2 (A S) (B S) A,B,S 3 (B S) (C A S) (D A S) C,D,B,A,S C 2 G A D 1 S 4 B 5 6 Brian Williams, Fall 10 88 44 Breadth-First with Visited List Pick first element of Q; Add path extensions to end of Q Q Visited 1 (S) S 2 (A S) (B S) A,B,S 3 (B S) (C A S) (D A S) C,D,B,A,S C 2 G A D 1 S 4 B 5 3 6 Brian Williams, Fall 10 89 Breadth-First with Visited List Pick first element of Q; Add path extensions to end of Q Q Visited 1 (S) S 2 (A S) (B S) A,B,S 3 (B S) (C A S) (D A S) C,D,B,A,S 4 (C A S) (D A S) (G B S)* G,C,D,B,A,S C 2 G A D 1 S B 5 3 6 * We could stop here, when the first path to the goal is generated. Brian Williams, Fall 10 90 45 Breadth-First with Visited List Pick first element of Q; Add path extensions to end of Q Q Visited 1 (S) S 2 (A S) (B S) A,B,S 3 (B S) (C A S) (D A S) C,D,B,A,S 4 (C A S) (D A S) (G B S)* 4 C 2 G A D 1 S G,C,D,B,A,S B 5 3 6 * We could stop here, when the first path to the goal is generated. Brian Williams, Fall 10 91 Breadth-First with Visited List Pick first element of Q; Add path extensions to end of Q Q Visited 1 (S) S 2 (A S) (B S) A,B,S 3 (B S) (C A S) (D A S) C,D,B,A,S 4 (C A S) (D A S) (G B S)* G,C,D,B,A,S 5 (D A S) (G B S) G,C,D,B,A,S 4 C 2 G A 5 D 1 S B 3 6 Brian Williams, Fall 10 92 46 Breadth-First with Visited List Pick first element of Q; Add path extensions to end of Q Q Visited 1 (S) S 2 (A S) (B S) A,B,S 3 (B S) (C A S) (D A S) C,D,B,A,S 4 (C A S) (D A S) (G B S)* G,C,D,B,A,S 5 (D A S) (G B S) G,C,D,B,A,S 6 (G B S) G,C,D,B,A,S 4 C 6 G 2 A 5 D 1 S B 3 Brian Williams, Fall 10 93 Breadth-First with Visited List Pick first element of Q; Add path extensions to end of Q Q Visited 1 (S) S 2 (A S) (B S) A,B,S 3 (B S) (C A S) (D A S) C,D,B,A,S 4 (C A S) (D A S) (G B S)* G,C,D,B,A,S 5 (D A S) (G B S) G,C,D,B,A,S 6 (G B S) G,C,D,B,A,S Brian Williams, Fall 10 4 C 6 G 2 A 5 D 1 S B 3 94 47 Depth-first with Visited List Pick first element of Q; Add path extensions to front of Q 3 C Q Visited 1 (S) S 2 (A S) (B S) A, B, S 3 (C A S) (D A S) (B S) C,D,B,A,S 4 (D A S) (B S) C,D,B,A,S 5 (G D A S) (B S) G,C,D,B,A,S 5 2 G A 4 D 1 S B Brian Williams, Fall 10 95 For each search type, where do we place the children on the queue? Depth First Search (DFS) S A D Depth-first: B C D G Add path extensions to front of Q Pick first element of Q C G C G Breadth First Search (BFS) S A D Breadth-first: B C D G Add path extensions to back of Q Pick first element of Q C G C G Brian Williams, Fall 10 96 48 What You Should Know • Most problem solving tasks may be formulated as state space search. • State space search is formalized using graphs, simple paths, search trees, and pseudo code. • Depth-first and breadth-first search are framed, among others, as instances of a generic search strategy. • Cycle detection is required to achieve efficiency and completeness. Brian Williams, Fall 10 97 Appendix Brian Williams, Fall 10 98 49 Breadth-First (without Visited list) Pick first element of Q; Add path extensions to end of Q Q 1 (S) C 2 G A 3 D 1 4 S 5 B 6 7 Brian Williams, Fall 10 99 Breadth-First (without Visited list) Pick first element of Q; Add path extensions to end of Q Q 1 (S) 2 (A S) (B S) C 2 G A 3 D 1 4 S 5 B 6 7 Added paths in blue Brian Williams, Fall 10 100 50 Breadth-First (without Visited list) Pick first element of Q; Add path extensions to end of Q Q 1 (S) 2 (A S) (B S) 3 (B S) (C A S) (D A S) C 2 G A D 1 4 S 5 B 3 6 7 Added paths in blue Brian Williams, Fall 10 101 Breadth-First (without Visited list) Pick first element of Q; Add path extensions to end of Q Q 1 (S) 2 (A S) (B S) 3 (B S) (C A S) (D A S) 4 (C A S) (D A S) (D B S) (G B S)* 4 C 2 G A D 1 S 5 B 3 6 7 Added paths in blue Revisited nodes in pink * We could have stopped here, when the first path to the goal was generated. Brian Williams, Fall 10 102 51 Breadth-First (without Visited list) Pick first element of Q; Add path extensions to end of Q Q 4 1 (S) 2 (A S) (B S) 3 (B S) (C A S) (D A S) 4 (C A S) (D A S) (D B S) (G B S)* 5 (D A S) (D B S) (G B S) C 2 G A 5 D 1 S B 3 6 7 Brian Williams, Fall 10 103 Breadth-First (without Visited list) Pick first element of Q; Add path extensions to end of Q Q 4 1 (S) 2 (A S) (B S) 3 (B S) (C A S) (D A S) 4 (C A S) (D A S) (D B S) (G B S)* 5 (D A S) (D B S) (G B S) 6 (D B S) (G B S) (C D A S) (G D A S) C 2 A G 6 5 D 1 S B 3 7 Brian Williams, Fall 10 104 52 Breadth-First (without Visited list) Pick first element of Q; Add path extensions to end of Q Q 4 1 (S) 2 (A S) (B S) 3 (B S) (C A S) (D A S) 4 (C A S) (D A S) (D B S) (G B S)* 5 (D A S) (D B S) (G B S) 6 (D B S) (G B S) (C D A S) (G D A S) 7 (G B S) (C D A S) (G D A S)(C D B S)(G D B S) C 7 G 2 A 6 5 D 1 S B Brian Williams, Fall 10 3 105 53 MIT OpenCourseWare http://ocw.mit.edu 16.410 / 16.413 Principles of Autonomy and Decision Making Fall 2010 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.