algorithm - Floyd-Warshall algorithm for widest path
问题描述
I've been looking through graph algorithms for weighted directed graphs, in particular Floyd's algorithm for the All Pairs Shortest Path Problem. Here is my pseudocode implementation.
Let G be a weighted directed graph with nodes {1,...,n} and adjacency matrix A. Let B_k [i, j] be the shortest path from i to j which uses intermediate nodes <= k.
input A
if i = j then set B[i, j] = 0
set B[i, j] = 0
else if i != j && there is an arc(i, j)
set B[i, j] = A[i, j]
else
set B[i, j] = infinity
#B = B0
for k = 1 to n:
for i = 1 to n:
for j = 1 to n:
b_ij = min(b_ij, b_ik + b_kj)
return B
I was wondering if this algorithm (complexity O(n^3)) could be adapted to the widest path algorithm with similar complexity:
Given a weighted, directed graph (G, W), for each pair of nodes i, j find the bandwidth of the path from i to j with greatest bandwidth. If there is no path from i to j, we return 0.
Could anyone give me a pseudocode algorithm adapting the Floyd-Warshall algorithm for the widest path problem?
解决方案
我假设路径P的带宽是P中边的最低成本。
如果你使用b_ij = max(b_ij, min(b_ik, b_kj))
而不是b_ij = min(b_ij, b_ik + b_kj)
你可以解决最宽路径问题。此外,“无路径”初始化set B[i, j] = infinity
必须更改为set B[i, j] = -infinity
.
该演示实际上与原始问题中的相同:将前 k 个顶点归纳为中间顶点。运行时间未修改:ϴ(n^3)。
推荐阅读
- c++ - QOpenGLWidget 粉碎显示
- spring - 验证可选字段的请求参数名称 - spring boot
- android - 使用带有 Firemonkey Android 的蓝牙热敏打印机打印位图
- flutter - 如何将视图放在列表视图之上?
- selenium - 如何使用 selenium 了解凭据是否有效
- laravel - Laravel Nova 使用 ->fillUsing() 忽略字段如果为空
- amazon-dynamodb - @DynamoDBAutoGeneratedKey 属性是否总是递增的?
- javascript - Android React Native 应用程序在 getUserMedia WebRTC 调用时崩溃
- c++ - How to write custom binary file handler in c++ with serialisation of custom objects?
- python - 如何创建另一个列表python的重复列表