Sei sulla pagina 1di 82

7.

N ETWORK F LOW I

max-flow and min-cut problems


FordFulkerson algorithm
max-flow min-cut theorem
capacity-scaling algorithm
shortest augmenting paths
blocking-flow algorithm
simple unit-capacity networks
Lecture slides by Kevin Wayne
Copyright 2005 Pearson-Addison Wesley
http://www.cs.princeton.edu/~wayne/kleinberg-tardos

Last updated on 8/1/17 10:50 AM


7. N ETWORK F LOW I

max-flow and min-cut problems


FordFulkerson algorithm
max-flow min-cut theorem
capacity-scaling algorithm
shortest augmenting paths
blocking-flow algorithm
simple unit-capacity networks
SECTION 7.1
Flow network

A flow network is a tuple G = (V, E, s, t, c).


Digraph (V, E) with source s V and sink t V.
Non-negative capacity c(e) for each e E.

Intuition. Material flowing through a transportation network;


material originates at source and is sent to sink.

capacity
9

4 15 15 10
10

s 5 8 10 t

15
4 6 15 10

16
3
Minimum-cut problem

Def. An st-cut (cut) is a partition (A, B) of the vertices with s A and t B.

Def. Its capacity is the sum of the capacities of the edges from A to B.

cap(A, B) = c(e)
e Qmi Q7 A

10

s 5 t

15

capacity = 10 + 5 + 15 = 30
4
Minimum-cut problem

Def. An st-cut (cut) is a partition (A, B) of the vertices with s A and t B.

Def. Its capacity is the sum of the capacities of the edges from A to B.

cap(A, B) = c(e)
e Qmi Q7 A

10

s 8 t

dont include edges


from B to A

16
capacity = 10 + 8 + 16 = 34
5
Minimum-cut problem

Def. An st-cut (cut) is a partition (A, B) of the vertices with s A and t B.

Def. Its capacity is the sum of the capacities of the edges from A to B.

cap(A, B) = c(e)
e Qmi Q7 A

Min-cut problem. Find a cut of minimum capacity.

10

s 8 t

10

capacity = 10 + 8 + 10 = 28
6
Maximum-flow problem

Def. An st-flow (flow) f is a function that satisfies:


For each e E : 0 f (e) c(e) [capacity]
For each v V {s, t} : e BM iQ v
f (e) =
e Qmi Q7 v
f (e) [flow conservation]

flow capacity

inflow at v = 5 + 5 + 0 = 10

5/9 outflow at v = 10 + 0 = 10

5 5
10 0/4 /1 0 / 15 /
10
/ 5
10

s 5/5 5/8 v 10 / 10 t

10
/ 0 0 / 15 10
15 0/4 /6 /
10

10 / 16
7
Maximum-flow problem

Def. An st-flow (flow) f is a function that satisfies:


For each e E : 0 f (e) c(e) [capacity]
For each v V {s, t} : e BM iQ v
f (e) =
e Qmi Q7 v
f (e) [flow conservation]

Def. The value of a flow f is: val(f ) = f (e) f (e)


e Qmi Q7 s e BM iQ s

5/9

5 5
10 0/4 /1 0 / 15 /
10
/ 5
10

s 5/5 5/8 10 / 10 t

10
/ 0 0 / 15 10
15 0/4 /6 /
10

value = 5 + 10 + 10 = 25
10 / 16
8
Maximum-flow problem

Def. An st-flow (flow) f is a function that satisfies:


For each e E : 0 f (e) c(e) [capacity]
For each v V {s, t} : e BM iQ v
f (e) =
e Qmi Q7 v
f (e) [flow conservation]

Def. The value of a flow f is: val(f ) = f (e) f (e)


e Qmi Q7 s e BM iQ s

Max-flow problem. Find a flow of maximum value.

8/9

2 8
10 0/4 /1 0 / 15 /
10
/ 5
10

s 5/5 8/8 10 / 10 t

13
/ 3 0 / 15 10
15 0/4 /6 /
10

value = 10 + 5 + 13 = 28
13 / 16
9
7. N ETWORK F LOW I

max-flow and min-cut problems


FordFulkerson algorithm
max-flow min-cut theorem
capacity-scaling algorithm
shortest augmenting paths
blocking-flow algorithm
simple unit-capacity networks
SECTION 7.1
Towards a max-flow algorithm

Greedy algorithm.
Start with f (e) = 0 for each edge e E.
Find an st path P where each edge has f (e) < c(e).
Augment flow along path P.
Repeat until you get stuck.

flow capacity
flow network G and flow f

0/4

0
0 /
10 0/2 /8 0/6 10
/
0 value of flow

s 0 / 10 0/9 0 / 10 t 0

11
Towards a max-flow algorithm

Greedy algorithm.
Start with f (e) = 0 for each edge e E.
Find an st path P where each edge has f (e) < c(e).
Augment flow along path P.
Repeat until you get stuck.

flow network G and flow f

0/4

8
0
0 /
8 10 0/2 /8 0/6 10
/
0

8
s 0 / 10 0/9
0 / 10 t 0 +8=8

12
Towards a max-flow algorithm

Greedy algorithm.
Start with f (e) = 0 for each edge e E.
Find an st path P where each edge has f (e) < c(e).
Augment flow along path P.
Repeat until you get stuck.

flow network G and flow f

0/4

0
8 /
10 10 2
0/2 /8 0/6 10
/
8

2 2
s 0 / 10
0/9
8 / 10 t 8 + 2 = 10

13
Towards a max-flow algorithm

Greedy algorithm.
Start with f (e) = 0 for each edge e E.
Find an st path P where each edge has f (e) < c(e).
Augment flow along path P.
Repeat until you get stuck.

flow network G and flow f

0/4

6

0
10 2/2 8
/8 6
0/6 /
/ 10
10

6 8
s
0 / 10
2/9 10 / 10 t 10 + 6 = 16

14
Towards a max-flow algorithm

Greedy algorithm.
Start with f (e) = 0 for each edge e E.
Find an st path P where each edge has f (e) < c(e).
Augment flow along path P.
Repeat until you get stuck.

ending flow value = 16

flow network G and flow f

0/4

6
10 2/2 8
/8 6/6 /
/ 10
10

s 6 / 10 8/9 10 / 10 t 16

15
Towards a max-flow algorithm

Greedy algorithm.
Start with f (e) = 0 for each edge e E.
Find an st path P where each edge has f (e) < c(e).
Augment flow along path P.
Repeat until you get stuck.

but max-flow value = 19

flow network G and flow f

3/4

9
10 0/2 7
/8 6/6 /
/ 10
10

s 9 / 10 9/9 10 / 10 t 19

16
Why the greedy algorithm fails

Q. Why does the greedy algorithm fail?


A. Once greedy algorithm increases flow on an edge, it never decreases it.

Ex.
The max flow is unique; flow on edge (v, w) is zero.
Greedy algorithm could choose svwt for first augmenting path.

flow network G

v 2 t

2 1 2

s 2 w

Bottom line. Need some mechanism to undo bad decision. 17


Residual network (with respect to flow f)

Original edge. e = (u, v) E. original flow network G


Flow f (e). u 6 / 17 v
Capacity c(e).
flow capacity

Reverse edge. ereverse = (v, u).


Undo flow sent.
residual
residual network Gf
capacity
Residual capacity.
u 11 v
c(e) f (e) B7 e E
cf (e) = 6
f (e) B7 e`2p2`b2 E
reverse edge

edges with positive


residual capacity

Residual network. Gf = (V, Ef , s, t, cf ). where flow on a reverse edge

Ef = {e : f (e) < c(e)} {ereverse : f (e) > 0}.


negates flow on
corresponding forward edge

Key property: f is a flow in Gf iff f + f is a flow in G.


18
Augmenting path

Def. An augmenting path is a simple st path in the residual network Gf .

Def. The bottleneck capacity of an augmenting path P is the minimum


residual capacity of any edge in P.

Key property. Let f be a flow and let P be an augmenting path in Gf .


Then, after calling AUGMENT, the resulting f is a flow and
val( f ) = val( f ) + bottleneck(Gf, P).

AUGMENT ( f, c, P)
________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

b bottleneck capacity of path P.


FOREACH edge e P
IF (e E ) f (e) f (e) + b.
ELSE f (ereverse) f (ereverse) b.
RETURN f.
________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

19
FordFulkerson algorithm

FordFulkerson augmenting path algorithm.


Start with f (e) = 0 for each edge e E.
Find an st path P in the residual network Gf .
Augment flow along path P.
Repeat until you get stuck.

FORDFULKERSON (G)
________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________
_

FOREACH edge e E : f (e) 0.


Gf residual network with respect to f.
WHILE (there exists an st path P in Gf )
f AUGMENT (f, c, P).
augmenting path
Update Gf.
RETURN f.

20
7. N ETWORK F LOW I

max-flow and min-cut problems


FordFulkerson algorithm
max-flow min-cut theorem
capacity-scaling algorithm
shortest augmenting paths
blocking-flow algorithm
simple unit-capacity networks
Section 7.2
Relationship between flows and cuts

Flow value lemma. Let f be any flow and let (A, B) be any cut. Then,
the value of the flow f equals the net flow across the cut (A, B).

val(f ) = f (e) f (e)


e Qmi Q7 A e BM iQ A

net flow across cut = 5 + 10 + 10 = 25

5/9

5 5
10 0/4 /1 0 / 15 /
10
/ 5
10

s 5/5 5/8 10 / 10 t value of flow = 25

10
/ 0 0 / 15 10
15 0/4 /6 /
10

10 / 16
22
Relationship between flows and cuts

Flow value lemma. Let f be any flow and let (A, B) be any cut. Then,
the value of the flow f equals the net flow across the cut (A, B).

val(f ) = f (e) f (e)


e Qmi Q7 A e BM iQ A

net flow across cut = 10 + 5 + 10 = 25

5/9

5 5
10 0/4 /1 0 / 15 /
10
/ 5
10

s 5/5 5/8 10 / 10 t value of flow = 25

10
/ 0 0 / 15 10
15 0/4 /6 /
10

10 / 16
23
Relationship between flows and cuts

Flow value lemma. Let f be any flow and let (A, B) be any cut. Then,
the value of the flow f equals the net flow across the cut (A, B).

val(f ) = f (e) f (e)


e Qmi Q7 A e BM iQ A

net flow across cut = (10 + 10 + 5 + 10 + 0 + 0) (5 + 5 + 0 + 0) = 25

5/9

edges from B to A
5 5
10 0/4 /1 0 / 15 /
10
/ 5
10

s 5/5 5/8 10 / 10 t value of flow = 25

10
/ 0 0 / 15 10
15 0/4 /6 /
10

10 / 16
24
Relationship between flows and cuts

Flow value lemma. Let f be any flow and let (A, B) be any cut. Then,
the value of the flow f equals the net flow across the cut (A, B).

val(f ) = f (e) f (e)


e Qmi Q7 A e BM iQ A

Pf. val(f ) = f (e) f (e)


e Qmi Q7 s e BM iQ s

by flow conservation, all terms


except for v = s are 0 = f (e) f (e)
v A e Qmi Q7 v e BM iQ v

val(f ) = f (e) f (e)


e Qmi Q7 A e BM iQ A

25
Relationship between flows and cuts

Weak duality. Let f be any flow and (A, B) be any cut. Then, v( f ) cap(A, B).
Pf.
val(f ) = f (e) f (e)
e Qmi Q7 A e BM iQ A

f (e)
flow-value
lemma e Qmi Q7 A

c(e)
e Qmi Q7 A

= cap(A, B)

8/9

2 8
/1 /
10 0/4 5 0 / 15 10
/ 10
10

s 5/5 7/8 9 / 10 t s 5 t

12
2
/
15 0/4 /6 0 / 15 10 15
/
10

12 / 16

value of flow = 27 capacity of cut = 30 26


Certificate of optimality

Corollary. Let f be a flow and let (A, B) be any cut.


If val( f ) = cap(A, B), then f is a max flow and (A, B) is a min cut.

weak duality
Pf.
For any flow f , val(f ) cap(A, B) = val(f ).
For any cut (A, B), cap(A, B) val(f ) = cap(A, B).

8/9

2 8
/1 /
10 0/4 5 0 / 15 10
/ 10
10

s 5/5 8/8 10 / 10 t s 8 t

13
3
/
15 0/4 /6 0 / 15 10
/ 10
10

13 / 16

value of flow = 28 = capacity of cut = 28 27


Max-flow min-cut theorem

Augmenting path theorem. A flow f is a max flow iff no augmenting paths.


Max-flow min-cut theorem. Value of a max flow = capacity of a min cut.

Pf. The following three conditions are equivalent for any flow f :
i. There exists a cut (A, B) such that cap(A, B) = val(f ).
ii. f is a max flow.
if FordFulkerson terminates,
iii. There is no augmenting path with respect to f. then f is max flow

[i ii ]
Suppose that (A, B) is a cut such that cap(A, B) = val(f ).
Then, for any flow f , val(f ) cap(A, B) = val(f ).
Thus, f is a max flow.
weak duality by assumption

28
Max-flow min-cut theorem

Augmenting path theorem. A flow f is a max flow iff no augmenting paths.


Max-flow min-cut theorem. Value of a max flow = capacity of a min cut.

Pf. The following three conditions are equivalent for any flow f :
i. There exists a cut (A, B) such that cap(A, B) = val(f ).
ii. f is a max flow.
iii. There is no augmenting path with respect to f.

[ ii iii ] We prove contrapositive: ~iii ~ii.


Suppose that there is an augmenting path with respect to f.
Can improve flow f by sending flow along this path.
Thus, f is not a max flow.

29
Max-flow min-cut theorem

[ iii i]
Let f be a flow with no augmenting paths.
Let A be set of nodes reachable from s in residual network Gf.
By definition of cut A, s A.
By definition of flow f, t A. edge e = (v, w) with v B, w A
must have f(e) = 0
original flow network G
val(f ) = f (e) f (e)
A B
e Qmi Q7 A e BM iQ A

flow-value
lemma = c(e) t

e Qmi Q7 A

= cap(A, B) s

edge e = (v, w) with v A, w B


must have f(e) = c(e)

30
7. N ETWORK F LOW I

max-flow and min-cut problems


FordFulkerson algorithm
max-flow min-cut theorem
capacity-scaling algorithm
shortest augmenting paths
blocking-flow algorithm
simple unit-capacity networks
SECTION 7.3
Analysis (when capacities are integral)

Assumption. Capacities are integers between 1 and C.

Integrality invariant. Throughout the algorithm, the flow values f (e)


and the residual capacities cf (e) are integers.

Theorem. The algorithm terminates in at most val (f *) n C iterations,


where f * is a max flow.
Pf. Each augmentation increases the flow value by at least 1.

Corollary. The running time of FordFulkerson is O(m n C).


Corollary. If C = 1, the running time of FordFulkerson is O(m n).

Integrality theorem. Then exists a max flow f * for which every


flow value f *(e) is an integer.
Pf. Since algorithm terminates, theorem follows from invariant.

32
Bad case for FordFulkerson

Q. Is generic FordFulkerson algorithm poly-time in input size?


m, n, and log C

A. No. If max capacity is C, then algorithm can take C iterations.


svwt
swvt each augmenting path
sends only 1 unit of flow
svwt (# augmenting paths = 2C)

swvt

svwt v C t

swvt
C 1 C

s C w

33
Choosing good augmenting paths

Use care when selecting augmenting paths.


Some choices lead to exponential algorithms.
Clever choices lead to polynomial algorithms.
If capacities are irrational, algorithm not guaranteed to terminate
(or converge to correct answer)!

Goal. Choose augmenting paths so that:


Can find augmenting paths efficiently.
Few iterations.

34
Choosing good augmenting paths

Choose augmenting paths with:


Max bottleneck capacity (fattest).
Sufficiently large bottleneck capacity.
Fewest edges.

Theoretical Improvements in Algorithmic Efficiency


for Network Flow Problems

JACK EDMONDS

University of Waterloo, Waterloo, Ontario, Canada


AND

RICHARD M. K A R P

University of California, Berkeley, California

ABSTRACT. This paper presents new algorithms for t h e m a x i m u m flow problem, the Hitchcock
t r a n s p o r t a t i o n problem, and t h e general m i n i m u m - c o s t flow problem. U p p e r bounds on the
numbers of steps in these algorithms are derived, and are shown to compale favorably with
upper bounds on t h e numbers of steps required by earlier algorithms.
First, the paper states the m a x i m u m flow problem, gives the F o r d - F u l k e r s o n labeling method
for its solution, and points out t h a t an improper choice of flow a u g m e n t i n g p a t h s can lead to

Edmonds-Karp 1972 (USA)


severe c o m p u t a t i o n a l difficulties. T h e n rules of choice t h a t avoid these difficulties are given.
We show t h a t , if each flow a u g m e n t a t i o n is made along an a u g m e n t i n g p a t h h a v i n g a minimum Dinitz 1970 (Soviet Union)
n u m b e r of arcs, t h e n a m a x i m u m flow in an n-node network will be o b t a i n e d a f t e r no more t h a n
~(n a - n) a u g m e n t a t i o n s ; and t h e n we show t h a t if each flow change is chosen to produce a
m a x i m u m increase in the flow value then, provided the capacities are integral, a m a x i m u m flow
will be d e t e r m i n e d within at most 1 + logM/(M--1) if(t, S) a u g m e n t a t i o n s , wheref*(t, s) is the
value of the maximum flow and M is the m a x i m u m n u m b e r of arcs across a cut.
Next a new algorithm is given for the m i n i m u m - c o s t flow problem, in which all s h o r t e s t - p a t h
c o m p u t a t i o n s are performed on networks with all weights nonnegative. In particular, this
a l g o r i t h m solves the n X n assigmnent problem in O(n3) steps. Following t h a t we explore a invented in response to a class
" s c a l i n g " technique for solving a minimum-cost flow problem by t r e a t i n g a sequence of derived
problems w i t h "scaled d o w n " capacities. It is shown t h a t , using this technique, the solution of exercises by Adelson-Velski
a I i i t c h c o c k t r a n s p o r t a t i o n problem w i t h m sources and n sinks, m ~ n, and m a x i m u m flow B,
requires at most (n + 2) log2 (B/n) flow a u g m e n t a t i o n s . Similar results are also given for the
general minimum-cost flow problem. 35
An a b s t r a c t s t a t i n g the main results of the present paper was presented at the Calgary
Capacity-scaling algorithm

Intuition. Choose augmenting path with highest bottleneck capacity:


it increases flow by max possible amount in given iteration.
Dont worry about finding exact highest bottleneck path.
Maintain scaling parameter .
Let Gf () be the part of the residual network consisting of only
those arcs with capacity .

s s

0
0

10
10

11
11

2
2

0
0

12
12

17
17

2
2

t t

Gf Gf (), = 100 36
Capacity-scaling algorithm

CAPACITY-SCALING (G)
__________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

FOREACH edge e E : f (e) 0.


largest power of 2 C.

WHILE ( 1)
Gf () -residual network.
WHILE (there exists an st path P in Gf ())
f AUGMENT (f, c, P).
Update Gf ().
/ 2.

RETURN f.
__________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

37
Capacity-scaling algorithm: proof of correctness

Assumption. All edge capacities are integers between 1 and C.

Integrality invariant. All flow and residual capacity values are integral.

Theorem. If capacity-scaling algorithm terminates, then f is a max flow.


Pf.
By integrality invariant, when = 1 Gf () = Gf .
Upon termination of = 1 phase, there are no augmenting paths.

38
Capacity-scaling algorithm: analysis of running time

Lemma 1. The outer while loop repeats 1 + log2 C times.


Pf. Initially C / 2 < C; decreases by a factor of 2 in each iteration.

Lemma 2. Let f be the flow at the end of a -scaling phase.


Then, the max-flow value val( f ) + m . proof on next slide

Lemma 3. There are at most 2m augmentations per scaling phase.


Pf.
Let f be the flow at the end of the previous scaling phase.
Lemma 2 max-flow value val( f ) + 2 m .
Each augmentation in a -phase increases val( f ) by at least .

Theorem. The scaling max-flow algorithm finds a max flow in O(m log C)
augmentations. It can be implemented to run in O(m2 log C) time.
Pf. Follows from Lemma 1 and Lemma 3.

39
Capacity-scaling algorithm: analysis of running time

Lemma 2. Let f be the flow at the end of a -scaling phase.


Then, the max-flow value val( f ) + m .
Pf.
We show there exists a cut (A, B) such that cap(A, B) val( f ) + m .
Choose A to be the set of nodes reachable from s in Gf ().
By definition of cut A, s A.
By definition of flow f, t A. edge e = (v, w) with v B, w A
must have f(e) <
original flow network

val(f ) = f (e) f (e) A B


e Qmi Q7 A e BM iQ A

t
(c(e) )
e Qmi Q7 A e BM iQ A

c(e) s
e Qmi Q7 A e Qmi Q7 A e BM iQ A

cap(A, B) m
edge e = (v, w) with v A, w B
must have f(e) > c(e)
40
7. N ETWORK F LOW I

max-flow and min-cut problems


FordFulkerson algorithm
max-flow min-cut theorem
capacity-scaling algorithm
shortest augmenting paths
blocking-flow algorithm
simple unit-capacity networks
SECTION 17.2
Shortest augmenting path

Q. Which augmenting path?


A. The one with the fewest edges.

can find via BFS

SHORTEST-AUGMENTING-PATH (G)
_________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

FOREACH e E : f (e) 0.
Gf residual network with respect to flow f.
WHILE (there exists an st path in Gf )
P BREADTH-FIRST-SEARCH (Gf ).
f AUGMENT (G, f, P).
Update Gf.
RETURN f.
_________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

42
Shortest augmenting path: overview of analysis

Lemma 1. Throughout the algorithm, the length of a shortest augmenting


path never decreases.

Lemma 2. After at most m shortest-path augmentations, the length of a


shortest augmenting path strictly increases.

Theorem. The shortest-augmenting-path algorithm runs in O(m2 n) time.


Pf.
O(m + n) time to find shortest augmenting path via BFS.
O(m) augmentations for paths of length k.
If there is an augmenting path, there is a simple one.
1 k < n
O(m n) augmentations.

43
Shortest augmenting path: analysis

Def. Given a digraph G = (V, E) with source s, its level graph is defined by:
(v) = number of edges in shortest path from s to v.
LG = (V, EG) is the subgraph of G that contains only those edges (v, w) E
with (w) = (v) + 1.

graph G

s t

level graph LG

s t

= 0 = 1 = 2 = 3
44
Shortest augmenting path: analysis

Def. Given a digraph G = (V, E) with source s, its level graph is defined by:
(v) = number of edges in shortest path from s to v.
LG = (V, EG) is the subgraph of G that contains only those edges (v, w) E
with (w) = (v) + 1.

Property. Can compute level graph in O(m + n) time.


Pf. Run BFS; delete back and side edges.

Key property. P is a shortest sv path in G iff P is an sv path LG.

level graph LG

s t

= 0 = 1 = 2 = 3
45
Shortest augmenting path: analysis

Lemma 1. The length of a shortest augmenting path never decreases.


Let f and f be flow before and after a shortest-path augmentation.
Let L and L be level graphs of Gf and Gf .
Only back edges added to Gf
(any path with a back edge is longer than previous length)

level graph L

s t

= 0 = 1 = 2 = 3

level graph L

s t
46
Shortest augmenting path: analysis

Lemma 2. After at most m shortest-path augmentations, the length of a


shortest augmenting path strictly increases.
The bottleneck edge(s) is deleted from L after each augmentation.
No new edge added to L until length of shortest path strictly increases.

level graph L

s t

= 0 = 1 = 2 = 3

level graph L

s t
47
Shortest augmenting path: review of analysis

Lemma 1. Throughout the algorithm, the length of a shortest augmenting


path never decreases.

Lemma 2. After at most m shortest-path augmentations, the length of a


shortest augmenting path strictly increases.

Theorem. The shortest-augmenting-path algorithm runs in O(m2 n) time.


Pf.
O(m + n) time to find shortest augmenting path via BFS.
O(m) augmentations for paths of length k.
If there is an augmenting path, there is a simple one.
1 k < n
O(m n) augmentations.

48
Shortest augmenting path: improving the running time

Note. (m n) augmentations necessary on some flow networks.


Try to decrease time per augmentation instead.
Simple idea O(m n2 ) [Dinitz 1970]
Dynamic trees O(m n log n) [SleatorTarjan 1983]
JOURNAL OF COMPUTER AND SYSTEM SCIENCES 26, 362-391 (1983)

A Data Structure for Dynamic Trees

DANIEL D. SLEATOR AND ROBERT ENDRE TARJAN

Bell Laboratories, Murray Hill, New Jersey 07974

Received May 8, 1982; revised October 18, 1982

A data structure is proposed to maintain a collection of vertex-disjoint trees under a


sequence of two kinds of operations: a link operation that combines two trees into one by
adding an edge, and a cut operation that divides one tree into two by deleting an edge. Each
operation requires O(log n) time. Using this data structure, new fast algorithms are obtained
for the following problems:
(1) Computing nearest common ancestors.
(2) Solving various network flow problems including finding maximum flows, blocking
flows, and acyclic flows.
(3) Computing certain kinds of constrained minimum spanning trees.
(4) Implementing the network simplex algorithm for minimum-cost flows.

The most significant application is (2); an O(mn log n)-time algorithm is obtained to find a
maximum flow in a network of n vertices and m edges, beating by a factor of log n the fastest
algorithm previously known for sparse graphs.

1. INTR~DIJCTI~N 49
7. N ETWORK F LOW I

max-flow and min-cut problems


FordFulkerson algorithm
max-flow min-cut theorem
capacity-scaling algorithm
shortest augmenting paths
blocking-flow algorithm
simple unit-capacity networks
SECTION 18.1
Blocking-flow algorithm

Two types of augmentations.


Normal: length of shortest path does not change.
Special: length of shortest path strictly increases.

Phase of normal augmentations.


Explicitly maintain level graph LG.
Start at s, advance along an edge in LG until reach t or get stuck.
If reach t, augment and and update LG.
If get stuck, delete node from LG and go to previous node.

s t

level graph LG
51
Blocking-flow algorithm

Two types of augmentations.


Normal: length of shortest path does not change.
Special: length of shortest path strictly increases.
Phase of normal augmentations.
Explicitly maintain level graph LG.
Start at s, advance along an edge in LG until reach t or get stuck.
If reach t, augment and and update LG.
If get stuck, delete node from LG and go to previous node.

advance

s t

level graph LG
52
Blocking-flow algorithm

Two types of augmentations.


Normal: length of shortest path does not change.
Special: length of shortest path strictly increases.
Phase of normal augmentations.
Explicitly maintain level graph LG.
Start at s, advance along an edge in LG until reach t or get stuck.
If reach t, augment and and update LG.
If get stuck, delete node from LG and go to previous node.

augment

s t

level graph LG
53
Blocking-flow algorithm

Two types of augmentations.


Normal: length of shortest path does not change.
Special: length of shortest path strictly increases.
Phase of normal augmentations.
Explicitly maintain level graph LG.
Start at s, advance along an edge in LG until reach t or get stuck.
If reach t, augment and and update LG.
If get stuck, delete node from LG and go to previous node.

advance

s t

level graph LG
54
Blocking-flow algorithm

Two types of augmentations.


Normal: length of shortest path does not change.
Special: length of shortest path strictly increases.
Phase of normal augmentations.
Explicitly maintain level graph LG.
Start at s, advance along an edge in LG until reach t or get stuck.
If reach t, augment and and update LG.
If get stuck, delete node from LG and go to previous node.

retreat

s t

level graph LG
55
Blocking-flow algorithm

Two types of augmentations.


Normal: length of shortest path does not change.
Special: length of shortest path strictly increases.
Phase of normal augmentations.
Explicitly maintain level graph LG.
Start at s, advance along an edge in LG until reach t or get stuck.
If reach t, augment and and update LG.
If get stuck, delete node from LG and go to previous node.

advance

s t

level graph LG
56
Blocking-flow algorithm

Two types of augmentations.


Normal: length of shortest path does not change.
Special: length of shortest path strictly increases.
Phase of normal augmentations.
Explicitly maintain level graph LG.
Start at s, advance along an edge in LG until reach t or get stuck.
If reach t, augment and and update LG.
If get stuck, delete node from LG and go to previous node.

augment

s t

level graph LG
57
Blocking-flow algorithm

Two types of augmentations.


Normal: length of shortest path does not change.
Special: length of shortest path strictly increases.
Phase of normal augmentations.
Explicitly maintain level graph LG.
Start at s, advance along an edge in LG until reach t or get stuck.
If reach t, augment and and update LG.
If get stuck, delete node from LG and go to previous node.

advance

s t

level graph LG
58
Blocking-flow algorithm

Two types of augmentations.


Normal: length of shortest path does not change.
Special: length of shortest path strictly increases.
Phase of normal augmentations.
Explicitly maintain level graph LG.
Start at s, advance along an edge in LG until reach t or get stuck.
If reach t, augment and and update LG.
If get stuck, delete node from LG and go to previous node.

retreat

s t

level graph LG
59
Blocking-flow algorithm

Two types of augmentations.


Normal: length of shortest path does not change.
Special: length of shortest path strictly increases.
Phase of normal augmentations.
Explicitly maintain level graph LG.
Start at s, advance along an edge in LG until reach t or get stuck.
If reach t, augment and and update LG.
If get stuck, delete node from LG and go to previous node.

retreat

s t

level graph LG
60
Blocking-flow algorithm

Two types of augmentations.


Normal: length of shortest path does not change.
Special: length of shortest path strictly increases.
Phase of normal augmentations.
Explicitly maintain level graph LG.
Start at s, advance along an edge in LG until reach t or get stuck.
If reach t, augment and and update LG.
If get stuck, delete node from LG and go to previous node.

end of phase

s t

level graph LG
61
Blocking-flow algorithm

INITIALIZE (G, f ) ADVANCE (v)


_______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________ ________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

LG level-graph of Gf. IF (v = t)
P . AUGMENT(P).
GOTO ADVANCE (s). Remove saturated edges from LG.
_______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

P .
GOTO ADVANCE (s).
RETREAT (v)
_______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

IF (v = s) IF (there exists edge (v, w) LG)


STOP. Add edge (v, w) to P.
ELSE GOTO ADVANCE (w).
Delete v (and all incident edges) from LG.
Remove last edge (u, v) from P. ELSE
GOTO ADVANCE (u). GOTO RETREAT (v).
_______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________
________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

62
Blocking-flow algorithm: analysis

Lemma. A phase can be implemented to run in O(m n) time.


Pf.
Initialization happens once per phase. O(m) using BFS

At most m augmentations per phase. O(mn) per phase

(because an augmentation deletes at least one edge from LG)


At most n retreats per phase. O(m + n) per phase

(because a retreat deletes one node from LG)


At most m n advances per phase. O(mn) per phase

(because at most n advances before retreat or augmentation)

Theorem. [Dinitz 1970] The blocking-flow algorithm runs in O(mn2) time.


Pf.
By lemma, O(mn) time per phase.
At most n phases (as in shortest-augmenting-path analysis).

63
Choosing good augmenting paths: summary

year method # augmentations running time

1955 augmenting path nC O(m n C)

1970 fattest augmenting path m log (mC) O(m2 log n log (mC))

1972 capacity scaling m log C O(m2 log C)

1985 improved capacity scaling m log C O(m n log C)

1970 shortest augmenting path mn O(m2 n)

1970 blocking flow mn O(m n2 )

1983 dynamic trees mn O(m n log n )

augmenting path algorithms with m edges, n nodes and integer capacities between 1 and C

64
Maximum-flow algorithms: theory

year method worst case discovered by

1951 simplex O(m3 C) Dantzig

1955 augmenting path O(m2 C) FordFulkerson

1970 shortest augmenting path O(m3) Dinitz, EdmondsKarp

1970 fattest augmenting path O(m2 log m log( m C )) Dinitz, EdmondsKarp

1977 blocking flow O(m 5/2) Cherkassky

1978 blocking flow O(m 7/3) Galil

1983 dynamic trees O(m2 log m) SleatorTarjan

1985 improved capacity scaling O(m2 log C) Gabow

1997 length function O(m3/2 log m log C) GoldbergRao

2012 compact network O(m2 / log m) Orlin

? ? O(m) ?

max-flow algorithms for sparse digraphs with m edges, integer capacities between 1 and C

65
Maximum-flow algorithms: practice

Push-relabel algorithm (SECTION 7.4). [GoldbergTarjan 1988]


Increases flow one edge at a time instead of one augmenting path at a time.

A New Approach to the Maximum-Flow Problem

ANDREW V. GOLDBERG
Massachusetts Institute of Technology, Cambridge, Massachusetts

AND
ROBERT E. TARJAN
Princeton University, Princeton, New Jersey, and AT&T Bell Laboratories, Murray Hill, New Jersey

Abstract. All previously known efftcient maximum-flow algorithms work by finding augmenting paths,
either one path at a time (as in the original Ford and Fulkerson algorithm) or all shortest-length
augmenting paths at once (using the layered network approach of Dinic). An alternative method based
on the preflow concept of Karzanov is introduced. A preflow is like a flow, except that the total amount
flowing into a vertex is allowed to exceed the total amount flowing out. The method maintains a preflow
in the original network and pushes local flow excess toward the sink along what are estimated to be
shortest paths. The algorithm and its analysis are simple and intuitive, yet the algorithm runs as fast as
any other known method on dense.graphs, achieving an O(n)) time bound on an n-vertex graph. By
incorporating the dynamic tree data structure of Sleator and Tarjan, we obtain a version of the algorithm
running in O(nm log(n/m)) time on an n-vertex, m-edge graph. This is as fast as any known method
for any graph density and faster on graphs of moderate density. The algorithm also admits efticient
distributed and parallel implementations. A parallel implementation running in O(nlog n) time using
n processors and O(m) space is obtained. This time bound matches that of the Shiloach-Vishkin
algorithm, which also uses n processors but requires O(n) space.

Categories and Subject Descriptors: F.2.2 [Analysis of Algorithms and Problem Complexity]: Non-
numerical Algorithms and Problems; G.2.2 [Discrete Mathematics]: Graph Theory-graph algorithms; 66
Maximum-flow algorithms: practice

Warning. Worst-case running time is generally not useful for predicting or


comparing max-flow algorithm performance in practice.

Best in practice. Push-relabel method with gap relabeling: O(m 3/2).

On I m p l e m e n t i n g P u s h - R e l a b e l M e t h o d
for the M a x i m u m Flow P r o b l e m
EUROPEAN
JOURNAL
OF OPERATIONAL
Boris V. Cherkassky 1 and Andrew V. Goldberg 2 RESEARCH
ELSEVIER European Journal of Operational Research 97 (1997) 509-542
1 Central Institute for Economics and Mathematics,
Krasikova St. 32, 117418, Moscow, Russia
cher@eemi.msk.su
2 Computer Science Department, Stanford University Theory and Methodology
Stanford, CA 94305, USA
goldberg~cs. stanford, edu Computational investigations of maximum flow algorithms
Ravindra K . A h u j a a, M u r a l i K o d i a l a m b, A j a y K . M i s h r a c, J a m e s B . O r l i n d,.

A b s t r a c t . We study efficient implementations of the push-relabel method a Department t~'lndustrial and Management Engineering. Indian Institute of Technology. Kanpur, 208 016, India
for the maximum flow problem. The resulting codes are faster than the b AT& T Bell Laboratories, Holmdel, NJ 07733, USA
c KA'F-ZGraduate School of Business, University of Pittsburgh, Pittsburgh, PA 15260, USA
previous codes, and much faster on some problem families. The speedup d Sloun School of Management, Massachusetts Institute of Technology. Cambridge. MA 02139. USA
is due to the combination of heuristics used in our implementations. We
also exhibit a family of problems for which the running time of all known Received 30 August 1995; accepted 27 June 1996
methods seem to have a roughly quadratic growth rate.
Abstract

1 Introduction The maximum flow algorithm is distinguished by the long line of successive contributions researchers have made in
obtaining algorithms with incrementally better worst-case complexity. Some, but not all, of these theoretical improvements
The rnaximum flow problem is a classical combinatorial problem that comes up have produced improvements in practice. The purpose of this paper is to test some of the major algorithmic ideas developed
in a wide variety of applications. In this paper we study implementations of the in the recent years and to assess their utility on the empirical front. However, our study differs from previous studies in
several ways. Whereas previous studies focus primarily on CPU time analysis, our analysis goes further and provides 67
push-rdabel [13, 17] method for the problem.
detailed insight into algorithmic behavior. It not only observes how algorithms behave but also tries to explain why
Maximum-flow algorithms: practice

Computer vision. Different algorithms work better for some dense


problems that arise in applications to computer vision.

In IEEE Transactions on PAMI, Vol. 26, No. 9, pp. 1124-1137, Sept. 2004 p.1

An Experimental Comparison of VERMA, BATRA: MAXFLOW REVISITED 1

Min-Cut/Max-Flow Algorithms for


Energy Minimization in Vision MaxFlow Revisited:
Yuri Boykov and Vladimir Kolmogorov An Empirical Comparison of Maxflow
Algorithms for Dense Vision Problems
Abstract

After [15, 31, 19, 8, 25, 5] minimum cut/maximum flow algorithms on graphs emerged as Tanmay Verma IIIT-Delhi
an increasingly useful tool for exact or approximate energy minimization in low-level vision. tanmay08054@iiitd.ac.in Delhi, India
The combinatorial optimization literature provides many min-cut/max-flow algorithms with
Dhruv Batra TTI-Chicago
dbatra@ttic.edu Chicago, USA
dierent polynomial time complexity. Their practical eciency, however, has to date been

studied mainly outside the scope of computer vision. The goal of this paper is to provide an

experimental comparison of the eciency of min-cut/max flow algorithms for applications

in vision. We compare the running times of several standard algorithms, as well as a


Abstract

new algorithm that we have recently developed. The algorithms we study include both Algorithms for finding the maximum amount of flow possible in a network (or max-
Goldberg-Tarjan style push-relabel methods and algorithms based on Ford-Fulkerson flow) play a central role in computer vision problems. We present an empirical compari-
son of different max-flow algorithms on modern problems. Our problem instances arise
style augmenting paths. We benchmark these algorithms on a number of typical graphs
from energy minimization problems in Object Category Segmentation, Image Deconvo-
in the contexts of image restoration, stereo, and segmentation. In many cases our new lution, Super Resolution, Texture Restoration, Character Completion and 3D Segmen-
algorithm works several times faster than any of the other methods making near real-time tation. We compare 14 different implementations and find that the most popularly used
implementation of Kolmogorov [5] is no longer the fastest algorithm available, especially
performance possible. An implementation of our max-flow/min-cut algorithm is available
for dense graphs.
upon request for research purposes.

Index Terms Energy minimization, graph algorithms, minimum cut, maximum

flow, image restoration, segmentation, stereo, multi-camera scene reconstruction. 1 Introduction



Yuri Boykov is with the Computer Science Department at the University of Western Ontario, Canada,
yuri@csd.uwo.ca. Vladimir Kolmogorov is with Microsoft Research, Cambridge, England, vnk@microsoft.com.
This work was mainly done while the authors were with Siemens Corp. Research, Princeton, NJ.
Over the past two decades, algorithms for finding the maximum amount of flow possible in
a network (or max-flow) have become the workhorses of modern computer vision and ma- 68
chine learning from optimal (or provably-approximate) inference in sophisticated discrete
7. N ETWORK F LOW I

max-flow and min-cut problems


FordFulkerson algorithm
max-flow min-cut theorem
capacity-scaling algorithm
shortest augmenting paths
blocking-flow algorithm
simple unit-capacity networks
Bipartite matching

Q. Which max-flow algorithm to use for bipartite matching?


Generic augmenting path: O(m val( f * )) = O(m n).
Capacity scaling: O(m2 log C) = O(m2).
Blocking flow: O(m n2).

Q. Suggests more sophisticated algorithms are not so fast when C = 1.


A. No, just need more clever analysis!

Next. We prove that shortest-augmenting-path algorithm can be


implemented to run in O(m n1/2) time.
SIAM J. CoMavx.
Vol. 4, No. 4, December 1975

NETWORK FLOW AND TESTING GRAPH CONNECTIVITY*


SHIMON EVEN" AND R. ENDRE TARJAN:I:
Abstract. An algorithm of Dinic for finding the maximum flow in a network is described. It is
then shown that if the vertex capacities are all equal to one, the algorithm requires at most O(IV[ 1/2 IEI)
time, and if the edge capacities are all equal to one, the algorithm requires at most O(I VI 2/3. IEI) time.
Also, these bounds are tight for Dinics algorithm.
These results are used to test the vertex connectivity of a graph in O(IVI 1/z. IEI 2) time and the
edge connectivity in O(I V[ 5/3. IEI) time.

Key words. Dinics algorithm, maximum flow, connectivity, vertex connectivity, edge connec- 70
tivity
Simple unit-capacity networks

Def. A flow network is a simple unit-capacity network if:


Every edge has capacity 1.
Every node (other than s or t) has either (i) exactly one entering edge
or (ii) exactly one leaving edge (or both).

Property. Let G be a simple unit-capacity network and let f be a 01 flow,


then Gf is a simple unit-capacity network.

Ex. Bipartite matching.


1

1 1

71
Simple unit-capacity networks

Shortest-augmenting-path algorithm.
Normal augmentation: length of shortest path does not change.
Special augmentation: length of shortest path strictly increases.

Theorem. [EvenTarjan 1975] In simple unit-capacity networks, the shortest-


augmenting-path algorithm computes a maximum flow in O(m n1/2) time.
Pf.
Lemma 1. Each phase of normal augmentations takes O(m) time.
Lemma 2. After at most n1/2 phases, val( f ) val( f *) n1/2.
Lemma 3. After at most n1/2 additional augmentations, flow is optimal.

Lemma 3. After at most n1/2 additional augmentations, flow is optimal.


Pf. Each augmentation increases flow value by at least 1.

72
Simple unit-capacity networks

Phase of normal augmentations.


Explicitly maintain level graph LG.
Start at s, advance along an edge in LG until reach t or get stuck.
If reach t, augment and and update LG. delete all edges in augmenting path from LG

If get stuck, delete node from LG and go to previous node.

advance

s t

level graph LG

73
Simple unit-capacity networks

Phase of normal augmentations.


Explicitly maintain level graph LG.
Start at s, advance along an edge in LG until reach t or get stuck.
If reach t, augment and and update LG. delete all edges in augmenting path from LG

If get stuck, delete node from LG and go to previous node.

augment

s t

level graph LG

74
Simple unit-capacity networks

Phase of normal augmentations.


Explicitly maintain level graph LG.
Start at s, advance along an edge in LG until reach t or get stuck.
If reach t, augment and and update LG. delete all edges in augmenting path from LG

If get stuck, delete node from LG and go to previous node.

advance

s t

level graph LG

75
Simple unit-capacity networks

Phase of normal augmentations.


Explicitly maintain level graph LG.
Start at s, advance along an edge in LG until reach t or get stuck.
If reach t, augment and and update LG. delete all edges in augmenting path from LG

If get stuck, delete node from LG and go to previous node.

retreat

s t

level graph LG

76
Simple unit-capacity networks

Phase of normal augmentations.


Explicitly maintain level graph LG.
Start at s, advance along an edge in LG until reach t or get stuck.
If reach t, augment and and update LG. delete all edges in augmenting path from LG

If get stuck, delete node from LG and go to previous node.

advance

s t

level graph LG

77
Simple unit-capacity networks

Phase of normal augmentations.


Explicitly maintain level graph LG.
Start at s, advance along an edge in LG until reach t or get stuck.
If reach t, augment and and update LG. delete all edges in augmenting path from LG

If get stuck, delete node from LG and go to previous node.

augment

s t

level graph LG

78
Simple unit-capacity networks

Phase of normal augmentations.


Explicitly maintain level graph LG.
Start at s, advance along an edge in LG until reach t or get stuck.
If reach t, augment and and update LG. delete all edges in augmenting path from LG

If get stuck, delete node from LG and go to previous node.

end of phase

level graph LG

79
Simple unit-capacity networks: analysis

Phase of normal augmentations.


Explicitly maintain level graph LG.
Start at s, advance along an edge in LG until reach t or get stuck.
If reach t, augment and and update LG.
If get stuck, delete node from LG and go to previous node.

Lemma 1. A phase of normal augmentations takes O(m) time.


Pf.
O(m) to create level graph LG.
O(1) per edge since each edge traversed and deleted at most once.
O(1) per node since each node deleted at most once.

80
Simple unit-capacity networks: analysis

Lemma 2. After at most n1/2 phases, val( f ) val( f *) n1/2.


After n1/2 phases, length of shortest augmenting path is > n1/2.
Level graph has more than n1/2 levels.
Let 1 h n1/2 be layer with min number of nodes: | Vh | n1/2.

level graph LG for flow f

s t

V0 V1 Vh Vn1/2
81
Simple unit-capacity networks: analysis

Lemma 2. After at most n1/2 phases, val( f ) val( f *) n1/2.


After n1/2 phases, length of shortest augmenting path is > n1/2.
Level graph has more than n1/2 levels.
Let 1 h n1/2 be layer with min number of nodes: | Vh | n1/2.
Let A = {v : (v) < h} {v : (v) = h and v has 1 outgoing residual edge}.
capf (A, B) | Vh | n1/2 val( f ) val( f *) n1/2.
residual network Gf residual edges

s t

V0 V1 Vh Vn1/2
82

Potrebbero piacerti anche