Shortest Path and Informed Search Assignment
Total Page:16
File Type:pdf, Size:1020Kb
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 = <V, E> 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 • Beam search • Hill climbing • 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 tree 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, x, u, v> •sĺp u = <s, x, u> •sĺp x = <s, x> •xĺp v = <x, u, v> •xĺ p v = <x, u> Brian Williams, Spring 03 10 •uĺp v = <u, 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). • <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.