DaLecture19.en.handout
DaLecture19.en.handout
Ford-Fulkerson Algorithm
Edmonds-Karp Algorithm
817
Maximum Traffic Flow
Given: Road Network with capacities
819
Flow Network
Which of the following graphs are flow networks?
s s s
2 4 −2 4 3 1
3
7
a b a 0 b a b
6
4 4 6 4 2
t t t
s s s
5 3 6 9
7 6
a b a b a 1 b
6 7 4 8
t t t
820
Flow in Flow Network
Flow is function f : E → ≥0 such that R |f | = 16
Bounded Capacity: ∀e ∈ E : f (e) ≤ c(e)
s
Conservation of flow: ∀v ∈ V \ {s, t} : 6/16 10/13
X X
f (e) = f (e) 0/4
a b
e∈E − (v) e∈E + (v)
| {z } | {z } 6/12 3/9 13/14
=:f − (v) =:f + (v)
10/13
c d
v
13/20 3/4
t
Size of flow: |f | := f + (s) = f − (t)
821
Flow
Which of the following are flows?
s s s
3/4 3/3 1/2 3/6 6/6 1/2
3/6 2/2
a b a 4/4 b a b
s s s
2/2 6/7 0/2 0/1
822
Maximal Flow
Given: Flow network: G = (V, E, c), directed, positively weighted,
without antiparallel edges, with source s and sink t
11/14
b d
11/13 4/4
0/9
s 0/4 7/7 t |fmax | = 23
12/16 19/20
a c
12/12
s
4 4
a 3 b
2 6
t
824
Intuition: Flow as set of paths s t
|f | = 16
s s
3
10 6/16 10/13
3 0/4
a b a b
3 6/12 3/9 13/14
3 3 3 10
10 10/13
c d c d
3
13/20 3/4
10 3
t t
825
Greedy Algorithm?
Residual capacity of an edge e: r(e) := c(e) − f (e)
Residual capacity of a path p: mine∈p r(e)
Greedy: Starting with f (e) = 0 for all e ∈ E, as long as there exists a path
s t with remaining capacity d > 0, increase flow along this path by d.
2 |f | = 8
a c
0 0
s → a → b → d → t: 3
s 4 4 t s → a → c → t: 2
0
s → b → c → t: 3
4 3
b d
0 but |fmax | = 10
G+
f := (V, E, r := c − f ) 826
Problem with Greedy
a a
5 5 5 5
s 3 t s t
3 3 3 3
b b
G = (V, E, c) |fmax | = 8
2 a 2 a 3
2 2
s 3 3 t s 3 3 t
3 3 3
b b
Greedy: |f | = 5 Redirection
827
Redirection using flow decrement
2 a a
2 5/5 2/5
s 3 3 t s 3/3 t
3 0/3 3/3
b b
before G = (V, E, f /c)
2 a 3 a
2 5/5 5/5
s 3 3 t s 0/3 t
3 3 3/3 3/3
b
after b
G = (V, E, f 0 /c)
Increment: r(e)
flow through e can be increased by at most u v
r(e) := c(e) − f (e) G+
f := (V, E, r := c − f )
Decrement:
flow through e can be decreased by at most f (e)
f (e) u v
←
−
G−
f := (V, E , f )
⇒ flow through ←
−
e can be increased by at
most f (e)
829
Residual Network
12/12
a c
8/16 14/20
s 4/4 6/7 t
4/9
10/13 4/4
b d
10/14
12
0
8 a c 14
8 4 6
s 4 0 1 6 t
5
3
0
4
10 b d
4
10
−
Residual network: Gf := G+
f ∪ Gf = (V, Ef , cf )
830
Ford-Fulkerson: Flow augmentation
12
0
12 a c 18
12/12
a c
12/16 18/20
4 0 2
s 0/4
0/9
6/7 t s 0 4 1 6 t
9
10/13 4/4
3
b d 0
10/14
4
10 b d
4
10
return f
832
Example Ford-Fulkerson
4
0
5 a c 5
4/4
a c
5/5 5/5
0 3 0
s 1/7
3/3
2/4 t s 1 6 2 2 t
0
5/7 5/6
2 1
b d
3/3
0 5
5 b d
3
100 100
s 1 t
100 100
834
Solution
u u
2 2
2/100 2/100
98
98
s 1/1
0/1 t s 1 0 t
98
98
2/100 2/100
2 2
v v
After i iterations: |f | = i
⇒ in total |fmax | = 200 iterations
835
Running Time Analysis of Ford-Fulkerson
Running time of each iteration: search of an augmenting path s t
⇒ BFS or DFS: O(|V | + |E|) = O(|E|)
(|V | ≤ |E| + 1, because all non-reachable nodes can be ignored.)
Number of iterations:
In every step, the size of the flow increases by d > 0.
integer capacities ⇒ increment by ≥ 1 ⇒ at most |fmax | iterations
100 100
s 1 t
100 100
837
Solution
u u
100 100
100/100 100/100
0
0
s 0/1 t s 1 0 t
0
0
100/100 100/100
100 100
v v
838
Flows and Cuts: Bottleneck Intuition
Upper bounds on size of flow:
what can flow out of s: c+ (s) 11
s
what can flow into t: c− (t) 6 7
what can flow through arbitrary cut 13
what can flow through bottleneck: cmin a b
1
9
cmin 3 6
2
8
c d
s t
10
6 4
t
⇒ flow |f | ≤ bottleneck
⇒ maximum flow ≤ bottleneck 839
Cut
|f | = 6
(s, t)-Cut of graph G = (V, E, c): Partition
(S, T) of V such that s ∈ S, t ∈ T s
3/6 3/7
E(S, T ) := {(u, v) ∈ E : u ∈ S, v ∈ T }
1/1
Size of cut: a b
c(S, T ) := e∈E(S,T) c(e)
P
1/2
Flow through cut of flow network: 2/3 5/6
f (S, T ) := e∈E(S,T) f (e) − e∈E(T,S) f (e) 1/8
P P
c d
Observation:
∀f, S, T : |f | = f (S, T ) ≤ c(S, T ) 2/6 4/4
t c(S, T) = 18
⇒ |fmax | ≤ cmin f (S, T ) = 6
840
f (S, T ) = |f | for every (s, t)-cut E(S, T )
S T S0 T0
f (S 0 , T 0 ) = f (S, T ) − f (Sv− , v) − f (v, Sv+ ) + f (v, Tv+ ) − f (Tv− , v)
= f (S, T ) + f (v, Sv+ ) + f (v, Tv+ ) − f (Sv− , v) + f (Tv− , v)
= f (S, T )
I.H.
= |f |
841
Maximum Flow and Minimum Cut
3
3 a c 5
3/3 0
a c 3 1
3/6 5/6 0
s 0/1 2/8 t s 0 1 6 2 t
0/2 2
0
6/7 4/4
b d 1 4
6/6 0
6 b d
6
⇒ |fmax | = cmin
842
Max-Flow Min-Cut Theorem
843
Quiz Max-Flow-Min-Cut
b
3 4
2
s t
5
3 1
a
844
Summary
845
Application Examples
Maximum Rate:
water in sewage system
cars in traffic
current in electrical networks
components on conveyors
information flow in communication networks
Scheduling
Image Segmentation
Bipartite Matching
846
Bipartite Graph
A graph where V can be partitioned into disjoint sets U and W such that
each e ∈ E provides a node in U and a node in W is called bipartite.
847
Maxium Bipartite Matching
848
Corresponding flow network
s t
U W U W
Theorem 23
If the capacities of a flow network are integers, then the maximal flow
generated by the Ford-Fulkerson method provides integer numbers for
each f (u, v), u, v ∈ V .
[without proof]
Consequence: Ford-Fulkerson generates for a flow network that
corresponds to a bipartite graph a maximal matching
M = {(u, v) : f (u, v) = 1}.
850