A * algorithm is part of the essence of thinking is reflected in how greedy

I first learning article reprinted from here.
A * algorithm in detail

Finally, I come to make a summary.

Under the first few definitions

F = G + H
value G is the distance from the node reaches the parent node, the parent node coupled to the node from the grandfather, father nodes recursively until a starting point.
Here the distance, but also can be said to consume, spend like.
Links in the above G, is seeking out by the distance, the distance 14 diagonally, the other for 10.

The value H is a forecast to the end point of the distance, estimated consumption is constant. (That is to say at this time map data is static)

Pending points: deal node

open and close: 2 pcs node set

Learning A * algorithm, we have to focus on these issues:

  1. What point into the open?
    The starting point into the open
    around the handle points that can be processed (wall ah, rivers and the like, can not handle), non-close, non-open entry open
  2. What point into the close?
    Point to be processed into the close
  3. What point is pending point
    traversing open, find the smallest point F
  4. What parent node points for the point
    when a non-open open point is added, the point that point to be treated in the parent node.
    And when there is less than the original G G point around a new point processing, the processing point becomes the parent node point.
  5. A point when the value of G will change?
    When this point is in the open, and around a deal node, and the parent node points to deal node, the new G smaller than the original G, the parent node changes led to a change of G.

Process:

Initial settings: open added starting point, the starting point of F = 0

  1. Judgment open end it there? There is over, do not continue. Judgment open to empty it? Empty ends.
  2. Find the smallest point open in F as a deal Node, deal Node into the close in
  3. Point node to close around the deal, false regardless of the point
  4. The parent node points open deal node to deal node set around the point G to obtain a new comparison with the original G,
    if G is smaller than the original, is ok, the parent node or the point is reset to the original parent node
  5. The other points around the deal into open node, the parent node is provided to deal node, and obtain F, G, H.
  6. Back to 1.

How greedy thoughts embodied?

What is greed? Ie, the current operation is made now it seems the best.
A * each selected from open smallest point F as deal node, because F H received the impact, so there is bound to deal node close to the end of the trend.
After each selected deal node, update, and also open the node of G deal node around to ensure that these points are the starting point from the lowest point of consumption (ie consumption distance).
So when the end condition, end into the open, open to become a child node of a point. And its parent node is the word being promised, so the end is the starting point for the current to reach the shortest point.
Every step to ensure that the current minimum, and ultimately it must be the shortest it?
Without
example:
1--10--10--10 = 31
10 - 1 - 1 - 1 = 13
first select the shortest one, every choice is the shortest time later, a second longer but that above the final .

Select this step because I could pit some of the choices, but this loss will be after the big profits.

Personal superficial opinions want to help you! Thank you for reading!

Released five original articles · won praise 4 · Views 655

Guess you like

Origin blog.csdn.net/weixin_43764671/article/details/101572915