Bellman Ford算法中的负重周期检测

发布于 2025-02-10 06:20:15 字数 446 浏览 2 评论 0 原文

在Bellman Ford的最短路径发现算法中,测试如何“ VD> Ud + W(U,V)”检测负重的周期?有人可以用例子解释吗?

pseudocode:

“

来源:

In the Bellman Ford's Algorithm for shortest path finding, how is the test "v.d > u.d + w(u,v)" detecting cycles of negative weight? Could someone explain it with an example?

Pseudocode:

enter image description here

Source: https://www2.hawaii.edu/~suthers/courses/ics311f20/Notes/Topic-18.html

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

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

发布评论

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

评论(1

够运 2025-02-17 06:20:15

考虑此图,其中1是启动顶点。 N-1 = 2回合边缘松弛后,每个节点的最短距离为[0,-1,-2]。如果该图不包含负周期,则必须完成最短的距离,因为没有长度> = n 的最短路径。但是,考虑重量-1的边缘(3,1)。即使在2轮放松之后,我们也可以再放松这个边缘。这意味着有最短的路径,长度 n 。这意味着有一个负周期。

enter image description here

Consider this graph where 1 is the starting vertex. After n-1=2 rounds of edge relaxations, shortest distances to each node is [0,-1,-2]. If the graph does not contain negative cycles, shortest distances must be finalised as there is no shortest path with length >= n. However, consider the edge (3,1) with weight -1. We can relax this edge one more time, even after the 2 rounds of relaxation. That means there is a shortest path with length n. That means there is a negative cycle.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文