I've tried to solve a question about the maximum-flow problem. I have one source and two sinks. I need to find a maximum flow in this network. This part is general max-flow. However, both targets have to get same amount of flow in this special version of the max-flow problem.
Is there anyone who can help me what should I do to do that?
Let s
be your source vertex and t1
and t2
the two sinks.
You can use the following algorithm:
Use regular max-flow with two sinks, for example by connecting
t1
andt2
to a super-sink via edges with infinite capacities. You now have the solution with maximumexcess(t1) + excess(t2)
, but it might be imbalanced.If
excess(t1) == excess(t2)
, you are done. Otherwise, w.l.o.g. letexcess(t1) > excess(t2)
Run another round of max-flow with source
t1
and sinkt2
in the residual network of step 1. Restrict the flow outgoing fromt1
toc = floor((excess(t1) - excess(t2)) / 2)
, for example by introducing a super-sourceS
connected tot1
via an edge with the given capacityc
. Now,excess(t2)
is the maximum flow you can send to both sinks.If you need to reconstruct the flow values for each edge, do another round of max-flow to transport the
excess(t1) - excess(t2)
leftover units of flow back to the source.
The complexity is that of your max-flow algorithm.
If you already know how to solve max-flow with lower-bound capacities, you can also binary search the solution, resulting in complexity O(log W * f)
where W
is the solution value and f
is the max-flow complexity.
来源:https://stackoverflow.com/questions/21268613/modification-to-maximum-flow-algorithm