algorithm - 在A*搜索算法中,为什么要加上g(n)?

标签 algorithm priority-queue

Per the wikipedia page

...f(n) = g(n) + h(n)

where n is the last node on the path, g(n) is the cost of the path from the start node to n, and h(n) is a heuristic that estimates the cost of the cheapest path from n to the goal.

为什么我们要考虑从起始节点到我们当前位置的路径成本?我一直在尝试实现这个算法来解决一个问题,并且一直在使用优先级队列,当我执行 g(n) + h(n) 时,它比仅使用严格的 h(n) 花费的时间更长。仅使用 h(n) 是否有意义,因为假设如果启发式算法是准确的,您只关心与目标的距离有多近?

编辑:实际上我刚刚发现我的 g(n) 函数计算错误,但逻辑上我仍然不明白为什么 g(n) + h(n) 会比 h(n) 更好。

最佳答案

了解为什么遗漏 g(n) 会导致算法不正确的一个简单方法是,实际成本永远不会进入算法。它完全依赖于启发式,只能保证是下限。

关于algorithm - 在A*搜索算法中,为什么要加上g(n)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41972765/

相关文章:

java - 遍历树找到节点

Java - 在比较器中进行排序以在优先级队列中使用

java - 使用优先级堆/比较器时输出不规则

algorithm - 诊断动态规划与优先级队列的情况

c++ - 为什么字符串中的最后一个符号在 'std::remove' 之后加倍?

algorithm - 先验算法

algorithm - 最长公共(public)子序列打印所有子序列

algorithm - 在这种情况下是否有确定 3d 位置的算法? (下图)

c++ - 指向彼此的对象的 priority_queue

Java 对象优先级队列::检查对象成员的方法?