最短路径不是图中的路径

发布于 2024-09-13 17:32:04 字数 159 浏览 2 评论 0原文

我想知道是否有一种算法可以找到图中的最短路径。

假设我有一张图,其中有几条从一个顶点到另一个顶点的路径。这些路径中的两个或多个具有相同的成本。我如何标记、查找等这些顶点之间的所有最短路径?据我所知,Dijkstra 或 Bellman-Ford 算法会找到最短路径,但它们只“选择”一条。

I was wondering if there is an algorithm which would find shortest paths in graph.

Let's say that I have a graph where there are couples of path from one vertex to another. Two or more of these paths have the same cost. How can I mark, find etc all shortest paths between these vertices ? As far as I know Dijkstra or Bellman-Ford algorithms will find shortest path but they "choose" only one.

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

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

发布评论

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

评论(2

春夜浅 2024-09-20 17:32:04

Dijkstra 算法给出了所有可能的中间节点的成本,以及到达接收器的最短路径的成本。您可以通过从接收器到源(向后)进行深度优先搜索来获取从源到接收器的所有路径,其中仅当该边的成本等于从源到两个节点的最短路径。当然,您会以相反的顺序获得路径,但反转它们很容易。

Dijkstra's algorithm gives you the cost to all the possible intermediate nodes, and the cost of the shortest path to the sink. You can get all the paths from source to sink by doing a depth first search from the sink to the source (going backwards), where you traverse an edge (backwards) only if the cost of that edge is equal to the difference between cost of the shortest path from the source to the two nodes. Of course you get the paths in reverse order, but reversing them is easy.

.

淡淡離愁欲言轉身 2024-09-20 17:32:04

看看Floyd-Warshall

在计算机科学中,
Floyd–Warshall 算法(有时
称为 WFI
算法或
Roy-Floyd 算法)是一个图
寻找分析算法
加权图中的最短路径
(有上升沿或下降沿
权重)。单次执行
算法会找到长度
最短路径的(权重总和)
但在所有顶点对之间
它不返回详细信息
路径本身。该算法是一个
动态规划示例。

Take a look at Floyd-Warshall.

In computer science, the
Floyd–Warshall algorithm (sometimes
known as the WFI
Algorithm or
Roy–Floyd algorithm) is a graph
analysis algorithm for finding
shortest paths in a weighted graph
(with positive or negative edge
weights). A single execution of the
algorithm will find the lengths
(summed weights) of the shortest paths
between all pairs of vertices though
it does not return details of the
paths themselves. The algorithm is an
example of dynamic programming.

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