改进的 a-star 寻路启发式设计

发布于 2025-01-03 14:08:47 字数 959 浏览 3 评论 0原文

第一的, 理想的路径是(按重要性排序):

1. shortest

我的启发式 (f) 是:

manhattan distance (h) + path length (g)

这是有问题的,因为它偏向于转向目标然后蜿蜒返回的路径。

第二, 理想的路径是:

1. shortest
2. approaches the destination from the same y coordinate (if of equal length)

我的启发式保持不变。在达到目标后,我最后检查了第二个标准。启发式的效率稍低(为了解决转向问题),这也导致总是搜索必要的相邻坐标。

第三, 理想路径:

1. shortest
2. approaches the destination from the same y coordinate (if of equal length)
3. takes the least number of turns

现在我尝试采用启发式 (f):

manhattan distance (h) + path length (g) * number of turns (t)

这当然适用于标准 #1 和 #3,并从本质上解决了转向问题。不幸的是,现在的效率太高了,以至于最后对标准 #2 的测试不起作用,因为所探索的节点集不够大,无法重建最佳解决方案。

谁能告诉我如何将标准 #2 纳入我的启发式 (f) 中,或者如何解决这个问题?

标准 2 示例:如果目标是 (4,6) 并且通往 (3,6) 和 (4,5) 的路径长度相同,则理想解决方案应该经过 (3,6),因为它从Y 平面代替来自 X 平面的 (4,5)。然而,如果长度不相同,那么无论它接近哪个平面,都必须优先考虑最短路径。

FIRST,
The ideal path was (in order of importance):

1. shortest

My heuristic (f) was:

manhattan distance (h) + path length (g)

This was buggy because it favored paths which veered towards the target then snaked back.

SECOND,
The ideal path was:

1. shortest
2. approaches the destination from the same y coordinate (if of equal length)

My heuristic stayed the same. I checked for the second criteria at the end, after reaching the target. The heuristic was made slightly inefficient (to fix the veering problem) which also resulted in the necessary adjacent coordinates always being searched.

THIRD,
The ideal path:

1. shortest
2. approaches the destination from the same y coordinate (if of equal length)
3. takes the least number of turns

Now I tried making the heuristic (f):

manhattan distance (h) + path length (g) * number of turns (t)

This of course works for criteria #1 and #3, and fixes the veering problem inherently. Unfortunately it's now so efficient that testing for criteria #2 at the end is not working because the set of nodes explored is not large enough to reconstruct the optimal solution.

Can anyone advise me how to fit criteria #2 into my heuristic (f), or how else to tackle this problem?

CRITERIA 2 example: If the goal is (4,6) and the paths to (3,6) and (4,5) are of identical length, then the ideal solution should go through (3,6) because it approaches from the Y plane instead, of (4,5) which comes from the X plane. However if the length is not identical, then the shortest path must be favored regardless of what plane it approaches in.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

嗳卜坏 2025-01-10 14:08:47

您似乎对 A* 启发式感到困惑,Russell & Norvig 调用 h,部分路径成本为 g。这些共同构成了优先级 f = g + h

启发式应该是对从当前点达到目标所需成本的乐观估计。如果向上、向下、向左和向右移动并且至少需要单位成本,曼哈顿距离适合 h

但是,您的标准 2 应该位于路径成本 g 中,而不是 h 中。我不确定“从相同的 y 坐标接近目的地”到底是什么意思,但是您可以通过为所有其他方法提供无限或非常高的路径成本来禁止/惩罚进入目标节点。完全没有必要修改启发式h

到目前为止所经过的圈数也应该包含在部分路径成本g中。如果您可以廉价地计算出这样的数字,您可能希望在 h 中包含对还需要转多少圈的(乐观)估计。

You seem to be confusing the A* heuristic, what Russell & Norvig call h, with the partial path cost g. Together, these constitute the priority f = g + h.

The heuristic should be an optimistic estimate of how much it costs to reach the goal from the current point. Manhattan distance is appropriate for h if steps go up, down, left and right and take at least unit cost.

Your criterion 2, however, should go in the path cost g, not in h. I'm not sure what exactly you mean by "approaches the destination from the same y coordinate", but you can forbid/penalize entry into the goal node by giving all other approaches an infinite or very high path cost. There's strictly no need to modify the heuristic h.

The number of turns taken so far should also go in the partial path cost g. You may want to include in h an (optimistic) estimate of how many turns there are left to take, if you can compute such a figure cheaply.

初见你 2025-01-10 14:08:47

用某种 HACK 的方式回答我自己的问题。如果您知道解决此问题的更好方法,仍然对其他答案、想法、评论感兴趣。

Hacked 曼哈顿距离是向 Y 平面中最近的正方形计算的,而不是目的地本身:

dy = min(absolute_value(dy), absolute_value(dy-1));

然后在构造启发式 (f) 时:

h = hacked_manhattan_distance();
if (h < 2)
   // we are beside close to the goal
   // switch back to real distance
    h = real_manhattan_distance();

Answering my own question with somewhat of a HACK. Still interested in other answers, ideas, comments, if you know of a better way to solve this.

Hacked manhattan distance is calculated towards the nearest square in the Y plane, instead of the destination itself:

dy = min(absolute_value(dy), absolute_value(dy-1));

Then when constructing heuristic (f):

h = hacked_manhattan_distance();
if (h < 2)
   // we are beside close to the goal
   // switch back to real distance
    h = real_manhattan_distance();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文