' Smart search Algorithm ' * algorithm _ Search algorithm

Source: Internet
Author: User

A * algorithm

is a heuristic search algorithm.

People who understand BFS, DFS, or Dijkstra algorithms should know that. These algorithms are a way of blindly searching around.

Heuristic Search:

Heuristic search is the search in the state space to evaluate the location of each search, get the best location, and then from this location to search until the target. This can omit a lot of fearless search path, mention the efficiency. In heuristic search, the evaluation of position is very important. Different valuations can have different effects. Therefore, the key of a * algorithm is how to build this heuristic function.

The formula is expressed as: F (n) =g (n) +h (n),

F (n) is a valued function from the initial point through node N to the target point,

g (n) is the actual cost from the initial node to the N node in the state space,

H (N) is the estimated cost of the optimal path from N to the target node.

A * algorithm is associated with breadth, depth first, and Dijkstra algorithms:

1, g (n) = 0 o'clock: The algorithm is similar to DFS.

2, h (n) = 0 o'clock: The algorithm is similar to BFS.

3, if h (0) = 0, only need the G (n) (that is, the shortest path from the beginning to any point N), then converted to a single source shortest path problem.

A * Algorithm analysis:

The most significant difference between a * algorithm and other search path algorithms is the design of its estimation function, which is the formula: F (n) =g (n) +h (n) in the design of H (N).

The general calculation of H (N) has the following methods:

1. Manhattan Distance: |x1-x2| + |y1-y2|.

2, European distance: two points between the line distance.

3, Chebyshev distance: Max (|x2-x1|,|y2-y1|).

The Green Line in this picture represents the European distance and the other is Manhattan distance.

In the figure, the Chebyshev distance from F6 to E2 is: 4

In the next analysis, our H (n) is the Manhattan distance, and g (n) is the European path.

Suppose we need to search for the following:

The green is the starting point, the red is the target, the blue is the obstacle, and the black is the passable path.

The value of f is the and of G and H. The results of the first step search can be seen in the following chart. The scores of F,g and H are written in each square. As indicated by the square on the right side of the starting lattice, F is printed in the upper-left corner, G in the lower-left corner, and h in the lower-right corner.

Next we'll talk about the process of a * algorithm:

1, add the starting grid to the open list.

2, repeat the following work:

A to open a grid with the lowest f value (best estimate) in the list, switch it to the close list.

b) to judge each lattice in the adjacent lattice

* If it is not available or is already in the closed list, skip it. The reverse is as follows.

* If it's not in the open list, add it. Take the current grid as the parent node of the grid. Record the f,g of this lattice, and the H value.

* If it is already in the open list, check to see if the new path is better with the G value as the reference. A lower g value means a better path. If so, change the parent node of the lattice to the current grid and recalculate the G and F values of the lattice. If you keep your open list sorted by F value, you may need to sort the open list again after the change.

c) Stop, when you

* The target is added to the close list (annotation), when the path is found, or

* No target grid found, the open list is empty. At this point, the path does not exist.

3. Save the path. Start with the target grid and move along the parent node of each cell until you return to the starting grid. This is your path.

In the next article, I'll use a * algorithm to solve a classic eight-digit problem.

from:http://blog.csdn.net/cyh_24/article/details/8018752

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.