Talk about A *

Source: Internet
Author: User

Recently suddenly think of a * this heuristic search, generally used to find the shortest path, but the feeling of its valuation function is not very clear, in fact, the problem falls on the validity of a *.

Reference:

Http://liyanblog.cn/articles/2012/09/19/1348045903617.html

Https://en.wikipedia.org/wiki/a*_search_algorithm

Http://baike.baidu.com/link?url=UCU0dU7DIkhKx111EQcB2DZf28Z3do3JbEQfM-l-N8hfVaApT7RUGgVo93tIN-lQtovCst0TysYGG0rd-P2KhK

Back to A * above, actually look at a * first eye, will feel is a BFS, is on the basis of BFS added a valuation function, and this valuation function is the key to a *, because a * is not like BFS a wild search, it through this valuation function to guide the next search should go which node, which path. The advantage is that in large-scale searches, the time complexity of BFS is certainly unbearable, and a * can come in handy.

So there are two questions about A *:

1. What exactly is a valuation function

2. How to request the valuation function

1. Valuation function

In fact, the valuation function is more intuitive, but also not how to around.
Define the Valuation function f (x) = g (x) + H (x)


Suppose now is the path that requires a to B:
g (x): Represents the consumption from a to X, actual consumption.
H (x): Represents the consumption of X to B, estimated consumption. When selected is the actual minimum consumption of the highest aging rate, and in the current general K short Circuit is the first to use SPFA and other short-circuit algorithm to find the reverse shortest path, and then this as H (X) for the next K short-circuit solution.

Note that: In fact, the consumption is not the shortest consumption or actual consumption of such, but the programmer given an estimated consumption. The calculation method chosen here will affect the efficiency and correctness of the final search, so it should be possible to ensure that the actual consumption and consumption are positively correlated. (Personal opinion, there will be a strict proof later)

There are two problems with the valuation function: time consumption and correctness.

The specific time consumption calculation is definitely related to the valuation function, so there will be some considerations, here is not much to pull, directly consider the worst time consumption, that is equivalent to the valuation function has no effect, is the ordinary BFS consumption.

Correctness: Exactly how to choose the valuation function is correct, or is arbitrary choice?

We can first consider a limit case, assuming that we choose the H (x) is the actual shortest, we can find that the value of the function f (x) = g (x) + H (x) is actually a through X to reach the actual minimum consumption of B, then we choose a minimum estimate value, go that one can be guaranteed to be correct.

Because g (x) is actually the actual calculation of consumption, so we are not artificially set, we can not consider, this time we need to focus on the next H (X) selection.

Baidu Encyclopedia above has a saying:

Estimated value h (x) <= x to the actual consumption of the target node, in this case, the search for more points, large search range, low efficiency. But the optimal solution can be obtained.
And if H (x) =d (x), that is, the distance estimate h (x) equals the shortest distance, then the search will be strictly along the shortest path, at which time the search efficiency is the highest.

If the value > actual value of the search, the number of points, search scope is small, high efficiency, but can not guarantee the optimal solution.

First of all, regardless of whether this argument is correct or not, simply from these conditions to prove that it is more difficult, because the actual consumption is what we do not know, it is more difficult to explain this is correct.

And the wiki has a proof (picture comes on wiki):

This is very rigorous, here is to ask F to g of the shortest.

Suppose the condition satisfies: H (x) <= D (x, y) + H (Y), where D (x, y) represents the distance from any x to its neighbor (that is, the connected node) Y, and the meaning of H (x) is the previous estimated path from X to the end of G.

And the deduction is more obvious, can be regarded as starting from F, and then follow a path to the end of the node G, that is, the search process, here is the assumption that L (P) is the shortest path through a number of points midway, then can be guaranteed to use a * The path is expected to be less than equal to the actual shortest path , then A * will be able to find the shortest possible.

At this time we return to the Baidu Encyclopedia, H (x) <= x to the actual consumption of the target node is able to find the shortest, in fact, is almost a meaning.

In fact, we are concerned about the programming time or how to choose this function, from the above is already very obvious, it is small enough to be able to ensure that the actual corresponding to all possible distances are small OK, this is relatively easy to meet, but this is only to ensure correctness, efficiency this aspect or to be carefully selected under.

2. Valuation Function Update

Directly with the current node, the next step around it can be updated, mainly to update f (x) = g (x) + H (x), g (x) is for the last node of the G (x) is updated, the rest is not related to the previous node.

Talk about A *

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.