Flow Network
Flow Network
As shown in the flow network given below, a source vertex has all outgoing edges
and no incoming edges, more formally we can say In_degree[source]=0 and sink
vertex has all incoming edges and no outgoing edge more formally
out_degree[sink]=0.
Also, any flow network should satisfy all the underlying conditions --
For all the vertices (except the source and the sink vertex), input flow must
be equal to output flow.
For any given edge(Ei) in the flow network, 0≤flow(Ei)≤capacity(Ei) must
hold, we can not send more flow through an edge than its capacity.
Total outflow from the source vertex must be equal to total inflow to the
sink vertex.
The underlying image represents a flow network, where the first value of each
edge represents the amount of the flow through it (which is initially set to 0) and
the second value represents the capacity of the edge.
The maximum flow is the maximal possible value of the flow of the network
where the flow is defined as, "sum of all the flow that gets produced in source s, or
sum of all the flow that gets consumed in the sink t ".
If we try to co-relate this problem with a real-life problem, we can visualize all the
edges as water pipes, where the capacity of edge (here pipe) is the maximum
amount of water that can flow through it per unit time. Where s is analogous to the
Water plant and t is analogous to the drainage plant.
It follows the conditions necessary for a flow network that more water than pipe's
capacity can't flow through it and water inflow and outflow of water at every
vertex (house) must be equal as water can't magically disappear or appear.
Maximum amount of flow that the network would allow to flow from source to
sink vertex.
Ford-Fulkerson Algorithm for finding Maximum Flow
This algorithm was developed by L.R. Ford and Dr. R. Fulkerson in 1956. Before
diving deep into the algorithms let's define two more things for better
understanding at later stages -
In the Ford-Fulkerson method, firstly we set the flow of each edge e to 0. Then we
look if an augmenting path exists between s and t. If such a path exists then we will
increase the flow along those edges.
We repeat this process until there is at least on more augmenting path in the
residual graph. Once there are no more augmenting paths maximal flow is
achieved.
Let us see what does increasing the flow along an augmenting path means. Let X
be the minimum residual capacity found among the edges of augmenting path.
Then, for every edge (u,v) in the path we do f(u,v)+=X (Forward edges) and
f(v,u)−=X (backward edges).
Now we use the above network to demonstrate how the Ford-Fulkerson method
works.
Example
We can see that the initial flow of all the paths is 0. Now we will search for an
augmenting path in the network.
Now, we will check for other possible augmenting paths, one such path can be
s→D→C→t with residual capacities as 4, 2, and 5 of which 2 is the minimum. So
we will increase a flow of 2 along the path.
One can easily observe from the figure that we can't increase the flow along paths
A→B and D→C as their flow has reached their maximum capacity. So to find
other augmenting paths, we must take care that these edges must not be part of the
path.
So we will increase the flow of 1 along the path after which our network will look
like -
Now there are no more augmenting paths possible in the network, so the maximum
flow is the total flow going out of source or total flow coming in sink i.e.
6+4=5+5=10
Applications.
In traffic movements, to find how much traffic can move from a City A to
City B.
In electrical systems, to find the maximum current that could flow the wires
without causing any short circuit.
In the water/sewage management system, to find maximum capacity of the
network.
FORD-FULKERSON (G, s, t)
1. for each edge (u, v) ∈ E [G]
2. do f [u, v] ← 0
3. f [u, v] ← 0
4. while there exists a path p from s to t in the residual network G f.
5. do cf (p)←min?{ Cf (u,v):(u,v)is on p}
6. for each edge (u, v) in p
7. do f [u, v] ← f [u, v] + cf (p)
8. f [u, v] ←-f[u,v]
example: Each Directed Edge is labeled with capacity. Use the Ford-Fulkerson algorithm to find
the maximum flow.
Solution: The left side of each part shows the residual network Gf with a shaded augmenting
path p,and the right side of each part shows the net flow f.