Before learning a A * algorithm, first recall a very classical single source shortest path algorithm Dijkstra
1) Maintain a table dist, storing the distance from the current points to s
2) Remove the minimum value from the Dist table (obviously the process can be optimized with a heap) and use this minimum value to relax the dist value of the other points
3) repeat 2) process until the minimum value of the corresponding node is T
The concept of the Open table and the close table is actually used in the next
The Open table stores the points to be expanded to a certain extent corresponding to the list in the Dijkstra
The close table stores the points that have been expanded to prevent duplicates
So let's talk about what a * algorithm does on the basis of the Dijkstra algorithm . ?
Let us recall that the multi-source shortest path algorithm to find out what the results, in fact, far beyond our needs, we finally get the dist, is s to all points of the shortest distance.
However, when we need only the shortest path from S to T, what do we need to expand the points that we do not need to expand, even if it corresponds to the current smallest dist? The smallest dist does not necessarily help in solving the shortest path of s to T.
So we need to introduce an evaluation function
F (P) =h (P) +g (p)
where G (P) represents the actual shortest distance from S to P, and H (p) represents the estimated distance from p to t
G (p) is easy to solve, because when you start evaluating p, it shows that its dist is currently the smallest, without a doubt that its current dist is g (p)
H (p) depends on the problem setting, depending on the situation, usually set to a Manhattan distance or Euclidean distance from P to T (the former is more commonly used in a rasterized map)
When you find that f (p) is even larger than the current T dist, there is no need to expand p. Pretend you've expanded, and limbo p into the close table!
Here is a premise, H (p) estimated distance must be less than or equal to the actual shortest distance from p to T, which is more obvious, but is the basis of a * algorithm optimization (in fact, is a very basic idea of search pruning)
Give a A * process first
1) Place the beginning S into the open table
2) Evaluation of the dist smallest adjacent node in the Open table, and the evaluation of unqualified directly into the close table (child you are hopeless, wash and sleep.
Otherwise, expand the point into the Open table to expand (Little man has a future, I hand-picked to watch you
Expand the later point, also put in the close table (the dry is dry, can be removed unloads
3) The close table appears in the T! Don't say anything, the algorithm is over.
If you need to record a path, just record what point the point is extended from, and record the parent node.
Finally think about why a * algorithm emphasizes the Open table so much
Because the * algorithm uses the evaluation function to reduce the number of expansions, Dijkstra starts by extending all the points again, thus eliminating the need for an open table (because its open table contains all the points by default)
However, a * is an evaluation of whether or not to be placed in the Open Table extension, which is where the optimization.
Application of A * algorithm in finding the shortest path