Dijkstra 算法在寻找最短路径方面比 A* 算法更好吗?

发布于 2024-10-17 16:19:15 字数 38 浏览 1 评论 0原文

Dijkstra 算法在寻找最短路径方面比 A* 算法更好吗?

How is Dijkstra algorithm better tham A* algorithm for finding shortest path?

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

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

发布评论

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

评论(2

我只土不豪 2024-10-24 16:19:15

它并不擅长寻找最短路径。只要您对 A* 有一个可接受的启发式算法,它就会比 Dijkstra 更快地找到短路路径。

正如 Mehrad 在评论中指出的那样,如果你给它一个返回 0 的启发式函数,A* 就会降级为 Dijktras。

A* 的维基百科文章 有大量关于所有这些的好信息。

It is not better at finding the shortest path. As long as you have an admissible heuristic for A* it will find the shorted path quicker than Dijkstra's would.

And as Mehrad pointed out in the comments, A* degrades into Dijktras if you give it a heuristic function that returns 0.

The wikipedia article for A* has a ton of good information on all of this.

箹锭⒈辈孓 2024-10-24 16:19:15

如果您想找到从给定源节点到图中所有节点的最短路径,Dijkstra 比 A* 更好,因为如果您不在特定目标处停止,Dijkstra 无论如何都会覆盖整个图。与简单的 Dijkstra A* 相比,A* 是一种面向目标的算法,因此需要知道源节点和目标节点。如果您想使用 A* 算法用 N 个节点覆盖整个图,您基本上必须从源节点运行该算法 N 次。

Dijkstra 也可能更适合查找从源节点到图形的许多目标的最短路径。根据目标的位置(尤其是距源的距离)、目标的数量 M、图表的大小、A* 启发式的质量,将会存在一些盈亏平衡点,其中运行 Dijkstra 的性能比运行更好或更低M 倍 A* 算法。

编辑:受到 Matthew 正确批评评论的启发,我稍微改了一下并添加了注释:

  • Dijkstra 在寻找到所有节点的最短路径方面并不比 A* 更好。正确的是:不比 A* 差。
  • 要找到到具有 A* 的所有节点的最短路径,需要将估计到目标节点的成本的函数设置为零(因为没有目标节点)。将估计到目标节点的成本的函数设置为零,使得 A* 与 Dijkstra 相同; Dijkstra 是 A* 的特例。 怀疑的,因为非零函数是 A* 的核心。)
  • (如果函数设置为零,是否应该将该算法称为“A*”(而不仅仅是“Dijkstra”)是值得 到所有节点的最短路径,我们也可以说:Dijkstra 就足够了。 A* 的细化是没有必要的,并且对我们没有帮助。
  • 最后一句话也适用于在图中进行搜索,例如:查找标记有特定标志且最接近给定源节点的节点。由于您事先不知道目标,因此不可能定义一个函数来估计搜索节点的成本,因此 A*(狭义的非零函数)不适用。

If you want to find the shortest paths from a given source node to all nodes in a graph Dijkstra is better than A* since Dijkstra covers the whole graph anyway if you don't stop at a specific target. In contrast to simple Dijkstra A* is a goal-oriented algorithms and therefore needs to know both source and target node. If you wanted to cover the whole graph with N nodes with an A* algorithm you basically have to run the algorithm N times from the source node.

Dijkstra might also be better for finding the shortest paths from a source node to many targets of the graph. Depending on the location of the targets (especially distance from the source), number of targets M, size of the graph, quality of the A* heuristic there will be some break-even point where running one Dijkstra is better or less performant than running M times the A* algorithm.

Edit: Inspired by Matthew's correct critical comment I rephrase a bit and add remarks:

  • Dijkstra is not better in finding the shortest paths to all nodes than A*. Correct would be: It's not worse than A*.
  • To find the shortest paths to all nodes with A* one would set the function which estimates the costs to the target node to zero (since there is no target node). Setting the function which estimates the costs to the target node to zero makes A* identical with Dijkstra; Dijkstra is a special case of A*. (It's questionable if one should call the algorithm still "A*" (and not simply "Dijkstra") if the function is set to zero, because having a non-zero function is the core of A*.)
  • When we try to find the shortest path to all nodes, we could also say: Dijkstra is sufficient. The refinement of A* is not necessary and doesn't help us here.
  • The last remark is also true for searching in a graph, for instance: Find the node marked with a specific flag which is closest to a given source node. Since you don't know the target in advance it's not possible to define a function which estimates the costs to the searched node, thus A* (in the narrower sense of a non-zero function) is not applicable.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文