Professional Documents
Culture Documents
Aximum LOW: The Tao of Flow
Aximum LOW: The Tao of Flow
How to do it...
Why you want it...
Where you find it...
Maximum Flow 1
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.
Source
2 s 3
2 1 2
1 2
2 4
2
2 1
t
Sink
Maximum Flow 2
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
1 2
11
2 2
0 2
11 20
2 4
0 22 1
2 1
1 t 1
Sink
Maximum Flow 3
The Logic of Flow
Flow:
flow(u,v) edge(u,v)
-Capacity rule: edge (u,v)
0 flow(u,v) capacity(u,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 4
Maximum Flow Problem
Given a network N, find a flow f of maximum
value.
Applications:
- Traffic movement
- Hydraulic systems
- Electrical circuits
- Layout
Source
2 s 3
2 2
2 11 2
1 1
11 21
2 4
1 22 0
2 1
2 t 1
Sink
Example of Maximum Flow
Maximum Flow 5
Augmenting Flow
2 s 2
2 1 A network with a flow
1 of value 3
1
2 2
1 t 2
s
2
2 Augmenting
1 path
0
2
2 t
2 s 2
2 2
1
0
2 2
2 t 2
Maximum Flow 6
Augmenting Path
Forward Edges
flow(u,v) < capacity(u,v)
flow can be increased!
Backward Edges
flow(u,v) > 0
flow can be decreased!
Maximum Flow 7
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.)
Maximum Flow 8
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.
Maximum Flow 9
Finding the Maximum Flow
2 s 2 Initialize the network with
0 0 a null flow. Note the
1 capacities above the
0 edges, and the flow
2 2 below the edges.
0 t 0
2 s 2
2 0
1 Send another unit of flow
1 through the network.
2 2
1 t 1
Maximum Flow 10
Finding the Maximum Flow
s Send another unit of flow
2 2 through the network.
2 1 Note that there still ex-
1 ists an augmenting
1 path, that can proceed
2 2
backward against the
1 t 2
directed central edge.
Maximum Flow 11
Residual Network
Residual Network Nf = (V, Ef, cf, s, t)
N Nf
cf(u,v)=c(u,v)f(u,v)
v
f(u,v) v
c(u,v)
u u cf(v,u)=f(u,v)
2 s 2 s 1
2 1
2 1
1
1 1
2 2
1 2
1 t 2 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;
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]
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?
Source
Vs 2 s 3
6
4 2
X
1 6
2 4
1
8 7
Vt t
Sink
Capacity of a cut X = (Vs,Vt):
- c(X) = capacity(v,w) = (1+2+1+3) = 7
vVs
wVt
Maximum Flow 17
Maximum Flow vs.
Minimum Cut
(value of maximum flow)
=
(capacity of minimum cut)
Source
Vs 22 s 3 3
62
41 20
X
11 6 3
22 40
1 1
83 73
Vt t
Sink
Source
Vs 22 s 3 3
62
41 20
X
11 6 3
22 40
1 1
83 73
Vt t
Sink
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|.
s 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.
Maximum Flow 20