Download presentation
Presentation is loading. Please wait.
1
Crowd Simulation (INFOMCRWS) - A* Search
Wouter van Toll January 15, 2018
2
Goals Understand the A* algorithm Reason about its properties
Know that it applies to many problems November 28, 2018 INFOMCRWS: A* Search
3
Contents A* basics Heuristics Properties and proofs
Solving other problems Variants of A* + Pen-and-paper exercises! November 28, 2018 INFOMCRWS: A* Search
4
November 28, 2018 INFOMCRWS: A* Search
5
A* basics Getting started November 28, 2018 INFOMCRWS: A* Search
6
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 November 28, 2018 INFOMCRWS: A* Search
7
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) November 28, 2018 INFOMCRWS: A* Search
8
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 November 28, 2018 INFOMCRWS: A* Search
9
A* formalized Edge costs Each edge (v,v’) has a cost c(v,v’) ≥ 0
Heuristics For each vertex v, h(v) estimates the path cost to vg We assume that h(v) never overestimates the actual cost OPEN set A “wavefront” for expansion, starting at vs Sorted by f(v) = g(v) + h(v) g(v) = cost of best path to v found so far CLOSED set A set of already expanded vertices November 28, 2018 INFOMCRWS: A* Search
10
Exercise 1 November 28, 2018 INFOMCRWS: A* Search
11
Exercise 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 November 28, 2018 INFOMCRWS: A* Search
12
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 November 28, 2018 INFOMCRWS: A* Search
13
Solution November 28, 2018 INFOMCRWS: A* Search
14
Greek: εὑρίσκω (“I find / discover”)
Heuristics Greek: εὑρίσκω (“I find / discover”) November 28, 2018 INFOMCRWS: A* Search
15
Properties of heuristics (1/2)
1. 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 2. 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 November 28, 2018 INFOMCRWS: A* Search
16
Properties of heuristics (1/2)
3. A heuristic h is consistent/monotone if: the decrease in h is never bigger than the increase in g Formally: h(vg) = 0 For any vertex v and any successor v’ of v during the search: h(v) ≤ c(v,v’) + h(v’) November 28, 2018 INFOMCRWS: A* Search
17
Exercise 2 November 28, 2018 INFOMCRWS: A* Search
18
Exercise 2 Look at various problems and heuristics
Check if the heuristics are perfect/admissible/consistent Note: A heuristic can have multiple properties! November 28, 2018 INFOMCRWS: A* Search
19
Solution Admissible? Consistent? Perfect?
a) 4-neighbor grid / Manhattan yes no b) 4-neighbor grid / Euclidean c) 8-neighbor grid / Manhattan d) 8-neighbor grid / Euclidean e) Graph example 1 f) Graph example 2 November 28, 2018 INFOMCRWS: A* Search
20
Properties and Proofs Reasoning about A* November 28, 2018
INFOMCRWS: A* Search
21
Exercise 3 November 28, 2018 INFOMCRWS: A* Search
22
Every consistent heuristic
Exercise 3 Prove the following statement: 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! November 28, 2018 INFOMCRWS: A* Search
23
Solution November 28, 2018 INFOMCRWS: A* Search
24
Other properties (1/2) 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 November 28, 2018 INFOMCRWS: A* Search
25
Other properties (2/2) 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 may find even better paths to v later, so we cannot (safely) use a closed set! November 28, 2018 INFOMCRWS: A* Search
26
Solving other problems
Graph search in other places November 28, 2018 INFOMCRWS: A* Search
27
Navigation mesh 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 Solution: visibility graph (more expensive but optimal) November 28, 2018 INFOMCRWS: A* Search
28
Navigation mesh Multi-layered environments How to improve the search?
3D distance as heuristic? Geodesic distance as heuristic? Higher-level graph that says how the layers are connected? November 28, 2018 INFOMCRWS: A* Search
29
Abstract graph search Remember: A* can find optimal path in graphs
Many search problems can be defined as graph problems “Optimal” doesn’t always have to be “shortest” Can even be non-geometric Example: Sliding puzzle Vertex = Edge = Heuristic = puzzle state move (sliding 1 piece) ??? November 28, 2018 INFOMCRWS: A* Search
30
Variants of A* November 28, 2018 INFOMCRWS: A* Search
31
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 Resources: ARA*: Anytime A* with Provable Bounds on Sub-Optimality (Likhachev et al., 2003) ANA*: Anytime Nonparametric A* (van den Berg et al., 2011) November 28, 2018 INFOMCRWS: A* Search
32
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 Resources: D* Lite (Koenig & Lihkachev, 2002) Lifelong Planning A* (Koenig et al., 2004) Dynamically Pruned A* (van Toll & Geraerts, 2015) November 28, 2018 INFOMCRWS: A* Search
33
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 Use coarse graph plan as heuristic Resources: Hierarchical A*: Searching Abstraction Hierarchies Efficiently (Holte et al., 1996) Near-Optimal Hierarchical Pathfinding (Botea et al., 2004) (Optimality?) (Precomputed or on the fly?) November 28, 2018 INFOMCRWS: A* Search
34
Closing Comments */ November 28, 2018 INFOMCRWS: A* Search
35
Recap: Goals Understand the A* algorithm Reason about its properties
Know that it applies to many problems November 28, 2018 INFOMCRWS: A* Search
36
Conclusions A* is widely used and analyzed Not just for grids
Many interesting (provable) properties New variants are still being made today Not just for grids Modelling the problem is most of the work Of course, there’s much more to say Lots of resources online November 28, 2018 INFOMCRWS: A* Search
37
The final slide Questions? November 28, 2018 INFOMCRWS: A* Search
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.