Presentation is loading. Please wait.

Presentation is loading. Please wait.

Applications of Network Flow Problem. 7.5 Bipartite Matching.

Similar presentations


Presentation on theme: "Applications of Network Flow Problem. 7.5 Bipartite Matching."— Presentation transcript:

1 Applications of Network Flow Problem

2 7.5 Bipartite Matching

3 3 Matching. n Input: undirected graph G = (V, E). n M  E is a matching if each node appears in at most edge in M. n Max matching: find a max cardinality matching. Matching

4 4 Bipartite Matching Bipartite matching. n Input: undirected, bipartite graph G = (L  R, E). n M  E is a matching if each node appears in at most edge in M. n Max matching: find a max cardinality matching. 1 3 5 1' 3' 5' 2 4 2' 4' matching 1-2', 3-1', 4-5' RL Maximum matching in a bipartite matching is particularly important as it has many applications. We will look at some later.

5 5 Bipartite Matching Bipartite matching. n Input: undirected, bipartite graph G = (L  R, E). n M  E is a matching if each node appears in at most edge in M. n Max matching: find a max cardinality matching. 1 3 5 1' 3' 5' 2 4 2' 4' RL max matching 1-1', 2-2', 3-3' 4-4 '

6 6 Max flow formulation. n Create digraph G' = (L  R  {s, t}, E' ). n Direct all edges from L to R, and assign infinite (or unit) capacity. n Add source s, and unit capacity edges from s to each node in L. n Add sink t, and unit capacity edges from each node in R to t. Bipartite Matching s 1 3 5 1' 3' 5' t 2 4 2' 4' 1 1  RL G'

7 7 Theorem. Max cardinality matching in G = value of max flow in G'. Pf.  n Given max matching M of cardinality k. n Consider flow f that sends 1 unit along each of k paths. n f is a flow, and has cardinality k. ▪ Bipartite Matching: Proof of Correctness s 1 3 5 1' 3' 5' t 2 4 2' 4' 11  1 3 5 1' 3' 5' 2 4 2' 4' G' G

8 8 Theorem. Max cardinality matching in G = value of max flow in G'. Pf.  n Let f be a max flow in G' of value k. n Integrality theorem  k is integral and can assume f is 0-1. n Consider M = set of edges from L to R with f(e) = 1. – each node in L and R participates in at most one edge in M – |M| = k: consider cut (L  s, R  t) ▪ Bipartite Matching: Proof of Correctness 1 3 5 1' 3' 5' 2 4 2' 4' G s 1 3 5 1' 3' 5' t 2 4 2' 4' 11  G'

9 9 Def. A matching M  E is perfect if each node appears in exactly one edge in M. Q. When does a bipartite graph have a perfect matching? n Clearly we must have |L| = |R|. n What other conditions are necessary? n What conditions are sufficient? Perfect Matching

10 10 Notation. Let S be a subset of nodes, and let N(S) be the set of nodes adjacent to nodes in S. Observation. If a bipartite graph G = (L  R, E), has a perfect matching, then |N(S)|  |S| for all subsets S  L. Pf. Each node in S has to be matched to a different node in N(S). Perfect Matching No perfect matching: S = { 2, 4, 5 } N(S) = { 2', 5' }. 1 3 5 1' 3' 5' 2 4 2' 4' L R

11 11 Marriage Theorem. [Frobenius 1917, Hall 1935] Let G = (L  R, E) be a bipartite graph with |L| = |R|. Then, G has a perfect matching iff |N(S)|  |S| for all subsets S  L. Pf.  This was the previous observation. Marriage Theorem 1 3 5 1' 3' 5' 2 4 2' 4' L R No perfect matching: S = { 2, 4, 5 } N(S) = { 2', 5' }.

12 12 Pf.  Suppose G does not have a perfect matching. n Formulate as a max flow problem and let (A, B) be min cut in G'. n By max-flow min-cut, cap(A, B) < | L |. n Define L A = L  A, L B = L  B, R A = R  A. n cap(A, B) = | L B | + | R A |. n Since min cut can't use  edges: N(L A )  R A. n |N(L A )|  | R A | = cap(A, B) - | L B | < | L | - | L B | = | L A |. n Choose S = L A. ▪ Proof of Marriage Theorem L A = {2, 4, 5} L B = {1, 3} R A = {2', 5'} N(L A ) = {2', 5'} s 1 3 5 1' 3' 5' t 2 4 4' 1  2' 1 1 1 A  G' 

13 7.6 Disjoint Paths

14 14 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. Def. Two paths are edge-disjoint if they have no edge in common. Ex: communication networks. s 2 3 4 Edge Disjoint Paths 5 6 7 t

15 15 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. Def. Two paths are edge-disjoint if they have no edge in common. Ex: communication networks. s 2 3 4 Edge Disjoint Paths 5 6 7 t

16 16 Max flow formulation: assign unit capacity to every edge. Theorem. Max number edge-disjoint s-t paths equals max flow value. Pf.  n Suppose there are k edge-disjoint paths P 1,..., P k. n Set f(e) = 1 if e participates in some path P i ; else set f(e) = 0. n Since paths are edge-disjoint, f is a flow of value k. ▪ Edge Disjoint Paths st 1 1 1 1 1 1 1 1 1 1 1 1 1 1

17 17 Max flow formulation: assign unit capacity to every edge. Theorem. Max number edge-disjoint s-t paths equals max flow value. Pf.  n Suppose max flow value is k. n Integrality theorem  there exists 0-1 flow f of value k. n 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 n Produces k (not necessarily simple) edge-disjoint paths. ▪ Edge Disjoint Paths st 1 1 1 1 1 1 1 1 1 1 1 1 1 1 can eliminate cycles to get simple paths if desired

18 18 Network connectivity. Given a digraph G = (V, E) and two nodes s and t, find min number of edges whose removal disconnects t from s. Def. A set of edges F  E disconnects t from s if all s-t paths uses at least on edge in F. Network Connectivity s 2 3 4 5 6 7 t

19 19 Edge Disjoint Paths and Network Connectivity Theorem. [Menger 1927] The max number of edge-disjoint s-t paths is equal to the min number of edges whose removal disconnects t from s. Pf.  n Suppose the removal of F  E disconnects t from s, and |F| = k. n All s-t paths use at least one edge of F. Hence, the number of edge-disjoint paths is at most k. ▪ s 2 3 4 5 6 7 t s 2 3 4 5 6 7 t

20 20 Disjoint Paths and Network Connectivity Theorem. [Menger 1927] The max number of edge-disjoint s-t paths is equal to the min number of edges whose removal disconnects t from s. Pf.  n Suppose max number of edge-disjoint paths is k. n Then max flow value is k. n Max-flow min-cut  cut (A, B) of capacity k. n Let F be set of edges going from A to B. n |F| = k and disconnects t from s. ▪ s 2 3 4 5 6 7 t s 2 3 4 5 6 7 t A

21 7.8 Assigning papers to referees

22 22 Evaluating/refereeing Papers Constraints: n There are n 1 paper submissions and n 2 reviewers/referees n i can referee paper j only if i is qualified and there is no conflict n Referee i can work on at most c i papers. n Paper j needs at least p j reports. Goal. Assign papers to referees subject to these constraints, if possible. If no such assignment exists, the algorithm should report that it is not possible.

23 23 Referee Assignment Algorithm. Formulate as a max-flow problem. n Include an edge (i, j) if i can referee paper j with capacity = 1 n Add edge with capacity c i from source to vertex i. n Add edge with capacity p j from vertex j’ to sink t. Claim: If this graph has a flow of p 1 + p 2 + … + p k, then assignment is possible. Otherwise, it is not possible. s 1 3 5 1' 3' 5' t 2 4 2' 4' referees papers p1p1 1 c1c1

24 7.10 Image Segmentation

25 25 Image Segmentation Image segmentation. n Central problem in image processing. n Divide image into coherent regions. Ex: Three people standing in front of complex background scene. Identify each person as a coherent object.

26 26 Image Segmentation Foreground / background segmentation. n Label each pixel in picture as belonging to foreground or background. n V = set of pixels, E = pairs of neighboring pixels. n a i  0 is likelihood pixel i in foreground. n b i  0 is likelihood pixel i in background. n p ij  0 is separation penalty for labeling one of i and j as foreground, and the other as background. Goals. n Accuracy: if a i > b i in isolation, prefer to label i in foreground. n Smoothness: if many neighbors of i are labeled foreground, we should be inclined to label i as foreground. n Find partition (A, B) that maximizes: foreground background

27 27 Image Segmentation Formulate as min cut problem. n Maximization. n No source or sink. n Undirected graph. Turn into minimization problem. n Maximizing is equivalent to minimizing n or alternatively

28 28 Image Segmentation Formulate as min cut problem. n G' = (V', E'). n Add source to correspond to foreground; add sink to correspond to background n Use two anti-parallel edges instead of undirected edge. st p ij ij ajaj G' bibi

29 29 Image Segmentation Consider min cut (A, B) in G'. n A = foreground. n Precisely the quantity we want to minimize. G' st ij A if i and j on different sides, p ij counted exactly once p ij bibi ajaj

30 7.11 Project Selection

31 31 Project Selection Projects with prerequisites. n Set P of possible projects. Project v has associated revenue p v. – some projects generate money: create interactive e-commerce interface, redesign web page – others cost money: upgrade computers, get site license n Set of prerequisites E. If (v, w)  E, can't do project v and unless also do project w. n A subset of projects A  P is feasible if the prerequisite of every project in A also belongs to A. Project selection. Choose a feasible subset of projects to maximize revenue. can be positive or negative

32 32 Project Selection: Prerequisite Graph Prerequisite graph. n Include an edge from v to w if can't do v without also doing w. n {v, w, x} is feasible subset of projects. n {v, x} is infeasible subset of projects. v w x v w x feasibleinfeasible

33 33 Min cut formulation. n Assign capacity  to all prerequisite edge. n Add edge (s, v) with capacity -p v if p v > 0. n Add edge (v, t) with capacity -p v if p v < 0. n For notational convenience, define p s = p t = 0. st -p w u v w x yz Project Selection: Min Cut Formulation  pvpv -p x      pypy pupu -p z 

34 34 Claim. (A, B) is min cut iff A  { s } is optimal set of projects. n Infinite capacity edges ensure A  { s } is feasible. n Max revenue because: s t -p w u v w x yz Project Selection: Min Cut Formulation pvpv -p x pypy pupu    A

35 35 Open-pit mining. (studied since early 1960s) n Blocks of earth are extracted from surface to retrieve ore. n Each block v has net value p v = value of ore - processing cost. n Can't remove block v before w or x. Open Pit Mining v xw

36 7.12 Baseball Elimination "See that thing in the paper last week about Einstein?... Some reporter asked him to figure out the mathematics of the pennant race. You know, one team wins so many of their remaining games, the other teams win this number or that number. What are the myriad possibilities? Who's got the edge?" "The hell does he know?" "Apparently not much. He picked the Dodgers to eliminate the Giants last Friday." - Don DeLillo, Underworld

37 37 Baseball Elimination Which teams have a chance of finishing the season with most wins? n Montreal eliminated since it can finish with at most 80 wins, but Atlanta already has 83. n w i + r i < w j  team i eliminated. n Only reason sports writers appear to be aware of. n Sufficient, but not necessary! Team i Against = r ij Wins w i To play r i Losses l i AtlPhiNYMon Montreal77382120- New York786 60-0 Philly803791-02 Atlanta83871-161

38 38 Baseball Elimination Which teams have a chance of finishing the season with most wins? n Philly can win 83, but still eliminated... n 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. Team i Against = r ij Wins w i To play r i Losses l i AtlPhiNYMon Montreal77382120- New York786 60-0 Philly803791-02 Atlanta83871-161

39 39 Baseball Elimination

40 40 Baseball Elimination Baseball elimination problem. n Set of teams S. n Distinguished team s  S. n Team x has won w x games already. n Teams x and y play each other r xy additional times. n Is there any outcome of the remaining games in which team s finishes with the most (or tied for the most) wins?

41 41 Can team 3 finish with most wins? n Assume team 3 wins all remaining games  w 3 + r 3 wins. n Divvy remaining games so that all teams have  w 3 + r 3 wins. Baseball Elimination: Max Flow Formulation s 1-5 2-5 4-5 2 4 5 t 1-2 1-4 2-4 1 r 24 = 7  w 3 + r 3 - w 4 team 4 can still win this many more games games left  game nodes team nodes

42 42 Theorem. Team 3 is not eliminated iff max flow saturates all edges leaving source. n Integrality theorem  each remaining game between x and y added to number of wins for team x or team y. n Capacity on (x, t) edges ensure no team wins too many games. Baseball Elimination: Max Flow Formulation s 1-5 2-5 4-5 2 4 5 t 1-2 1-4 2-4 1  team 4 can still win this many more games games left  game nodes team nodes r 24 = 7 w 3 + r 3 - w 4

43 43 Baseball Elimination: Explanation for Sports Writers Which teams have a chance of finishing the season with most wins? n Detroit could finish season with 49 + 27 = 76 wins. Team i Against = r ij Wins w i To play r i Losses l i NYBalBosTor Toronto632772770- Boston69276682-0 Baltimore7128633-27 NY752859-387 Detroit4927863400 Det - 0 4 3 - AL East: August 30, 1996

44 44 Baseball Elimination: Explanation for Sports Writers Which teams have a chance of finishing the season with most wins? n Detroit could finish season with 49 + 27 = 76 wins. Certificate of elimination. R = {NY, Bal, Bos, Tor} n Have already won w(R) = 278 games. n Must win at least r(R) = 27 more. n Average team in R wins at least 305/4 > 76 games. Team i Against = r ij Wins w i To play r i Losses l i NYBalBosTor Toronto632772770- Boston69276682-0 Baltimore7128633-27 NY752859-387 Detroit4927863400 Det - 0 4 3 - AL East: August 30, 1996

45 45 Baseball Elimination: Explanation for Sports Writers Certificate of elimination. If then z is eliminated (by subset T). Theorem. [Hoffman-Rivlin 1967] Team z is eliminated iff there exists a subset T* that eliminates z. Proof idea. Let T* = team nodes on source side of min cut.

46 46 Baseball Elimination: Explanation for Sports Writers Pf of theorem. n Use max flow formulation, and consider min cut (A, B). n Define T* = team nodes on source side of min cut. n 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 y x t x-y r 24 = 7   w z + r z - w x team x can still win this many more games games left

47 47 Baseball Elimination: Explanation for Sports Writers Pf of theorem. n Use max flow formulation, and consider min cut (A, B). n Define T* = team nodes on source side of min cut. n Observe x-y  A iff both x  T* and y  T*. n n Rearranging terms: ▪

48 Extra Slides

49 49 k-Regular Bipartite Graphs Dancing problem. n Exclusive Ivy league party attended by n men and n women. n Each man knows exactly k women; each woman knows exactly k men. n Acquaintances are mutual. n Is it possible to arrange a dance so that each woman dances with a different man that she knows? Mathematical reformulation. Does every k-regular bipartite graph have a perfect matching? Ex. Boolean hypercube. 1 3 5 1' 3' 5' 2 4 2' 4' women men

50 50 Theorem. [König 1916, Frobenius 1917] Every k-regular bipartite graph has a perfect matching. Pf. Size of max matching = value of max flow in G'. Consider flow: n f is a flow and its value = n  perfect matching. ▪ k-Regular Bipartite Graphs Have Perfect Matchings 1 3 5 1' 3' 5' 2 4 2' 4' s t 1 1 1 G' 1 1/k 1 flow f

51 51 Census Tabulation (Exercise 7.39) Feasible matrix rounding. n Given a p-by-q matrix D = {d ij } of real numbers. n Row i sum = a i, column j sum b j. n Round each d ij, a i, b j up or down to integer so that sum of rounded elements in each row (column) equals row (column) sum. n Original application: publishing US Census data. Goal. Find a feasible rounding, if one exists. 17.243.146.87.3 12.79.62.40.7 11.33.61.26.5 16.3410.414.5 17377 131021 11317 161015 original matrix feasible rounding

52 52 Census Tabulation Feasible matrix rounding. n Given a p-by-q matrix D = {d ij } of real numbers. n Row i sum = a i, column j sum b j. n Round each d ij, a i, b j up or down to integer so that sum of rounded elements in each row (column) equals row (column) sum. n Original application: publishing US Census data. Goal. Find a feasible rounding, if one exists. Remark. "Threshold rounding" can fail. 1.050.35 1.650.55 0.9 original matrix feasible rounding 1001 2110 111

53 53 Census Tabulation Theorem. Feasible matrix rounding always exists. Pf. Formulate as a circulation problem with lower bounds. n Original data provides circulation (all demands = 0). n Integrality theorem  integral solution  feasible rounding. ▪ 17.243.146.87.3 12.79.62.40.7 11.33.61.26.5 16.3410.414.5 s 1 2 3 1' 2' 3' t row column 17, 18 12, 13 11, 12 16, 17 10, 11 14, 15 3, 4 0,  lower bound upper bound


Download ppt "Applications of Network Flow Problem. 7.5 Bipartite Matching."

Similar presentations


Ads by Google