Sec Augmenting Path Algorithms
Sec Augmenting Path Algorithms
Greedy-algorithm:
ñ start with f (e) = 0 everywhere
ñ find an s-t path with f (e) < c(e) on every edge
ñ augment flow along the path
ñ repeat as long as possible
1
0 0|1
0|2 0
s 0|30 t
0|1 0
0 0|2
0|1
20 |20 0
0
20
s 0|30 t
0|1
0 20 |20
0
0|1
|20 0
20
s 20|30 t
0|1
0 |20
20
0|1
|20 0
20
s 20|30 t
0|1
0 |20
20
10|20
G u
14|16
v
Gf u
12
24 v
Definition 1
An augmenting path with respect to flow f , is a path from s to t
in the auxiliary graph Gf that contains only edges with non-zero
capacity.
Definition 1
An augmenting path with respect to flow f , is a path from s to t
in the auxiliary graph Gf that contains only edges with non-zero
capacity.
2 0|4 4
G 0|
1 0 0|2 0|8 0|6 10
0|
Flow value = 0
2 4 4
0
Gf 10 0 0 6 0
8 10
2 0
0
s 10 3
9 5
10 t
0 0 0
2 0|4 4
G 0|
1 0 0|2 0|8 0|6 10
0|
Flow value = 0
2 4 4
0
Gf 10 0 0 6 0
8 10
2 0
0
s 10 3
9 5
10 t
0 0 0
2 0|4 4
G 8 0|
8 |10 0|2 0|8 0|6 10
0
8
s 0|10 3 0|9 5 0|10 t
Flow value = 8
2 4 4
0
Gf 10 0 0 6 0
8 10
2 0
0
s 10 3
9 5
10 t
0 0 0
2 0|4 4
G 0|
10 0|2 8|8 0|6 10
8|
Flow value = 8
2 4 4
0
Gf 2 0 8 6 0
0 10
2 0
8
s 10 3
9 5 2 t
0 0 8
2 0|4 4
G 0|
10 0|2 8|8 0|6 10
8|
Flow value = 8
2 4 4
0
Gf 2 0 8 6 0
0 10
2 0
8
s 10 3
9 5 2 t
0 0 8
2 0|4 4
G 2 0|
10 |10 0|2 8|8 0|6 10
8
2 10
s 0|10 3 0|9 5 8|10 t
Flow value = 10
2 4 4
0
Gf 2 0 8 6 0
0 10
2 0
8
s 10 3
9 5 2 t
0 0 8
2 0|4 4
G 0|
0 8|8 10
|1 2|2 0|6
10
Flow value = 10
2 4 4
0
Gf 0 2 8 6 0
0 10
0 0
10
s 10 3 7 5
0 t
0 2 10
2 0|4 4
G 0|
0 8|8 10
|1 2|2 0|6
10
Flow value = 10
2 4 4
0
Gf 0 2 8 6 0
0 10
0 0
10
s 10 3 7 5
0 t
0 2 10
2 0|4 4
G 6
6
0|
10 8|8 10
10| 2|2 0|6
6 8
s 0|10 3 2|9 5 10|10 t
Flow value = 16
2 4 4
0
Gf 0 2 8 6 0
0 10
0 0
10
s 10 3 7 5
0 t
0 2 10
2 0|4 4
G 6|
0 8|8 10
|1 2|2 6|6
10
Flow value = 16
2 4 4
0
Gf 0 2 8 0 6
0 4
0 6
10
s 4 3 1 5
0 t
6 8 10
2 0|4 4
G 6|
0 8|8 10
|1 2|2 6|6
10
Flow value = 16
2 4 4
0
Gf 0 2 8 0 6
0 4
0 6
10
s 4 3 1 5
0 t
6 8 10
2
2 0|4 4
G 0
8
6|
10 8|8 10
10| 2|2
2|2 6|6
8
s 6|10 3 8|9 5 10|10 t
Flow value = 18
2 4 4
0
Gf 0 2 8 0 6
0 4
0 6
10
s 4 3 1 5
0 t
6 8 10
2 2|4 4
G 68|
0 8|8 10
|1 0|2
2|2 6|6
10
Flow value = 18
2 2 4
2
Gf 0 0 8 0 8
0 2
2 6
10
s 2 3 1 5
0 t
8 8 10
2 2|4 4
G 68|
0 8|8 10
|1 0|2
2|2 6|6
10
Flow value = 18
2 2 4
2
Gf 0 0 8 0 8
0 2
2 6
10
s 2 3 1 5
0 t
8 8 10
3
2 2|4 4
G 7 9
68|
10 8|8 10
10| 0|2
2|2 6|6
9 9
s 8|10 3 8|9 5 10|10 t
Flow value = 19
2 2 4
2
Gf 0 0 8 0 8
0 2
2 6
10
s 2 3 1 5
0 t
8 8 10
2 3|4 4
G 69|
0 7|8 1
|1 0|2
2|2 6|6 0
10
Flow value = 19
2 1 4
3
Gf 0 0 7 0 9
1 1
2 6
10
s 1 3
0 5
0 t
9 9 10
2 3|4 4
G 69|
0 7|8 1
|1 0|2
2|2 6|6 0
10
Flow value = 19
2 1 4
3
Gf 0 0 7 0 9
1 1
2 6
10
s 1 3
0 5
0 t
9 9 10
Theorem 2
A flow f is a maximum flow iff there are no augmenting paths.
Theorem 3
The value of a maximum flow is equal to the value of a minimum
cut.
Proof.
Let f be a flow. The following are equivalent:
1. There exists a cut A, B such that val(f ) = cap(A, B).
2. Flow f is a maximum flow.
3. There is no augmenting path w.r.t. f .
Theorem 2
A flow f is a maximum flow iff there are no augmenting paths.
Theorem 3
The value of a maximum flow is equal to the value of a minimum
cut.
Proof.
Let f be a flow. The following are equivalent:
1. There exists a cut A, B such that val(f ) = cap(A, B).
2. Flow f is a maximum flow.
3. There is no augmenting path w.r.t. f .
Theorem 2
A flow f is a maximum flow iff there are no augmenting paths.
Theorem 3
The value of a maximum flow is equal to the value of a minimum
cut.
Proof.
Let f be a flow. The following are equivalent:
1. There exists a cut A, B such that val(f ) = cap(A, B).
2. Flow f is a maximum flow.
3. There is no augmenting path w.r.t. f .
Theorem 2
A flow f is a maximum flow iff there are no augmenting paths.
Theorem 3
The value of a maximum flow is equal to the value of a minimum
cut.
Proof.
Let f be a flow. The following are equivalent:
1. There exists a cut A, B such that val(f ) = cap(A, B).
2. Flow f is a maximum flow.
3. There is no augmenting path w.r.t. f .
Theorem 2
A flow f is a maximum flow iff there are no augmenting paths.
Theorem 3
The value of a maximum flow is equal to the value of a minimum
cut.
Proof.
Let f be a flow. The following are equivalent:
1. There exists a cut A, B such that val(f ) = cap(A, B).
2. Flow f is a maximum flow.
3. There is no augmenting path w.r.t. f .
Theorem 2
A flow f is a maximum flow iff there are no augmenting paths.
Theorem 3
The value of a maximum flow is equal to the value of a minimum
cut.
Proof.
Let f be a flow. The following are equivalent:
1. There exists a cut A, B such that val(f ) = cap(A, B).
2. Flow f is a maximum flow.
3. There is no augmenting path w.r.t. f .
1. =⇒ 2.
This we already showed.
2. =⇒ 3.
If there were an augmenting path, we could improve the flow.
Contradiction.
3. =⇒ 1.
ñ Let f be a flow with no augmenting paths.
ñ Let A be the set of vertices reachable from s in the residual
graph along non-zero capacity edges.
ñ Since there is no augmenting path we have s ∈ A and t ∉ A.
1. =⇒ 2.
This we already showed.
2. =⇒ 3.
If there were an augmenting path, we could improve the flow.
Contradiction.
3. =⇒ 1.
ñ Let f be a flow with no augmenting paths.
ñ Let A be the set of vertices reachable from s in the residual
graph along non-zero capacity edges.
ñ Since there is no augmenting path we have s ∈ A and t ∉ A.
1. =⇒ 2.
This we already showed.
2. =⇒ 3.
If there were an augmenting path, we could improve the flow.
Contradiction.
3. =⇒ 1.
ñ Let f be a flow with no augmenting paths.
ñ Let A be the set of vertices reachable from s in the residual
graph along non-zero capacity edges.
ñ Since there is no augmenting path we have s ∈ A and t ∉ A.
1. =⇒ 2.
This we already showed.
2. =⇒ 3.
If there were an augmenting path, we could improve the flow.
Contradiction.
3. =⇒ 1.
ñ Let f be a flow with no augmenting paths.
ñ Let A be the set of vertices reachable from s in the residual
graph along non-zero capacity edges.
ñ Since there is no augmenting path we have s ∈ A and t ∉ A.
1. =⇒ 2.
This we already showed.
2. =⇒ 3.
If there were an augmenting path, we could improve the flow.
Contradiction.
3. =⇒ 1.
ñ Let f be a flow with no augmenting paths.
ñ Let A be the set of vertices reachable from s in the residual
graph along non-zero capacity edges.
ñ Since there is no augmenting path we have s ∈ A and t ∉ A.
1. =⇒ 2.
This we already showed.
2. =⇒ 3.
If there were an augmenting path, we could improve the flow.
Contradiction.
3. =⇒ 1.
ñ Let f be a flow with no augmenting paths.
ñ Let A be the set of vertices reachable from s in the residual
graph along non-zero capacity edges.
ñ Since there is no augmenting path we have s ∈ A and t ∉ A.
val(f )
X X
val(f ) = f (e) − f (e)
e∈out(A) e∈into(A)
X X
val(f ) = f (e) − f (e)
e∈out(A) e∈into(A)
X
= c(e)
e∈out(A)
X X
val(f ) = f (e) − f (e)
e∈out(A) e∈into(A)
X
= c(e)
e∈out(A)
= cap(A, V \ A)
X X
val(f ) = f (e) − f (e)
e∈out(A) e∈into(A)
X
= c(e)
e∈out(A)
= cap(A, V \ A)
Here the first equality uses the flow value lemma, and the
second exploits the fact that the flow along incoming edges
must be 0 as the residual graph does not have edges leaving A.
Assumption:
All capacities are integers between 1 and C.
Invariant:
Every flow value f (e) and every residual capacity cf (e) remains
integral troughout the algorithm.
Assumption:
All capacities are integers between 1 and C.
Invariant:
Every flow value f (e) and every residual capacity cf (e) remains
integral troughout the algorithm.
Theorem 5
If all capacities are integers, then there exists a maximum flow
for which every flow value f (e) is integral.
Theorem 5
If all capacities are integers, then there exists a maximum flow
for which every flow value f (e) is integral.
0|2
000 00
0|2 0
s 0|1 t
0|2 0
00 00
0 0|2
00
20 0
20
00
0 0
s t
1 00
0 20
20
00
0
Question:
Can we tweak the algorithm so that the running time is
polynomial in the input length?
00
20 0
20
00
0 0
s t
1 00
0 20
20
00
0
Question:
Can we tweak the algorithm so that the running time is
polynomial in the input length?
99
19 0
20
00
1 1
s t
0 99
0 19
20
00
1
Question:
Can we tweak the algorithm so that the running time is
polynomial in the input length?
99
19 0
20
00
1 1
s t
0 99
0 19
20
00
1
Question:
Can we tweak the algorithm so that the running time is
polynomial in the input length?
99
19 1
19
99
1 0
s t
1 99
1 19
19
99
1
Question:
Can we tweak the algorithm so that the running time is
polynomial in the input length?
99
19 1
19
99
1 0
s t
1 99
1 19
19
99
1
Question:
Can we tweak the algorithm so that the running time is
polynomial in the input length?
98
19 1
19
99
2 1
s t
0 98
1 19
19
99
2
Question:
Can we tweak the algorithm so that the running time is
polynomial in the input length?
98
19 1
19
99
2 1
s t
0 98
1 19
19
99
2
Question:
Can we tweak the algorithm so that the running time is
polynomial in the input length?
98
19 2
19
98
2 0
s t
1 98
2 19
19
98
2
Question:
Can we tweak the algorithm so that the running time is
polynomial in the input length?
98
19 2
19
98
2 0
s t
1 98
2 19
19
98
2
Question:
Can we tweak the algorithm so that the running time is
polynomial in the input length?
2 1 5
∞
∞ ∞
∞ ∞
∞
∞
∞
s ∞ 3 r 6 ∞ t
∞ ∞ ∞
∞ ∞
∞
∞ ∞
∞
∞
4 r2 7
∞
2 1 5
∞
∞ ∞
∞ ∞
∞
∞
∞
s ∞ 3 r 6 ∞ t
∞ ∞ ∞
∞ ∞
∞
∞ ∞
∞
∞
4 r2 7
∞
2 r2 5
∞
∞ ∞
∞ ∞
∞
∞
∞
s ∞ 3
0 6 ∞ t
∞ ∞ ∞
∞ ∞
∞
∞ ∞
∞
∞
4 r + r2 7
∞
2 r2 5
∞
∞ ∞
∞ ∞
∞
∞
∞
s ∞ 3
0 6 ∞ t
∞ ∞ ∞
∞ ∞
∞
∞ ∞
∞
∞
4 r + r2 7
∞
2
0 5
∞
∞ ∞
∞ ∞
∞
∞
∞
s ∞ 3 r2 6 ∞ t
∞ ∞ ∞
∞ ∞
∞
∞ ∞
∞
∞
4 r 7
∞
2
0 5
∞
∞ ∞
∞ ∞
∞
∞
∞
s ∞ 3 r2 6 ∞ t
∞ ∞ ∞
∞ ∞
∞
∞ ∞
∞
∞
4 r 7
∞
2 r2 5
∞
∞ ∞
∞ ∞
∞
∞
∞
s ∞ 3
0 6 ∞ t
∞ ∞ ∞
∞ ∞
∞
∞ ∞
∞
∞
4 r3 7
∞
2 r2 5
∞
∞ ∞
∞ ∞
∞
∞
∞
s ∞ 3
0 6 ∞ t
∞ ∞ ∞
∞ ∞
∞
∞ ∞
∞
∞
4 r3 7
∞
2 r4 5
∞
∞ ∞
∞ ∞
∞
∞
∞
s ∞ 3 r3 6 ∞ t
∞ ∞ ∞
∞ ∞
∞
∞ ∞
∞
∞
4
0 7
∞
2 r4 5
∞
∞ ∞
∞ ∞
∞
∞
∞
s ∞ 3 r3 6 ∞ t
∞ ∞ ∞
∞ ∞
∞
∞ ∞
∞
∞
4
0 7
∞
Several possibilities:
Several possibilities:
ñ Choose path with maximum bottleneck capacity.
Several possibilities:
ñ Choose path with maximum bottleneck capacity.
ñ Choose path with sufficiently large bottleneck capacity.
Several possibilities:
ñ Choose path with maximum bottleneck capacity.
ñ Choose path with sufficiently large bottleneck capacity.
ñ Choose the shortest augmenting path.
Lemma 6
The length of the shortest augmenting path never decreases.
Lemma 7
After at most O(m) augmentations, the length of the shortest
augmenting path strictly increases.
Lemma 6
The length of the shortest augmenting path never decreases.
Lemma 7
After at most O(m) augmentations, the length of the shortest
augmenting path strictly increases.
Lemma 6
The length of the shortest augmenting path never decreases.
Lemma 7
After at most O(m) augmentations, the length of the shortest
augmenting path strictly increases.
Theorem 8
The shortest augmenting path algorithm performs at most
O(mn) augmentations. This gives a running time of O(m2 n).
Proof.
ñ We can find the shortest augmenting paths in time O(m)
via BFS.
ñ O(m) augmentations for paths of exactly k < n edges.
Theorem 8
The shortest augmenting path algorithm performs at most
O(mn) augmentations. This gives a running time of O(m2 n).
Proof.
ñ We can find the shortest augmenting paths in time O(m)
via BFS.
ñ O(m) augmentations for paths of exactly k < n edges.
Theorem 8
The shortest augmenting path algorithm performs at most
O(mn) augmentations. This gives a running time of O(m2 n).
Proof.
ñ We can find the shortest augmenting paths in time O(m)
via BFS.
ñ O(m) augmentations for paths of exactly k < n edges.
Theorem 8
The shortest augmenting path algorithm performs at most
O(mn) augmentations. This gives a running time of O(m2 n).
Proof.
ñ We can find the shortest augmenting paths in time O(m)
via BFS.
ñ O(m) augmentations for paths of exactly k < n edges.
Define the level `(v) of a node as the length of the shortest s-v
path in Gf .
Define the level `(v) of a node as the length of the shortest s-v
path in Gf .
Define the level `(v) of a node as the length of the shortest s-v
path in Gf .
Define the level `(v) of a node as the length of the shortest s-v
path in Gf .
2 4 4
0
Gf
10 0 2 6 0
LG 6 10
2 0
0
s 10 3
9 5
10 t
0 0 0
First Lemma:
The length of the shortest augmenting path never decreases.
Shortest Augmenting Path
First Lemma:
The length of the shortest augmenting path never decreases.
First Lemma:
The length of the shortest augmenting path never decreases.
First Lemma:
The length of the shortest augmenting path never decreases.
First Lemma:
The length of the shortest augmenting path never decreases.
2 4 4
0
Gf
10 0 2 6 0
LG 6 10
2 0
0
s 10 3
9 5
10 t
0 0 0
Shortest Augmenting Path
First Lemma:
The length of the shortest augmenting path never decreases.
2 4 4
0
Gf
10 0 2 6 0
LG 6 10
2 0
0
s 10 3
9 5
10 t
0 0 0
Shortest Augmenting Path
First Lemma:
The length of the shortest augmenting path never decreases.
2 4 4
0
Gf
10 0 2 6 0
LG 6 10
2 0
0
s 1 3
0 5 1 t
9
0 9
0 9
0
Shortest Augmenting Path
Second Lemma: After at most m augmentations the length of
the shortest augmenting path strictly increases.
Shortest Augmenting Path
Second Lemma: After at most m augmentations the length of
the shortest augmenting path strictly increases.
2 4 4
0
Gf
10 0 2 6 0
EL 6 10
2 0
0
s 10 3
9 5
10 t
0 0 0
Shortest Augmenting Path
Second Lemma: After at most m augmentations the length of
the shortest augmenting path strictly increases.
2 4 4
0
Gf
10 0 2 6 0
EL 6 10
2 0
0
s 10 3
9 5
10 t
0 0 0
Shortest Augmenting Path
Second Lemma: After at most m augmentations the length of
the shortest augmenting path strictly increases.
2 4 4
0
Gf
10 0 2 6 0
EL 6 10
2 0
0
s 1 3
0 5 1 t
9
0 9
0 9
0
Shortest Augmenting Paths
Theorem 9
The shortest augmenting path algorithm performs at most
O(mn) augmentations. Each augmentation can be performed in
time O(m).
Note:
There always exists a set of m augmentations that gives a
maximum flow.
Theorem 9
The shortest augmenting path algorithm performs at most
O(mn) augmentations. Each augmentation can be performed in
time O(m).
Note:
There always exists a set of m augmentations that gives a
maximum flow.
Theorem 9
The shortest augmenting path algorithm performs at most
O(mn) augmentations. Each augmentation can be performed in
time O(m).
Note:
There always exists a set of m augmentations that gives a
maximum flow.
Theorem 9
The shortest augmenting path algorithm performs at most
O(mn) augmentations. Each augmentation can be performed in
time O(m).
Note:
There always exists a set of m augmentations that gives a
maximum flow.
Note that EL is not the set of edges of the level graph but a
subset of level-graph edges.
Note that EL is not the set of edges of the level graph but a
subset of level-graph edges.
Note that EL is not the set of edges of the level graph but a
subset of level-graph edges.
Note that EL is not the set of edges of the level graph but a
subset of level-graph edges.
Several possibilities:
Several possibilities:
ñ Choose path with maximum bottleneck capacity.
ñ Choose path with sufficiently large bottleneck capacity.
ñ Choose the shortest augmenting path.
Gf 1 Gf (99) 1
5 5
11 0 87 11
0 0
s t s t
1 2 2
0 13 20 13 20
3 3
0
2 2
Algorithm 2 maxflow(G, s, t, c)
1: foreach e ∈ E do fe ← 0;
2: ∆ ← 2dlog2 Ce
3: while ∆ ≥ 1 do
4: Gf (∆) ← ∆-residual graph
5: while there is augmenting path P in Gf (∆) do
6: f ← augment(f , c, P )
7: update(Gf (∆))
8: ∆ ← ∆/2
9: return f
Assumption:
All capacities are integers between 1 and C.
Assumption:
All capacities are integers between 1 and C.
Invariant:
All flows and capacities are/remain integral throughout the
algorithm.
Assumption:
All capacities are integers between 1 and C.
Invariant:
All flows and capacities are/remain integral throughout the
algorithm.
Correctness:
The algorithm computes a maxflow:
ñ because of integrality we have Gf (1) = Gf
Assumption:
All capacities are integers between 1 and C.
Invariant:
All flows and capacities are/remain integral throughout the
algorithm.
Correctness:
The algorithm computes a maxflow:
ñ because of integrality we have Gf (1) = Gf
ñ therefore after the last phase there are no augmenting
paths anymore
Assumption:
All capacities are integers between 1 and C.
Invariant:
All flows and capacities are/remain integral throughout the
algorithm.
Correctness:
The algorithm computes a maxflow:
ñ because of integrality we have Gf (1) = Gf
ñ therefore after the last phase there are no augmenting
paths anymore
ñ this means we have a maximum flow.
Lemma 11
There are dlog Ce iterations over ∆.
Proof: obvious.
Lemma 11
There are dlog Ce iterations over ∆.
Proof: obvious.
Lemma 12
Let f be the flow at the end of a ∆-phase. Then the maximum
flow is smaller than val(f ) + m∆.
Proof: less obvious, but simple:
Lemma 11
There are dlog Ce iterations over ∆.
Proof: obvious.
Lemma 12
Let f be the flow at the end of a ∆-phase. Then the maximum
flow is smaller than val(f ) + m∆.
Proof: less obvious, but simple:
ñ There must exist an s-t cut in Gf (∆) of zero capacity.
Lemma 11
There are dlog Ce iterations over ∆.
Proof: obvious.
Lemma 12
Let f be the flow at the end of a ∆-phase. Then the maximum
flow is smaller than val(f ) + m∆.
Proof: less obvious, but simple:
ñ There must exist an s-t cut in Gf (∆) of zero capacity.
ñ In Gf this cut can have capacity at most m∆.
Lemma 11
There are dlog Ce iterations over ∆.
Proof: obvious.
Lemma 12
Let f be the flow at the end of a ∆-phase. Then the maximum
flow is smaller than val(f ) + m∆.
Proof: less obvious, but simple:
ñ There must exist an s-t cut in Gf (∆) of zero capacity.
ñ In Gf this cut can have capacity at most m∆.
ñ This gives me an upper bound on the flow that I can still
add.
Lemma 13
There are at most 2m augmentations per scaling-phase.
Lemma 13
There are at most 2m augmentations per scaling-phase.
Proof:
ñ Let f be the flow at the end of the previous phase.
Lemma 13
There are at most 2m augmentations per scaling-phase.
Proof:
ñ Let f be the flow at the end of the previous phase.
ñ val(f ∗ ) ≤ val(f ) + 2m∆
Lemma 13
There are at most 2m augmentations per scaling-phase.
Proof:
ñ Let f be the flow at the end of the previous phase.
ñ val(f ∗ ) ≤ val(f ) + 2m∆
ñ Each augmentation increases flow by ∆.
Lemma 13
There are at most 2m augmentations per scaling-phase.
Proof:
ñ Let f be the flow at the end of the previous phase.
ñ val(f ∗ ) ≤ val(f ) + 2m∆
ñ Each augmentation increases flow by ∆.
Theorem 14
We need O(m log C) augmentations. The algorithm can be
implemented in time O(m2 log C).