Workshop: A* Search
Goals Understand the A* algorithm Reason about its properties Know that it applies to many problems 4/6/2019 Workshop: A* Search
Contents A* basics Heuristics Properties and proofs Solving other problems Variants of A* 4/6/2019 Workshop: A* Search
Getting started A* Basics 4/6/2019 Workshop: A* Search
A* is born General-purpose graph search Very popular, also in games P. Hart, N. Nilsson, B. Raphael. A Formal Basis for the Heuristic Determination of Minimum Cost Paths (1968) General-purpose graph search Compute optimal paths Sub-optimal paths if you want to Easy to implement Very popular, also in games Many versions assume grids and distance-based costs But it’s way broader than that 4/6/2019 Workshop: A* Search
Graph search 1959: Dijkstra’s algorithm Given a graph G = (V,E) Edges e є E have non-negative costs Start vertex vs є V Compute minimum-cost paths from vs to all other vertices O(|E| + |V| log |V|) time (with the right data structures) 4/6/2019 Workshop: A* Search
Graph search 1968: A* algorithm Given a graph G = (V,E) Edges e є E have non-negative costs Start vertex vs є V, goal vertex vg є V Compute a minimum-cost path from vs to vg 4/6/2019 Workshop: A* Search
A* versus Dijkstra A* steers towards the goal using heuristics An estimate of the path cost to the goal “Dijkstra is A* without heuristics” Best-first search Expand the most promising vertex Choice of heuristic determines the behavior Optimal vs. sub-optimal paths Running time Possibility for speed-ups 4/6/2019 Workshop: A* Search
Formalized Edge costs Heuristics OPEN set CLOSED set Each edge (v,v’) has a cost c(v,v’) ≥ 0 Heuristics For each vertex v, a function h(v) estimates the path cost to vg We assume that h(v) never overestimates the actual cost (we’ll explain why later) OPEN set A “wavefront” of vertices to expand, starting at vs Sorted by f(v) = g(v) + h(v) g(v) = cost of the optimal path to v found so far CLOSED set A set of already expanded vertices 4/6/2019 Workshop: A* Search
Assignment 1 Grid example Run A* by hand and see what happens Cells are either free or blocked Each cell is connected to 4 neighbours (if they are free) Costs are uniform (e.g. 1 per cell connection) Run A* by hand and see what happens Pseudocode on next slide 4/6/2019 Workshop: A* Search
Pseudocode 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 g(vs) = 0, parent(vs) = NULL OPEN = {vs}, CLOSED = Ø while OPEN ≠ Ø v = argmin v’ є OPEN f(v’) if v = vg return the path to vs via parent pointers Remove v from OPEN Add v to CLOSED for each outgoing edge (v,v’) є E if v’ є CLOSED continue if v’ є OPEN or g(v) + c(v,v’) < g(v’) g(v’) = g(v) + c(v,v’) f(v’) = g(v’) + h(v’) parent(v’) = v Add / update v’ in OPEN return 4/6/2019 Workshop: A* Search
Solution 4/6/2019 Workshop: A* Search
εὑρίσκω (“I find / discover”) Heuristics 4/6/2019 Workshop: A* Search
3 important properties A heuristic h is perfect if: it always equals the actual path cost to the goal Formally: h(v) = g*(v,vg) for all v A heuristic h is admissible if: it never overestimates the actual path cost to the goal Formally: h(v) ≤ g*(v,vg) for all v A heuristic h is consistent/monotone if: the decrease in h is never bigger than the increase in g Formally: 1. h(vg) = 0 2. For any vertex v and any successor v’ of v during the search: h(v) ≤ c(v,v’) + h(v’) 4/6/2019 Workshop: A* Search
Assignment 2 Look at various problems and heuristics Check if the heuristics are perfect/admissible/consistent Note: A heuristic can have multiple properties! 4/6/2019 Workshop: A* Search
Reasoning about A* Properties and proofs 4/6/2019 Workshop: A* Search
Every consistent heuristic Assignment 3 Prove the following: Hints Admissible: h(v) ≤ g*(v,vg) for all v Consistent: 1. h(vg) = 0 2. For any vertex v and any successor v’ of v during the search: h(v) ≤ c(v,v’) + h(v’) You could use induction Every consistent heuristic is admissible! 4/6/2019 Workshop: A* Search
Other properties If h is admissible, A* returns an optimal path An inadmissible heuristic may still be useful (faster?) Anytime A*: Start non-optimal and improve while you have time If h is perfect, A* does not expand any vertices that are not on an optimal path If h is consistent, the optimal path to a vertex v is known as soon as v is expanded This allows us to use a closed set If h is inconsistent, we cannot (safely) use a closed set! 4/6/2019 Workshop: A* Search
Solving other problems Graph search in other places Solving other problems 4/6/2019 Workshop: A* Search
Navigation meshes Polygonal cells Dual graph A* on the graph h = 2D distance to goal vertex Result: sequence of cells Shorten the path within cells Optimal path? Graph: yes Original geometry: not always Multi-layered environments Heuristics? 4/6/2019 Workshop: A* Search
Abstract graph search Remember: A* can find optimal path in graphs Many search problems can be defined as graph problems Can be non-geometric Example: Sliding puzzle Vertex = puzzle state Edge = move (sliding 1 piece) Heuristic = ??? 4/6/2019 Workshop: A* Search
Variants of A* 4/6/2019 Workshop: A* Search
Anytime A* Start with a fast and imperfect search e.g. an inadmissible heuristic e.g. limited search space path cost ≤ (1+ε) * optimal cost Improve the path while time is available Check out: ARA*: Anytime A* with Provable Bounds on Sub-Optimality Likhachev et al. (2003) ANA*: Anytime Nonparametric A* van den Berg et al. (2011) 4/6/2019 Workshop: A* Search
Dynamic A* Related to / combined with anytime A* Re-plan the path when the environment changes Remember the A* search space from the initial plan Update the vertices where g changes + good for unknown environments - memory usage, structural changes Check out: D* Lite; Koenig & Lihkachev (2002) Lifelong Planning A*; Koenig et al. (2004) Dynamically Pruned A*; van Toll & Geraerts (2015) 4/6/2019 Workshop: A* Search
Hierarchical A* Exploit the environment’s hierarchy Various options Multiple “levels” of graphs e.g. highways versus city streets; multi-layered buildings Various options First plan on coarse graph, then on fine graph Optimality? Use coarse graph plan as heuristic Precomputed or on the fly? Check out: Hierarchical A*: Searching Abstraction Hierarchies Efficiently Holte et al. (1996) Near-Optimal Hierarchical Pathfinding (HPA*) Botea et al. (2004) 4/6/2019 Workshop: A* Search
Conclusions 4/6/2019 Workshop: A* Search
Goals Understand the A* algorithm Reason about its properties Know that it applies to many problems 4/6/2019 Workshop: A* Search
Conclusions A* is widely used and analyzed Not just for grids Modelling the problem is most of the work Of course, there’s much more to say Lots of resources online 4/6/2019 Workshop: A* Search