MaxFlow Fib
MaxFlow Fib
2/2
A D
2/2
2/4 0/9 1/1
1/5
S B 0/3 T
1/2
4/4 5/5
C E
5/5
2/2 S = {s,c,d}
a d
2/2 T={a,b,e,t}
2/4 0/9 1/1
1/5
s b 0/3 t
1/2 c(S,T)=(4+5+5)+(3+2)=19
4/4 5/5
c e f(S,T)=(2+1+5)+(0+2−1−2)=7
5/5
The s − t cut
Given (G = (V , E ), s, t, c) a s − t cut is a partition of V = S ∪ T
so S ∩ T = ∅), with s ∈ S and t ∈ T .
The flowPacross
Pthe cut: P P
f (S) = u∈S v ∈T f (u, v ) − v ∈S u∈T f (v , u).
P P
The capacity of the cut: c(S) = u∈S v ∈T f (u, v )
Notice because of the capacity constrain: f (S) ≤ c(S)
2/2 S = {s,c,a}
a d
2/2 T={d,b,e,t}
2/4 0/9 1/1
1/5
s b 0/3 t
1/2 c(S,T)=2+5+5=12
4/4 5/5
c e f(S,T)=2+1+5−1=7
5/5
Notation
Given v ∈ G and cut (S, T ) and a v ∈ S, let S 0 = S − {v }. Then
I Denote f (S 0 , T ) flow between S 0 and T (without passing by
v ), i.e.
f (S 0 , T ) = u∈S 0 w ∈T f (u, w ) − w ∈T u∈S 0 f (w , u)
P P P P
with (u, w ) ∈ E and (u, w ) ∈ E ,
P
I denote f (v , T ) flow v → T i.e. f (v , T ) = u∈T f (v , u),
P
I denote f (T , v ) flow T → v i.e. f (T , v ) = u∈T f (u, v ),
denote f (S 0 , v ) flow S 0 → v i.e. f (S 0 , v ) = u∈S 0 f (u, v ),
P
I
T
s S’ t
S v
Any s − t cut has the same flow
Theorem
Given (G , s, t, c) the flow through any s − t cut (S, T ) is
f (S) = |f |.
Proof (Induction on |S|)
I If S = {s} then f (S) = |f |.
I Assume it is true for S 0 = S − {v }, i.e. f (S 0 ) = |f |.
Notice f (S 0 ) = f (S 0 , T ) + f (S 0 , v ) − f (v , S 0 ). Moreover from
the flow conservation, f (S 0 , v ) + f (T , v ) = f (v , S 0 ) + f (v , T )
⇒ f (v , T ) − f (T , v ) = f (S 0 , v ) − f (v , S 0 )
| {z }
∗
I Then f (S) = f (S 0 , T ) + f (v , T ) − f (T , v ), using (∗)
f (S) = f (S 0 ) = |f | 2
T
s S’ t
S v
Residual network
Given a network (G = (V , E ), s, t, c) together with a flow f on it,
the residual network, (Gf = (V , Ef ), cf ) is the network with the
same vertex set and edge set:
I if c(u, v ) − f (u, v ) > 0 then (u, v ) ∈ Ef and
cf (u, v ) = c(u, v ) − f (u, v ) > 0 (forward edges), and
I if f (u, v ) > 0 then (v , u) ∈ Ef and cf (v , u) = f (u, v )
(backward edges). i.e. there are f (u, v ) units of flow we can
undo, by pushing flow backward
I the cf are denoted residual capacity.
2/2 a 0/1 a 1
2
s 2/3 t s 2 1 t
Gf
0/1 b 2/2 1 b 2
Residual network: Augmenting paths
a 1 a 1/1 a 1
2 2/2 2
Gf s 2 1 t s 1/3 t s 1 2 t
1 2 1/1 2/2 G f´ 1 2
b f´ b b
P: dotted line
Residual network: Augmenting paths
Lemma
Consider f 0 =Augment(P, f ), then f 0 is a flow in G .
Proof: We have to prove that (1) ∀e ∈ E , 0 ≤ f (e) ≤ c(e) and
that ∀v flow to v = flow out of v .
I Capacity law Forward edges (u, v ) ∈ P we increase f (u, v ) by
b, as b ≤ c(u, v ) − f (u, v ) then
f 0 (u, v ) = f (u, v ) + b ≤ c(u, v ).
Backward edges (u, v ) ∈ P we decrease f (v , u) by b, as
b ≤ f (v , u), f 0 (v , u) = f (u, v ) − b ≥ 0.
I Conservation law, ∀v ∈ P given edges e1 , e2 in P and incident
to v , it is easy to check the 4 cases based whether e1 , e2 are
forward or backward edges. 2
Max-Flow Min-Cut theorem
Theorem
For any (G , s, t, c) the value of the max flow f ∗ is equal to the
capacity of the min s − t-cut (over all s − t cuts in G )
This is typical example of LP duality!
Proof:
I For any s − t cut (S, T ) in G ⇒ f (S) ≤ c(S, T ).
I Suppose by hypothesis that f ∗ in G is a max flow, i.e. f ∗ has
no augmenting path, then Gf ∗ has no s ; t path. Let
Ss = {v ∈ V |∃s ; v in Gf ∗ }, notice t 6∈ Ss and moreover
(Ss , V − {Ss }) is a s − t cut in Gf ∗ ⇒ ∀v ∈ Ss , u ∈ V − {Ss }
we have not residual edges in the cut, so that in G
f ∗ (v , u) = c(v , u), and therefore
c(Ss , V − {Ss }) = f ∗ (Ss , V − {Ss }) in G .
I As any max-flow must be ≤ min-cut, then in particular
(Ss , V − {Ss }) is a min-cut in G and it is equal to the
max-flow f ∗ . 2
Ford-Fulkerson algorithm
L.R. Ford, D.R. Fulkerson:
Maximal flow through a
network. Canadian J. of Math.
1956.
Lemma
If f is a flow in G and f 0 is the flow after an augmentation, then
|f | < |f 0 |.
Proof: Let P be the augmenting path in Gf . The first edge e ∈ P
leaves s, and as G has no incoming edges to s, e is a forward edge.
Moreover P is simple ⇒ never returns to s. Therefore, the value of
the flow increases in edge e. 2
Correctness of Ford-Fulkerson
Lemma
Let C be the minimum cut value, Ford-Fulkerson terminates after
finding at most C augmenting paths.
Proof: The value of the flow increases by ≥ 1 after each
augmentation. 2
Edmonds-Karp(G , s, t, c)
For all e = (u, v ) ∈ E let f (u, v ) = 0
G0 = G a
C C
while there is an s t path in Gf
s 1 1 t
do
P = BFS(Gf , s, t) C b C
f 0 = Augment(f , P)
Update Gf = Gf 0 and f = f 0 The BFS in EK will
choose: or
end while
return f
Level graph
Given G = (V , E ), s, define LG = (V , EG ) to be its the level graph
by:
I `(v ) = number of edges in shortest path s v in G ,
I LG = (V , EG ) is the subgraph of G that contains only edges
(v , w ) ∈ E s.t. `(w ) = `(v ) + 1.
Notice:
I Using BFS we can compute LG in O(n + m)
I Important property: P is a shortest s ; t in G iff P is an
s ; t path in LG .
a 2 d a 2 d
2 2
4 1 4 1
9
s 5 b 3 t s 5 b t
2
4 5 4 5
G LG
c e c e
5 5
1 2 3 1 2 3
The working of the EK algorithm
G,f G,f´
a 2 d a 2 d
2 1/2
4 9 1 4 9 1/1
s 5 b 3 t s 1/5 b 3 t
2
2
4/4 4/4
4/5 4/5
c e c e
4/5 4/5
a 2 d a 2 d 1
2 1
4 1 4 9 1
9
s 5 b 3 4 t s 4 b 2 3 4 t
2
4 1 4
1 1
Gf 4 G f’ 4
c e c e
1 1
a 2 d a 1/2 d
1/2 1/1
4 1/1 1/4
s
1/5 b 3 t 4
2 s b
2 3 t
L 1 L 1
c e c e
The working of the EK algorithm
a 1/2 d 1 a 1 1 d 1
1/1
1/4 1 3 9 1
s b 3 t s 4 b 2 3 4 t
2 1 4
1 1
G f’’ 4
c e c e
1
a 1/2 d a 1 d
1/4 1/1 2/2 1
9
1/5 s 4 b 1 t
s b 2 3 t 2
4/5 1
4/4 L f’’
c e c e
4/5 1
G,f’’
a 2/2 d
2/4 1/1 2/2
9
1/5
s b 2 1/3 t
4/4 5/5
G,f*
c e
4/5
EK algorithm: Properties
Lemma
Throughout the algorithm, the length of the shortest path never
decreases.
Proof:
I Let f and f 0 be the flow before and after a shortest path
augmentation
I let L and L0 be the levels graphs of Gf and Gf 0 .
I Only back edges added to Gf 0 . 2
Lemma
After at most m shortest path augmentations, the length of P is
monotonically increasing.
Proof:
I The bottleneck edge is deleted from L after each
augmentation.
I No new edge is added to L until length of shortest path
strictly increases 2
Complexity of Edmonds-Karp algorithm
The running time is the same than the algorithm to find the
max-flow.
2/2
a d 2 a 2 d
2/2
2/4 0/9 1/1 2 9 1 2
1/5 4
s b 0/3 t s b 3 t
1/2 1
4/4 S 1
5/5 4 1 5
c e c e
5/5 5
The max-flow problems: History
Max matchings = 4
Maximum matching: flow formulation
1 1
s t
1 1
Maximum matching: flow formulation
1 1
s t
1 1
Maximum matching: Analysis
Theorem
Max flow in Ĝ =Max bipartite matching in G .
Proof ≤
Given a matching M in G with k-edges,
consider the flow F that sends 1 unit along each one of the k
paths.
f is a flow and has value k.
0
1 1 1
1
1 1
1
s t
1
1 1 1
0 1
1
1 11
Maximum matching: Analysis
Max flow ≤Max bipartite matching
I If there is a flow f in Ĝ , |f | = k, as capacities are Z∗ ⇒ an
integral flow existsis.
I Consider the cut C = ({s} ∪ L, R ∪ {t}) in Ĝ .
I Let F be the set of edges in C with flow=1, then |F | = k.
I Each node in L is in at most one e ∈ F and every node in R is
in at most one head of an e ∈ F
I Therefore, exists a bipartite matching F in G with |F | ≤ |f | 2
0
1 1 1
1
1 1
1
s t
1
1 1 1
1 0
1 11 1
Disjoint path problem
c
e d
s t
a b
Disjoint path problem
c
e d
s t
a b
Disjoint path problem: Max flow formulation
Theorem
The max number of edge disjoint paths s ; t is equal to the max
flow value
1 c 1 1 c 1
1 1 1 1
1 e 1 d 1 e d
1 t 1 t
s s
1 1
1 1 1 1 1 1
a b a b
Max flow=3 1
1
Disjoint path problem: Proof of the Theorem
source or a sink. 4
−3 3 −3
s
3 3 3 3
G G’ 3
−3 2 2 −3 2 2
S 2
2 2 2 2
4 4 t
T 4
Analysis
−3
3/ 3 −3
s
1/ 3 2/ 3 1/ 3 2/ 3
G 2/2 G’ 3/ 3 2/ 2
−3 2 −3 2
2/ 2
2/2 2/ 2 2/ 2 2/ 2
4 4 t
4/ 4
Analysis
−3
3/ 3 −3
s
1/ 3 2/ 3 1/ 3 2/ 3
G 2/2 G’ 3/ 3 2/ 2
−3 2 −3 2
2/ 2
2/2 2/ 2 2/ 2 2/ 2
4 4 t
4/ 4
Main results
−3 −1
[ 2,3] 3 1 3
G −3 2 2 G’ −5 2 2
2 2 2 2
4 4
Main result
Theorem
There exists a circulation in G iff there exists a circulation in G 0 .
Moreover, if all demands, capacities and lower bounds in G are
integers, then there is a circulation in G that is integer-valued.
Sketch Proof Need to prove f (e) is a circulation in G iff
f 0 (e) = f (e) − `(e) is a circulation in G 0 .
The integer-valued circulation part is a consequence of the
integer-value circulation Theorem for f 0 in G 0 . 2
Survey design problem
Problem:Design a survey among customers of products
I Each customer will receive questions about some products.
I Each customer i can only be asked bout a number of products
between ci and ci0 ([ci , ci0 ]) which he has purchased.
I For each product j we want to collect date for a minimum of
pj distinct customers and a maximum of pj0 ([pj , pj0 ])
Survey design problem
C P
a 1 Customers C={a,b,c,d} a:[1,2] 1: [1,2]
b:[1,3] 2: [1,2]
b 2 Products P={1,2,3,4,5,6} c:[1,2] 3: [1,2]
G
Customer Buys d:[2,4] 4: [1,2]
c 3
a 1,2 5: [0,1]
b 1,2,4 6: [1,2]
d 4
c 3,6
5 d 3,4,5,6
6
Survey design problem: Max flow formulation
Capacities: c(t, s) = ∞ s t
c(i, j) = 1,
c(s, i) = [ci , ci0 ],
0,1
c(j, t) = [pj , pj0 ].
Notice if f is the flow:
I f (i, j) = 1 ⇒ customer i is asked about product j,
I f (s, i) # products to ask customer i for opinion,
I f (j, t) = # customers to be asked to review product j,
I f (t, s) is the number of questions asked.
Max flow formulation: Example
10
a 1 2
[1,2] 1 1 [1,2] a 1,2 a:[1,2] 1: [1,2]
2 [1,3] 2 [1,2] b 1,2,4 b:[1,3] 2: [1,2]
3 b 1 2 [1,2] t c 3,6 c:[1,2] 3: [1,2]
s 2 1 2 d 3,4,5,6 d:[2,3] 4: [1,2]
1 [1,2]
[1,2] c 3
1 2 [1,2] 5: [0,1]
[2,3] 3 1 6: [1,2]
d 4 [0,1] 1 1
1
1
5
6
Main result
Given a set of pixels classify each pixel as part of the main object
or as part of the background.
Important problem in different techniques for image processing.
Foreground/background segmentation
I We aim to label each pixel as belonging to the foreground or
the background
I Picture pixels as a grid of dots.
I Define the undirected graph G = (V , E ), where, V = set
pixels in image, E = pairs of neighbors of pixels (in the grid)
I For each pixel i, ai ≥ 0 is likelihood that i is in the foreground
and bi ≥ 0 is likelihood that i is in the background.
I For each (i, j) of neighboring pixels, there is a separation
penalty pij ≥ 0 for placing one in the foreground and the
other in the background.
Foreground/background segmentation
Goals:
I For i isolated, if ai > bi we prefer to label i as foreground
(otherwise we label i as background)
I If many neighbors of i are labeled foreground we prefer to
label i as foreground. This makes the labeling smoother by
minimizing the amount of foreground/background
I We want to partition V into A (set of foreground pixels) and
B (set of background pixels), such that we maximize the
objective function:
X X X
ai + bj − pij
i∈A j∈B (i,j)∈E ,|A∩{i,j}|=1
Formulate as a min-cut problem
We transform G = (V , E ) to G 0 = (V 0 , E 0 ) by
I Add a upper node s representing the foreground
I Add a lower node t representing the background
I V 0 = V ∪ {s, t}
I For each (v , u) ∈ E create antiparallel directed edges (u, v )
and (v , u) in E 0
I For each pixel i create directed edges (s, i) and (i, t)
I E 0 = {(s, v ) ∪ (v , t)}v ∈E ∪ {(u, v ) ∪ (v , u)}(u,v )∈E
The undirected pixel graph G and the digraph G 0
G’
Adding capacities to the edges of G 0
s aw
puw
av
u w
ax
pvu bu pwx
v x
bw
pxv bv t
Min-cut in G 0
An s − t cut (A0 , B 0 ) corresponds to a partition of the pixels into
(A0 − {s}, B 0 − {t}), where
I Edges (s, j) with j ∈ B contributes with aj to c(A0 , B 0 ),
I edges (i, t) where i ∈ A contributes with bj to c(A0 , B 0 ),
I edges (i, j) where i ∈ A and j ∈ B contributes with pij to
c(A0 , B 0 )
Therefore,
X X X
c(A0 , B 0 ) = bi + aj + pij s aw
puw
i∈A j∈B (i,j)∈E ,|A∩{i,j}|=1 av
B0
u w
ax
We want to find the min value of the pvu bu pwx
max-flow s − t in G 0 . pxv bv t
Conclusions