MAXIMUM FLOW
How to do it...
Why you want it...
Where you find it...
The Tao of Flow:
Let your body go with the flow.
-Madonna, Vogue
Maximum flow...because youre worth it.
-Loreal
Go with the flow, Joe.
-Paul Simon, 50 ways to leave your lover
Life is flow; flow is life.
-Ford & Fulkerson, Ford & Fulkerson Algorithm
Use the flow, Luke!
-Obi-wan Kenobi, Star Wars
Learn flow, or flunk the course
-CS16 Despot, as played by Roberto Tamassia
Maximum Flow
Flow Networks
Flow Network:
- digraph
- weights, called capacities on edges
- two distinguishes vertices, namely
- Source, s:
Vertex with no incoming edges.
- Sink, t:
Vertex with no outgoing edges.
2
2
Source
s
1
3
2
2
2
4
1
t
Sink
Maximum Flow
Capacity and Flow
Edge Capacities:
Nonnegative weights on network edges
Flow:
- Function on network edges:
0 flow capacity
flow into vertex = flow out of vertex
value: combined flow into the sink
Source
2 s 3
2
1
11
2
2
0
2
20
11
2
4
22
1
0
2
1
t
1
1
Sink
Maximum Flow
The Logic of Flow
Flow:
flow(u,v) edge(u,v)
-Capacity rule: edge (u,v)
0 flow(u,v) capacity(u,v)
-Conservation rule: vertex v s, t
flow(u,v) = flow(v,w)
uin(v)
wout(v)
-Value of flow:
|f| = flow(s,w) = flow(u,t)
wout(s)
uin(t)
Note:
- means for all
- in(v) is the set of vertices u such that there is and
edge from u to v
- out(v) is the set of vertices w such that there is an
edge from v to w
Maximum Flow
Maximum Flow Problem
Given a network N, find a flow f of maximum
value.
Applications:
- Traffic movement
- Hydraulic systems
- Electrical circuits
- Layout
11
2
2
2
1
2
1
2
2
Source
s
11
22
t
Sink
3
2
2
1
21
4
0
1
1
Example of Maximum Flow
Maximum Flow
Augmenting Flow
2
2
2
1
s
1
1
t
2
1
A network with a flow
of value 3
2
2
s
2
2
1
0
2
2
Augmenting
path
t
2
2
2
2
s
1
0
t
2
2
2
2
Voila! We have increased the flow value to 4!
But wait! Whats an augmenting path?!?
Maximum Flow
Augmenting Path
Forward Edges
flow(u,v) < capacity(u,v)
flow can be increased!
v
u
Backward Edges
flow(u,v) > 0
flow can be decreased!
v
u
Maximum Flow
Maximum Flow Theorem
A flow has maximum value
if and only if
it has no augmenting path.
Proof:
Flow is maximum No augmenting path
(The only-if part is easy to prove.)
No augmenting path Flow is maximum
(Proving the if part is more difficult.)
Maximum Flow
Ford & Fulkerson Algorithm
One day, Ford phoned his buddy Fulkerson and said,
Hey Fulk! Lets formulate an algorithm to
determine maximum flow. Fulk responded in kind
by saying, Great idea, Ford! Lets just do it! And
so, after several days of abstract computation, they
came up with the Ford Fulkerson Algorithm,
affectionately known as the Ford & Fulkerson
Algorithm.
initialize network with null flow;
Method FindFlow
if augmenting paths exist then
find augmenting path;
increase flow;
recursive call to FindFlow;
And now, for some algorithmic animation...
Maximum Flow
Finding the Maximum Flow
2
0
2
0
2
1
2
0
2
2
2
1
Maximum Flow
s
1
0
t
s
1
1
t
s
1
1
t
2
0
2
0
2
0
2
1
2
0
Initialize the network with
a null flow. Note the
capacities above the
edges, and the flow
below the edges.
Send one unit of flow
through the network.
Note the path of the
flow unit traced in red.
The incremented flow
values are in blue.
Send another unit of flow
through the network.
2
1
10
Finding the Maximum Flow
2
2
2
1
2
2
2
2
2
2
2
2
Maximum Flow
s
1
1
t
s
1
0
t
s
1
0
t
2
1
2
2
2
2
2
2
2
2
2
2
Send another unit of flow
through the network.
Note that there still exists an augmenting
path, that can proceed
backward against the
directed central edge.
Send one unit of flow
through the augmenting path. Note that
there are no more augmenting paths. That
means...
With the help of both Ford
& Fulkerson, we have
achieved this networks maximum
flow.
Is this power, or what?!?
11
Residual Network
Residual Network Nf = (V, Ef, cf, s, t)
N
Nf
v
f(u,v)
c(u,v)
cf(u,v)=c(u,v)f(u,v)
v
u
cf(v,u)=f(u,v)
In the residual network Nf, all edges (w,z) with
capacity cf(w,z) = 0 are removed.
Augmenting path in
Directed path in the
network N
residual network Nf
2
2
2
1
s
1
1
t
2
1
2
2
s
2
1
1
t
1
Augmenting paths can be found performing a
depth-first search on the residual network Nf
Maximum Flow
12
Maximum Flow Algorithm
Part I: Setup
Start with null flow:
f(u,v) = 0 (u,v)E;
Initialize residual network:
Nf = N;
Part II: Loop
repeat
search for directed path p in Nf from s to t
if (path p found)
Df = min {cf(u,v), (u,v) p};
for (each (u,v) p) do
if (forward (u,v))
f(u,v) = f(u,v) + Df;
if (backward (u,v))
f(u,v) = f(u,v) - Df;
update Nf;
until (no augmenting path);
Maximum Flow
13
Maximum Flow: Time
Complexity
And now, the moment youve all been waiting
for...the time complexity of Ford & Fulkersons
Maximum Flow algorithm. Drum roll, please!
[Pause for dramatic drum roll music]
O( F (n + m) )
where F is the maximum flow value, n is the
number of vertices, and m is the number of edges
The problem with this algorithm, however, is that it
is strongly dependent on the maximum flow value F.
For example, if F=2n the algorithm may take
exponential time.
Then, along came Edmonds & Karp...
Maximum Flow
14
Maximum Flow: Improvement
Theorem: [Edmonds & Karp, 1972]
By using BFS, Breadth First Search, a maximum
flow can be computed in time...
O((n + m) n m) =
5
O(n )
Note:
- Edmonds & Karp algorithm runs in time O(n5)
regardless of the maximum flow value.
- The worst case usually does not happen in
practice.
Maximum Flow
15
CUTS
What is a cut ?
a)a skin-piercing laceration
b)sharp lateral movement
c)opposite of paste
d)getting dropped from the team
e)frontsies on the lunch line
f)common CS16 attendence phenomenon
g)line of muscular definition
h)Computer Undergraduate Torture (e.g., CS16,
Roberto Tamassia, dbx, etc.)
i)a partition of the vertices X=(Vs,Vt), with s Vs
and t Vt
The answer is:
j)all of the above...but for the educational purposes,
well use choice i)
Maximum Flow
16
What Is A Cut?
Vs
2
4
Source
s
6
Vt
2
4
2
8
t
Sink
Capacity of a cut X = (Vs,Vt):
- c(X) = capacity(v,w) = (1+2+1+3) = 7
vVs
wVt
The cut partition (X in this case) must pass through
the entire network, and can not pass through a
vertex.
Maximum Flow
17
Maximum Flow vs.
Minimum Cut
(value of maximum flow)
=
(capacity of minimum cut)
Source
s
22
3 3
Vs
41
62
11
40
22
83
Vt
20
1 1
6 3
73
t
Sink
Value of maximum flow: 7 flow units
Capacity of minimum cut: 7 flow units
Maximum Flow
18
Finding a Minimum Cut
Let Vs be the set of vertices reached by augmenting
paths from the source s, Vt the set of remaining
vertices, and place the cut partition X accordingly.
Source
s
22
3 3
Vs
41
62
11
40
22
83
Vt
20
1 1
6 3
73
t
Sink
Hence, a minor modification of the Ford &
Fulkerson algorithm gives a minimum cut
Value of maximum flow: 7 flow units
Capacity of minimum cut: 7 flow units
Maximum Flow
19
Why is that a Minimum Cut?
Let f be a flow of value |f| and X a cut ofcapacity |X|.
Then, |f| <=|X|.
t
X
Hence, if we find a flow f* of value |f*| and a cut X*
of capacity |X*|=|f*|, then f* must be the maximum
flow and X* must be the minimum cut.
We have seen that from the flow obtained by the
Ford and Fulkerson algorithm we can construct a cut
with capacity equal to the flow value. Therefore,
- we have given an alternative proof that the Ford
and Fulkerson algorithm yields a maximum flow
- we have shown how to construct a minimum cut
Maximum Flow
20