Network Flows
(and why you should like them)
Outline
• Flow networks
• Maximum flow
• Ford-Fulkerson
• Push-Relabel
• How does this link to ML2
• Parametric Max-flow
Flow Networks
• A flow network G = (V, E) is a directed graph.
• Each edge (u,v) ∈ E has a nonnegative capacity c(u,v) ≥ 0.
• Two special vertices exist: a source s and a sink t.
• If (u,v) ∉ E, we assume that c(u,v) = 0.
• For our convenience let’s say that G is connected.
Flow
• A flow in G is a real-valued function f : V × V → R which satisfies:
• 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∈Vf (u,v)=0.
Examples: Network + Flow
• What’s the flow value |f|?
• How can flow be augmented?
• How can we know if flow is a maximal flow?
The Residual Network
•
Flow edges (u,v) are weighted with their residual capacity c(v, u) − f (v, u).
•
Reverse flow edges (v,u) are inserted and also set to the residual capacity c(v, u)−f (v, u). This can lead to values bigger then c(v, u).
•
Edges with zero weight are usually not drawn in our examples.
Augmenting Path
•
An augmenting path p is a simple path from s to t in the residual network.
•
The residual capacity, this is the amount our flow can be augmented along the augmenting path, is given by
c
f(p) = min {c
f(u,v) : (u,v) is on p}.
•
In our example this value is 4!
Augmenting Path
• The found c f (p) can now be added to each arrow in s−t-direction and subtracted from the others.
Flow Update
Maximal Flow
no augmenting path from s to t
• The final flow is |f | = ∑ v∈V f (u,t ) = ∑ v∈V f (s,v ).
Max-Flow Min-Cut Theorem
• but, wait…
let’s get the cut-thing straightened out first!
Graph Cut?
• A cut C=(S, T ) is a partition of V of a Graph G=(V,E )
• An s-t cut C=(S,T ) of G is a cut of G such that s∈S and t ∈T.
• The cut-edges of a cut C are the set:
{ (u,v)∈E | u ∈S, v ∈T }
• If edges have weights, the cost of a cut can easily
be determined by summing the cost of all cut-edges.
Max-Flow Min-Cut Theorem
• It proves the equivalence of the following
conditions in a flow network G = (V,E) with source s and sink t :
• f is a maximum flow in G.
• The residual network G f contains no augmenting paths.
• |f | = c(S,T ), for some cut (S,T ) of G.
(With s ∈ S ; t ∈ T !)
What’s next?
• We know what it is, but…
• …we cannot find it yet!
Max-Flow Algorithms
Max-Flow Algorithms Maximum Flow overview
method algorithm runtime
Ford-Fulkerson naive
Ford-Fulkerson Edmonds-Karp push-relabel naive
push-relabel relabel-to-front push-relabel + dynamic trees
O (E | f ? | )
The Ford-Fulkerson Algorithm
The Ford-Fulkerson Algorithm
The Ford-Fulkerson Algorithm
• Can you think of a bad instance?
The Ford-Fulkerson Algorithm
• Ford-Fulkerson takes O(Eᐧf
max).
• Edmonds-Karp can do it in O(VᐧE 2 ).
• They avoid the problem of the ‘bad instance’ by changing their search for the augmenting path from DFS style to
adequately formulated shortest path search.
Push Relabel
• Soften our definition of a flow to something called a pre-flow:
• 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∈Vf (u,v) = 0.
⩽
The Push-Relabel Algorithm
push-relabel algorithms
Maximum Flow
• Define preflow
• Define height function
• Preflow with height function has no augmenting path Flow with height function is a maximum flow
8 u, v 2 V : f (u, v ) c(u, v) 8 u, v 2 V : f (u, v ) = f (v, u) 8 u 2 V { s, t } : P
v 2 V f (u, v ) 0
h(s) = | V | , h(t) = 0
h(u) h(v ) + 1 if c(u, v ) f (u, v) 0
The Push-Relabel Algorithm
push-relabel by example
Maximum Flow
0 9
s t
12 0
14 0
4 10 7 0
20 0
13 0
160
4 0
h(s) = | V | , h(t) = 0,
if c(u, v) f (u, v) 0 :
h(u) h(v ) + 1
The Push-Relabel Algorithm Maximum Flow
0 1 2 3 4 5 6 7 8
13
16 10
4 9 7 4
14
20 12
s t
h(s) = | V | , h(t) = 0,
if c(u, v) f (u, v) 0 : h(u) h(v ) + 1
push-relabel by example
The Push-Relabel Algorithm Maximum Flow
0 1 2 3 4 5 6 7 8
10 4 9 7 4
14
20 12
t
h(s) = | V | , h(t) = 0,
if c(u, v) f (u, v) 0 : h(u) h(v ) + 1
16 13
s
✓ ✓
push-relabel by example
The Push-Relabel Algorithm
7 4
Maximum Flow
0 1 2 3 4 5 6 7 8
10 4 9
14
20 12
t
h(s) = | V | , h(t) = 0,
if c(u, v) f (u, v) 0 : h(u) h(v ) + 1
16 13
s
✓ ✓
16 13
✓
push-relabel by example
The Push-Relabel Algorithm Maximum Flow
0 1 2 3 4 5 6 7 8
10 9
7 4
20 12
t
h(s) = | V | , h(t) = 0,
if c(u, v) f (u, v) 0 : h(u) h(v ) + 1
16 13
s
✓ ✓
16
13
✓
14 4
push-relabel by example
The Push-Relabel Algorithm Maximum Flow
0 1 2 3 4 5 6 7 8
10 9
7 4
20 12
t
h(s) = | V | , h(t) = 0,
if c(u, v) f (u, v) 0 : h(u) h(v ) + 1
16 13
s
✓ ✓
16 13
✓
1 4
13
push-relabel by example
The Push-Relabel Algorithm Maximum Flow
0 1 2 3 4 5 6 7 8
10 9 7 4
20 12
t
h(s) = | V | , h(t) = 0,
if c(u, v) f (u, v) 0 : h(u) h(v ) + 1
16 13
s
✓ ✓
16
13
✓
1 4
13
push-relabel by example
The Push-Relabel Algorithm Maximum Flow
0 1 2 3 4 5 6 7 8
10 9 7 4
20 12
t
h(s) = | V | , h(t) = 0,
if c(u, v) f (u, v) 0 : h(u) h(v ) + 1
16 13
s
✓ ✓
16 7
✓
1 4
13
4 2
push-relabel by example
The Push-Relabel Algorithm Maximum Flow
0 1 2 3 4 5 6 7 8
10 9
20 12
t
h(s) = | V | , h(t) = 0,
if c(u, v) f (u, v) 0 : h(u) h(v ) + 1
16 13
s
✓ ✓
16 7
✓
13 1
4 2
7 4 4
push-relabel by example
The Push-Relabel Algorithm
20
Maximum Flow
0 1 2 3 4 5 6 7 8
10 9
12
t
h(s) = | V | , h(t) = 0,
if c(u, v) f (u, v) 0 : h(u) h(v ) + 1
16 13
s
✓ ✓
16 7
✓
11 3
4
2 7 4
4
push-relabel by example
The Push-Relabel Algorithm Maximum Flow
0 1 2 3 4 5 6 7 8
10
9 t
h(s) = | V | , h(t) = 0,
if c(u, v) f (u, v) 0 : h(u) h(v ) + 1
16 13
s
✓ ✓
16
7
✓
11 3
4
2 7 4
4
12
20
push-relabel by example
The Push-Relabel Algorithm Maximum Flow
0 1 2 3 4 5 6 7 8
10
9 t
h(s) = | V | , h(t) = 0,
if c(u, v) f (u, v) 0 : h(u) h(v ) + 1
16 13
s
✓ ✓
4
19
✓
11 3
4
2 7 4
4
12
20
push-relabel by example
The Push-Relabel Algorithm Maximum Flow
0 1 2 3 4 5 6 7 8
10
9 t
h(s) = | V | , h(t) = 0,
if c(u, v) f (u, v) 0 : h(u) h(v ) + 1
16 13
s
✓ ✓
4
19
✓
11 3
4
2 7 4
4
12
20
push-relabel by example
The Push-Relabel Algorithm Maximum Flow
0 1 2 3 4 5 6 7 8
6
9 t
h(s) = | V | , h(t) = 0,
if c(u, v) f (u, v) 0 : h(u) h(v ) + 1
16 13
s
✓ ✓
19
✓
11 3
4
6 7 4
8
12
20
push-relabel by example
The Push-Relabel Algorithm Maximum Flow
0 1 2 3 4 5 6 7 8
6
t
h(s) = | V | , h(t) = 0,
if c(u, v) f (u, v) 0 : h(u) h(v ) + 1
16
13
s
✓ ✓
19
✓
11 3
4 6
7 4 8
12
20 9
push-relabel by example
The Push-Relabel Algorithm Maximum Flow
0 1 2 3 4 5 6 7 8
12
t
h(s) = | V | , h(t) = 0,
if c(u, v) f (u, v) 0 : h(u) h(v ) + 1
16
13
s
✓ ✓
19
✓
11 3
4 6
7 4 2
12
20 9
push-relabel by example
The Push-Relabel Algorithm Maximum Flow
0 1 2 3 4 5 6 7 8
12
t
h(s) = | V | , h(t) = 0,
if c(u, v) f (u, v) 0 : h(u) h(v ) + 1
16
13
s
✓ ✓
19
✓
11 3
4 6
4 7
2
12
20 9
push-relabel by example
The Push-Relabel Algorithm Maximum Flow
0 1 2 3 4 5 6 7 8
12
t
h(s) = | V | , h(t) = 0,
if c(u, v) f (u, v) 0 : h(u) h(v ) + 1
16
13
s
✓ ✓
✓
11 3
23 6
4 7
2
12 1
9
19
push-relabel by example
The Push-Relabel Algorithm Maximum Flow
0 1 2 3 4 5 6 7 8
t
h(s) = | V | , h(t) = 0,
if c(u, v) f (u, v) 0 : h(u) h(v ) + 1
16 13
s
✓ ✓
✓
11 3
23 6
4 7
2
1 9
19 12
12
push-relabel by example
The Push-Relabel Algorithm Maximum Flow
0 1 2 3 4 5 6 7 8
t
h(s) = | V | , h(t) = 0,
if c(u, v) f (u, v) 0 : h(u) h(v ) + 1
16 13
s
✓ ✓
✓
11 3
23 6
4 7
8
1 9
19 6
12
push-relabel by example
The Push-Relabel Algorithm Maximum Flow
0 1 2 3 4 5 6 7 8
t
h(s) = | V | , h(t) = 0,
if c(u, v) f (u, v) 0 : h(u) h(v ) + 1
16 13
s
✓ ✓
✓
14
23 3
4 7
8
1 9
19 6
12 3
push-relabel by example
The Push-Relabel Algorithm Maximum Flow
0 1 2 3 4 5 6 7 8
t
h(s) = | V | , h(t) = 0,
if c(u, v) f (u, v) 0 : h(u) h(v ) + 1
16
s 13
✓ ✓
✓
14
23 3
4 7
8
1 9
19 6
12 3
push-relabel by example
The Push-Relabel Algorithm Maximum Flow
0 1 2 3 4 5 6 7 8
t
h(s) = | V | , h(t) = 0,
if c(u, v) f (u, v) 0 : h(u) h(v ) + 1
16
s 13
✓ ✓
✓
14
23 3
4 7
5
1 9
19 9
12 3
push-relabel by example
The Push-Relabel Algorithm Maximum Flow
0 1 2 3 4 5 6 7 8
t
h(s) = | V | , h(t) = 0,
if c(u, v) f (u, v) 0 : h(u) h(v ) + 1
16 13
s
✓ ✓
✓
14
23 3
4 7
5
1 9
19 9
12
3
push-relabel by example
The Push-Relabel Algorithm Maximum Flow
0 1 2 3 4 5 6 7 8
t
h(s) = | V | , h(t) = 0,
if c(u, v) f (u, v) 0 : h(u) h(v ) + 1
16 13
s
✓ ✓
✓
14
23 3
4 7
5
1 9
19 9
12
3
push-relabel by example
The Push-Relabel Algorithm Maximum Flow
0 1 2 3 4 5 6 7 8
t
h(s) = | V | , h(t) = 0,
if c(u, v) f (u, v) 0 : h(u) h(v ) + 1
16 13
s
✓ ✓
✓
14
23 3
4 7
8
1 9
19 6
12
3
push-relabel by example
The Push-Relabel Algorithm Maximum Flow
0 1 2 3 4 5 6 7 8
t
h(s) = | V | , h(t) = 0,
if c(u, v) f (u, v) 0 : h(u) h(v ) + 1
16 13
s
✓ ✓
✓
14
23 3
7 4 8
1 9
19 6
12
3
push-relabel by example
The Push-Relabel Algorithm Maximum Flow
0 1 2 3 4 5 6 7 8
t
h(s) = | V | , h(t) = 0,
if c(u, v) f (u, v) 0 : h(u) h(v ) + 1
16 13
s
✓ ✓
11 ✓
23 6
7 4 8
1 9
19 6
12
3
push-relabel by example
The Push-Relabel Algorithm Maximum Flow
0 1 2 3 4 5 6 7 8
t
h(s) = | V | , h(t) = 0,
if c(u, v) f (u, v) 0 : h(u) h(v ) + 1
16
13
s
✓ ✓
11 ✓
23 6
7 4 8
1 9
19 6
12
3
push-relabel by example
The Push-Relabel Algorithm Maximum Flow
0 1 2 3 4 5 6 7 8
t
h(s) = | V | , h(t) = 0,
if c(u, v) f (u, v) 0 : h(u) h(v ) + 1
16
7
s
✓ ✓
11 ✓
23 7 4
8
1 9
19 6
12
3 6
• no overflowing regular flow
• height function maximum flow!
push-relabel by example
The Push-Relabel Algorithm
relabel-to-front algorithm
Maximum Flow
• Push-relabel algorithm has runtime
Better than Ford-Fulkerson method!
• The order in which we “push” and “relabel” is arbitrary
• We can do better if we choose a good order
• Relabel-to-front achieves runtime with “dynamic trees” even
O (V 2 E )
O (V 3 )
Max-Flow Algorithms Maximum Flow overview
method algorithm runtime
Ford-Fulkerson naive
Ford-Fulkerson Edmonds-Karp push-relabel naive
push-relabel relabel-to-front push-relabel + dynamic trees
O (E | f ? | )
Network Flows
(and why you should like them)
How does this link to ML2
How does this link to ML2
unary costs
ising & edge costs
How does this link to ML2
unary costs
ising & edge costs
How does this link to ML2
• Binary submodular problem → ‘graph cut’!
• K-ary submod. problem → ‘binarize’ → graph cut!
• Metric k-ary problem → α-Expansion → needs gc!
• Semimetric k-ary problem → αβ-Swap → needs gc!
Network Flows
(and why you should like them)
Parametric Max-Flow
Parametric Max-Flow
• Why parametric?
Kolmogorov, V., Boykov, Y., & Rother, C.; (ICCV 2007);
Applications of parametric maxflow in computer vision.
Parametric Max-Flow
Kolmogorov, V., Boykov, Y., & Rother, C.; (ICCV 2007);
Applications of parametric maxflow in computer vision.
Goal: constructing a complete list (x1
,I
1),…,(x
k,I
k)
such that solutions x
iis optimal for interval λ∈I
iand
sup I
i⩽ I
jfor adjacent intervals in the list.
Parametric Max-Flow
Kolmogorov, V., Boykov, Y., & Rother, C.; (ICCV 2007);
Applications of parametric maxflow in computer vision.
Goal: constructing a complete list (x1
,I
1),…,(x
k,I
k)
such that solutions x
iis optimal for interval λ∈I
iand
sup I
i⩽ I
jfor adjacent intervals in the list.
Parametric Max-Flow
Kolmogorov, V., Boykov, Y., & Rother, C.; (ICCV 2007);
Applications of parametric maxflow in computer vision.
Goal: constructing a complete list (x1
,I
1),…,(x
k,I
k)
such that solutions x
iis optimal for interval λ∈I
iand
sup I
i⩽ I
jfor adjacent intervals in the list.
Parametric Max-Flow
Kolmogorov, V., Boykov, Y., & Rother, C.; (ICCV 2007);
Applications of parametric maxflow in computer vision.
Goal: constructing a complete list (x1
,I
1),…,(x
k,I
k)
such that solutions x
iis optimal for interval λ∈I
iand
sup I
i⩽ I
jfor adjacent intervals in the list.
Parametric Max-Flow
Kolmogorov, V., Boykov, Y., & Rother, C.; (ICCV 2007);
Applications of parametric maxflow in computer vision.
Goal: constructing a complete list (x1
,I
1),…,(x
k,I
k)
such that solutions x
iis optimal for interval λ∈I
iand
sup I
i⩽ I
jfor adjacent intervals in the list.
Parametric Max-Flow
Kolmogorov, V., Boykov, Y., & Rother, C.; (ICCV 2007);
Applications of parametric maxflow in computer vision.
Goal: constructing a complete list (x1
,I
1),…,(x
k,I
k)
such that solutions x
iis optimal for interval λ∈I
iand
sup I
i⩽ I
jfor adjacent intervals in the list.
Parametric Max-Flow
Kolmogorov, V., Boykov, Y., & Rother, C.; (ICCV 2007);
Applications of parametric maxflow in computer vision.
Goal: constructing a complete list (x1
,I
1),…,(x
k,I
k)
such that solutions x
iis optimal for interval λ∈I
iand
sup I
i⩽ I
jfor adjacent intervals in the list.
Parametric Max-Flow
Kolmogorov, V., Boykov, Y., & Rother, C.; (ICCV 2007);
Applications of parametric maxflow in computer vision.
Goal: constructing a complete list (x1
,I
1),…,(x
k,I
k)
such that solutions x
iis optimal for interval λ∈I
iand
sup I
i⩽ I
jfor adjacent intervals in the list.
Parametric Max-Flow
What we just did is known as the ES-method
[Eisner and Severence, 1976]
Goal: maintaining a list (x1,I1),…,(xk,Ik) such that solutions xi is optimal for interval λ∈Ii and sup Ii ⩽ Ij for adjacent intervals in the list.
Parametric Max-Flow
Goal: maintaining a list (x1,I1),…,(xk,Ik) such that solutions xi is optimal for interval λ∈Ii and sup Ii ⩽ Ij for adjacent intervals in the list.
Runtime?!
We have to minimize the energy potentially for all possible break- points B. (Number of call to max- flow is in fact bounded by 2B+2.) A proof exists that |B| can be
exponential in the size of the problem. Not so cool!
…but…
What we just did is known as the ES-method
[Eisner and Severence, 1976]
Parametric Max-Flow
• The monotone case is simpler!
• Monotone??? → All b u are positive (or all negative).
Parametric Max-Flow
• Linear many max-flow operations are enough.
(Not exponentially many any more!)
• Max-flow can be “warm-started” by reusing the
previous residual flow network!
Parametric Max-Flow
Kolmogorov, V., Boykov, Y., & Rother, C.; (ICCV 2007);
Applications of parametric maxflow in computer vision.
λ 1
λ 2
Parametric Max-Flow
Kolmogorov, V., Boykov, Y., & Rother, C.; (ICCV 2007);
Applications of parametric maxflow in computer vision.
• Fix bright part to label ‘1’.
• Fix green part to label ‘0’.
• Compute max-flow only on the violet areas.
This gives you an intermediate result at λ.
Parametric Max-Flow
Kolmogorov, V., Boykov, Y., & Rother, C.; (ICCV 2007);
Applications of parametric maxflow in computer vision.
• Fix bright part to label ‘1’.
• Fix green part to label ‘0’.
• Compute max-flow only on the violet areas.
This gives you an intermediate result at λ.
λ
Parametric Max-Flow
• Some more examples (playing with priors):
Parametric Max-Flow
• Tests on Ising Prior (k 2 )
k1 = 1, k2 = 0.01, k3 = 0
9389 cuts 6058 cuts k1 = 1, k2 = 0.1, k3 = 0
k1 = 1, k2 = 1, k3 = 0
2027 cuts 2104 cuts k1 = 1, k2 = 10, k3 = 0
Parametric Max-Flow
• Tests on Edge Prior (k 3 )
k1 = 1, k2 = 0, k3 = 10
4515 cuts
18833 cuts
k1 = 1, k2 = 0, k3 = 1 k1 = 1, k2 = 0, k3 = 0.1
18833 cuts
k1 = 1, k2 = 0, k3 = 100
469 cuts