根据您的评论,我假设所有弧都是定向的并且容量为 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
其主体中所有 s 的列表。输出需要后处理以去除非最大流。
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
并在列表中拼接弧线。另一方面,也许您的图表足够小,这无关紧要。