Lecture Notes on Max-Flow Algorithms | CS 573, Study notes of Algorithms and Programming

Material Type: Notes; Class: Algorithms; Subject: Computer Science; University: University of Illinois - Urbana-Champaign; Term: Spring 1999;

Typology: Study notes

Pre 2010

Uploaded on 03/16/2009

koofers-user-0vj
koofers-user-0vj 🇺🇸

10 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Algorithms Lecture 15: Max-Flow Algorithms
A process cannot be understood by stopping it. Understanding must move
with the flow of the process, must join it and flow with it.
The First Law of Mentat, in Frank Herbert’s Dune (1965)
There’s a difference between knowing the path and walking the path.
Morpheus [Laurence Fishburne], The Matrix (1999)
15 Max-Flow Algorithms
15.1 Recap
Fix a directed graph
G
= (
V,E
)that does not contain both an edge
uv
and its reversal
vu
, and fix a
capacity function c:EIR0. For any flow function f:EIR0, the residual capacity is defined as
cf(uv) =
c(uv)f(uv)if uvE
f(vu)if vuE
0 otherwise
.
The residual graph
Gf
= (
V,Ef
), where
Ef
is the set of edges whose non-zero residual capacity is positive.
s t
10/20
0/10
10/10
0/5
10/10
5/15
5/10
5/20
0/15
s t
10
10
5
10
515 5
10
5
15
5
10
10
A flow fin a weighted graph Gand its residual graph Gf.
In the last lecture, we proved the Max-flow Min-cut Theorem: In any weighted directed graph network,
the value of the maximum (
s,t
)-flow is equal to the cost of the minimum (
s,t
)-cut. The proof of the
theorem is constructive. If the residual graph contains a path from
s
to
t
, then we can increase the flow
by the minimum capacity of the edges on this path, so we must not have the maximum flow. Otherwise,
we can define a cut (
S,T
)whose cost is the same as the flow
f
, such that every edge from
S
to
T
is
saturated and every edge from
T
to
S
is empty, which implies that
f
is a maximum flow and (
S,T
)is a
minimum cut.
s t
10
10
5
10
515 5
10
5
15
5
10
10
s t
10/20
5/10
5/10
5/5
10/10
5/15
0/10
10/20
0/15
An augmenting path in Gfand the resulting (maximum) flow f0.
1
pf3
pf4
pf5

Partial preview of the text

Download Lecture Notes on Max-Flow Algorithms | CS 573 and more Study notes Algorithms and Programming in PDF only on Docsity!

A process cannot be understood by stopping it. Understanding must move with the flow of the process, must join it and flow with it. — The First Law of Mentat, in Frank Herbert’s Dune (1965)

There’s a difference between knowing the path and walking the path. — Morpheus [Laurence Fishburne], The Matrix (1999)

15 Max-Flow Algorithms

15.1 Recap

Fix a directed graph G = ( V , E ) that does not contain both an edge u  v and its reversal v  u , and fix a

capacity function c : E → IR≥ 0. For any flow function f : E → IR≥ 0 , the residual capacity is defined as

cf ( u  v ) =

c ( u  v ) − f ( u  v ) if u  v ∈ E

f ( v  u ) if v  u ∈ E

0 otherwise

The residual graph Gf = ( V , Ef ), where Ef is the set of edges whose non-zero residual capacity is positive.

s t

10/

0/

10/

0/

10/

5/

5/

5/

0/ s t 10

10

5

10

15 5 5

10 5

15

5

10 10

A flow f in a weighted graph G and its residual graph Gf.

In the last lecture, we proved the Max-flow Min-cut Theorem: In any weighted directed graph network, the value of the maximum ( s , t ) -flow is equal to the cost of the minimum ( s , t ) -cut. The proof of the theorem is constructive. If the residual graph contains a path from s to t , then we can increase the flow by the minimum capacity of the edges on this path, so we must not have the maximum flow. Otherwise, we can define a cut ( S , T ) whose cost is the same as the flow f , such that every edge from S to T is saturated and every edge from T to S is empty, which implies that f is a maximum flow and ( S , T ) is a minimum cut.

s t 10

10

5

10

15 5 5

10 5

15

5

10 10 s t

10/

5/

5/

5/

10/

5/

0/

10/

0/

An augmenting path in Gf and the resulting (maximum) flow f ′.

15.2 Ford-Fulkerson

It’s not hard to realize that this proof translates almost immediately to an algorithm, first developed by Ford and Fulkerson in the 1950s: Starting with the zero flow, repeatedly augment the flow along any path st in the residual graph, until there is no such path. If every edge capacity is an integer, then every augmentation step increases the value of the flow by a positive integer. Thus, the algorithm halts after | f ∗| iterations, where f ∗^ is the actual maximum flow. Each iteration requires O ( E ) time, to create the residual graph Gf and perform a whatever-first-search

to find an augmenting path. Thus, in the words case, the Ford-Fulkerson algorithm runs in O ( E | f ∗|)

time. If we multiply all the capacities by the same (positive) constant, the maximum flow increases everywhere by the same constant factor. It follows that if all the edge capacities are rational , then the Ford-Fulkerson algorithm eventually halts. However, if we allow irrational capacities, the algorithm can loop forever, always finding smaller and smaller augmenting paths. Worse yet, this infinite sequence of augmentations may not even converge to the maximum flow! Perhaps the simplest example of this effect was discovered by Uri Zwick. Consider the graph shown below, with six vertices and nine edges. Six of the edges have some large integer capacity X , two have capacity 1, and one has capacity φ = (

p 5 − 1 ) / 2 ≈ 0 .618034, chosen so that 1 − φ = φ^2. To prove that the Ford-Fulkerson algorithm can get stuck, we can watch the residual capacities of the three horizontal edges as the algorithm progresses. (The residual capacities of the other six edges will always be at least X − 3.)

t

s X (^) X X

X X X

1 1 ϕ

A B C Uri Zwick’s non-terminating flow example, and three augmenting paths.

The Ford-Fulkerson algorithm starts by choosing the central augmenting path, shown in the large figure above. The three horizontal edges„ in order from left to right, now have residual capacities 1, 0, φ. Suppose inductively that the horizontal residual capacities are φk −^1 , 0, φk^ for some non-negative integer k.

  1. Augment along B , adding φk^ to the flow; the residual capacities are now φk +^1 , φk , 0.
  2. Augment along C , adding φk^ to the flow; the residual capacities are now φk +^1 , 0, φk.
  3. Augment along B , adding φk +^1 to the flow; the residual capacities are now 0, φk +^1 , φk +^2.
  4. Augment along A , adding φk +^1 to the flow; the residual capacities are now φk +^1 , 0, φk +^2.

15.4 Dinits/Edmonds-Karp: Short Pipes

The second Edmonds-Karp heuristic was actually proposed by Ford and Fulkerson in their original max-flow paper, and first analyzed by the Russian mathematician Dinits (sometimes transliterated Dinic) in 1970. Edmonds and Karp published their independent and slightly weaker analysis in 1972. So naturally, almost everyone refers to this algorithm as ‘Edmonds-Karp’.^2

Choose the augmenting path with fewest edges.

The correct path can be found in O ( E ) time by running breadth-first search in the residual graph. More surprisingly, the algorithm halts after a polynomial number of iterations, independent of the actual edge capacities! The proof of this upper bound relies on two observations about the evolution of the residual graph. Let fi be the current flow after i augmentation steps, let Gi be the corresponding residual graph. In particular, f 0 is zero everywhere and G 0 = G. For each vertex v , let leveli ( v ) denote the unweighted shortest path distance from s to v in Gi , or equivalently, the level of v in a breadth-first search tree of Gi rooted at s. Our first observation is that these levels can only increase over time.

Lemma 1. leveli + 1 ( v ) ≥ leveli ( v ) for all vertices v and integers i.

Proof: The claim is trivial for v = s , since leveli ( s ) = 0 for all i. Choose an arbitrary vertex v 6 = s , and

let s  · · ·  u  v be a shortest path from s to v in Gi + 1. (If there is no such path, then leveli + 1 ( v ) = ∞,

and we’re done.) Because this is a shortest path, we have leveli + 1 ( v ) = leveli + 1 ( u ) + 1, and the inductive hypothesis implies that leveli + 1 ( u ) ≥ leveli ( u ).

We now have two cases to consider. If u  v is an edge in Gi , then leveli ( v ) ≤ leveli ( u ) + 1, because

the levels are defined by breadth-first traversal.

On the other hand, if u  v is not an edge in Gi , then v  u must be an edge in the i th augmenting path.

Thus, v  u must lie on the shortest path from s to t in Gi , which implies that leveli ( v ) = leveli ( u ) − 1 ≤

leveli ( u ) + 1. In both cases, we have leveli + 1 ( v ) = leveli + 1 ( u ) + 1 ≥ leveli ( u ) + 1 ≥ leveli ( v ). É

Whenever we augment the flow, the bottleneck edge in the augmenting path disappears from the residual graph, and some other edge in the reversal of the augmenting path may (re-)appear. Our second observation is that an edge cannot appear or disappear too many times.

Lemma 2. During the execution of the Dinits/Edmonds-Karp algorithm, any edge u  v disappears from

the residual graph Gf at most V / 2 times.

Proof: Suppose u  v is in two residual graphs Gi and Gj + 1 , but not in any of the intermediate residual

graphs Gi + 1 ,... , Gj , for some i < j. Then u  v must be in the i th augmenting path, so leveli ( v ) =

leveli ( u ) + 1, and v  u must be on the j th augmenting path, so levelj ( v ) = levelj ( u ) − 1. By the previous

lemma, we have levelj ( u ) = levelj ( v ) + 1 ≥ leveli ( v ) + 1 = leveli ( u ) + 2. (^2) To be fair, Edmonds and Karp discovered their algorithm a few years before publication—getting ideas into print takes time, especially in the early 1970s—which is why some authors believe they deserve priority. I don’t buy it; Dinits also presumably discovered his algorithm a few years before its publication. (In Soviet Union, result publish you.) On the gripping hand, Dinits’s paper also described an improvement to the algorithm presented here that runs in O ( V^2 E ) time instead of O ( V E^2 ), so maybe that ought to be called Dinits’s algorithm.

In other words, the distance from s to u increased by at least 2 between the disappearance and

reappearance of u  v. Since every level is either less than V or infinite, the number of disappearances is

at most V / 2. É

Now we can derive an upper bound on the number of iterations. Since each edge can disappear at most V / 2 times, there are at most EV / 2 edge disappearances overall. But at least one edge disappears on each iteration, so the algorithm must halt after at most EV / 2 iterations. Finally, since each iteration

requires O ( E ) time, Dinits’ algorithm runs in O ( V E^2 ) time overall.