1 A* search Outline In this topic, we will look at the A* search algorithm: –It solves the single-source shortest path problem –Restricted to physical.

Slides:



Advertisements
Similar presentations
Review: Search problem formulation
Advertisements

Problem solving with graph search
The A* Algorithm Héctor Muñoz-Avila. The Search Problem Starting from a node n find the shortest path to a goal node g ?
CS 206 Introduction to Computer Science II 04 / 01 / 2009 Instructor: Michael Eckmann.
Weighted graphs Example Consider the following graph, where nodes represent cities, and edges show if there is a direct flight between each pair of cities.
CSE 390B: Graph Algorithms Based on CSE 373 slides by Jessica Miller, Ruth Anderson 1.
Informed Search Methods How can we improve searching strategy by using intelligence? Map example: Heuristic: Expand those nodes closest in “as the crow.
CSE 326: Data Structures Lecture #19 Approaches to Graph Exploration Bart Niswonger Summer Quarter 2001.
CS 206 Introduction to Computer Science II 11 / 07 / 2008 Instructor: Michael Eckmann.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Heuristic State Space Seach Henry Kautz. Assignment.
The Shortest Path Problem. Shortest-Path Algorithms Find the “shortest” path from point A to point B “Shortest” in time, distance, cost, … Numerous.
CSCI 3160 Design and Analysis of Algorithms Tutorial 2 Chengyu Lin.
State Space Search Algorithms CSE 472 Introduction to Artificial Intelligence Autumn 2003.
Review: Search problem formulation
Artificial Intelligence
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
Shortest Path Problems Directed weighted graph. Path length is sum of weights of edges on path. The vertex at which the path begins is the source vertex.
Lecture 3 Informed Search CSE 573 Artificial Intelligence I Henry Kautz Fall 2001.
Shortest path algorithm. Introduction 4 The graphs we have seen so far have edges that are unweighted. 4 Many graph situations involve weighted edges.
CS 206 Introduction to Computer Science II 11 / 05 / 2008 Instructor: Michael Eckmann.
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
CS 206 Introduction to Computer Science II 03 / 30 / 2009 Instructor: Michael Eckmann.
HEURISTIC SEARCH. Luger: Artificial Intelligence, 5 th edition. © Pearson Education Limited, 2005 Portion of the state space for tic-tac-toe.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Algorithm design techniques
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Shortest Paths Introduction to Algorithms Shortest Paths CSE 680 Prof. Roger Crawfis.
Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada ece.uwaterloo.ca.
Graphs II Robin Burke GAM 376. Admin Skip the Lua topic.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Graph Algorithms Shortest-Path.
Jim Anderson Comp 122, Fall 2003 Single-source SPs - 1 Chapter 24: Single-Source Shortest Paths Given: A single source vertex in a weighted, directed graph.
1 Shortest Path Problem Topic 11 ITS033 – Programming & Algorithms C B A E D F Asst. Prof. Dr. Bunyarit Uyyanonvara IT Program,
Dijkstras Algorithm Named after its discoverer, Dutch computer scientist Edsger Dijkstra, is an algorithm that solves the single-source shortest path problem.
COSC 2007 Data Structures II Chapter 14 Graphs III.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
State-Space Searches. 2 State spaces A state space consists of A (possibly infinite) set of states The start state represents the initial problem Each.
Chapter 24: Single-Source Shortest Paths Given: A single source vertex in a weighted, directed graph. Want to compute a shortest path for each possible.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada ece.uwaterloo.ca.
Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Slides by: Eric Ringger, adapted from slides by Stuart Russell of UC Berkeley. CS 312: Algorithm Design & Analysis Lecture #36: Best-first State- space.
Graph Algorithms GAM 376 Robin Burke Fall Outline Graphs Theory Data structures Graph search Algorithms DFS BFS Project #1 Soccer Break Lab.
Heuristic Functions. A Heuristic is a function that, when applied to a state, returns a number that is an estimate of the merit of the state, with respect.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Single Source Shortest Paths Chapter 24 CSc 4520/6520 Fall 2013 Slides adapted from George Bebis, University of Reno, Nevada.
CSE 326: Data Structures Lecture #17 Heuristic Graph Search Henry Kautz Winter Quarter 2002.
1 Graph theory Outline A graph is an abstract data type for storing adjacency relations –We start with definitions: Vertices, edges, degree and sub-graphs.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
1 Single-source shortest path Shortest Path Given a weighted directed graph, one common problem is finding the shortest path between two given vertices.
Chapter 3 Solving problems by searching. Search We will consider the problem of designing goal-based agents in observable, deterministic, discrete, known.
Outline This topic covers merge sort
Programming Abstractions
Topological Sort In this topic, we will discuss: Motivations
Heuristic Search Introduction to Artificial Intelligence
Shortest Path Problems
unweighted path lengths
The A* Algorithm Héctor Muñoz-Avila.
Programming Abstractions
Enumerating Distances Using Spanners of Bounded Degree
Poisson distribution.
All-pairs Shortest Path
All-pairs shortest path
Outline This topic covers Prim’s algorithm:
Shortest Path Problems
CSE 417: Algorithms and Computational Complexity
Presentation transcript:

1 A* search Outline In this topic, we will look at the A* search algorithm: –It solves the single-source shortest path problem –Restricted to physical environments –First described in 1968 by Peter Hart, Nils Nilsson, and Bertram Raphael –Similar to Dijkstra’s algorithm –Uses a hypothetical shortest distance to weight the paths

2 A* search Background Assume we have a heuristic lower bound for the length of a path between any two vertices E.g., a graph embedded in a plane –the shortest distance is the Euclidean distance –use this to guide our search for a path

3 A* search Idea Consider this map of Slovenia

4 A* search Idea Suppose we want to go from Kamnik to Bohinj

5 A* search Idea A lower bound for the length of the shortest path to Bohinj is h(Kamnik, Bohinj) = 53 km 53 km

6 A* search Idea Any actual path must be at least as long as 53 km 53 km

7 A* search Idea Suppose we have a 28 km shortest path from Kamnik to Kranj: d(Kamnik, Kranj) = 28 km 28 km

8 A* search Idea A lower bound on the shortest distance from Kranj to the destination is now h(Kranj, Bohinj) = 32 km 28 km 32 km

9 A* search Idea Thus, we weight of the path up to Kranj is w(Kranj) = d(Kamnik, Kranj) + h(Kranj, Bohinj) = 60 km 32 km 28 km

10 A* search Idea Any path extending this given path to Bohimj must be at least 60 km 28 km 32 km

11 A* search The value w(Kranj) represents the shortest possible distance from Kamnik to Bohinj given that we follow the path to Kranj As with Dijkstra’s algorithm, we must start with the null path starting at Kamnik: w(Kamnik)= d(Kamnik, Kamnik) + h(Kamnik, Bohimj) = 0 km + 53 km 53 km Idea Bohimj Kamnik

12 A* search Algorithm Description Suppose we are finding the shortest path from vertex a to a vertex z The A* search algorithm initially: –Marks each vertex as unvisited –Starts with a priority queue containing only the initial vertex The priority of any vertex v in the queue is the weight w(v) which assumes we have found the shortest path to v Shortest weights have highest priority

13 A* search Algorithm Description The algorithm then iterates: –Pops the vertex u with highest priority Mark the vertex u of the path as visited –Ignore all visited adjacent vertices v –For each remaining unenqueued adjacent vertex v : Push v with w(v) = d(a, u) + d(u, v) + h(v, z) –For each enqueued adjacent vertex v : Determine if w(v) = d(a, u) + d(u, v) + h(v, z) is less than the current weight/priority of v, and if so, update the path leading to v and its priority Continue iterating until the item popped from the priority queue is the destination vertex z

14 A* search Comparison of Priorities Suppose we have a path with w(Smarca) = 4 km + 52 km = 56 km 52 km 4 km

15 A* search Comparison of Priorities We can extend this path to Moste: w(Moste)= 4 km + 5 km + 48 km = 57 km 48 km 9 km

16 A* search Comparison of Priorities We can also extend this path to Menges: w(Menges)= 4 km + 4 km + 51 km = 59 km 51 km 8 km

17 A* search The smaller weight path to Moste has priority—extend it first 48 km Comparison of Priorities 9 km

18 A* search Comparison with Dijkstra’s Algorithm This differs from Dijkstra’s algorithm which gives weight only to the known path –Dijkstra would chose Menges next: d(Kamnik, Moste) = 9 km > 8 km = d(Kamnik, Menges) Difference: –Dijkstra’s algorithm radiates out from the initial vertex –The A* search algorithm directs its search towards the destination

19 A* search Comparison with Dijkstra’s Algorithm Graphically, we can suggest the behaviour of the two algorithms as follows: –Suppose we are moving from a to z : Representative search patterns for Dijkstra’s and the A* search algorithms z a a z

20 A* search Comparison with Dijkstra’s Algorithm Dijkstra’s algorithm is the A* search algorithm when using the discrete distance –No vertex is better than any other vertex Representative search patterns for Dijkstra’s and the A* search algorithms z a a z

A* Search Algorithm 21 Optimality Guarantees? The A* search algorithm will not always find the optimal path with a poor heuristic distance –Find the shortest path from A to C: B is enqueued with weight w( B ) = = 6 C is enqueued with weight w( C ) = = 3 –Therefore, C is dequeued next and as it is the destination, we are finished Reference: Andrew Moore, Carnegie Mellon University

A* Search Algorithm 22 Admissible Heuristics This heuristic overestimates the actual distance from B to C –The Euclidean distance doesn’t suffer this problem: The path the crow flies is always shorter than the road the wolf runs Reference: Andrew Moore, Carnegie Mellon University

A* Search Algorithm 23 Admissible Heuristics Admissible heuristics h must always be optimistic: –Let d(u, v) represent the actual shortest distance from u to v –A heuristic h(u, v) is admissible if h(u, v) ≤ d(u, v) –The heuristic is optimistic or a lower bound on the distance Using the Euclidean distance between two points on a map is clearly an admissible heuristic –The flight of the crow is shorter than the run of the wolf

24 A* search Optimality Conditions The effectiveness of the A* search algorithm depends on the heuristic h(v) Can be shown to run in polynomial time if |h(u, v) – d(u, v)| = O(ln(d(u, v))) where d(u, v) is the length of the actual shortest path –I.e., doubling the length of the optimal solution only increases the error by a constant –Not likely with a road map and the Euclidean distance

A* Search Algorithm 25 The N Puzzle Consider finding the solution to the following puzzle –Take a random permutation of 8 or 15 numbered tiles and a blank formed in a rigid square Reference: Andrew Moore, Carnegie Mellon University

A* Search Algorithm 26 The N Puzzle You are allowed to move a tile adjacent to the blank into the location of the blank

A* Search Algorithm 27 The N Puzzle The objective is to find a minimum number of moves which will transform the tiles into a standard solution

A* Search Algorithm 28 The N Puzzle There are 9! and 16! initial permutations –Half of these, through a sequence of moves, can be transformed into the desired solutions

A* Search Algorithm 29 The N Puzzle Each solution defines a vertex in a graph with edges denoting allowable moves –It is not a tree, but the smallest cycle has a length of 12 E.g., cycle 8, 7, and 3

A* Search Algorithm 30 The N Puzzle The graph of solvable eight puzzles has: – vertices – edges The fifteen puzzle graph has: – vertices – edges In general and in the limit: – (N + 1)!/2 vertices – (N + 1)! edges

A* Search Algorithm 31 The N Puzzle Finding a solution requires one to find the shortest path –All edges have weight 1 Dijkstra’s algorithm is painfully slow –This puzzle requires that vertices be searched To use the A* search, we need a heuristic lower bound on the distance

A* Search Algorithm 32 The N Puzzle We will consider three distances which we will use with the A* search: –The discrete distance If two objects are equal, the distance is 0, otherwise it is 1 –The Hamming distance The number of tiles (including the blank) which are in an incorrect location –The Manhattan distance The sum of the minimum number of moves required to put a tile in its correct location

A* Search Algorithm 33 The N Puzzle For example, consider this permutation: –It does not equal the solution, so the discrete distance is 1 –8 out of 9 tiles/blanks are in the incorrect location; therefore the Hamming distance is 8 –It requires = 16 moves to move each tile into the correct location, therefore the Manhattan distance is 16

A* Search Algorithm 34 The N Puzzle As discussed before, the discrete distance does not improve the situation: it is equivalent to Dijkstra’s algorithm Using the same permutation as before: –The Hamming distance isn’t much better: It reduces the vertices searched from to It is only useful when we are very close to the actual solution –The Manhattan distance, however, allows the A* search to find the minimal path with only 6453 vertices searched

35 A* search The N Puzzle How much better is it to use the Manhattan distance over the Hamming or discrete? –With the Hamming distance, there is only a small change –For 100 random puzzles, we have a plot the number of vertices visited using the discrete distance versus the number of vertices visited using the Hamming distance –The line is the identity function –The colour, blue to red, indicates the length of the solution; from 13 to 28

36 A* search The N Puzzle However, comparing the number of vertices visited when using the Manhattan distance, there is a significant reduction by a factor of almost 100 –A more significant improvement with shorter paths

37 A* search The N Puzzle An implementation of N puzzles are located at This includes: –An N puzzle class: N_puzzle –An updatable heap class: Updateable_heap

38 A* search Summary This topic has presented the A* search algorithm –Assumes a hypothetical lower bound on the length of the path to the destination –Requires an appropriate heuristic Useful for Euclidean spaces (vector spaces with a norm) –Faster than Dijkstra’s algorithm in many cases Directs searches towards the solution

39 A* search References Wikipedia, [1]Andrew Moore, Carnegie Mellon University, “A* Heuristic Search”, [2]Stuart Russell and Peter Norvig, Artificial Intelligence: A Modern Approach, 2 nd Ed., Prentice Hall, Chapters 4 and 5. These slides are provided for the ECE 250 Algorithms and Data Structures course. The material in it reflects Douglas W. Harder’s best judgment in light of the information available to him at the time of preparation. Any reliance on these course slides by any party for any other purpose are the responsibility of such parties. Douglas W. Harder accepts no responsibility for damages, if any, suffered by any party as a result of decisions made or actions based on these course slides for any other purpose than that for which it was intended.