I'm trying to devise an algorithm that will simulate a network of pipes with multiple sources and multiple sinks of specific capacity.
So far I have tried using the classic Ford-Fulkerson algorithm but the issue i run into is this, given the following graph:
S
|
a
/ \
B C
Given S with a source capacity of 1, and both B and C with a sink capacity of 1 - a flow will result S - a - B, saturating B to 1 and leaving C with flow 0.
I'm trying to distribute flow uniformly across the network, so that both B and C receive 0.5. Any ideas?
Thanks!
Say you have n sources s1, ..., sn with source capacities ci and m sinks t1, ..., tm. Let f = sumi ci. We want to find a feasible flow in the network where every source i has a net flow of -ci and every sink has a net flow of f / m.
We can solve this by introducing a super source S and a super sink T and connecting each of the sources i to S via an edge (si, S) of capacity ci. We connect each ti to T via an edge of capacity f / m. Then we just run max-flow with source S and sink T.
If it is not possible to push exactly f / m units of flow to each sink, it is not clear what you want to optimize, but you might find the following two approaches useful: