为什么不Dijkstra算法工作负重量的边缘?

编程入门 行业动态 更新时间:2024-10-19 11:45:58
本文介绍了为什么不Dijkstra算法工作负重量的边缘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有人可以告诉我为什么Dijkstra算法单源最短路径假定边缘必须是非负的。

Can somebody tell me why Dijkstra's algorithm for single source shortest path assumes that the edges must be non-negative.

我说的只是边缘不是负重量周期。

I am talking about only edges not the negative weight cycles.

推荐答案

回想一下,在Dijkstra算法,一旦顶点被标记为关闭(进出开集的) - 算法找到最短路径它,然后将永远不会再开发这个节点 - 它假定开发这条道路的路径是最短的。

Recall that in Dijkstra's algorithm, once a vertex is marked as "closed" (and out of the open set) - the algorithm found the shortest path to it, and will never have to develop this node again - it assumes the path developed to this path is the shortest.

但随着负权重 - 这可能不是真的。例如:

But with negative weights - it might not be true. For example:

A / \ / \ / \ 5 2 / \ B--(-10)-->C V={A,B,C} ; E = {(A,C,2), (A,B,5), (B,C,-10)}

Dijkstra算法从A将首先开发C,稍后会无法找到 A-> B-&GT的温度

修改深一点的解释:

请注意,这是重要的,因为在每一个放松步骤中,算法假定的成本,以关闭节点的确是最小的,并且因此下一个将被选择的节点也是最小的。

Note that this is important, because in each relaxation step, the algorithm assumes the "cost" to the "closed" nodes is indeed minimal, and thus the node that will next be selected is also minimal.

它的想法是:如果我们在开这样的顶点,它的成本是最小的 - 通过添加任何的正数的任何顶点 - 在极小永远不会改变。 没有对正数的约束 - 上述假设是不正确的

The idea of it is: If we have a vertex in open such that its cost is minimal - by adding any positive number to any vertex - the minimality will never change. Without the constraint on positive numbers - the above assumption is not true.

由于我们知道每个顶点这是封闭是最小的 - 我们可以放心地做放松步骤 - 没有回头看。如果我们确实需要回头看 - 贝尔曼 - 福特提供了一个递归式的(DP这样做的)溶液

Since we do "know" each vertex which was "closed" is minimal - we can safely do the relaxation step - without "looking back". If we do need to "look back" - Bellman-Ford offers a recursive-like (DP) solution of doing so.

更多推荐

为什么不Dijkstra算法工作负重量的边缘?

本文发布于:2023-11-29 16:54:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1647008.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:算法   重量   边缘   工作   Dijkstra

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!