07maxflow Applications
07maxflow Applications
Network Flow
1
7.5 Bipartite Matching
Bipartite Matching
Bipartite matching.
■ Input: undirected, bipartite graph G = (L ∪ R, E).
■ M ⊆ E is a matching if each node appears in at most edge in M.
■ Max matching: find a max cardinality matching.
1 1'
2 2' matching
1-2', 3-1', 4-5'
3 3'
4 4'
L 5 5' R
4
Bipartite Matching
Bipartite matching.
■ Input: undirected, bipartite graph G = (L ∪ R, E).
■ M ⊆ E is a matching if each node appears in at most edge in M.
■ Max matching: find a max cardinality matching.
1 1'
3 3'
4 4'
L 5 5' R
5
Bipartite Matching
G' 1 ∞ 1'
1 1
2 2'
s 3 3' t
4 4'
L 5 5' R
6
Bipartite Matching: Proof of Correctness
1 1' 1 ∞ 1'
1 1
2 2' 2 2'
3 3' s 3 3' t
4 4' 4 4'
G G'
5 5' 5 5'
7
Bipartite Matching: Proof of Correctness
1 ∞ 1' 1 1'
1 1
2 2' 2 2'
s 3 3' t 3 3'
4 4' 4 4'
G' G
5 5' 5 5'
8
Perfect Matching
9
Perfect Matching
Notation. Let S be a subset of nodes, and let N(S) be the set of nodes
adjacent to nodes in S.
1 1'
4 4'
L 5 5' R
10
Marriage Theorem
1 1'
4 4'
L 5 5' R
11
7.6 Disjoint Paths
Edge Disjoint Paths
Disjoint path problem. Given a digraph G = (V, E) and two nodes s and t,
find the max number of edge-disjoint s-t paths.
2 5
s 3 6 t
4 7
15
Edge Disjoint Paths
Disjoint path problem. Given a digraph G = (V, E) and two nodes s and t,
find the max number of edge-disjoint s-t paths.
2 5
s 3 6 t
4 7
16
Edge Disjoint Paths
1
1 1
1 1
1
s 1 1 t
1
1 1 1 1
Theorem. Max number edge-disjoint s-t paths equals max flow value.
Pf. ≤
■ Suppose there are k edge-disjoint paths P1, . . . , Pk.
■ Set f(e) = 1 if e participates in some path Pi ; else set f(e) = 0.
■ Since paths are edge-disjoint, f is a flow of value k. ▪
17
Edge Disjoint Paths
1
1 1
1 1
1
s 1 1 t
1
1 1 1 1
Theorem. Max number edge-disjoint s-t paths equals max flow value.
Pf. ≥
■ Suppose max flow value is k.
■ Integrality theorem ⇒ there exists 0-1 flow f of value k.
■ Consider edge (s, u) with f(s, u) = 1.
– by conservation, there exists an edge (u, v) with f(u, v) = 1
– continue until reach t, always choosing a new edge
■ Produces k (not necessarily simple) edge-disjoint paths. ▪
can eliminate cycles to get simple paths if desired
18
Network Connectivity
2 5
s 3 6 t
4 7
19
Edge Disjoint Paths and Network Connectivity
Pf. ≤
■ Suppose the removal of F ⊆ E disconnects t from s, and |F| = k.
■ All s-t paths use at least one edge of F. Hence, the number of edge-
disjoint paths is at most k. ▪
2 5 2 5
s 3 6 t s 3 6 t
4 7 4 7
20
Disjoint Paths and Network Connectivity
Pf. ≥
■ Suppose max number of edge-disjoint paths is k.
■ Then max flow value is k.
■ Max-flow min-cut ⇒ cut (A, B) of capacity k.
■ Let F be set of edges going from A to B.
■ |F| = k and disconnects t from s. ▪
2 5 2 5
A
s 3 6 t s 3 6 t
4 7 4 7
21
7.7 Extensions to Max Flow
Circulation with Demands
23
Circulation with Demands
-8 -6 supply
6 1
4 7 7 7
10 6 6 9
4 2
-7
3
3 4 11
10 0 4
capacity demand
flow
24
Circulation with Demands
-8 -6 supply
G:
4 7 7
10 6 9
4
-7
3 4 11
10 0
demand
25
Circulation with Demands
7 8 6 supply
G':
7 7
10 6 9
4
3 4
0
10 11 demand
26
Circulation with Demands
Pf. Follows from max flow formulation and integrality theorem for max
flow.
27
7.10 Image Segmentation
Image Segmentation
Image segmentation.
■Central problem in image processing.
■Divide image into coherent regions.
34
Image Segmentation
Goals.
■ Accuracy: if ai > bi in isolation, prefer to label i in foreground.
■ Smoothness: if many neighbors of i are labeled foreground, we
should be inclined to label i as foreground.
■ Find partition (A, B) that maximizes: ∑ a i + ∑ b j − ∑ pij
i∈ A j∈B (i, j) ∈ E
foreground background A{i, j} = 1
35
€
Graph Cut
J. Kosecka
Interactive Foreground Segmentation
■ or alternatively ∑ a j + ∑ bi + ∑ pij
j∈B i∈ A (i, j) ∈ E
€ A{i, j} = 1
38
€
Image Segmentation
aj
i pij j
s t
bi
G'
39
Image Segmentation
aj
i pij j
s t
bi
A
G'
40
Graph Cut
Formulated as maximum cost flow - Network flow problem from Graph Theory
Kolmogorov, Boykov (et al)
Ex.:Foreground/Background Segmentation
45
Project Selection: Prerequisite Graph
Prerequisite graph.
■ Include an edge from v to w if can't do v without also doing w.
■ {v, w, x} is feasible subset of projects.
■ {v, x} is infeasible subset of projects.
■ Select a set of projects A such that every project in A has also
prerequisite in A
w w
v x v x
feasible infeasible
46
Project Selection: Min Cut Formulation
u ∞ w
∞
pu ∞ -pw
s py y ∞ z -pz t
pv ∞ -px
v ∞ x
∞
47
Project Selection: Min Cut Formulation
€ w u
A pu
-pw
s py y z t
pv ∞ -px
v ∞ x
∞
48
7.12 Baseball Elimination
Which teams have a chance of finishing the season with most wins?
■Montreal eliminated since it can finish with at most 80 wins, but
Atlanta already has 83.
■wi + ri < wj ⇒ team i eliminated.
■Only reason sports writers appear to be aware of.
■Sufficient, but not necessary!
51
Baseball Elimination
Which teams have a chance of finishing the season with most wins?
■Philly can win 83, but still eliminated . . .
■If Atlanta loses a game, then some other team wins one.
Remark. Answer depends not just on how many games already won and
left to play, but also on whom they're against.
52
Baseball Elimination
54
Baseball Elimination: Max Flow Formulation
1-2
1
∞
1-5
s r24 = 7 2-4 ∞ 4 w3 + r3 - w4 t
2-5
Theorem. Team 3 is not eliminated iff max flow saturates all edges
leaving source.
■ Integrality theorem ⇒ each remaining game between x and y added
to number of wins for team x or team y.
■ Capacity on (x, t) edges ensure no team wins too many games.
1-2
1
∞
1-5
s r24 = 7 2-4 ∞ 4 w3 + r3 - w4 t
2-5
Which teams have a chance of finishing the season with most wins?
■Detroit could finish season with 49 + 27 = 76 wins.
57
Baseball Elimination: Explanation for Sports Writers
Which teams have a chance of finishing the season with most wins?
■Detroit could finish season with 49 + 27 = 76 wins.
Certificate of elimination.
# remaining games
#
wins
T ⊆ S, w(T ) := ∑ wi , g(T ) := ∑ gx y ,
i∈T {x, y} ⊆ T
59
Baseball Elimination: Explanation for Sports Writers
Pf of theorem.
■ Use max flow formulation, and consider min cut (A, B).
■ Define T* = team nodes on source side of min cut.
■ Observe x-y ∈ A iff both x ∈ T* and y ∈ T*.
– infinite capacity edges ensure if x-y ∈ A then x ∈ A and y ∈ A
– if x ∈ A and y ∈ A but x-y ∈ T, then adding x-y to A decreases
capacity of cut
∞
s r24 = 7 x-y ∞ x wz + rz - wx t
60
Baseball Elimination: Explanation for Sports Writers
Pf of theorem.
■ Use max flow formulation, and consider min cut (A, B).
■ Define T* = team nodes on source side of min cut.
■ Observe x-y ∈ A iff both x ∈ T* and y ∈ T*.
■ g(S − {z}) > cap(A, B)
capacity of game edges leaving s capacity of team edges leaving s
= g(S − {z}) − g(T *) + ∑ (wz + gz − wx )
x ∈ T*
= g(S − {z}) − g(T *) − w(T *) + | T * | (wz + gz )
€ w(T *) + g(T *)
■ Rearranging terms: wz + gz < ▪
|T*|
61