algorithm - 在最大流问题中,如何找到给出最大流的所有可能路径集?

标签 algorithm graph network-flow

我明白 Ford-Fulkerson Algorithm可以找到一个流网络中可以从源(s)流向汇(t)的最大流量。
但是是否有一种算法可以找到所有可能的路径集,从而提供最大流量?

一个例子:
在下面这个网络中,所有边的容量都是 1。不难看出从 st 的最大流量是 3。但是如何找到组合承载该流量的路径?

预期产出:
路径集 1:s-0-1-t、s-2-3-t、s-5-6-t
路径集 2:s-0-1-t、s-2-4-t、s-5-6-t
路径集 3:s-0-3-t、s-2-4-t、s-5-6-t
路径集 4:s-0-4-t、s-2-3-t、s-5-6-t

enter image description here

有人问了类似的问题here但似乎没有得到明确的答复。

最佳答案

根据您的评论,我假设所有弧都是有向的且容量为 1。

高级伪代码是

define EnumerateFlows(G, s, t):
    if G has no s-t path:
        yield []  # solution with no paths
    else:
        for P in EnumeratePaths(G, s, t):
            derive G' = G - P
            let s-u be the first arc in P
            derive G'' = G' - {arcs s-v such that v < u}  # ensure canonically ordered solutions only
            for F in EnumerateFlows(G'', s, t):
                yield [P, F...]  # solution with P followed by the elements of F

其中函数的返回值是函数体内所有 yield 的列表。输出需要后处理以去除非最大流。

EnumeratePaths 无疑在 Stack Overflow 上有一个解决方案,但为了完整性,

define EnumeratePaths(G, s, t):
    if s = t:
        yield [s]
    else:
        for u in {successors of s in t}:
            for P in EnumeratePaths(G - {s-u}, u, t):
                yield [s, P...]

为了改进EnumerateFlows,值得添加一个检查以确保残差图中仍然存在最大流。

至于低级实现建议,我的建议是对 G 使用邻接表表示,并在列表中和列表外拼接弧。另一方面,也许您的图表足够小以至于无关紧要。

关于algorithm - 在最大流问题中,如何找到给出最大流的所有可能路径集?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53825638/

相关文章:

algorithm - 从加权图中选择边,使得每个顶点都是一条边的端点,并且边权重之和最小

java - 应用网络流

graph - 在 O(V+E) 的图中寻找瓶颈边

algorithm - 拼图 : Find the order of n persons standing in a line (based on their heights)

sql - 在六边形区域中选择相邻单元格

algorithm - 求任意 N 个顶点之间所有路径的图算法

algorithm - 带边缘移除的寻路 : multiple paths to a destination,

python - 在 Matplotlib 中划分 x 和 y 标签

c++ - 使用 Boost Graph 读取 GraphML 文件时使用 vertex_name

algorithm - 在完全二部图中找到第二个最大加权匹配