chapter 26 maximum flow how do we transport the maximum amount data from source to sink? some of...
TRANSCRIPT
Chapter 26
Maximum Flow
How do we transport the maximum amount data from source to sink?
Some of these slides are adapted from Lecture Notes of Kevin Wayne.
Contents
Contents. Maximum flow problem. Minimum cut problem. Max-flow min-cut theorem. Augmenting path algorithm. Capacity-scaling. Shortest augmenting path.
Networks
communication
Network
telephone exchanges,computers, satellites
Nodes Arcs
cables, fiber optics,microwave relays
Flow
voice, video,packets
circuitsgates, registers,processors
wires current
mechanical joints rods, beams, springs heat, energy
hydraulicreservoirs, pumpingstations, lakes
pipelines fluid, oil
financial stocks, currency transactions money
transportationairports, rail yards,street intersections
highways, railbeds,airway routes
freight,vehicles,passengers
chemical sites bonds energy
biological genes pathways interactions
Max flow and min cut.Two very rich algorithmic problems.Cornerstone problem in combinatorial
optimization.Beautiful mathematical duality.
Nontrivial applications / reductions.Network connectivity.Bipartite matching.Data mining. Image processing. Airline scheduling.Project selection.Network reliability.
Security of statistical data.
Distributed computing.
Egalitarian stable matching.
Distributed computing.
Computational biology.
Many many more . . .
Maximum Flow & Minimum Cut
Flow network: G = (V, E, s, t, c). (V, E) = weighted directed graph. Two distinguished vertices (nodes):
s=source, t=sink. c(u,v) = capacity of edge (arc) e=(u,v).
Flow Network
Capacity
s
2
3
4
5
6
7
t
15
5
30
15
10
8
15
9
6 10
10
10 15 4
4
A positive s-t flow is a func. p: V ´ V ® R that satisfies: For all u, v Î V: 0 p(u,v) c(u,v) (capacity
constrain)
For all u V–{s, t}: (flow conservation)
(flows out) (flows in)
Positive Flows
VvVv
uvpvup ),(),(
s
2
3
4
5
6
7
t
15
5
30
15
10
8
15
9
6 10
10
10 15 4
4
4
0
0
0
0
0 0
0 4 4
04 0
00Capacity
Flow
Positive Flows A positive s-t flow is a func. p: V ´ V ® R that satisfies: For all u, v Î V: 0 p(u,v) c(u,v) (capacity
constrain) For all u V–{s, t}: (flow
conservation)
(flows out) (flows in)MAX FLOW: positive s-t flow that maximizes net flow out of the source.
VvVv
uvpvup ),(),(
Vv
vspp ),(
0
Value = 4
Capacity
0
s
2
3
4
5
6
7
t
15
5
30
15
10
8
15
9
6 10
10
10 15 4
4
4 0
0
0 0
0 4 4
04 0
00
Flow
Positive Flows A positive s-t flow is a func. p: V ´ V ® R that satisfies: For all u, v Î V: 0 p(u,v) c(u,v) (capacity
constrain) For all u V–{s, t}: (flow
conservation)
(flows out) (flows in) MAX FLOW: find positive s-t flow that maximizes net flow out of the source.
VvVv
uvpvup ),(),(
Vv
vspp ),(
s
2
3
4
5
6
7
t
15
5
30
15
10
8
15
9
6 10
10
10 15 4
4
10
6
6
11
11
1 10
3 8 8
04 0
Value = 2400
Capacity
Flow
Positive Flows A positive s-t flow is a func. p: V ´ V ® R that satisfies: For all u, v Î V: 0 p(u,v) c(u,v) (capacity
constrain) For all u V–{s, t}: (flow
conservation)
(flows out) (flows in) MAX FLOW: positive s-t flow that maximizes net flow out of the source.
VvVv
uvpvup ),(),(
Vv
vspp ),(
s
2
3
4
5
6
7
t
15
5
30
15
10
8
15
9
6 10
10
10 15 4
4
10
9
9
14
14
4 10
4 8 9
10 0
Value = 2800
Capacity
Flow
Maximum flow problem
Maximize the flow over a flow network.
s
2
3
4
5
6
7
t
15
5
30
15
10
8
15
9
6 10
10
10 15 4
4
10
9
9
14
14
4 10
4 8 9
10 0
Value = 2800
Capacity
Flow
Problem formulation
Net flow Net flow
Graph G=(V,E) – a flow network Directed, each edge has capacity c(u,v) ³ 0 Two special vertices: source s, and sink t For any other vertex v, there is a path s®…®v®…®t
A (net) s-t flow is a func. f : V ´ V ® R that satisfies Capacity constraint: For all u, v Î V: f(u,v) £
c(u,v) Skew symmetry: For all u, v Î V: f(u,v) = –
f(v,u) Flow conservation: For all u Î V – {s, t}:
, or( , ) ( , ) 0
( , ) ( , ) 0v V
v V
f u v f u V
f v u f V u
Cancellation of flows
Do we want to have flows going in both directions between two vertices? No! such flows cancel (maybe partially)
each other Skew symmetry – notational
convenience
13
11
54
15
10
14
19
3
s t9
a b
c d
2 5
3
3
6
6
13
11
54
15
10
14
19
3
s t9
a b
c d
3
3
3
6
6
Equivalence of Definitions
Define net flow in terms of positive flows
f(u, v) = p(u, v) - p(v, u)
How do we know f defined this way is a net flow?
Capacity constrain Flow conservation Skew symmetry
Equivalence of Definitions
Define positive flow in terms of net flow
p(u, v) = f(u, v) if f(v, u) >0 = 0 o.w.
How do we know p defined this way is a positive flow?
Capacity constrain Flow conservation
In literature, 2 views of flow are used. The current version (3rd edition) of our book uses positive flow.
Flow conservation Define positive flow in terms of net flow
p(u, v) = f(u, v) if f(v, u) >0 = 0 o.w.
0),(
),(),(
show toNeed
Vv
VvVv
vuf
Given
uvpvup
0),(),(
),(),(
),(),(
0),(0),(
0),(0),(
VvVv
vufVv
vufVv
vufVv
vufVv
uvpvup
uvpvup
vufvuf
Implicit Summation Notation
Function over sets summation:
Flow conservation for positive flow:
Flow conservation for net flow:
},{ ),,(),( tsVuuVpVup
YyXx
yxfYXf ),(),(
},{ ,0),( tsVuVuf
Flow Conservation Theorem
proof: ?
( , ) ( , ) ( , )v V
f f s v f s V f V t
s
2
3
4
5
6
7
t
15
5
30
15
10
8
15
9
6 10
10
10 15 4
4
10
9
9
14
14
4 10
4 8 9
10 0
Value = 2800
Capacity
Flow
28 28
Lemma G = (V,E) is a flow network. f is a net flow
in G. f (X,X) = 0, X, Y V f (X,Y) = − f (Y,X), X, Y V f (XY, Z) = f (X,Z)+ f (Y,Z), X,Y,ZV & XY= f (Z, XY) = f (Z,X)+ f (Z,Y), X,Y,ZV & XY=
Proof: …
Flow Conservation Theorem
proof:
. ),(
),(),(
}),{,(),(
),(
),(),(),(
},{
tVf
uVftVf
tsVVftVf
sVVf
VsVfVVfVsff
tsVu
( , ) ( , ) ( , )v V
f f s v f s V f V t
).,(),(
)},{}({),(0
VsVfVsf
VssVfVVf
Flow conservation
An s-t cut is a node partition (S, T) s.t. s S, t T. The capacity of an s-t cut (S, T) is:
Min s-t cut: find an s-t cut of minimum capacity.
Cuts
Vvu
TvSu
vuc
,,
).,(
s
2
3
4
5
6
7
t
15
5
30
15
10
8
15
9
6 10
10
10 15 4
4
Capacity = 30
Cuts An s-t cut is a node partition (S, T) s.t. s S, t T. The capacity of an s-t cut (S, T) is:
Min s-t cut: find an s-t cut of minimum capacity.
s
2
3
4
5
6
7
t
15
5
30
15
10
8
15
9
6 10
10
10 15 4
4
Capacity = 62
Vvu
TvSu
vuc
,,
).,(
Cuts An s-t cut is a node partition (S, T) s.t. s S, t T. The capacity of an s-t cut (S, T) is:
Min s-t cut: find an s-t cut of minimum capacity.
Vvu
TvSu
vuc
,,
).,(
s
2
3
4
5
6
7
t
15
5
30
15
10
8
15
9
6 10
10
10 15 4
4
Capacity = 28
Recall the example
s
2
3
4
5
6
7
t
15
5
30
15
10
8
15
9
6 10
10
10 15 4
4
10
9
9
14
14
4 10
4 8 9
10 0
Value = 2800
Capacity
Flow
Lemma 1. Let f be a net flow, and let (S, T) be a cut. Then, the net flow sent across the cut is equal to the amount reaching t.
Flows and Cuts
Value = 24
s
2
3
4
5
6
7
t
15
5
30
15
10
8
15
9
6 10
10
10 15 4
4
10
6
6
10
10
0 10
4 8 8
0
4 0
00
Flows and Cuts
10
6
6
10
10
0 10
4 8 8
04 0
00
s
2
3
4
5
6
7
t
15
5
30
15
10
8
15
9
6 10
10
10 15 4
4
Value = 24
Lemma 1. Let f be a flow, and let (S, T) be a cut. Then, the net flow sent across the cut is equal to the amount reaching t.
Flows and Cuts
Value = 24
Lemma 1. Let f be a flow, and let (S, T) be a cut. Then, the net flow sent across the cut is equal to the amount reaching t.
10
6
6
10
10
0 10
4 8 8
04 0
0
s
2
3
4
5
6
7
t
15
5
30
15
10
8
15
9
6 10
10
10 15
4 0
4
Proof of the Lemma 1 For any flow f , the flow across any
cut (S, T) is the flow value | f |, i.e. f (S, T) = | f | = f (s, V).
Proof:f (S, T) = f (S, V−S) = f (S, V) –
f (S, S) = f (s, V) + f (S-s, V) = | f |.
(flow conservation)
(lemma 1)
Flows and CutsLemma 2. f is a flow & (S, T) is a cut. Then |f| c(S, T).
Proof.
Corollary. Let f be a flow, and let (S, T) be a cut. If |f| = c(S, T), then f is a max flow and (S, T) is a min cut.
s
t
S T
7
6
84
Su Tv
Su Tv
TScvuc
vufTSff
),(),(
),(),(||
Max Flow and Min Cut
Corollary. Let f be a flow, and let (S, T) be a cut. If |f| = c(S, T), then f is a max flow and (S, T) is a min cut.
Flow value = 28
s
2
3
4
5
6
7
t
15
5
30
15
10
8
15
9
6 10
10
10 15 4
4
10
9
9
14
14
4 10
4 8 9
1
0 0
00
Cut capacity = 62
Max Flow and Min Cut
Corollary. Let f be a flow, and let (S, T) be a cut. If |f| = c(S, T), then f is a max flow and (S, T) is a min cut.
Flow value = 28
s
2
3
4
5
6
7
t
15
5
30
15
10
8
15
9
6 10
10
10 15 4
4
10
9
9
14
14
4 10
4 8 9
1
0 0
00
Cut capacity = 28
Summary
Lemma 1. Let f be a flow, and let (S, T) be a cut. Then, the net flow sent across the cut is equal to the amount reaching t.
Lemma 2. f is a flow & (S, T) is a cut. Then |f| c(S, T).Corollary. Let f be a flow, and let (S, T)
be a cut. If |f| = c(S, T), then f is a max flow and (S, T) is a min cut.
Contents
Maximum flow problem. Minimum cut problem. Max-flow min-cut theorem. Augmenting path algorithm. Capacity-scaling. Shortest augmenting path.
Max-Flow Min-Cut Theorem
MAX-FLOW MIN-CUT THEOREM (Ford-Fulkerson, 1956): In any network, the value of the max flow is equal to the value of the min cut.Proof: ?
Flow value = 28
s
2
3
4
5
6
7
t
15
5
30
15
10
8
15
9
6 10
10
10 15 4
4
10
9
9
14
14
4 10
4 8 9
1
0 0
00
Cut capacity = 28
Flow value = 0
s
4
2
5
3 t
4
0 0
0 0 0
0
40
4 4
10 13 10
Towards an Algorithm Find an s-t path where each edge e=(u,v) has c(e) > f(e) and "augment" flow along the path.
Towards an Algorithm Find an s-t path where each arc e=(u,v) has c(e) > f(e) and "augment" flow along the path. Repeat until you get stuck.
Flow value = 10
s
4
2
5
3 t
4
0 0
0 0 0
0
40
4 4
10 13 1010 10 10
A Greedy AlgorithmThe design of this algorithm?
Towards an Algorithm Find an s-t path where each arc has u(e) > f(e) and "augment" flow along the path. Repeat until you get stuck. The straight forward greedy algorithm fails. Flow value = 10
s
4
2
5
3 t 10 13 10
4
0 00
40
4 4
10 10 10
Flow value = 14
s
4
2
5
3 t 10 13 10
4 4
4 4
10
4 4
106
4
4
Residual Network Let f be a flow on G = (V, E). The residual
network Gf = (V, Ef ) is the graph with strictly positive residual capacities:
cf (u,v) = c(u,v)−f (u,v) > 0, (where f (u,v) >0)
Ef = {(u,v)VV| cf (u,v)>0}. Gf contains edges of G that can admit more net
flow.(Gf GGT, where GT has G’s edges in reverse.)
s
2
3
5
6
t 5
11
11
5
4
15
5 12 5
8 3
41
79
s
2
3
5
6
t
13
16
14
9
12
4
20
7
11
12
15
811
4
4
7110
flow network and flow f
residual network
Residual Arcs Original graph G = (V, E). Flow f(u,v). Arc e = (u, v) E.
Residual graph: Gf = (V, Ef ). Residual arcs e = (u, v) and eR = (v, u). "Undo" flow sent.
u v 17
6
Capacity
Flow
u v 11
Residual capacity
6
Residual capacity
Residual Graph & Augmenting Paths
Residual graph: Gf = (V, Ef ).
s
4
2
5
3 t 10 13 10
4
4
4 4G
s
4
2
5
3 t 10 10 10
4
4
4 4
3
Gf
10 10 10
s
4
2
5
3 t 10 13 10
4
4
4 4G
s
4
2
5
3 t 10 10 10
4
4
4 4
3
Gf
10 10 10
Augmenting Path Augmenting path = path in residual graph.
Relation between flows on G & Gf
Lemma: Let f be a flow on G=(V,E), f ’ be a flow on the residual network Gf of G. Then the flow sum (f +f ’)(u,v) f (u,v)+f ’(u,v) is a flow on G and |f +f ’|=|f |+|f ’|.
Proof: f +f ’ is a flow on G (flow conservation, capacity constrain, skew
symmetry)
|f +f ’| = |f |+|f ’|
.|'|||
),('),(
),)('(|'|
ff
vsfvsf
vsffff
Vv Vv
Vv
Augmenting Path Augmenting path = path in residual graph. Max flow no augmenting paths ???
s
4
2
5
3 t 10 13 10
4
4
4 4G
s
4
2
5
3 t 10 10 10
4
4
4 4
3
Gf
10 10 10
Flow value = 14
Max-Flow Min-Cut Theorem
Augmenting path theorem (Ford-Fulkerson, 1956): A flow f is a max flow if and only if there are no augmenting paths.
MAX-FLOW MIN-CUT THEOREM (Ford-Fulkerson, 1956): the value of the max flow is equal to the value of the min cut.
We prove both theorems simultaneously by showing the TFAE: (i) f is a max flow. (ii) There is no augmenting path relative to f. (iii) There exists a cut (S, T) such that |f| = c(S,
T).
Proof We prove both simultaneously by showing the TFAE: (i) f is a max flow. (ii) There is no augmenting path relative to f. (iii) There exists a cut (S, T) such that |f| = c(S,
T).
(i) (ii) Let f be a flow. If there exists an augmenting path, then we
can improve f by sending flow along path. (proof by contradiction)
(iii) (i) This was the Corollary to Lemma 2.
Proof (ii) (iii)Let f be a flow with no augmenting paths. Let S be set of vertices reachable from s in
residual graph. Let T=V−S. Is t T. ?
(clearly s S, and t S by definition of f , o.w. augmenting path)
For each u S, v T, f (u,v) = c(u,v). ? (o.w. cf (u,v)=c(u,v)−f (u,v)>0, then v S).
Therefore: ?|f | = f (S,T) = c(S,T).
Residual Network
s
t
S T
Ford-Fulkerson algorithm
Let G=(V, E) be a flow network.
Ford-Fulkerson(G,s,t,c) 01 for each edge (u,v) in E do 02 f(u,v) ¬ f(v,u) ¬ 0 03 while there exists a path p from s to t in residual network Gf do04 cf = min{cf(u,v): (u,v) is in p} 05 for each edge (u,v) in p do06 f(u,v) ¬ f(u,v) + cf
07 f(v,u) ¬ -f(u,v)08 return f
Cost?
(E)
(V+E)depth first search orbreadth first search
(E)
( ? )
Performance
If capacities are integers, O(|E|f *), f *
is max flow found by the algorithm (not a polynomial algorithm).
Example: 1000
0
s
4
2
t 1
100
100
0
0
0
100
Performance
1001
s
4
2
t 1
100
100
1
1100
Original network and flow1
99
s
4
2
t 1
99
99
0
1100
1
0
Residual network
Performance
Maximum flow: 200
100
s
4
2
t
100
1
1
0
1
1100
100
1
200 iterations possible.
Net flow: 2.
Performance
For noninteger capacities, might never terminate.
Need more efficient algorithm (Edmonds-Karp, 1972): Augment along breadth-first augmenting
path in Gf (shortest path) Augment along max-capacity
augmenting path in Gf (capacity-scaling)
BFS for Shortest Paths
Finished Discovered Undiscovered
S2
2
2
2
22
S
3
3 3
3
3
S11
1
Data structure for BFS?
Edmonds-Karp Algorithm
Takes only two iterations.
100 100
100 100100
s
4
2
t 1
100
100
100
Shortest Augmenting Path
Intuition: choosing path via breadth first search. Easy to implement.
may implement by coincidence! Finds augmenting path with fewest number of
arcs.
FOREACH e E f(e) 0Gf residual graph
WHILE (there exists augmenting path) //find such a path P by BFS f augment(f, P) update GfRETURN f
ShortestAugmentingPath(V, E, s, t)
Cost?
Shortest Augmenting Path: Overview of
AnalysisLemma1. Throughout the algorithm, the length of the shortest path increases. Proof ahead.
Lemma2. After at most |E| shortest path augmentations, the length of the shortest augmenting path increases at least by one. Proof ahead.
Theorem. The shortest augmenting path algorithm runs in O(|V||E|2) time. O(|V|+|E|) time to find a shortest augmenting path via
BFS. O(|E| + |E||V|) augmenting paths. (lemma 2)
(If there is an augmenting path, it must be a simple one.)
Þ O(|V||E|) augmentations.Þ O((|V|+|E|)*(|V||E|)) = O(|V||E|2) running time.
Shortest Augmenting Path: Analysis
Level graph of (V, E, s). For each vertex v, define (v) to be the length (number of
edges) of shortest path from s to v. LG = (V, EG) is subgraph of G that contains only those edges
(v, w) E
with (w) = (v) + 1.
s
2
3
5
6 t
= 0 = 1 = 2 = 3
LG:
s
2
3
5
6 t
G:
Shortest Augmenting Path: Analysis
Level graph of (V, E, s). For each vertex v, define (v) to be the length of shortest
path from s to v. L = LG = (V, F) is subgraph of G that contains only those
edges (v,w) E with (w) = (v) + 1.
Compute in O(|V|+|E|) time using BFS, deleting back and side edges.
P is a shortest s-v path in G if and only if it is an s-v path in L.
s
2
3
5
6 t
= 0
= 1
= 2
= 3
L:
Shortest Augmenting Path: Analysis
Lemma1. the length of the shortest path increases. Let f and f' be flow before and after a shortest path
augmentation. Let L and L' be level graphs of residual network Gf and Gf '
Only back edges added to Gf ' path with back edge has length greater than previous length
s
2
3
5
6 t
= 0 = 1 = 2 = 3
L
s
2
3
5
6 t
L'
Shortest Augmenting Path: Analysis
Lemma2. After at most |E| shortest path augmentations, the length of the shortest augmenting path strictly increases. At least one edge (the bottleneck edge) is deleted from L
after each augmentation. No new edges added to L until length of shortest path to t
strictly increases.
s
2
3
5
6 t
= 0 = 1 = 2 = 3
L
s
2
3
5
6 t
L'
Length=3
Length=3
Shortest Augmenting Path: Review of AnalysisTheorem. The shortest augmenting path algorithm runs in O(|V||E|2) time. O(|V|+|E|) time to find a shortest augmenting path via
BFS. O(|V||E|) augmentations.Þ O((|V|+|E|)*(|V||E|)) = O(|V||E|2) running time.
More rigorous proof is given in our textbook.
Other approaches: Augment along max-capacity augmenting path in Gf
(capacity-scaling)
Capacity Scaling Intuition: choosing path with highest bottleneck capacity increases flow by max possible amount. In practice, don't worry about finding exact highest
bottleneck path. Maintain scaling parameter . Let Gf () be the subgraph of the residual graph consisting
of only arcs with capacity at least .
110
s
4
2
t 1
170
102
122
Gf
110
s
4
2
t
170
102
122
Gf (100)
Capacity Scaling Assumption: all capacities are integers
between 0 & U.
FOREACH e E, f(e) 0(smallest power of 2 greater than or equal to U)/2
WHILE ( 1) Gf() -residual graph WHILE (there exists augmenting path P in Gf()) f augment(f, P) update Gf() / 2 RETURN f
ScalingMaxFlow(V, E, s, t)
Theorem. The algorithm runs in O(|E|2 log (2U) ) time.
Capacity Scaling: Analysis
L1. If all edges capacities are integers, then throughout the algorithm, all flow and residual capacity values remain integers. Thus, = 1 Gf() = Gf , so upon termination f is a max flow.
L2. The outer while loop repeats 1 + log2 U times. Initially U/2 < U, and decreases by a factor of 2 each
iteration.
L3. Let f be the flow at the end of a -scaling phase. Then value of the maximum flow is at most | f |+| E |. (proof ahead)
L4. There are at most 2|E| augmentations per scaling phase. Let f be the flow at the end of the previous scaling phase. L3 |f*| | f | + |E| (2). Each augmentation in a -phase increases | f | by at least .
Theorem. The algorithm runs in O(|E|2 log (2U) ) time.
Capacity Scaling: Analysis
L3. Let f be the flow at the end of a -scaling phase. Then value of the maximum flow is at most |f| + |E| . We show that at the end of a -phase, there exists a cut (S,
T) such that c(S, T) | f | + |E| . Choose S to be the set of nodes reachable from s in Gf().
clearly s S, and t S by definition of S
Δ|E|-T)c(S,
)v,s(c
))v,s(c(
)s,v(f)v,s(ff
VvVvVv
VvVv
VvVv
s
t
Original Network
S T
Choosing Good Augmenting Paths:
Summary
First 4 rules assume edge capacities are between 0 and U.
Method Augmentations
Augmenting path |V|U
Max capacity |E| log U
Capacity scaling |E| log U
Shortest path |E||V|
Running time
|E||V|U
|E| log U (|E| + |V| log |V|)
|E|2 log U
|E|2|V|
Improved shortest path |E||V| |E||V|2
Improved capacity scaling |E| log U |E||V| log U
History
Dantzig
Discoverer
Simplex
Method Big-Oh
|E||V|2U1951
Year
Ford, Fulkerson Augmenting path |E||V|U1955
Edmonds-Karp Shortest path |E|2|V|1970
Dinitz Shortest path |E||V|21970
Edmonds-Karp, Dinitz Capacity scaling |E|2 log U1972
Dinitz-Gabow Capacity scaling |E||V| log U1973
Karzanov Preflow-push |V|31974
Sleator-Tarjan Dynamic trees |E||V| log |V|1983
Goldberg-Tarjan FIFO preflow-push |E||V| log (|V|2 / |E|)1986
. . . . . . . . .. . .
Goldberg-Rao Length function|E|3/2 log (|V|2 / |E|) log U
|E||V|2/3 log (|V|2 / |E|) log U1997
Network with multiple sources and sinks
Can be reduced to a single source & single sink max problem
15
14
19
30
s1 t1
a b
c d
11
1
9
13
s2 t2
e b
f d
5
4
12
23
s3 t3
g b
h d
k9 4s t
Maximum bipartite matching
Bipartite graph G=(V,E): Undirected V = V1V2, V1V2=. e=(u, v)E, uV1 and vV2
Complete bipartite: u V1, u is joined with every v V2
Matching: set of edges with no vertex included twice
Maximum matching: a matching of maximum cardinality i.e. no matching contains more edges
Applications
Dating assignment L – women, R – men. An edge between vertices: they have a chance
to be “compatible” (can be matched) Job placement
Companies make job offers Students have job choices An edge between vertices: the student can fit
the job
Example Problem: Given N men and M women, find
a matching between men and women. Participants list members of opposite sex they
like to date.
Zeus Amy Diane
Yancey Amy ClareDiane
Xavier Amy ClareErika
Wyatt Diane AmyBertha
Victor Diana Amy
Man 1st 2nd 3rd
Men’s Preference List
Can we find a perfect match? What is the max match?
Example Problem: Job placement
Can we find a perfect match? What is the max match?
Eliza IBM GoogleSun
Dave Apple Dell
Carol HP SunIBM
Bob Apple GoogleDell
Alice Apple HPDell
Student 1st 2nd 3rd
Students Preference List
Frank HP GoogleSun
Maximum bipartite matching
How can we reformulate this problem to become a max-flow problem?
Maximum bipartite matching
How can we reformulate this problem to become a max-flow problem? Keep all edges & vertices Add source connected to all vertices in one set Add sink connected to all vertices in another
set Set all capacities to 1
Theorem: The set of edges in the maxflow solution gives the solution to the maximum matching problem. Proof homework
Matching
s t
A
D
B
C
E
F
A
I
D
H
S
G
Eliza Sun
Dave Apple
Carol IBM
Bob Dell
Alice HP
Student 1st 2nd 3rd
Solution
Frank Google
111
1
1
1
11 1
11
1 11
1 1
1 1
11
1
111111
LemmaLemma 1:
Let G=(V,E), V = V1V2, V1V2=.Let G’=(V’,E’), V’ = V{s,t}, E’=…. flow networkThen: If M is a matching, then there is an integer valued flow f on
G’ with |f|=|M|. If f is an integer valued flow on G’, then there is a matching
M on G with cardinality |M|=|f|Proof:
M →f, s.t.|f|=|M|If (u,v)M, define: f(s,u)=f(u,v)=f(v,t)=1; f(u,s)=f(v,u)=f(t,v)=-1; (u,v)M, f(u,v)=0,then f is a flow and |f|=|M| ?
f →M, s.t.|M|=|f|since f is an integer valued flow, f(u,v)=1 or 0.|M|=f(V1’, V2’) = |f|
(skew symmetry, capacity constraints, flow conservation)
Integrality TheoremIntegrality Theorem: If the capacity of a flow
network is an integer function, maximum flow f produced by Ford-Fulkerson method is an integer-valued flow.
Proof: homework
Corollary: If |M| is the cardinality of a maximum matching M, then the value of a maximum flow f = |M|.
Proof: ? Show contrapositive.suppose M is a max matching and f is not a max flow,
i.e. f ’,s.t.|f ’|>|f|Then M’, s.t.|M’|=|f ’|>|f|=|M|Contradicting our assumption that M is a
maximum matching.