A* Search Algorithm
A* is a pathfinding algorithm that uses heuristics to guide its search. It can be considered as a generalization of Dijkstra’s algorithm. A* only finds a path between two given nodes, where as Dijkstra’s algorithm finds the shortest path tree from a start node.
Variables and Functions[1]
A* formulates the problem space using a weighted directed graph and uses the following variables and functions:
c_{ij} : cost of the arc going out from nodei to nodej .g(n) : the cost of the path from start nodes ton with minimum cost so far found by A*.h(n) : heuristic function that estimates the cost of the cheapest path fromn to the goal node. If the heuristic function is admissible, A* is guaranteed to find an optimal path. Ifh(n) is also consistent, nodes never need to be reopened once closed.f(n) : evaluation function or f-value. Defined as follows:f(n) = g(n) + h(n) - OpenSet: a min-priority queue containing all currently open nodes, ordered by their f-values.
\Gamma(n_i) : successor operator. Yields all the successorsn_j ofn_i and the arc costsc_{ij} .
Algorithm
Following pseudocode is adapted from the original article [1:1]:
- First mark
s as open, calculate thef(s) and add it to the priority queue. - Select the open node
n whose f-value is smallest from the queue. Resolve ties arbitrarily, but always in favor of any goal node. - If
n is a goal node, markn as closed and terminate the algorithm. - Otherwise, mark
n as closed and apply the successor operator\Gamma ton . Calculate f-values for each successor ofn and mark as open each successor not already marked closed. Go to Step 2.