Maximum Flow
CSC 172
SPRING 2002
LECTURE 27
Flow Networks
Digraph
Weights, called capacities, on edges
Two distinct veticiesSource, “s” (no incoming edges)
Sink, “t” (no outgoing edges)
Example
Source
s
t
Sink
2
2
2
2
2
3
1
21
1
4
2
Capacity and Flow
Edge Capacities
Non-negative 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
Example
Source
s
t
Sink
2
2
2
2
2
3
1
21
1
4
1 21
0 21
0
11
1
1
22
FormallyFlow(u,v) edge(u,v)
Capacity rule edge(u,v)
0 <= flow <= capacity
Conservation rule
uin(v) flow(u,v) = uout(v) flow(v,w)
Value rule
|f| = wout(s) flow(s,w) = uin(t) flow(u,t)
Maximum Flow Problem
Given a network N, find a flow of maximum value
ApplicationsTraffic movement
Hydraulic systems
Electrical circuits
Layout
Example
Source
s
t
Sink
2
2
2
2
2
3
1
21
1
4
2 21
1 11
1
21
0
1
22
Augmenting Path
t
s
2
2
1
12
2
2
12
1
Network with flow 3
Augmenting Path
t
s
2
2
1
12
2
2
12
1
Network with flow 3
t
s
2
2
2
10
2
Augmenting Path
Augmenting Path
t
s
2
2
1
12
2
2
12
1
Network with flow 3
t
s
2
2
2
10
2
Augmenting Path
t
s
2
2
2
12
2
2
02
2Result
Augmenting Path
Forward Edges
flow(u,v) < capacity
we can increase flow
Backward edges
flor(u,v) > 0
flow can be decreased
Max Flow Theorem
A flow has maximum value if and only if it has no augmenting path
Ford & Fulkerson Flow Algorithm
Initialize network with null flow
Method FindFlow
if augmenting path exists then
find augmenting path
increase flow
recursively call FindFlow
Finding Flow
t
s
2
2
0
12
2
0
00
0
Initialize Network
Finding Flow
t
s
2
2
0
12
2
1
11
0
Send one unit of flow through
Finding Flow
t
s
2
2
0
12
2
2
11
1
Send another unit of flow through
Finding Flow
t
s
2
2
1
12
2
2
12
1
Send another unit of flow through
Finding Flow
t
s
2
2
2
12
2
2
02
2
Send another unit of flow through
Note that there is still an augmentingPath that can proceed backwards
Finding Flow
t
s
2
2
2
12
2
2
02
2
Send another unit of flow through
Note that there are no moreAugmenting paths
Residual Network Nf
v
u c(u,v)
f(u,v)
Residual Network Nf
v
u c(u,v)
f(u,v)
v
ucf(u,v)=f(u,v)
cf(u,v)=c(u,v)-f(u,v)
Residual Network
In Nf all edges (w,z) with capacity cf(w,z)=0 are removed
Augmenting Path in N is a direct path in Nf
Augmenting paths can be found by performing a depth-first search on the residual network Nf
Finding Augmenting Path
t
s
2
2
1
12
2
2
12
1
Finding Augmenting Path
t
s
2
2
1
12
2
2
12
1
t
s
1
1
12
2
1
1