A* Algorithm
- Put the start node S on the nodes list, called OPEN
- If OPEN is empty, exit with failure
- Remove from OPEN and place on CLOSED a node n for which
f(n) is minimum
- If n is a goal node, exit (trace back pointers from n to S)
- Expand n, generating all its successors and attach to
them pointers back to n. For each successor n' of n
- If n' is not already on OPEN or CLOSED estimate
h(n'),g(n')=g(n)+ c(n,n'), f(n')=g(n')+h(n'), and place it on OPEN.
- If n' is already on OPEN or CLOSED, then check if
g(n') is lower for the new version of n'. If so, then:
(i) Redirect pointers backward from n' along path yielding lower
g(n').
(ii) Put n' on OPEN.
If g(n') is not lower for the new version, do nothing.
- Goto 2
Example
Consider the following search space where the start state is S and
the goal state is G. The left figure shows the arcs labeled with
the costs of the associated operators. The right figure shows the
states labeled with the value of the heuristic function, h, if it is
ever applied at that state.
S ... Initial State S 8
/|\ /|\
1/ 5 \8 / | \
/ | \ / | \
A B C 8 A B 4 C 3
/|\ | / /|\ | /
3/ 7 9 4 /5 / | \ | /
/ | \|/ / | \|/
D E G .... Goal State D E G
* * 0
Edge Costs Heuristic = Estimated Costs = h(n)
- Summary of g(n), h(n),
f(n) = g(n) + h(n), as well as
h*(n), the hypothetical perfect heuristic:
n g(n) h(n) f(n) h*(n)
S 0 8 8 9
A 1 8 9 9
B 5 4 9 4
C 8 3 11 5
D 4 inf inf inf
E 8 inf inf inf
G 10/9/13 0 10/9/13 0
Notice that since h(n) <= h*(n) for all n, h is admissible
Optimal path = S B G
Cost of the optimal path = 9