Shortest Path and Informed Search

Brian C. Williams 16.410 - 13 October 27th, 2003

Slides adapted from: 6.034 Tomas Lozano Perez, Winston, and Russell and Norvig AIMA Brian Williams, Spring 03 1

Assignment

• Reading: – Shortest path: Cormen Leiserson & Rivest, “Introduction to Algorithms” Ch. 25.1-.2 – Informed search and exploration: AIMA Ch. 4.1-2 • Homework: – Online problem set #6 due Monday November 3rd.

Brian Williams, Spring 03 2 How do we maneuver?

Brian Williams, Spring 03 3

Images taken from NASA's website: http://www.nasa.gov/.

Roadmaps are an effective state space abstraction

Brian Williams, Spring 03 4 Courtesy of U.S. Geological survey. Weighted Graphs and Path Lengths u v 1 10 9 s 2 3 4 6 7 5 2 x y Graph G = Weight function w: E ĺƒ Path p = < vo, v1, … vk > w Path weight (p) = Ȉ w(vi-1,vi) Shortest path weight į(u,v) = min {w(p) : u ĺp v } else ’

Brian Williams, Spring 03 5

Outline • Creating road maps for path planning • Exploring roadmaps: Shortest Paths – Single Source • Dijkstra;s algorithm – Informed search • Uniform cost search • Greedy search • A* search • • Avoiding adversaries – (Next Lecture)

Brian Williams, Spring 03 6 Single Source Shortest Path u v 1 10 9 s 2 3 4 6 7 5 2 x y

Problem: Compute shortest path to all vertices from source s

Brian Williams, Spring 03 7

Single Source Shortest Path u v 1 10 89 9 s 0 2 3 4 6 7 5 572 x y

Problem: Compute shortest path to all vertices from source s • estimate d[v] estimated shortest path length from s to v

Brian Williams, Spring 03 8 Single Source Shortest Path u v 1 10 89 9 s 0 2 3 4 6 7 5 572 x y

Problem: Compute shortest path to all vertices from source s • estimate d[v] estimated shortest path length from s to v • predecessor ʌ[v] final edge of shortest path to v • induces shortest path

Brian Williams, Spring 03 9

Properties of Shortest Path u v 1 10 89 9 s 0 2 3 4 6 7 5 572 x y • Subpaths of shortest paths are shortest paths. •sĺp v = •sĺp u = •sĺp x = •xĺp v =

•xĺ p v = Brian Williams, Spring 03 10 •uĺp v = Properties of Shortest Path u v 1 10 89 9 s 0 2 3 4 6 7 5 572 x y

Corollary: Shortest paths are grown from shortest paths. • The length of shortest path s ĺp u ĺ v is į(s,v) = į(s,u) + w(u,v). •   E į(s,v) ”į(s,u) + w(u,v) Brian Williams, Spring 03 11

Idea: Start With Upper Bound u v 1 10 ’’ 9 s 0 2 3 4 6 7 5 ’’2 x y Initialize-Single-Source(G, s) 1. for each vertex v  V[G] 2. do d[u] ĸ ’ 3. ʌ[v] ĸ NIL O(v) 4. d[s] ĸ 0

Brian Williams, Spring 03 12 Relax Bounds to Shortest Path

u v u v 22 5 9 5 6 Relax(u, v) Relax(u, v) u v u v 22 57 56

Relax (u, v, w) 1. if d[u] + w(u,v) < d[v] 2. do d[v] ĸ d[u] + w(u,v) 3. ʌ[v] ĸ u

Brian Williams, Spring 03 13

Properties of Relaxing Bounds

u v u v 22 5 9 5 6 Relax(u, v) Relax(u, v) u v u v 22 59 56 After calling Relax(u, v, w) • d[u] + w(u,v) • d[v] d remains a shortest path upperbound after repeated calls to Relax. Once d[v] is the shortest path its value persists

Brian Williams, Spring 03 14 Dijkstra’s Algorithm Assume all edges are non-negative. Idea: Greedily relax out arcs of minimum cost nodes u v 1 10 ’’ 9 s 0 2 3 4 6 7 5 ’’2 x y

Q = {s,u,v,x,y} Vertices to relax S = {} Vertices with shortest path value

Brian Williams, Spring 03 15

Dijkstra’s Algorithm Assume all edges are non-negative. Idea: Greedily relax out arcs of minimum cost nodes u v 1 10 ’’ 9 s 0 2 3 4 6 7 5 ’’2 x y

Q = {x,y,u,v} Vertices to relax S = {s} Vertices with shortest path value

Brian Williams, Spring 03 16 Dijkstra’s Algorithm Assume all edges are non-negative. Idea: Greedily relax out arcs of minimum cost nodes u v 1 10 10 ’ 9 s 0 2 3 4 6 7 5 ’’2 x y

Q = {x,y,u,v} Vertices to relax S = {s} Vertices with shortest path value Shortest path edge Ȇ[v] = arrows

Brian Williams, Spring 03 17

Dijkstra’s Algorithm Assume all edges are non-negative. Idea: Greedily relax out arcs of minimum cost nodes u v 1 10 10 ’ 9 s 0 2 3 4 6 7 5 5 2 ’ x y

Q = {x,y,u,v} Vertices to relax S = {s} Vertices with shortest path value Shortest path edge Ȇ[v] = arrows

Brian Williams, Spring 03 18 Dijkstra’s Algorithm Assume all edges are non-negative. Idea: Greedily relax out arcs of minimum cost nodes u v 1 10 10 ’ 9 s 0 2 3 4 6 7 5 5 2 ’ x y

Q = {x,y,u,v} Vertices to relax S = {s} Vertices with shortest path value Shortest path edge Ȇ[v] = arrows

Brian Williams, Spring 03 19

Dijkstra’s Algorithm Assume all edges are non-negative. Idea: Greedily relax out arcs of minimum cost nodes u v 1 10 8 14 9 s 0 2 3 4 6 7 5 5 2 7 x y

Q = {y,u,v} Vertices to relax S = {s, x} Vertices with shortest path value Shortest path edge Ȇ[v] = arrows

Brian Williams, Spring 03 20 Dijkstra’s Algorithm Assume all edges are non-negative. Idea: Greedily relax out arcs of minimum cost nodes u v 1 10 8 14 9 s 0 2 3 4 6 7 5 572 x y

Q = {y,u,v} Vertices to relax S = {s, x} Vertices with shortest path value Shortest path edge Ȇ[v] = arrows

Brian Williams, Spring 03 21

Dijkstra’s Algorithm Assume all edges are non-negative. Idea: Greedily relax out arcs of minimum cost nodes u v 1 10 8 13 9 s 0 2 3 4 6 7 5 572 x y

Q = {u,v} Vertices to relax S = {s, x, y} Vertices with shortest path value Shortest path edge Ȇ[v] = arrows

Brian Williams, Spring 03 22 Dijkstra’s Algorithm Assume all edges are non-negative. Idea: Greedily relax out arcs of minimum cost nodes u v 1 10 89 9 s 0 2 3 4 6 7 5 572 x y

Q = {v} Vertices to relax S = {s, x, y, u} Vertices with shortest path value Shortest path edge Ȇ[v] = arrows

Brian Williams, Spring 03 23

Dijkstra’s Algorithm Assume all edges are non-negative. Idea: Greedily relax out arcs of minimum cost nodes u v 1 10 89 9 s 0 2 3 4 6 7 5 572 x y

Q = {} Vertices to relax S = {s, x, y, u, v} Vertices with shortest path value Shortest path edge Ȇ[v] = arrows

Brian Williams, Spring 03 24 Dijkstra’s Algorithm

Repeatedly select minimum cost node and relax out arcs DIJKSTRA(G,w,s) 1. Initialize-Single-Source(G, s) O(V) 2. S ĸ‡ 3. Q ĸ V[G] 4. while Q  ‡ O(V) or O(lg V) 5. do u ĸ Extract-Min(Q) w fib heap 6. S ĸ S ‰ {u} 7. for each vertex v  Adj[u] * O(V) 8. do Relax(u, v, w) O(E) = O(V2+E) Brian Williams, Spring 03 = O(VlgV+E)25

Outline • Creating road maps for path planning • Exploring roadmaps: Shortest Paths – Single Source • Dijkstra;s algorithm – Informed search • Uniform cost search • Greedy search • A* search • Beam search • Hill climbing • Avoiding adversaries – (Next Lecture)

Brian Williams, Spring 03 26 Informed Search Extend search tree nodes to include path length g C 0 g = 8 S 2 3 G A 2 B 5 A 2 24 D 6 D C 4 6 D G 10 S 5 1 5 9 CG8 9 CG8 B

Problem: Find the path to the goal G with the shortest path length g.

Brian Williams, Spring 03 27

Classes of Search

Blind Depth-First Systematic exploration of whole tree (uninformed) Breadth-First until the goal is found. Iterative-Deepening

Best-first Uniform-cost Using path “length” as a measure, (informed) Greedy finds “shortest” path. A*

Brian Williams, Spring 03 28 Uniform cost search spreads evenly from start

xx

A B goal start

Does uniform cost search find the shortest path?

Brian Williams, Spring 03 29

Uniform Cost edge cost path length C 0 2 S 3 G A 2 24 D S 5 1 5 B

Enumerates partial paths in order of increasing path length g.

May expand vertex more than once.

Brian Williams, Spring 03 30 Uniform Cost edge cost path length C 0 2 S 3 G A 2 A 2 B 5 24 D S 5 1 5 B

Enumerates partial paths in order of increasing path length g.

May expand vertex more than once.

Brian Williams, Spring 03 31

Uniform Cost edge cost path length C 0 2 S 3 G A 2 A 2 B 5 24 D 6 DC4 S 5 1 5 B

Enumerates partial paths in order of increasing path length g.

May expand vertex more than once.

Brian Williams, Spring 03 32 Uniform Cost edge cost path length C 0 2 S 3 G A 2 A 2 B 5 24 D 6 DC4 S 5 1 5 B

Enumerates partial paths in order of increasing path length g.

May expand vertex more than once.

Brian Williams, Spring 03 33

Uniform Cost edge cost path length C 0 2 S 3 G A 2 A 2 B 5 24 D 6 D C 46D G 10 S 5 1 5 B

Enumerates partial paths in order of increasing path length g.

May expand vertex more than once.

Brian Williams, Spring 03 34 Uniform Cost edge cost path length C 0 2 S 3 G A 2 A 2 B 5 24 D 6 D C 4 6 D G 10 S 5 1 5 9 C G 8 B

Enumerates partial paths in order of increasing path length g.

May expand vertex more than once.

Brian Williams, Spring 03 35

Uniform Cost edge cost path length C 0 2 S 3 G A 2 A 2 B 5 24 D 6 D C 4 6 D G 10 S 5 1 5 9 CG8 9 CG8 B

Expands nodes already visited Enumerates partial paths in order of increasing path length g.

May expand vertex more than once.

Brian Williams, Spring 03 36 Uniform Cost edge cost path length C 0 2 S 3 G A 2 A 2 B 5 24 D 6 D C 4 6 D G 10 S 5 1 5 9 CG8 9 C G 8 B

Expands nodes already visited Enumerates partial paths in order of increasing path length g.

May expand vertex more than once.

Brian Williams, Spring 03 37

Uniform Cost edge cost path length C 0 2 S 3 G A 2 A 2 B 5 24 D 6 D C 4 6 D G 10 S 5 1 5 9 CG8 9 CG8 B

Expands nodes already visited Enumerates partial paths in order of increasing path length g.

May expand vertex more than once.

Brian Williams, Spring 03 38 Why Expand a Vertex More Than Once?

edge cost path length 0 S A 1 A 2 D 4 2 1 D G S 4

• The shortest path from S to G is (G D A S). • D is reached first using path (D S). Suppose we expanded only the first path to visit each vertex X?

Brian Williams, Spring 03 39

Why Expand a Vertex More Than Once?

edge cost path length 0 S A 1 A 2 D 5 2 1 D G S 4 3 D • The shortest path from S to G is (G D A S). • D is reached first using path (D S). • This prevents path (D A S) Suppose we expanded only the from being expanded. first path to visit each vertex X?

Brian Williams, Spring 03 40 Why Expand a Vertex More Than Once?

edge cost path length 0 S A 1 A 2 D 5 2 1 D G S 4 3 D G 10 • The shortest path from S to G is (G D A S). • D is reached first using path (D S). • This prevents path (D A S) Suppose we expanded only the from being expanded. first path to visit each vertex X?

Brian Williams, Spring 03 41

Why Expand a Vertex More Than Once?

edge cost path length 0 S A 1 A 2 D 5 2 1 D G S 4 3 DG10 • The shortest path from S to G is (G D A S). • D is reached first using path (D S). • This prevents path (D A S) Suppose we expanded only the from being expanded. first path to visit each vertex X? • The suboptimal path (G D S) is returned. Brian Williams, Spring 03 42 Uniform Cost Let Q be a list of partial paths, Let S be the start node and Let G be the Goal node. Let g be the path length from S to N. 1. Initialize Q with partial path (S) as only entry; set Visited = ( ) 2. If Q is empty, fail. Else, pick partial path N from Q with best g 3. If head(N) = G, return N (we’ve reached the goal!) 4. (Otherwise) Remove N from Q 5. Find all children of head(N) not in Visited and create all the one-step extensions of N to each child. 6. Add to Q all the extended paths; 7. Add children of head(N) to Visited

8. Go to step 2. Brian Williams, Spring 03 43

Implementing the Search Strategies Depth-first: Pick first element of Q Uses visited list Add path extensions to front of Q Breadth-first: Pick first element of Q Uses visited list Add path extensions to end of Q Uniform-cost: Pick first element of Q No visited list Add path extensions to Q in order of increasing path length g.

Brian Williams, Spring 03 44 Uniform Cost using BFS Pick first element of Q; Insert path extensions, sorted by g.

Q C 2 1 (0 S) 3 G A 2 2 (2 A S) (5 B S) 1 2 4 3 D S 5 4 1 5 B 5 6

7

Here we: • Insert on queue in order of g. • Remove first element of queue. Brian Williams, Spring 03 45

Uniform Cost using BFS Pick first element of Q; Insert path extensions, sorted by g.

Q C 2 2 1 (0 S) 3 G A 2 2 (2 A S) (5 B S) 1 2 4 3 (4 C A S) (5 B S) (6 D A S) D S 5 4 1 5 B 5 6

7

Here we: • Insert on queue in order of g. • Remove first element of queue. Brian Williams, Spring 03 46 Uniform Cost using BFS Pick first element of Q; Insert path extensions, sorted by g. 3 Q C 2 2 1 (0 S) 3 G A 2 2 (2 A S) (5 B S) 1 2 4 3 (4 C A S) (5 B S) (6 D A S) D S 5 4 (5 B S) (6 D A S) 1 5 B 5 6

7

Here we: • Insert on queue in order of g. • Remove first element of queue. Brian Williams, Spring 03 47

Uniform Cost using BFS Pick first element of Q; Insert path extensions, sorted by g. 3 Q C 7 2 2 1 (0 S) 3 G A 2 2 (2 A S) (5 B S) 5,6 1 24 3 (4 C A S) (5 B S) (6 D A S) D S 5 4 (5 B S) (6 D A S) 1 5 B 5 (6 D B S) (6 D A S) (10 G B S) 4 6 (6 D A S) (8 G D B S) (9 C D B S) (10 G B S) (8 G D A S) (8 G D B S) (9 C D A S) (9 C D B S) 7 (10 G B S)

Brian Williams, Spring 03 48 Can we stop as soon as the goal is enqueued? Q 1 (0 S) 2 (2 A S) (5 B S) 3 (4 C A S) (5 B S) (6 D A S) 4 (5 B S) (6 D A S) 5 (6 D B S) (6 D A S) (10 G B S) 6 (6 D A S)(8 G D B S) (9 C D B S) (10 G B S) (8 G D A S) (8 G D B S) (9 C D A S) (9 C D B S) 7 (10 G B S) • Other paths to the goal that are shorter may not yet be enqueued. • Only when a path is pulled off the Q are we guaranteed that no shorter path will be added. • This assumes all edges are positive.

Brian Williams, Spring 03 49

Implementing the Search Strategies Depth-first: Pick first element of Q Uses visited list Add path extensions to front of Q Breadth-first: Pick first element of Q Uses visited list Add path extensions to end of Q Uniform-cost: Pick first element of Q No visited list Add path extensions to Q in increasing order of path length g. Best-first: (generalizes uniform-cost) Pick first element of Q No visited list Add path extensions in increasing order of any cost function f Brian Williams, Spring 03 50 Best-first Search Algorithm Let Q be a list of partial paths, Let S be the start node and Let G be the Goal node. Let f be a cost function on N. 1. Initialize Q with partial path (S) as only entry 2. If Q is empty, fail. Else, pick partial path N from Q with best f 3. If head(N) = G, return N (we’ve reached the goal!) 4. (Otherwise) Remove N from Q 5. Find all children of head(N) and create all the one-step extensions of N to each child. 6. Add to Q all the extended paths; 7. Go to step 2.

Brian Williams, Spring 03 51

Classes of Search

Blind Depth-First Systematic exploration of whole tree (uninformed) Breadth-First until the goal is found. Iterative-Deepening

Best-first Uniform-cost Using path “length” as a measure, Greedy finds “shortest” path. A*

Brian Williams, Spring 03 52 Chicago, Il Uniform cost search spreads evenly from start

Rapid City, ND Boston, Ma xx

A B goal

start Greedy search is directed towards the goal.

Uniform cost search explores the direction away from the goal as much as with the goal.

Brian Williams, Spring 03 53

Greedy Search

Search in an order imposed by a heuristic function, measuring cost to go.

Heuristic function h – is a function of the current node n, not the partial path s to n.

• Estimated distance to goal – h (n,G) • Example: straight-line distance in a road network.

• “Goodness” of a node – h (n) • Example: elevation • Foothills, plateaus and ridges are problematic.

Brian Williams, Spring 03 54 Greedy Pick first element of Q; Insert path extensions, sorted by h. 1 C Q 0 2 G A 1 (10 S) 4 10 2 D S 3 1 3 B 4 5

Heuristic values in red Added paths in blue; heuristic value of head is in front. Order of nodes in blue.

Brian Williams, Spring 03 55

Greedy Pick first element of Q; Insert path extensions, sorted by h. 1 C Q 0 2 G A 1(10 S) 4 10 2 (2 A S) (3 B S) D S 3 1 3 B 4 5

Heuristic values in red Added paths in blue; heuristic value of head is in front. Order of nodes in blue.

Brian Williams, Spring 03 56 Greedy Pick first element of Q; Insert path extensions, sorted by h. 1 C Q 0 2 2 G A 1(10 S) 4 10 2 (2 A S) (3 B S) D S 3 (1 C A S) (3 B S) (4 D A S) 1 3 B 4 5

Heuristic values in red Added paths in blue; heuristic value of head is in front. Order of nodes in blue.

Brian Williams, Spring 03 57

Greedy Pick first element of Q; Insert path extensions, sorted by h. 3 1 C Q 0 2 2 G A 1(10 S) 4 10 2 (2 A S) (3 B S) D S 3 (1 C A S) (3 B S) (4 D A S) 1 3 B 4(3 B S) (4 D A S) 5

Heuristic values in red Added paths in blue; heuristic value of head is in front. Order of nodes in blue.

Brian Williams, Spring 03 58 Greedy Pick first element of Q; Insert path extensions, sorted by h. 3 1 C Q 0 2 2 G A 1(10 S) 4 10 2 (2 A S) (3 B S) D S 3 (1 C A S) (3 B S) (4 D A S) 1 3 B 4(3 B S) (4 D A S) 4 5 (0 G B S) (4 D A S) (4 D B S)

Heuristic values in red Added paths in blue; heuristic value of head is in front. Order of nodes in blue.

Brian Williams, Spring 03 59

Greedy Pick first element of Q; Insert path extensions, sorted by h. 1 C 2 0 Q 2 3 G A 2 1 (10 S) 4 10 2 4 2 (2 A S) (3 B S) D S 5 3 (1 C A S) (3 B S) (4 D A S) 3 1 5 B 4 (3 B S) (4 D A S) 5 (0 G B S) (4 D A S) ) (4 D B S)

Heuristic values in red Added paths in blue; heuristic value of head is in front. Edge cost in green. Was the shortest path produced?

Brian Williams, Spring 03 60 Classes of Search

Blind Depth-First Systematic exploration of whole tree (uninformed) Breadth-First until the goal is found. Iterative-Deepening

Best-first Uniform-cost Using path “length” as a measure, Greedy finds “shortest” path. A*

Brian Williams, Spring 03 61

Uniform cost search spreads evenly from start

xx

A B goal start

Brian Williams, Spring 03 62 Uniform cost search spreads evenly from the start

Greedy goes for the goal, but forgets its past. xx

A B goal start A* biases uniform cost towards the goal by using h A* finds an optimal solution • f = g + h if h never over estimates. • g = distance from start Then h is called “admissible” Brian Williams, Spring 03 • h = estimated distance63 to goal.

Simple Optimal Search Algorithm BFS + Admissible Heuristic Let Q be a list of partial paths, Let S be the start node and Let G be the Goal node. Let f = g + h be an admissible heuristic function 1. Initialize Q with partial path (S) as only entry; 2. If Q is empty, fail. Else, use f to pick “best” partial path N from Q 3. If head(N) = G, return N (we’ve reached the goal) 4. (Otherwise) Remove N from Q; 5. Find all the descendants of head(N) and create all the one-step extensions of N to each descendant. 6. Add to Q all the extended paths. 7. Go to step 2.

Brian Williams, Spring 03 64 In the example, is h an admissible heuristic? 1 C 2 2 3 G A 2 0 • A is ok 4 2 4 D 10 • B is ok S 5 1 • C is ok 5 3 B • D is too big, needs to be ” 2 • S is too big, can always use 0 for start Heuristic Values of h in Red Edge cost in Green A* finds an optimal solution if h never over estimates. Then h is called “admissible” Brian Williams, Spring 03 65

Admissible heuristics for 8 puzzle?

6 2 8 1 2 3 3 5 8 4 4 7 1 7 6 5 S G

What is the heuristic? • An underestimate of number of moves to the goal. Examples: 1. Number of misplaced tiles (7) 2. Sum of Manhattan distance of each tile to its goal location

(17) Brian Williams, Spring 03 66 A* Incorporates the Principle

S X shortest G

= shortest X X shortest S + G The shortest path from S through X to G = shortest path from S to X + shortest path from X to G. • Idea: when shortest from S to X is found, ignore other S to X paths. • When BFS dequeues the first partial path with head node X, this path is the shortest path from S to X. Given the first path to X, we don’t need to extend other paths to X;

delete them. Brian Williams, Spring 03 67

Simple Optimal Search Algorithm How do we add dynamic programming? Let Q be a list of partial paths, Let S be the start node and Let G be the Goal node. Let f = g + h be an admissible heuristic function 1. Initialize Q with partial path (S) as only entry; 2. If Q is empty, fail. Else, use f to pick the “best” partial path N from Q 3. If head(N) = G, return N (we’ve reached the goal) 4. (Else) Remove N from Q; 5. Find all children of head(N) and create all the one-step extensions of N to each child. 6. Add to Q all the extended paths. 7. Go to step 2.

Brian Williams, Spring 03 68 A* Optimal Search Algorithm BFS + Dyn Prog + Admissible Heuristic Let Q be a list of partial paths, Let S be the start node and Let G be the Goal node. Let f = g + h be an admissible heuristic function 1. Initialize Q with partial path (S) as only entry; set Expanded = ( ) 2. If Q is empty, fail. Else, use f to pick “best” partial path N from Q 3. If head(N) = G, return N (we’ve reached the goal) 4. (Else) Remove N from Q; 5. if head(N) is in Expanded, go to step 2, otherwise add head(N) to Expanded. 6. Find all the children of head(N) (not in Expanded) and create all the one-step extensions of N to each child. 7. Add to Q all the extended paths. 8. Go to step 2.

Brian Williams, Spring 03 69

A* (BFS + DynProg + Admissible Heuristic)

Pick first element of Q; Insert path extensions, sorted by path length + heuristic. 1 Q Expanded C 2 1 (0 S) 2 3 G A 2 0 1 1 2 4 D S 5 0 1 5 3 B

Heuristic Values of g in Red Edge cost in Green

Added paths in blue; cost f at head of each path.

Brian Williams, Spring 03 70 A* (BFS + DynProg + Admissible Heuristic)

Pick first element of Q; Insert path extensions, sorted by path length + heuristic. 1 Q Expanded C 2 1 (0 S) 2 3 G A 2 0 2 S 1 1 24D S 5 0 1 5 3 B

Heuristic Values of g in Red Edge cost in Green

Added paths in blue; cost f at head of each path

Brian Williams, Spring 03 71

A* (BFS + DynProg + Admissible Heuristic)

Pick first element of Q; Insert path extensions, sorted by path length + heuristic. 1 Q Expanded C 2 2 1 (0 S) 2 3 G A 2 0 2 (4 A S) (8 B S) S 1 1 24D 3 S A S 5 0 1 5 3 B

Heuristic Values of g in Red Edge cost in Green

Added paths in blue; cost f at head of each path

Brian Williams, Spring 03 72 A* (BFS + DynProg + Admissible Heuristic)

Pick first element of Q; Insert path extensions, sorted by path length + heuristic. 3 1 Q Expanded C 2 2 1 (0 S) 2 3 G A 2 0 2 (4 A S) (8 B S) S 1 1 24D 3 (5 C A S) (7 D A S) (8 B S) S A S 5 4 S A C 0 1 5 3 B

Heuristic Values of g in Red Edge cost in Green

Added paths in blue; cost f at head of each path

Brian Williams, Spring 03 73

A* (BFS + DynProg + Admissible Heuristic)

Pick first element of Q; Insert path extensions, sorted by path length + heuristic. 3 1 Q Expanded C 2 2 1 (0 S) 2 3 G A 2 0 2 (4 A S) (8 B S) S 1 4 1 24D 3 (5 C A S) (7 D A S) (8 B S) S A S 5 4 (7 D A S) (8 B S) S A C 0 1 5 3 B 5 S A C D

Heuristic Values of g in Red Edge cost in Green

Added paths in blue; cost f at head of each path

Brian Williams, Spring 03 74 A* (BFS + DynProg + Admissible Heuristic)

Pick first element of Q; Insert path extensions, sorted by path length + heuristic. 3 1 Q Expanded C 5 2 2 1 (0 S) 2 3 G A 2 0 2 (4 A S) (8 B S) S 1 4 1 2 4 D 3 (5 C A S) (7 D A S) (8 B S) S A S 5 4 (7 D A S) (8 B S) S A C 0 1 5 3 B 5 (8 G D A S) (8 B S) S A C D

Heuristic Values of g in Red Edge cost in Green

Added paths in blue; cost f at head of each path

Brian Williams, Spring 03 75

Cost and Performance Searching a tree with branching factor b, solution depth d, and max depth m Search Worst Worst Guaranteed to Optimal? Method Time Space find a path? Depth-First bm b*m Yes No Breadth-First bd+1 bd+1 Yes Yes for unit edge cost Best-First

Beam (beam width = k) Hill-Climbing (no backup) Hill-Climbing (backup)

Worst case time is proportional to number of nodes visited Worst case space is proportional to maximal length of Q Brian Williams, Spring 03 76 Cost and Performance Searching a tree with branching factor b, solution depth d, and max depth m Search Worst Worst Guaranteed to Optimal? Method Time Space find a path? Depth-First bm b*m Yes No Breadth-First bd+1 bd+1 Yes Yes for unit edge cost Best-First bd+1 bd+1 Beam (beam width = k) Hill-Climbing (no backup) Hill-Climbing (backup)

Worst case time is proportional to number of nodes visited Worst case space is proportional to maximal length of Q Brian Williams, Spring 03 77

Cost and Performance Searching a tree with branching factor b, solution depth d, and max depth m Search Worst Worst Guaranteed to Optimal? Method Time Space find a path? Depth-First bm b*m Yes No Breadth-First bd+1 bd+1 Yes Yes for unit edge cost

Best-First d+1 d+1 Yes if uniform cost or b b Yes A* w admissible heuristic. Beam (beam width = k) Hill-Climbing (no backup) Hill-Climbing (backup)

Worst case time is proportional to number of nodes visited Worst case space is proportional to maximal length of Q Brian Williams, Spring 03 78 Classes of Search

Blind Depth-First Systematic exploration of whole tree (uninformed) Breadth-First until the goal is found. Iterative-Deepening

Best-first Uniform-cost Uses path “length” measure. Finds Greedy “shortest” path. A*

Variants Beam Hill-Climbing (w backup) ID A*

Brian Williams, Spring 03 79

Hill-Climbing

Pick first element of Q; Replace Q with extensions (sorted by heuristic value)

C Q G 1 (10 S) A 2 (2 A S) (3 B S) D S 3 1 B 4 Heuristic Values A=2 C=1 S=10 B=3 D=4 G=0 Added paths in blue; heuristic value of head is in front.

Brian Williams, Spring 03 80 Hill-Climbing

Pick first element of Q; Replace Q with extensions (sorted by heuristic value)

C Q 2 G 1(10 S) A 2 (2 A S) (3 B S) D Removed S 3 (1 C A S) (4 D A S) 1 B 4 Heuristic Values A=2 C=1 S=10 B=3 D=4 G=0 Added paths in blue; heuristic value of head is in front.

Brian Williams, Spring 03 81

Hill-Climbing

Pick first element of Q; Replace Q with extensions (sorted by heuristic value) 3 C Q 2 G 1(10 S) A 2 (2 A S) (3 B S) D S 3 (1 C A S) (4 D A S) 1 B 4 ( ) Heuristic Values Fails to find a path! A=2 C=1 S=10 B=3 D=4 G=0 Added paths in blue; heuristic value of head is in front.

Brian Williams, Spring 03 82 Cost and Performance Searching a tree with branching factor b, solution depth d, and max depth m Search Worst Worst Guaranteed to Optimal? Method Time Space find a path? Depth-First bm b*m Yes No Breadth-First bd+1 bd+1 Yes Yes for unit edge cost

Best-First d+1 d+1 Yes if uniform cost or b b Yes A* w admissible heuristic. Beam (beam width = k) Hill-Climbing (no backup) Hill-Climbing (backup)

Worst case time is proportional to number of nodes visited Worst case space is proportional to maximal length of Q Brian Williams, Spring 03 83

Cost and Performance Searching a tree with branching factor b, solution depth d, and max depth m Search Worst Worst Guaranteed to Optimal? Method Time Space find a path? Depth-First bm b*m Yes No Breadth-First bd+1 bd+1 Yes Yes for unit edge cost

Best-First d+1 d+1 Yes if uniform cost or b b Yes A* w admissible heuristic. Beam (beam width = k) Hill-Climbing b*m (no backup) Hill-Climbing (backup)

Worst case time is proportional to number of nodes visited Worst case space is proportional to maximal length of Q Brian Williams, Spring 03 84 Cost and Performance Searching a tree with branching factor b, solution depth d, and max depth m Search Worst Worst Guaranteed to Optimal? Method Time Space find a path? Depth-First bm b*m Yes No Breadth-First bd+1 bd+1 Yes Yes for unit edge cost

Best-First d+1 d+1 Yes if uniform cost or b b Yes A* w admissible heuristic. Beam (beam width = k) Hill-Climbing b*m b (no backup) Hill-Climbing (backup)

Worst case time is proportional to number of nodes visited Worst case space is proportional to maximal length of Q Brian Williams, Spring 03 85

Cost and Performance Searching a tree with branching factor b, solution depth d, and max depth m Search Worst Worst Guaranteed to Optimal? Method Time Space find a path? Depth-First bm b*m Yes No Breadth-First bd+1 bd+1 Yes Yes for unit edge cost

Best-First d+1 d+1 Yes if uniform cost or b b Yes A* w admissible heuristic. Beam (beam width = k) Hill-Climbing b*m b No No (no backup) Hill-Climbing (backup)

Worst case time is proportional to number of nodes visited Worst case space is proportional to maximal length of Q Brian Williams, Spring 03 86 Hill-Climbing (with backup) Pick first element of Q; Add path extensions (sorted by heuristic value) to front of Q

C Q G 1 (10 S) A 2 (2 A S) (3 B S) D S 3 1 B 4 5 Heuristic Values A=2 C=1 S=10 B=3 D=4 G=0 Added paths in blue; heuristic value of head is in front.

Brian Williams, Spring 03 87

Hill-Climbing (with backup) Pick first element of Q; Add path extensions (sorted by heuristic value) to front of Q

C Q 2 G 1 (10 S) A 2 (2 A S) (3 B S) D S 3 (1 C A S) (4 D A S) (3 B S) 1 B 4 All new nodes before old 5 Heuristic Values A=2 C=1 S=10 B=3 D=4 G=0 Added paths in blue; heuristic value of head is in front.

Brian Williams, Spring 03 88 Hill-Climbing (with backup) Pick first element of Q; Add path extensions (sorted by heuristic value) to front of Q 3 C Q 2 G 1 (10 S) A 2 (2 A S) (3 B S) D S 3 (1 C A S) (4 D A S) (3 B S) 1 B 4 (4 D A S) (3 B S) 5 Heuristic Values A=2 C=1 S=10 B=3 D=4 G=0 Added paths in blue; heuristic value of head is in front.

Brian Williams, Spring 03 89

Hill-Climbing (with backup) Pick first element of Q; Add path extensions (sorted by heuristic value) to front of Q 3 C Q 2 G A 1 (10 S) 4 2 (2 A S) (3 B S) D S 3 (1 C A S) (4 D A S) (3 B S) 1 B 4 (4 D A S) (3 B S) 5 (0 G D A S) (1 C A S) (3 B S) Heuristic Values A=2 C=1 S=10 B=3 D=4 G=0 Added paths in blue; heuristic value of head is in front.

Brian Williams, Spring 03 90 Hill-Climbing (with backup) Pick first element of Q; Add path extensions (sorted by heuristic value) to front of Q 3 C 5 Q 2 G A 1 (10 S) 4 2 (2 A S) (3 B S) D S 3 (1 C A S) (4 D A S) (3 B S) 1 B 4 (4 D A S) (3 B S) 5 (0 G D A S) (1 C A S) (3 B S) Heuristic Values A=2 C=1 S=10 B=3 D=4 G=0 Added paths in blue; heuristic value of head is in front.

Brian Williams, Spring 03 91

Cost and Performance Searching a tree with branching factor b, solution depth d, and max depth m Search Worst Worst Guaranteed to Optimal? Method Time Space find a path? Depth-First bm b*m Yes No Breadth-First bd+1 bd+1 Yes Yes for unit edge cost

Best-First d+1 d+1 Yes if uniform cost or b b Yes A* w admissible heuristic. Beam (beam width = k) Hill-Climbing b*m b No No (no backup) Hill-Climbing (backup)

Worst case time is proportional to number of nodes visited Worst case space is proportional to maximal length of Q Brian Williams, Spring 03 92 Cost and Performance Searching a tree with branching factor b, solution depth d, and max depth m Search Worst Worst Guaranteed to Optimal? Method Time Space find a path? Depth-First bm b*m Yes No Breadth-First bd+1 bd+1 Yes Yes for unit edge cost

Best-First d+1 d+1 Yes if uniform cost or b b Yes A* w admissible heuristic. Beam (beam width = k) Hill-Climbing b*m b No No (no backup) Hill-Climbing bm b*m Yes No (backup)

Worst case time is proportional to number of nodes visited Worst case space is proportional to maximal length of Q Brian Williams, Spring 03 93

Classes of Search

Blind Depth-First Systematic exploration of whole tree (uninformed) Breadth-First until the goal is found. Iterative-Deepening

Best-first Uniform-cost Uses path “length” measure. Finds Greedy “shortest” path. A*

Variants Beam Hill-Climbing (w backup) ID A*

Brian Williams, Spring 03 94 Beam

Expand all Q elements; Keep the k best extensions (sorted by heuristic value)

C Q G 1 (10 S) A 2 D S 1 B

Idea: Incrementally expand the k best paths Heuristic Values A=2 C=1 S=10 B=3 D=4 G=0 Added paths in blue; heuristic value of head is in front.

Let k = 2

Brian Williams, Spring 03 95

Beam

Expand all Q elements; Keep the k best extensions (sorted by heuristic value)

C Q G 1 (10 S) A 2 (2 A S) (3 B S) D S 1 B

Idea: Incrementally expand the k best paths Heuristic Values A=2 C=1 S=10 B=3 D=4 G=0 Added paths in blue; heuristic value of head is in front.

Let k = 2

Brian Williams, Spring 03 96 Beam

Expand all Q elements; Keep the k best extensions (sorted by heuristic value)

C Q 2 G 1(10 S) A 2 (2 A S) (3 B S) D S (0 G B S) (1 C A S) 1 3 Keep 2 (4 D A S) (4 D B S) k best B

Idea: Incrementally expand the k best paths Heuristic Values A=2 C=1 S=10 B=3 D=4 G=0 Added paths in blue; heuristic value of head is in front.

Let k = 2

Brian Williams, Spring 03 97

Beam

Expand all Q elements; Keep the k best extensions (sorted by heuristic value)

C Q 3 2 G 1(10 S) A 2 (2 A S) (3 B S) D S (0 G B S) (1 C A S) 1 3 Keep 2 (4 D A S) (4 D B S) k best B

Idea: Incrementally expand the k best paths Heuristic Values A=2 C=1 S=10 B=3 D=4 G=0 Added paths in blue; heuristic value of head is in front.

Let k = 2

Brian Williams, Spring 03 98 Cost and Performance Searching a tree with branching factor b, solution depth d, and max depth m Search Worst Worst Guaranteed to Optimal? Method Time Space find a path? Depth-First bm b*m Yes No Breadth-First bd+1 bd+1 Yes Yes for unit edge cost

Best-First d+1 d+1 Yes if uniform cost or b b Yes A* w admissible heuristic. Beam (beam width = k) Hill-Climbing b*m b No No (no backup) Hill-Climbing bm b*m Yes No (backup)

Worst case time is proportional to number of nodes visited Worst case space is proportional to maximal length of Q Brian Williams, Spring 03 99

Cost and Performance Searching a tree with branching factor b, solution depth d, and max depth m Search Worst Worst Guaranteed to Optimal? Method Time Space find a path? Depth-First bm b*m Yes No Breadth-First bd+1 bd+1 Yes Yes for unit edge cost

Best-First d+1 d+1 Yes if uniform cost or b b Yes A* w admissible heuristic. Beam k*b (beam width = k) Hill-Climbing b*m b No No (no backup) Hill-Climbing bm b*m Yes No (backup)

Worst case time is proportional to number of nodes visited Worst case space is proportional to maximal length of Q Brian Williams, Spring 03 100 Cost and Performance Searching a tree with branching factor b, solution depth d, and max depth m Search Worst Worst Guaranteed to Optimal? Method Time Space find a path? Depth-First bm b*m Yes No Breadth-First bd+1 bd+1 Yes Yes for unit edge cost

Best-First d+1 d+1 Yes if uniform cost or b b Yes A* w admissible heuristic. Beam k*b*m k*b (beam width = k) Hill-Climbing b*m b No No (no backup) Hill-Climbing bm b*m Yes No (backup)

Worst case time is proportional to number of nodes visited Worst case space is proportional to maximal length of Q Brian Williams, Spring 03 101

Cost and Performance Searching a tree with branching factor b, solution depth d, and max depth m Search Worst Worst Guaranteed to Optimal? Method Time Space find a path? Depth-First bm b*m Yes No Breadth-First bd+1 bd+1 Yes Yes for unit edge cost

Best-First d+1 d+1 Yes if uniform cost or b b Yes A* w admissible heuristic. Beam k*b*m k*b No No (beam width = k) Hill-Climbing b*m b No No (no backup) Hill-Climbing bm b*m Yes No (backup)

Worst case time is proportional to number of nodes visited Worst case space is proportional to maximal length of Q Brian Williams, Spring 03 102 Outline • Creating road maps for path planning • Exploring roadmaps: Shortest Path – Single Source • Dijkstra;s algorithm – Informed search • Uniform cost search • Greedy search • A* search • Beam search • Hill climbing • Avoiding adversaries – (Next Lecture)

Brian Williams, Spring 03 103