Heuristic Search Technology *

Source: Internet
Author: User

Opening

This article describes the shortest path to find an algorithm, its word I prefer: heuristic search.

There are not many good articles for getting started, and this article is written for beginners, which is very suitable for an introductory article. Article positioning: Non-professional A * article, very suitable for getting started.

There is a picture of the truth, first show you: from the lower left corner of the figure to the upper right corner to find the shortest path, the gray part is an obstacle.

This is a general search method, similar to the effect of poor lifting

The following figure is a * search for the effect, that is, the algorithm described in this article.

It can be seen that a * algorithm reduces a lot of computational capacity, and its efficiency has been significantly improved.

Here's how the algorithm is implemented in your solution.

Image source: Http://en.wikipedia.org/wiki/a*_search_algorithm

Body

Search area Introduction

Is the center of this article discussion:

The green point on the left is the start of a search, the target point is the red dot B on the right, and the middle is blocked by an obstacle (blue section).

Our goal is to start from the starting point and find a shortest path to the target point.

The whole picture is divided into small squares just for this convenient discussion, more applications, can also be divided into other blocks of the diagram.

Start Search

The goal is to find the shortest path from point A to B, so we search from point a until we find target B.

The steps for searching are this:

1, starting from the beginning a to add a to the openlist. Openlist explains: It is a queue in which elements are blocks that may form the shortest path. Now there is only element a in the queue and more elements will be added later. The elements in the future will be examined, from the inside to find the elements that make up the shortest path.

2. See if the elements around the starting point are reachable (whether they can reach them from a) and add the reachable elements from a to openlist, and the nodes added to the openlist maintain a pointer to his father, also point A. If there is an obstruction around a, ignore it. From this figure, a can get all the elements around a, so add them to the openlist.

3, put the starting point A into the closelist, the point in the closelist means that the future does not need to consider it. For a node, a can reach points are added to the openlist, will not have to consider the case of a.

After the above three steps, the following is shown

The figure is surrounded by dark green is the point in the Openlist, a total of eight, are from the beginning a can reach the point, and each of them has a pointer to their parent node (the small needle direction in the figure) is highlighted in green surrounded by a point in the Closelist, You can see that start a is already in closelist.

Path selection

From the starting point, the next point to go is now eight, which is the next point to choose? The normal thought is to pick a point closest to the target value and away from the point in those points.

This is also the way of thinking, in the text

F = G + H

Representation, where:

For each point, there is its own G, H, F.

where g represents the distance from a specific point to a starting point, and H represents the value from that point to the target, then f is the value of the path through that point.

Here is a detailed description

G: The distance from the starting point to a particular node, that is, the parent of G plus the distance g from the parent node of G to start a. The figure is a square block with an edge length of 10, so it's the value of G's parent node

Plus 10 (upper and lower left and right adjacent) or add 14 (diagonal block adjacent, that is, the length of the diagonal, originally 14.14, for the convenience of calculation here to take the approximate value)

H:h can get estimates in a number of ways. The method referred to here is the value of Manhattan Method,h, which is the number of moving steps from the point of view through horizontal and vertical movement to reach the target point by 10 (the side length of the square block is 10). Note Just horizontal and vertical movement, not slash. and ignores obstacles in the diagram.

Insert a sentence:

Looking at the description of H, you may doubt the accuracy of this estimate, one thing is certain: the closer the estimate is to the real value, the faster the algorithm can find the shortest path. The method we use is really an estimate, but the accuracy of this estimate is not high, that is, it is only a rough estimate, because this method is easy to understand, so this method is used. It can be thought that valuations that are too close to the end do not necessarily result in the desired results. About the valuation function for more information see: http://www.policyalmanac.org/games/heuristics.htm

In order to select a point from the openlist to continue the search, it is necessary to calculate the value of F, H, G for each point in the openlist and then select a small point of F to explore the next step.

For the points in, their F, G, h values are indicated in the diagram.

The position of F, H, G is already marked in the point to the right of the starting point, and the other points are in the same position.

Now look at the point on the right of the starting point (that is, the point labeled with the letter) g=10, since the beginning is on the left. H=30, the horizontal movement of three squares can be to the target point B. F=g+h=40

Continue Search

Since our aim is to find the shortest path, the next step is to select the f smallest point from the openlist to do a further search, as follows:

(To facilitate the description, the selected point becomes point m)

1, check the points around M, in the closelist ignore it, if it is not in the openlist, then add Openlist, the same time to maintain a point to the parent node, while calculating the join point F H G value.

2. If the points around M are in openlist, then the paths from the beginning A through m to such points are not smaller than their G values, and if so, their G, F values (updated to small) are updated. If it is not, do nothing.

3. Remove m from openlist and join Closelist.

The result of the processing of the smallest point in openlist (that is, the point to the left of the starting point) is as follows:

The right side, upper right and bottom right of M are obstacles, so ignore them. The left side of M is in the closelist, not to him, and the rest is the upper, lower, upper left and lower left points of M. They are already in the openlist, so see from the beginning through m to their distance is not less than their G-value. By judging, they are larger than their G value, so do anything.

As you can see, the closelist now has two elements (highlighted green blocks)

The next step is the same as described above, from the openlist to find the minimum F, repeat the operation. It can be seen that the openlist now the smallest of the two, is just considering the point is directly above and directly below, in fact, it does not matter where to choose, but people are accustomed to select later to join the elements in the openlist, here Select the point below.

Similarly, the processing effect is as follows:

The following is a simple process:

Let's say that the point now is N.

n above in Closelist, not considered.

N left in Openlist, look at the distance from Origin through N to it is 14+10 greater than 10, do not operate, skip to the next step

The lower left side of N is added below the openlist, while the values of F, G, H and pointers to the parent node are also recorded.

The lower right side of N is considered an "unreachable point" because both points are on the diagonal of the obstacle, which is, of course, a man-made rule. You can also cancel this rule and add it to the openlist. This is only a rule, do not have to delve into.

The result of the processing is that there are now three elements in Closelist, with the highlighted Blue flag, and the same, the elements in the openlist are marked with dark green.

Repeat the steps above, each time you select F Minimum points from openlist to join Closelist, while processing the elements around this point:

Until the target node is also added to the closelist to stop.

The effect of processing is as follows:

If you look at it, you may have found that the G-value of the two points below the starting point, yes, is the point in the figure circled with an ellipse, the previous g=28, now 20. This is updated at the time of the algorithm, possibly one of these steps, when processing this point, found a shorter path 20, replaced the original 28.

Here, the problem has been basically solved, the final task is to get this path.

Just start from the target point and walk along their parent node until the start point. A shortest path is obtained.

As shown

Summarize

Now you should have a preliminary understanding of a * algorithm, summarize the implementation process of the algorithm:

1. Add the starting point to the Openlist

2. Repeat the following steps

A, find the f smallest node from the openlist and treat it as the current operation node

b, check the point around the current point, if you have been in openlist see if you can get a smaller g through the current point, if you can update the value of that point g,f, if in closelist or obstacles (unreachable) ignore them

C, remove the current point from the openlist, add to the Closelist

D. Stop when the target point is added to the closelist

3, save the path, starting from the target point, follow the parent node pointer, until the starting point is found.

Postscript

In fact, heuristic search is an optimization of the poor lifting, so that each search is closer to the target. This is achieved through the valuation function, and it is critical to find a valuation function for such problems.

Valuation function: The cost of starting from the current point to the target point. In fact, from this concept, it seems to be similar to the branch boundary method, are on the basis of exhaustive search optimization.

Heuristic Search Technology *

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.