0% found this document useful (0 votes)
14 views

Max Flow Slides

The document discusses maximum flow problems in networks. It defines flow, flow networks, and the maximum flow problem of finding the highest possible flow from a source node to a sink node. It also describes how to handle multiple sources and sinks by reducing it to a single-source single-sink problem.

Uploaded by

aryatel26
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Max Flow Slides

The document discusses maximum flow problems in networks. It defines flow, flow networks, and the maximum flow problem of finding the highest possible flow from a source node to a sink node. It also describes how to handle multiple sources and sinks by reducing it to a single-source single-sink problem.

Uploaded by

aryatel26
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 81

Maximum Flow

Revision of November 7, 2016

Maximum Flow 1 / 42
Outline

Introduction
Definitions
Multi-Source Multi-Sink

The Ford-Fulkerson Method


Residual Networks
Augmenting Paths
The Max-Flow Min-Cut Theorem
The Edmonds-Karp algorithm

Max Bipartite Matching


Odds and Ends

Maximum Flow 2 / 42
Maximum Flow

Main Reference: Sections 26.1-26.3 in CLRS.


Input: a directed graph G = (V, E) :
(flow network)
Source (producer) s and destination t.
Internal Nodes are warehouses
Edge costs are capacities
Maximum amount that can be shipped over edge
No storage at internal nodes
All goods shipped into warehouse must leave warehouse

Maximum Flow 3 / 42
Maximum Flow

Main Reference: Sections 26.1-26.3 in CLRS.


Input: a directed graph G = (V, E) :
(flow network)
Source (producer) s and destination t.
Internal Nodes are warehouses
Edge costs are capacities
Maximum amount that can be shipped over edge
No storage at internal nodes
All goods shipped into warehouse must leave warehouse
Objective:
Ship Maximum amount (flow) from s to t.
Maximum Flow 3 / 42
12
v1 v3

16

20
10
4
s t

7
9
13

4
v2 v4
14
A Flow Network and its capacities

Maximum Flow 4 / 42
12
v1 v3

16

20
10
4
s t

7
9
13

4
v2 v4
14
A Flow Network and its capacities

v 1 6/12 v3
6

8/
1

20
5/

1/4

6/7
10

s t
9
4/
6/
13

4
3/

v 2 9/14 v4

A flow: value 11

Maximum Flow 4 / 42
12
v1 v3

16

20
10
4
s t

7
9
13

4
v2 v4
14
A Flow Network and its capacities

v 1 6/12 v3 v1 12/12 v3

19
/1
6

8/

/2
11
1

20
5/

0
1/4

7/7
9
6/7
10

1/4
10
s t s t
9
4/

4
4/
12
6/

/1
13

v2 v4
3/

3
v 2 9/14 v4
11/14
A flow: value 11 A max-flow: value = 23

Maximum Flow 4 / 42
Flow Definition: I

A flow network is a graph G = (V, E) .


Source s ∈ V, , sink t ∈ V .

Every edge (u, v) ∈ E has capacity , c(u, v) ≥ 0 .


Assume that for every v ∈ V ,
there is a path from s to v and from v to t.

Maximum Flow 5 / 42
Flow Definition: II
A FLOW is a function f : V × V → R satisfying:
Capacity Constraint:
∀u, v, ∈ V, f (u, v) ≤ c(u, v).
Skew Symmetry:
∀u, v, ∈ V, f (u, v) = −f (v, u).
Flow Conservation:

∀u ∈ V − {s, t}, v∈V f (u, v) = 0.

Maximum Flow 6 / 42
Flow Definition: II
A FLOW is a function f : V × V → R satisfying:
Capacity Constraint:
∀u, v, ∈ V, f (u, v) ≤ c(u, v).
Skew Symmetry:
∀u, v, ∈ V, f (u, v) = −f (v, u).
Flow Conservation:

∀u ∈ V − {s, t}, v∈V f (u, v) = 0.


The VALUE of flow f is |f | = v∈V f (s, v) .

Maximum Flow 6 / 42
Flow Definition: II
A FLOW is a function f : V × V → R satisfying:
Capacity Constraint:
∀u, v, ∈ V, f (u, v) ≤ c(u, v).
Skew Symmetry:
∀u, v, ∈ V, f (u, v) = −f (v, u).
Flow Conservation:

∀u ∈ V − {s, t}, v∈V f (u, v) = 0.


The VALUE of flow f is |f | = v∈V f (s, v) .

MAXIMUM-FLOW PROBLEM:
Given G, c, s, t, find f that maximizes |f |.

Maximum Flow 6 / 42
Multi-Source Multi-Sink Problem

Max-Flow problem has only one source s, and one sink t.


Suppose there are
multiple sources s1 , s2 , . . . , sk and multiple sinks t1 , t2 , . . . , tℓ .

Maximum Flow 7 / 42
Multi-Source Multi-Sink Problem

Max-Flow problem has only one source s, and one sink t.


Suppose there are
multiple sources s1 , s2 , . . . , sk and multiple sinks t1 , t2 , . . . , tℓ .
Definition of a flow remains the same except that
Flow Conservation property now becomes ∑
∀u ∈ V − {s1 , s2 , . . . , sk , t1 , t2 , . . . , tℓ }, v∈V f (u, v) = 0
and our goal is to maximize
∑ k ∑
|f | = f (si , v).
i=1 v∈V

Maximum Flow 7 / 42
Multi-Source Multi-Sink Problem

Max-Flow problem has only one source s, and one sink t.


Suppose there are
multiple sources s1 , s2 , . . . , sk and multiple sinks t1 , t2 , . . . , tℓ .
Definition of a flow remains the same except that
Flow Conservation property now becomes ∑
∀u ∈ V − {s1 , s2 , . . . , sk , t1 , t2 , . . . , tℓ }, v∈V f (u, v) = 0
and our goal is to maximize
∑ k ∑
|f | = f (si , v).
i=1 v∈V

This problem can be reduced to the original one by in-


troducing a supersource s0 , a supersink t0 and edges
∪i (s0 , si ) and ∪j (tj , t0 ), all of which have capacity ∞.
Maximum Flow 7 / 42
A multi-source multi-sink problem and its equivalent single-
source single-sink version.

s1
10

12 3
s2 t1
5 15
8 6
s3 t2
14 20
7 13
s4 t3
11 18
2
s5

Maximum Flow 8 / 42
A multi-source multi-sink problem and its equivalent single-
source single-sink version.
s1
10
s1
10 12 3
s2 t1
12 3
s2 t1 5 15
5 15 8 6
8 6 s s3 t2 t
s3 t2 14 20
14 20
7 13
7 13 s4 t3
s4 t3
11 18 11 18
2 2
s5 s5

Maximum Flow 8 / 42
Manipulating Flows

Let X, Y ⊆ V. We define
∑∑
f (X, Y) = f (x, y).
x∈X y∈Y

The flow-conservation constraint then just says

∀u ∈ V − {s, t}, f (u, V) = 0.

Maximum Flow 9 / 42
Lemma: (Proof in Homework)

∀X ⊆ V, f (X, X) = 0.

∀X, Y ⊆ V, f (X, Y) = −f (Y, X).

∀X, Y, Z ⊆ V with X ∩ Y = ∅
f (X ∪ Y, Z) = f (X, Z) + f (Y, Z) and
f (Z, X ∪ Y) = f (Z, X) + f (Z, Y)

Maximum Flow 10 / 42
Flow f was defined as
amount that leaves source s.
We now see that this is the same as
amount that enters sink t.
|f | = f (s, V) definition
= f (V, V) − f (V − s, V) previous page
= −f (V − s, V) previous page
= f (V, V − s) previous page
= f (V, t) + f (V, V − s − t) previous page
= f (V, t) flow conservation

Maximum Flow 11 / 42
All optimization problems must deal with the question:
How to prove that solution is optimal (maximal/minimal)?

Maximum Flow 12 / 42
All optimization problems must deal with the question:
How to prove that solution is optimal (maximal/minimal)?

A common technique (for max problems) is to find a good


upper-bound on the cost of an optimal solution and then
show that our solution satisfies that bound.

Maximum Flow 12 / 42
All optimization problems must deal with the question:
How to prove that solution is optimal (maximal/minimal)?

A common technique (for max problems) is to find a good


upper-bound on the cost of an optimal solution and then
show that our solution satisfies that bound.
A CUT S, T of G is a partition of the vertices
V = S ∪ T, S ∩ T = ∅, s ∈ S, and t ∈ T.

Maximum Flow 12 / 42
All optimization problems must deal with the question:
How to prove that solution is optimal (maximal/minimal)?

A common technique (for max problems) is to find a good


upper-bound on the cost of an optimal solution and then
show that our solution satisfies that bound.
A CUT S, T of G is a partition of the vertices
V = S ∪ T, S ∩ T = ∅, s ∈ S, and t ∈ T.
The flow across the cut is f (S, T).

The capacity of a cut is C(S, T) = x∈S,y∈T c(x, y).
Note that for any cut, f (S, T) ≤ C(S, T).

Maximum Flow 12 / 42
12/12
v1 v3

6
/1

15
11

/2
1/4

0
7/7
10
s t

9
4/
8/
13

4
4/
v 2 11/14 v4
S T

Cut (S, T): S = {s, v1 , v2 }, T = {v3 , v4 , t}.


The flow value is |f | = 19 and C(S, T) = 26.
Note that, in this example, |f | < C(S, T).
Maximum Flow 13 / 42
Lemma:
If S, T is any cut, f any flow, then
|f | ≤ C(S, T).
Proof:

|f | = f (s, V)
= f (s, V) + f (S − s, V)
= f (S, V)
= f (S, V) − f (S, S)
= f (S, V − S)
= f (S, T)
≤ C(S, T)

We now develop the Ford-Fulkerson method for finding


max-flows. When FF terminates it provides a flow f and a
cut S, T such that |f | = C(S, T), so f is maximal.
Maximum Flow 14 / 42
The Ford-Fulkerson Method
Is iterative.
Starts with flow f = 0, (∀u, v, f (u, v) = 0)

Maximum Flow 15 / 42
The Ford-Fulkerson Method
Is iterative.
Starts with flow f = 0, (∀u, v, f (u, v) = 0)
At each step
Constructs a residual network Gf of f indicating how
much capacity “remains” to be used .
Finds an augmenting path s-t path p in Gf along which
flow can be pushed.
pushes f ′ units of flow along p.
Creates new flow f = f + f ′ .

Maximum Flow 15 / 42
The Ford-Fulkerson Method
Is iterative.
Starts with flow f = 0, (∀u, v, f (u, v) = 0)
At each step
Constructs a residual network Gf of f indicating how
much capacity “remains” to be used .
Finds an augmenting path s-t path p in Gf along which
flow can be pushed.
pushes f ′ units of flow along p.
Creates new flow f = f + f ′ .
Stops when there is no s-t path in current Gf .
S = set of nodes reachable from s in Gf & T = V − S.

Maximum Flow 15 / 42
The Ford-Fulkerson Method
Is iterative.
Starts with flow f = 0, (∀u, v, f (u, v) = 0)
At each step
Constructs a residual network Gf of f indicating how
much capacity “remains” to be used .
Finds an augmenting path s-t path p in Gf along which
flow can be pushed.
pushes f ′ units of flow along p.
Creates new flow f = f + f ′ .
Stops when there is no s-t path in current Gf .
S = set of nodes reachable from s in Gf & T = V − S.

At end of algorithm: |f | = C(S, T) ⇒ f is optimal


Maximum Flow 15 / 42
Residual networks

Given flow f , the residual network Gf consists of the edges


along which we can (still) push more flow. The amount
that can (still) be pushed across (u, v) is called the residual
capacity cf (u, v).

cf (u, v) = c(u, v) − f (u, v).

If there is flow from u to v then f (u, v) > 0 and cf (u, v) is the


remaining capacity on (u, v).

Maximum Flow 16 / 42
Residual Capacity: cf (u, v) = c(u, v) − f (u, v).

If there is flow from u to v then f (u, v) > 0


and cf (u, v) is the remaining capacity on (u, v).

Maximum Flow 17 / 42
Residual Capacity: cf (u, v) = c(u, v) − f (u, v).

If there is flow from u to v then f (u, v) > 0


and cf (u, v) is the remaining capacity on (u, v).
If there is flow from v to u then f (u, v) < 0,
and cf (u, v) = c(u, v) + f (v, u) is the capacity of (u, v)
plus amount of existing flow that can be pushed
backwards from u to v.

Maximum Flow 17 / 42
Residual Capacity: cf (u, v) = c(u, v) − f (u, v).

If there is flow from u to v then f (u, v) > 0


and cf (u, v) is the remaining capacity on (u, v).
If there is flow from v to u then f (u, v) < 0,
and cf (u, v) = c(u, v) + f (v, u) is the capacity of (u, v)
plus amount of existing flow that can be pushed
backwards from u to v.

The Residual Network Gf is Gf = (V, Ef ) where

Ef = {(u, v) ∈ V × V : cf (u, v) > 0}

Maximum Flow 17 / 42
v 1 12/12 v 3
6
/1

19
11

/ 20
1/4

7/7
10

s t
9
12

4
/1

4/
v 2 11/14 v4
3

A Flow

Maximum Flow 18 / 42
12
v 1 12/12 v 3 v1 v3
6

1
/1

19
11

11
/

19
20
1/4

11
s t
7/7
10

7
s t

9
9

1
12

4
12

4 v2 3 v4
/1

4/
v 2 11/14 v4
3

11
A Flow Its residual network

Maximum Flow 18 / 42
Lemma:

Let f be a flow in G = (V, E) and Gf its residual network.

Maximum Flow 19 / 42
Lemma:

Let f be a flow in G = (V, E) and Gf its residual network.Let


f ′ be a flow in Gf .

Define f + f ′ as (f + f ′ )(u, v) = f (u, v) + f ′ (u, v).


Then f + f ′ is a flow in G with value
|f + f ′ | = |f | + |f ′ |.

Augmenting path p is a simple s-t path in Gf .


The residual capacity of a.p. p is
cf (p) = min{cf (u, v) : (u, v) on p}.

Maximum Flow 19 / 42
Let p be an augmenting path in Gf and define

 cf (p) if (u, v) is on p
fp (u, v) = −cf (p) if (v, u) is on p

0 otherwise

Lemma: If f is a flow and p an a.p.in Gf then:


fp is a flow in Gf with |fp | = cf (p) > 0.
f ′ = f + fp is a flow in G with |f ′ | = |f | + |fp | > |f |.

Maximum Flow 20 / 42
12/12 v1 12 v3
v1 v3
16

5
15
/
11

11

15
/2

4
1/4

11
s t

7/7
10

7
s t

5
4/

4
8/

8
13

4
v2 v4

4/
v 2 11/14 v4
11
12
v 1 12/12 v 3 v1 v3
6

1
/1

19
11

11
/2

19
1/4

11
s t
7/7
10

7
s t

9
9

1
12

4
12

3
4

v2 v4
/1

4/

v 2 11/14 v4
3

11

An initial flow f .

Maximum Flow 21 / 42
12/12 v1 12 v3
v1 v3
16

5
15
/
11

11

15
/2

4
1/4

11
s t

7/7
10

7
s t

5
4/

4
8/

8
13

4
v2 v4

4/
v 2 11/14 v4
11
12
v 1 12/12 v 3 v1 v3
6

1
/1

19
11

11
/2

19
1/4

11
s t
7/7
10

7
s t

9
9

1
12

4
12

3
4

v2 v4
/1

4/

v 2 11/14 v4
3

11

An initial flow f .
Its residual network Gf and an augmenting path f ′ in Gf .

Maximum Flow 21 / 42
12/12 v1 12 v3
v1 v3
16

5
15
/
11

11

15
/2

4
1/4

11
s t

7/7
10

7
s t

5
4/

4
8/

8
13

4
v2 v4

4/
v 2 11/14 v4
11
12
v 1 12/12 v 3 v1 v3
6

1
/1

19
11

11
/2

19
1/4

11
s t
7/7
10

7
s t

9
9

1
12

4
12

3
4

v2 v4
/1

4/

v 2 11/14 v4
3

11

An initial flow f .
Its residual network Gf and an augmenting path f ′ in Gf .
The flow f + f ′ and its residual network.
Maximum Flow 21 / 42
Optimality

Theorem: (Max-Flow Min-Cut Theorem)


Let f be a flow.
Then the following three conditions are equivalent:

1 f is a maximum flow in G.

2 Gf contains no augmenting paths

3 |f | = C(S, T) for some (S, T) cut.

Maximum Flow 22 / 42
Proof:

(1) ⇒ (2): If Gf contained an augmenting path p then


|f + fp | > |f | so f could not be maximal.

Maximum Flow 23 / 42
Proof:

(1) ⇒ (2): If Gf contained an augmenting path p then


|f + fp | > |f | so f could not be maximal.
(2) ⇒ (3): Let S = {u ∈ V : ∃ path from s to v in Gf }.
T = V − S. Then
f (S, T) = f (S, V)−f (S, S) = f (S, V) = f (s, V)+f (S−s, V) = |f |.

Now note that ∀u ∈ S, v ∈ T, f (u, v) = c(u, v) since


otherwise cf (u, v) > 0 and v ∈ S.
Thus C(S, T) = f (S, T) = |f |.

Maximum Flow 23 / 42
Proof:

(1) ⇒ (2): If Gf contained an augmenting path p then


|f + fp | > |f | so f could not be maximal.
(2) ⇒ (3): Let S = {u ∈ V : ∃ path from s to v in Gf }.
T = V − S. Then
f (S, T) = f (S, V)−f (S, S) = f (S, V) = f (s, V)+f (S−s, V) = |f |.

Now note that ∀u ∈ S, v ∈ T, f (u, v) = c(u, v) since


otherwise cf (u, v) > 0 and v ∈ S.
Thus C(S, T) = f (S, T) = |f |.

(3) ⇒ (1): We previously saw that every flow f ′ must


satisfy |f ′ | ≤ C(S, T) so if |f | = C(S, T), f must be opti-
mal.
Maximum Flow 23 / 42
Theorem Proof

The Ford-Fulkerson Method

Starts with flow f ≡ 0, (∀u, v, f (u, v) = 0)

Construct residual network Gf .


If Gf contains no augmenting path, stop
(f is optimal by MFMC theorem).
Otherwise.
1 Find an augmenting path (s − t path) p in Gf
2 Let fp be the flow in Gf that pushes cf (p) units of flow
along p.
3 Let f = f + fp be new flow in G.

Maximum Flow 24 / 42
FF Example: Steps 1 & 2

v1 12
v3
16

20
10

9
4
s t

4
13

v2 14 v4

Maximum Flow 25 / 42
FF Example: Steps 1 & 2

12 v1 4/12
v1 v3 v3

61
4/

20
16

20

9
10

4/
10

4
9 s t
4

7
s t

4
4/
4

13
13

v2 14 v4 v2 v4
4/14

Maximum Flow 25 / 42
FF Example: Steps 1 & 2

12 v1 4/12
v1 v3 v3

61
4/

20
16

20

9
10

4/
10

4
9 s t
4

7
s t

4
4/
4

13
13

v2 14 v4 v2 v4
4/14
8
v1 v3
4
20
12
4

4
10

s t
4

7
5

4
13

10
v2 v4
4

Maximum Flow 25 / 42
FF Example: Steps 1 & 2

12 v1 4/12
v1 v3 v3

61
4/

20
16

20

9
10

4/
10

4
9 s t
4

7
s t

4
4/
4

13
13

v2 14 v4 v2 v4
4/14
8 4/12
v1 v3 v1 v3
4

7/
/1
20
12

20
11

7/10
4

7/7
4
10

4/
4
s t s t
4

7
5

4
4

4/
13

13
10
v2 v4 v2 v4
4 11/14

Maximum Flow 25 / 42
FF Example: Steps 2 & 3

8 4/12
v1 v3 v1 v3
4

7/
/1
20
12

2
11

0
7/10
4

7/7
4
10

4/
4
s t s t
4

7
5

4
4

4/
13

13
v2 10 v4 v2 v4
4 11/14

Maximum Flow 26 / 42
FF Example: Steps 2 & 3

8 4/12
v1 v3 v1 v3
4

7/
/1
20
12

2
11

0
7/10
4

7/7
4
10

4/
4
s t s t
4

7
5

4
4

4/
13

13
v2 10 v4 v2 v4
4 11/14

8
v1 4 v3 v1 12/12 v3

15
/1
5

13

/2
11
11

1/4

0
7

9
11
4

7/7
4/
s
3

10
s t
7
5

4
4

4/
13

8/

3
13

v2 v4 v2 v4
11 11/14

Maximum Flow 26 / 42
FF Example: Steps 3 & 4

8
v1 4 v3 v1 12/12 v3

15
/1
5

13

/2
11
11

1/4

0
7

9
11
4

7/7
4/
s
3

10
s t

7
5

4
4

4/
13

8/
3

13
v2 v4 v2 v4
11 11/14

Maximum Flow 27 / 42
FF Example: Steps 3 & 4

8
v1 4 v3 v1 12/12 v3

15
/1
5

13

/2
11
11

1/4

0
7

9
11
4

7/7
4/
s
3

10
s t

7
5

4
4

4/
13

8/
3

13
v2 v4 v2 v4
11 11/14

v1 12 v3 v1 12/12 v3

19
/1
5

/2
11
11

0
15
4

7/7
11

9
1/4
3

10
t s t
7
5
5

4
4

4/
12
8

3
/1

v2 v4 v2 v4
3

11 11/14

Maximum Flow 27 / 42
FF Example: Steps 4 & 5 (End)

v1 12 v3 v1 12/12 v3

19
/1
5

/2
11
11

0
15
4

7/7
11

9
1/4
3
s

10
t s t

7
5
5

4
4

4/
12
8

/1
v2 v4 v2 v4

3
11 11/14

Maximum Flow 28 / 42
FF Example: Steps 4 & 5 (End)

v1 12 v3 v1 12/12 v3

19
/1
5

/2
11
11

0
15
4

7/7
11

9
1/4
3
s

10
t s t

7
5
5

4
4

4/
12
8

/1
v2 v4 v2 v4

3
11 11/14

v1 12 v3
5

1
11

19
11
3

s t
7
9
1

4
12

3
v2 v4
11

Maximum Flow 28 / 42
Running Time & Finiteness

The FF method is not a completely defined algorithm since


it doesn’t specify how to choose the augmenting paths.

Maximum Flow 29 / 42
Running Time & Finiteness

The FF method is not a completely defined algorithm since


it doesn’t specify how to choose the augmenting paths.

In fact, if the capacities are irrational, it is possible that a


“bad” way of choosing the a.p. will lead to a non-terminating
algorithm that will never stop (it will keep on adding cheaper
and cheaper augmenting paths).

Maximum Flow 29 / 42
If the capacities are all integers
⇒ then each cp will be an integer ≥ 1
⇒ the algorithm must terminate after |f ∗ | steps,
where f ∗ is a max-flow.

Maintaining the graphs G and Gf and the flow f using ad-


jacency lists, while using DFS or BFS to find a s-t path,
the algorithm can then be implemented to run in O(|f ∗ ||E|)
time.

Note: This can be normalized to work if the capacities are


rational.

Maximum Flow 30 / 42
Running Time

Starts with flow f ≡ 0,

Maximum Flow 31 / 42
Running Time

Starts with flow f ≡ 0, O(|E|)

Maximum Flow 31 / 42
Running Time

Starts with flow f ≡ 0, O(|E|)

Construct residual network Gf .

Maximum Flow 31 / 42
Running Time

Starts with flow f ≡ 0, O(|E|)

Construct residual network Gf . O(|E|)

Maximum Flow 31 / 42
Running Time

Starts with flow f ≡ 0, O(|E|)

Construct residual network Gf . O(|E|)


If Gf contains no augmenting path, stop
(f is optimal by MFMC theorem).
Otherwise. Can be repeated O(|f ∗ |) times.

Maximum Flow 31 / 42
Running Time

Starts with flow f ≡ 0, O(|E|)

Construct residual network Gf . O(|E|)


If Gf contains no augmenting path, stop
(f is optimal by MFMC theorem).
Otherwise. Can be repeated O(|f ∗ |) times.
1 Find an augmenting s − t path p in Gf

Maximum Flow 31 / 42
Running Time

Starts with flow f ≡ 0, O(|E|)

Construct residual network Gf . O(|E|)


If Gf contains no augmenting path, stop
(f is optimal by MFMC theorem).
Otherwise. Can be repeated O(|f ∗ |) times.
1 Find an augmenting s − t path p in Gf O(|E|)

Maximum Flow 31 / 42
Running Time

Starts with flow f ≡ 0, O(|E|)

Construct residual network Gf . O(|E|)


If Gf contains no augmenting path, stop
(f is optimal by MFMC theorem).
Otherwise. Can be repeated O(|f ∗ |) times.
1 Find an augmenting s − t path p in Gf O(|E|)
2 Let fp be the flow in Gf that pushes cf (p) units of flow
along p.
3 Let f = f + fp be new flow in G.

Maximum Flow 31 / 42
Running Time

Starts with flow f ≡ 0, O(|E|)

Construct residual network Gf . O(|E|)


If Gf contains no augmenting path, stop
(f is optimal by MFMC theorem).
Otherwise. Can be repeated O(|f ∗ |) times.
1 Find an augmenting s − t path p in Gf O(|E|)
2 Let fp be the flow in Gf that pushes cf (p) units of flow
along p.
3 Let f = f + fp be new flow in G. O(|E|)

Maximum Flow 31 / 42
A pathological example in which each augmenting path
only increases flow value by 1 unit.

u u u
1,

1,

99 1
0

9
00

00
00

9,
9

9
,9

,9
0

99
0,

,0

,0
9

9
00

9
99

99
00

00
1,

1
s t s t s t
1

1
99
9

9
99

99
1,

1,

9,
0
00

00

99
9,

9,
00

99

99
0,

0,

9
0,

1
1
00

00
00

v v v
0

0
1,

u u
99 1

99
8

8
9,

9,
99

99
99

99
9,

9,
9

8
99

99

2
2

s t s t
1

1
99

99
8

8
99

99
9,

9,
99

99
9,

9,
99

99
9

8
2

2
1

v v

Maximum Flow 32 / 42
The Edmonds-Karp Algorithm

Always choose an augmenting path of minimum-length in


Gf (where each edge has unit length). This can be done in
O(E) time using BFS.
Theorem: The EK alg performs at most O(VE)
path-augmentations, so the E.K. alg runs in O(VE2 ) time.

Let δf (u, v) denote shortest-path distance from u to v in Gf .


The proof of the Theorem is a consequence of the follow-
ing two lemmas:

Maximum Flow 33 / 42
Lemma: ∀v ∈ V − {s, t}, δf (s, v) does not decrease after a
flow augmentation.

Lemma:
Edge (u, v) is critical on a.p. p if cf (u, v) = cf (p).
Suppose when running the E.K. algorithm that (u, v) is crit-
ical for a.p. p in Gf , and is later critical again for another
a.p. p′ in Gf ′ . Then
δf ′ (s, u) ≥ δf (s, u) + 2.
Augmenting paths are simple and do not contain s,t internally, so
δf (s, v) is always ≤ |V|−2 (as long as v is reachable). Combining
the two lemmas therefore shows that no specific edge can be-
come critical more than (|V| − 2)/2 = O(|V|) times. Some edge
is critical in each step, so there can be at most O(|V||E|) steps.

Maximum Flow 34 / 42
Application: Max Bipartite Matching

A graph G = (V, E) is bipartite if there exists partition V =


L ∪ R with L ∩ R = ∅ and E ⊆ L × R.
A Matching is a subset M ⊆ E such that ∀v ∈ V at most
one edge in M is incident upon v.
The size of a matching is |M| , the number of edges in M.
A Maximum Matching is matching M such that every other
matching M ′ satisfies |M ′ | ≤ M.
Problem: Given bipartite graph G, find a maximum match-
ing.

Maximum Flow 35 / 42
A bipartite graph with 2 matchings

L R L R

Maximum Flow 36 / 42
Our approach will be to write the Max Bipartite Matching
problem as a Max-Flow problem.

Our flow network will be G′ = (V ′ , E′ ) where


V ′ = V ∪ {s, t} and
E′ = {(s, u) : u ∈ L} ∪ {(u, v) : u ∈ L, v ∈ R and (u, v) ∈ E}
∪ {(v, t) : t ∈ R}

We also assign
∀(u, v) ∈ E′ , c(u, v) = 1.

Maximum Flow 37 / 42
Lemma: If f is an integer valued flow in G′ then there is a
matching M of G with |f | = |M|.
Similarly, if M is a matching of G then there is an integer
valued flow f with |f | = |M|.

Maximum Flow 38 / 42
Lemma: If f is an integer valued flow in G′ then there is a
matching M of G with |f | = |M|.
Similarly, if M is a matching of G then there is an integer
valued flow f with |f | = |M|.

This almost tells us that Max-Flow solves our problem.


The difficulty is that it’s possible that the max-flow might
not have integer value (it is possible that |f | might be an
integer but some f (u, v) might not be integers).

Maximum Flow 38 / 42
A bipartite graph and its associated flow network.
A matching and associated flow are illustrated

s t

L R L R

Maximum Flow 39 / 42
Theorem:

Let G′ = (V ′ , E′ ) be a flow network in which c is integral.


Then the max-flow f found by the F.F. method has the prop-
erty that

∀u, v, f (u, v)is integer valued.

Maximum Flow 40 / 42
Theorem:

Let G′ = (V ′ , E′ ) be a flow network in which c is integral.


Then the max-flow f found by the F.F. method has the prop-
erty that

∀u, v, f (u, v)is integer valued.

The proof is by induction on the steps in the FF method.


At each step the current flow f is integer so the residual
capacities are all integer.
This implies that the a.p. found has cf (p) integral, so the
new flow f + f ′ created is also integral.

Maximum Flow 40 / 42
The theorem guarantees that if G′ is the flow network cor-
responding to a bipartite matching problem then max flow
value |f | is the value of a maximum matching.

The flow found by the FF algorithm can be modified to yield


the max matching.

The FF algorithm run on this special graph will take O(VE)


time (why?).

Maximum Flow 41 / 42
Odds and Ends

A faster implementation of the FF method uses the


idea of blocking flows developed by Dinic. This ap-
proach finds many augmenting paths at once.
A totally different approach to the Max-Flow algorithm
is the push-relabel method (see CLRS for details).
This can run in O(|V|3 ) time as compared to the O(|V||E|2 )
of FF.
General Culture: The max-flow problem can be written
as a linear program. The FF method is essentially a
special case of the primal-dual algorithm for solving
combinatorial Linear Programs.
Maximum Flow 42 / 42

You might also like