Maximum Flow Ford-Fulkerson Algorithm
Maximum Flow Ford-Fulkerson Algorithm
Ford-Fulkerson Algorithm
Maximum Flow Problem
How can we maximize the flow in a network from a source or set of
sources to a destination or set of destinations?
2
Network Flow
• A Network is a directed graph G
• Edges represent pipes that carry flow
• Each edge (u,v) has a maximum capacity c(u,v)
• A source node s in which flow arrives
• A sink node t out which flow leaves
Goal:
Max Flow
3
The Problem
Use a graph to model material that flows through pipe
Each edge represents one pipe , and has a capacity, which is
an upper bound on the flow rate, in units/time.
Can think of edges as pipes of different sizes.
Want to compute max rate that we can ship material from a
designated source to a designated sink.
4
What is a Flow Network?
Each edge (u,v) has a nonnegative capacity c(u,v).
If (u,v) is not in E, assume c(u,v)=0.
We have a source s, and a sink t.
Assume that every vertex v in V is on some path from s to t.
e.g., c(s,v1)=16; c(v1,s)=0; c(v2,v3)=0
5
What is a Flow in a Network?
For each edge (u,v), the flow f(u,v) is a real-valued
function that must satisfy 3 conditions:
Capacity constraint: u,v V , f (u,v ) c (u,v )
Notes:
The skew symmetry condition implies that f(u,u)=0.
We show only the positive capacity/flows in the flow network.
6
Example of a Flow:
capacity
flo
w
capacity
7
The Value of a flow
The value of a flow is given by
| f | f ( s, v) f (v, t )
vV vV
This is the total flow leaving s = the total flow arriving in t.
8
Example:
|f| = f(s, v1) + f(s, v2) + f(s, v3) + f(s, v4) + f(s, t) =
11 + 8 + 0 + 0 + 0 = 19
9
A flow in a network
We assume that there is only flow in one direction at a time.
10
Residual Networks
The residual capacity of an edge (u,v) in a network with a flow f is
given by:
c f (u , v) c(u , v) f (u , v)
11
Example of Residual Network
Flow Network:
Residual
Network:
12
Augmenting Paths
An augmenting path p is a simple path from s
to t on the residual network.
We can put more flow from s to t through p.
We call the maximum capacity by which we
can increase the flow on p the residual
capacity of p.
c f ( p ) min{c f (u , v) : (u , v) is on p}
13
Augmenting Paths
Network:
Residual
Network:
Augmenting
path The residual capacity of this augmenting path is 4.
14
Computing Max Flow
Classic Method:
Identify
augmenting path
Increase flow along that path
Repeat
15
Ford-Fulkerson Method
16
Working
Initialize the flow with its value set to zero for each edge.
So long as there exists an augmenting path between s and t, add the path to the
flow.
Update the residual graph.
If required, we must also take into consideration the reverse path. Otherwise, we
might never find the maximum flow.