A* algorithm
Resources
https://www.redblobgames.com/pathfinding/a-star/introduction.html
https://stackabuse.com/graphs-in-java-a-star-algorithm/
A heuristic for shortest paths
- Dijkstra’s algorithm assumes it knows noting about nodes it hasn’t reached during the algorithm
- Suppose instead we have h(u) which is an estimate of the distance from node u to t
- A plausible choice for h(u) if we were implementing a driving direction application
h(u)= distance from u to t as the crow flies
A* algorithm
Maintain two values for every visited node
- g(u) = best distance from s to u found so far
- f(u) = g(u) + h(u) = estimate of the length of the best path from s to t through u
https://www.youtube.com/watch?v=-L-WgKMFuhE
Pseudocode
1 | // A* Search Algorithm |
Python implementation
1 | frontier = PriorityQueue() |
Choice of h(u)
Definition (Admissible):
Let h*(u) be the real shortest distance from u to t. A heuristic h(u) is admissible if h(u)
h*(u) for all u
- When h(u) = 0 for all u: A* is equivalent to Dijkstra’s algorithm
Theorem
If h(u) is admissible, then A* is guaranteed to find an optimal route to the destination t
TSP
- Post title:A* algorithm
- Post author:Yuxuan Wu
- Create time:2021-10-28 10:18:09
- Post link:yuxuanwu17.github.io2021/10/28/2021-10-28-A-algorithm/
- Copyright Notice:All articles in this blog are licensed under BY-NC-SA unless stating additionally.