简体   繁体   English

A *算法中的启发式值

[英]Heuristic value in A* algorithm

I am learning A* algorithm and dijkstra algorithm. 我正在学习A *算法和dijkstra算法。 And found out the only difference is the Heuristic value it used by A* algorithm. 并发现唯一的区别是A *算法使用的启发式值。 But how can I get these Heuristic value in my graph?. 但是,如何在图表中获得这些启发式值? I found a example graph for A* Algorithm(From A to J). 我找到了A *算法的示例图(从A到J)。 Can you guys help me how these Heuristic value are calculated. 你们能帮我这些启发式值的计算方式吗? 在此处输入图片说明

The RED numbers denotes Heuristic value. 红色数字表示启发式值。

My current problem is in creating maze escape. 我当前的问题是创建迷宫逃生。

The heuristic is an estimate of the additional distance you would have to traverse to get to your destination. 启发式方法是您到达目的地必须经过的额外距离的估计值。

It is problem specific and appears in different forms for different problems. 它是特定于问题的,针对不同的问题以不同的形式出现。 For your graph , a good heuristic could be: the actual distance from the node to destination, measured by an inch tape or centimeter scale. 对于您的图形,一个很好的启发法可能是: 从节点到目标的实际距离,以英寸胶带或厘米为单位进行度量。 Funny right but thats exactly how my college professor did it. 有趣的权利,但是那正是我的大学教授是如何做到的。 He took an inch tape on black board and came up with very good heuristic. 他在黑板上放了一英寸的胶带,并提出了很好的启发法。

So h(A) could be 10 units means the length measured by a measuring scale physically from A to J. 所以h(A)可以是10个单位,表示长度是通过一个从A到J的物理量尺来测量的。

Of course for your algorithm to work the heuristic must be admissible , if not it could give you wrong answer. 当然,为了使算法起作用,启发式算法必须是可以接受的 ,否则可能会给您错误的答案。

In order to get a heuristic that estimates (lower bounds) the minimum path cost between two nodes there are two possibilities (that I know of): 为了获得一种启发式的方法来估计(下限)两个节点之间的最小路径成本,有两种可能性(我知道):

Knowledge about the underlying space the graph is part of 关于图形所包含的基础空间的知识

As an example assume the nodes are points on a plane (with x and y coordinate) and the cost of each edge is the euclidean distance between the corresponding nodes. 例如,假设节点是平面上的点(具有x和y坐标),并且每个边的代价是相应节点之间的欧式距离。 In this case you can estimate (lower bound) the path cost from node U to node V by calculating the euclidean distance between U.position and V.position . 在这种情况下,您可以通过计算U.positionV.position之间的欧式距离来估计(下限)从节点U到节点V的路径成本。

Another example would be a road network where you know its lying on the earth surface. 另一个例子是道路网络,您知道它位于地球表面。 The cost on the edges might represent travel times in minutes. 边缘的成本可能代表以分钟为单位的旅行时间。 In order to estimate the path cost from node U to node V you can calculate the great-circle distance between the two and divide it by the maximum travel speed possible. 为了估算从节点U到节点V的路径成本,您可以计算两者之间的大圆距离,然后将其除以可能的最大行进速度。

Graph Embedding 图嵌入

Another possibility is to embed your graph in a space where you can estimate the path distance between two nodes efficiently. 另一种可能性是将图形嵌入到可以有效估计两个节点之间的路径距离的空间中。 This approach does not make any assumptions on the underlying space but requires precomputation. 这种方法没有对基础空间进行任何假设,但需要进行预计算。

For example you could define a landmark L in your graph. 例如,您可以在图形中定义界标L Then you precalculate the distance between each node of the graph to your landmark and safe this distance at the node. 然后,您可以预先计算图的每个节点到地标之间的距离,并在该节点处确保该距离。 In order to estimate the path distance during A* search you can now use the precalculated distances as follows: The path distance between node U and V is lower bounded by |dist(U, L) - dist(V,L)| 为了估计A *搜索期间的路径距离,现在可以按以下方式使用预先计算的距离:节点UV之间的路径距离由|dist(U, L) - dist(V,L)| .You can improve this heuristic by using more than one landmark. 您可以通过使用多个地标来改进这种启发式方法。

For your graph you could use node A and node H as landmarks, which will give you the graph embedding as shown in the image below. 对于您的图形,您可以将节点A和节点H用作界标,这将为您嵌入图形,如下图所示。 You would have to precompute the shortest paths between the nodes A and H and all other nodes beforehand in order to compute this embedding. 您必须预先计算节点A和H与所有其他节点之间的最短路径,以便计算此嵌入。 When you want to estimate for example the distance between two nodes B and J you can compute the distance in each of the two dimensions and use the maximum of the two distances as estimation. 例如,当您要估计两个节点B和J之间的距离时,可以计算两个维中每个的距离,并使用两个距离中的最大值作为估计。 This corresponds to the L-infinity norm . 这对应于L-无穷大范数

图嵌入

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM