Maximum Flow: Some of These Slides Are Adapted From Introduction
Maximum Flow: Some of These Slides Are Adapted From Introduction
Maximum Flow: Some of These Slides Are Adapted From Introduction
Princeton University COS 423 Theory of Algorithms Spring 2001 Kevin Wayne
Contents
Contents.
Capacity-scaling.
Network connectivity.
Bipartite matching.
Data mining.
Open-pit mining.
Airline scheduling.
Image processing.
Project selection.
Baseball elimination.
Network reliability.
Distributed computing.
Distributed computing.
10
Capacity
15
15
15
10
10
15
10
30
Flows
An s-t flow is a function f: E that satisfies:
For each e E:
f (e ) :
e in to v
4
10
Capacity
Flow
0
5
15
0
0 f(e) u(e)
f (e ) f (e )
e in to v
(conservation)
e out of v
f (e ) :
f (w, v )
w : ( w ,v ) E
e out of v
0
9
4 4
0
15
4
8
4 0
0
6
(capacity)
30
0
f (v , w )
w : ( v ,w ) E
15 0
0
10
4
10
15 0
0
10
7
5
Flows
An s-t flow is a function f: E that satisfies:
For each e E:
0 f(e) u(e)
f (e ) f (e )
e in to v
(capacity)
(conservation)
e out of v
MAX FLOW: find s-t flow that maximizes net flow out of the source.
4
10
Capacity
Flow
0
5
15
0
0
9
4 4
0
15
4
8
4 0
0
6
f (e )
e out of s
15 0
0
10
4
10
15 0
0
10
Value = 4
4
30
0
7
6
Flows
An s-t flow is a function f: E that satisfies:
For each e E:
0 f(e) u(e)
f (e ) f (e )
e in to v
(capacity)
(conservation)
e out of v
MAX FLOW: find s-t flow that maximizes net flow out of the source.
10
10
Capacity
Flow
3
5
15
11
6
9
4 4
0
15
8
8
4 0
1
6
15 0
6
10
8
10
15 0
10
10
Value = 24
4
30
11
7
7
Flows
An s-t flow is a function f: E that satisfies:
For each e E:
0 f(e) u(e)
f (e ) f (e )
e in to v
(capacity)
(conservation)
e out of v
MAX FLOW: find s-t flow that maximizes net flow out of the source.
10
10
Capacity
Flow
4
5
15
14
9
9
4 0
1
15
8
8
4 0
4
6
15 0
9
10
9
10
15 0
10
10
Value = 28
4
30
14
7
8
Networks
Network
Nodes
Arcs
Flow
voice, video,
packets
gates, registers,
processors
wires
current
joints
heat, energy
hydraulic
reservoirs, pumping
stations, lakes
pipelines
fluid, oil
financial
stocks, currency
transactions
money
highways, railbeds,
airway routes
freight,
vehicles,
passengers
sites
bonds
energy
communication
circuits
mechanical
transportation
chemical
Cuts
An s-t cut is a node partition (S, T) such that s S, t T.
u (e ) :
The capacity of an s-t cut (S, T) is:
e out of S
u (v , w ).
(v ,w ) E
v S, w T
10
15
15
15
10
10
15
10
30
Capacity = 30
10
Cuts
An s-t cut is a node partition (S, T) such that s S, t T.
u (e ) :
The capacity of an s-t cut (S, T) is:
e out of S
u (v , w ).
(v ,w ) E
v S, w T
10
15
15
15
10
10
15
10
30
Capacity = 62
11
Cuts
An s-t cut is a node partition (S, T) such that s S, t T.
u (e ) :
The capacity of an s-t cut (S, T) is:
e out of S
u (v , w ).
(v ,w ) E
v S, w T
10
15
15
15
10
10
15
10
30
Capacity = 28
12
f (e ) f (e )
e out of S
10
10
4
5
15
10
Value = 24
e in to S
e out of s
6
9
4 4
0
15
8
8
4 0
0
6
f (e )
30
10
15 0
6
10
8
10
15 0
10
10
7
13
f (e ) f (e )
e out of S
10
10
4
5
15
10
Value = 24
e in to S
e out of s
6
9
4 4
0
15
8
8
4 0
0
6
f (e )
30
10
15 0
6
10
8
10
15 0
10
10
7
14
f (e ) f (e )
e out of S
10
10
4
5
15
10
Value = 24
e in to S
e out of s
6
9
4 4
0
15
8
8
4 0
0
6
f (e )
30
10
15 0
6
10
8
10
15 0
10
10
7
15
e out of S
e in to S
Base case: S = { s }.
Inductive hypothesis: assume true for |S| < k.
consider cut (S, T) with |S| = k
S = S' { v } for some v s, t, |S' | = k-1 cap(S', T') = | f |.
adding v to S' increase cut capacity by
f (e ) f (e ) 0
e out of v
e in to v
t
v
v
s
S'
Before
After
16
f (e ) f (e )
e out of S
e in to S
f (e )
e out of S
u (e )
e out of S
4
8
cap(S, T)
s
7
6
Corollary. Let f be a flow, and let (S, T) be a cut. If |f| = cap(S, T), then
f is a max flow and (S, T) is a min cut.
17
10
10
4
5
15
15
9
9
4 0
1
15
15 0
9
10
8
8
9
10
4 0
4
6
15 0
10
10
Cut capacity = 28
30
15
Flow value = 28
18
"Good characterization."
Proof IOU.
10
10
4
5
15
15
9
9
4 0
1
15
15 0
9
10
8
8
9
10
4 0
4
6
15 0
10
10
Cut capacity = 28
30
15
Flow value = 28
19
Towards an Algorithm
Find an s-t path where each arc has u(e) > f(e) and "augment" flow
along the path.
0
4
0
10
0
4
2
0
4
0
4
0
13
0
10
Flow value = 0
20
Towards an Algorithm
Find an s-t path where each arc has u(e) > f(e) and "augment" flow
along the path.
0
4
X
0 10
10
0
4
2
0
4
0
4
X
0 10
13
X
0 10
10
Flow value = 10
21
Towards an Algorithm
Find an s-t path where each arc has u(e) > f(e) and "augment" flow
along the path.
0
4
10
10
4
5
10
10
0
4
0
4
0
4
10
13
4
5
4
5
10
10
Flow value = 14
4
5
6
13
10
10
t
22
Residual Arcs
Original graph G = (V, E).
Flow f(e).
Arc e = (v, w) E.
Capacity
v
17
Flow
11
6
Residual capacity
23
0
4
G
s
10
10
0
4
0
4
0
4
10
13
10
10
Gf
u (e ) f (e ) if e E
if e R E
f(e)
uf (e )
4
4
10
10
3
10
t
24
Augmenting Path
Augmenting path = path in residual graph.
4 0
X
4
G
s
10
10
4 X
0
4
4 X
0
4
0 4
X
4
10
X 6
13
Gf
10
10
4
4
10
10
3
10
t
25
Augmenting Path
Augmenting path = path in residual graph.
4
4
G
s
10
10
4
4
4
4
4
4
6
13
Flow value = 14
Gf
10
10
4
4
10
6
7
10
t
26
f is a max flow.
(ii)
(iii)
27
f is a max flow.
(ii)
(iii)
(i) (ii)
We show contrapositive.
Let f be a flow. If there exists an augmenting path, then we can
improve f by sending flow along path.
(ii) (iii)
Next slide.
(iii) (i)
f is a max flow.
(ii)
(iii)
(ii) (iii)
f (e )
e out of S
f (e )
e in to S
u (e )
e out of S
cap(S, T)
Original Network
29
Running Time
Assumption: all capacities are integers between 0 and U.
Invariant: every flow value f(e) and every residual capacities u f (e)
remains an integer throughout the algorithm.
Theorem: the algorithm terminates in at most | f * | nU iterations.
Corollary: if U = 1, then algorithm runs in O(mn) time.
Integrality theorem: if all arc capacities are integers, then there exists
a max flow f for which every flow value f(e) is an integer.
Note: algorithm may not terminate on some pathological instances
(with irrational capacities). Moreover, flow value may not even
converge to correct answer.
31
0
100
0
100
1 0
100
0
100
0
32
1
0
X
100
0
100
1
1 X
0
100
0
100
X
0 1
33
1
100
0
100
1 1
100
0
100
1
34
1
100
0 1
X
100
0
1 X
1
100
1 X
0
100
1
35
1
100
1
100
1 0
100
1
100
1
36
Few iterations.
(fat path)
(capacity-scaling)
(shortest path)
37
Capacity Scaling
Intuition: choosing path with highest bottleneck capacity increases
flow by max possible amount.
110
102
1
122
170
2
Gf
110
102
122
170
2
Gf (100)
38
Capacity Scaling
Intuition: choosing path with highest bottleneck capacity increases
flow by max possible amount.
39
L3. Let f be the flow at the end of a -scaling phase. Then value of the
maximum flow is at most | f | + m .
L4. There are at most 2m augmentations per scaling phase.
L3 |f*| | f | + m (2).
f (e ) f (e )
e out of S
(u (e ) )
u (e )
e out of S
e in to S
e out of S
e in to S
e out of S
e in to S
cap(S, T) - m
Original Network
41
Few iterations.
(fat path)
(capacity-scaling)
(shortest path)
42
Easy to implement.
may implement by coincidence!
Finds augmenting path with fewest number of arcs.
ShortestAugmentingPath(V, E, s, t)
FOREACH e E
f(e) 0
Gf residual graph
WHILE (there exists augmenting path)
find such a path P by BFS
f augment(f, P)
update Gf
RETURN f
43
Proof ahead.
Proof ahead.
44
=0
=1
=2
G:
s
LG :
t
=3
45
Compute in O(m+n) time using BFS, deleting back and side arcs.
=
0
=
1
=
2
=
3
L:
46
Let f and f' be flow before and after a shortest path augmentation.
path with back arc has length greater than previous length
2
L
s
=0
=1
=2
=3
L'
s
t
47
At least one arc (the bottleneck arc) is deleted from L after each
augmentation.
No new arcs added to L until length of shortest path strictly
increases.
2
L
s
=0
=1
=2
=3
L'
s
t
48
O(mn) augmentations.
Simple idea
Sleator-Tarjan, 1983
O(mn2)
49
LG
s
=0
=1
=2
=3
50
LG
augment
s
LG
delete 3
s
augment
LG
s
51
LG
augment
s
LG
s
52
advance
augment
retreat
53
54
Method
Augmenting path
Augmentations
nU
Running time
mnU
Max capacity
m log U
m log U (m + n log n)
Capacity scaling
m log U
m2 log U
m log U
mn log U
Shortest path
mn
m2n
mn
mn2
55
History
Year
Discoverer
Method
Big-Oh
1951
Dantzig
Simplex
mn2U
1955
Ford, Fulkerson
Augmenting path
mnU
1970
Edmonds-Karp
Shortest path
m2n
1970
Dinitz
Shortest path
mn2
1972
Edmonds-Karp, Dinitz
Capacity scaling
m2 log U
1973
Dinitz-Gabow
Capacity scaling
mn log U
1974
Karzanov
Preflow-push
n3
1983
Sleator-Tarjan
Dynamic trees
mn log n
1986
Goldberg-Tarjan
FIFO preflow-push
mn log (n2 / m)
...
...
...
...
Length function
1997
Goldberg-Rao
56