A* Path Finding Ref: A-star tutorial
Path Finding Problem Weighted Graph
The Problem start target wall Find a path of lowest cost Given
Terminology F G H Node Traversal cost: F = G + H Parent node; current node Traversal cost: F = G + H G: movement cost from starting point H: heuristic cost to the target (e.g., Manhattan distance) Open list & closed list Closed: traversal cost already determined Heuristics: (wiki) experience-based techniques for problem solving, learning, and discovery. Manhattan distance
A* Algorithm F Parent node G H Cost: F = G + H Take the node of lowest cost from open list; switch it to closed list; name it current node For its reachable and non-closed neighbors: If not in open list, add them. Make current node their parent. Evaluate costs G & H. Else (already in open), revise parent using G. update cost. (update if F becomes smaller) Stop when: target is added to closed list Open list is empty (fail to find target). No path
H G F closed current 60 14 74 60 40 14 54 10 50 50 10 60 30 10 40 60 14 74 50 10 60 40 14 54
H G F closed current 60 14 74 60 40 14 54 10 50 50 10 60 30 10 40 60 14 74 50 10 60 40 14 54 60 28 88 50 24 74
H G F closed current 60 14 74 60 40 14 54 10 50 50 10 60 30 10 40 60 14 74 50 10 60 40 14 54 60 28 88 50 24 74
H G F closed current 60 28 88 50 24 74 60 14 74 60 40 14 54 10 50 50 10 60 30 10 40 60 14 74 50 10 60 40 14 54 60 20 80 50 24 74
H G F closed current 60 28 88 50 24 74 60 14 74 60 40 14 54 10 50 50 10 60 30 10 40 60 14 74 50 10 60 40 14 54 60 20 80 50 24 74 40 34 74 70 38 108 60 34 94 50 38 88
H G F closed current 60 28 88 50 24 74 60 14 74 60 40 14 54 10 50 50 10 60 30 10 40 60 14 74 50 10 60 40 14 54 60 20 80 50 24 74 40 34 74 30 44 74 70 38 108 60 34 94 50 38 88 40 48 88
H G F closed current 60 28 88 50 24 74 60 14 74 60 40 14 54 10 50 50 10 60 30 10 40 60 14 74 50 10 60 40 14 54 20 54 78 10 58 68 60 20 80 50 24 74 40 34 74 30 44 74 20 54 74 70 38 108 60 34 94 50 38 88 40 48 88 30 58 88
H G F closed current 60 28 88 50 24 74 60 14 74 60 40 14 54 10 50 50 10 60 30 10 40 68 60 14 74 50 10 60 40 14 54 20 54 74 10 58 68 60 20 80 50 24 74 40 34 74 30 44 74 20 54 74 70 38 108 60 34 94 50 38 88 40 48 88 30 58 88
H G F closed current 60 28 88 50 24 74 60 14 74 60 40 14 54 10 50 50 10 60 30 10 40 68 60 14 74 50 10 60 40 14 54 20 54 74 10 58 68 60 20 80 50 24 74 40 34 74 30 44 74 20 54 74 70 38 108 60 34 94 50 38 88 40 48 88 30 58 88
H G F closed current 60 28 88 50 24 74 60 14 74 60 40 14 54 10 50 50 10 60 30 10 40 68 60 14 74 50 10 60 40 14 54 20 54 74 10 58 68 60 20 80 50 24 74 40 34 74 30 44 74 20 54 74 70 38 108 60 34 94 50 38 88 40 48 88 30 58 88
A* Demonstration (url)
A* Demo (url) Another JavaScript demo
Dijkstra, Best-first, A* Ref: url Comparison Dijkstra, Best-first, A* Ref: url
Dijkstra Algorithm Repeatedly examine the reachable & not-yet-visited vertices, adding its vertices to the set of vertices to be examined. Expand outwards from the starting point until it reaches the goal. guaranteed to find a shortest path from the starting point to the goal
Dijkstra Algorithm a b c d e z 1 - Input: weighted graph Iteration a b c d e z 1 - 5 4 6 1 8 a 2 z 2 Input: weighted graph Find shortest path from a to z 3 c 10 e Node a b c d e z Previous Node -
Dijkstra Algorithm a b c d e z 1 - 2 4 a b c d e z - b d 5 4 6 1 8 a 2 Iteration a b c d e z 1 - 2 4 5 4 6 1 8 a 2 z 2 3 c 10 e : visited (cost determined) Node a b c d e z Previous Node -
Dijkstra Algorithm a b c d e z 1 - 2 4 3 10 12 3 a b c d e z - c b d 5 Iteration a b c d e z 1 - 2 4 3 10 12 5 4 6 1 8 a 2 z 2 3 c 10 e 3 : visited (cost determined) Node a b c d e z Previous Node - c
Dijkstra Algorithm a b c d e z 1 - 2 4 3 10 12 8 a b c d e z - b b d 5 Iteration a b c d e z 1 - 2 4 3 10 12 5 4 6 1 8 a 2 z 2 3 c 10 e 8 : visited (cost determined) Node a b c d e z Previous Node - b
Dijkstra Algorithm a b c d e z 1 - 2 4 3 10 12 8 5 14 10 a b c d e z - Iteration a b c d e z 1 - 2 4 3 10 12 8 5 14 5 4 6 1 8 a 2 z 2 3 c 10 e : visited (cost determined) 10 Node a b c d e z Previous Node - d
Dijkstra Algorithm Path: zedbca a b c d e z 1 - 2 4 3 10 12 8 5 Iteration a b c d e z 1 - 2 4 3 10 12 8 5 14 6 5 4 6 1 8 a 2 z 2 3 c 10 e : visited (cost determined) 13 Node a b c d e z Previous Node - Path: zedbca e
Best-First Search Instead of selecting the vertex closest to the starting point, it selects the vertex closest to the goal. (Greedy) Best-First-Search is not guaranteed to find a shortest path.
Dijkstra better than Best First
A* combines the advantages of both
Implementation (google code)