Download presentation
Presentation is loading. Please wait.
Published byDale Thomas Modified over 9 years ago
1
3.2 Matchings and Factors: Algorithms and Applications This copyrighted material is taken from Introduction to Graph Theory, 2 nd Ed., by Doug West; and is not for further distribution beyond this course. These slides will be stored in a limited-access location on an IIT server and are not for distribution or use beyond Math 454/553. 1
2
3.2.1. Augmenting Path Algorithm Overview Two theorems to recall: Theorem 3.1.10 (Berge). A matching M in a graph G is a maximum matching in G iff G has no M-augmenting path. Theorem 3.1.16 (König,Egerváry) If G is bipartite, then a maximum matching and a minimum vertex cover of G have the same size (i.e., ’(G)= (G)). 3.2.1 Augmenting path algorithm (for bipartite graphs) Input An X,Y-bigraph G, a partial matching M, unsaturated U X Output One of two possibilities: An augmenting path from U to some y Y A minimum vertex cover Q 2 Contains copyrighted material from Introduction to Graph Theory by Doug West, 2 nd Ed. Not for distribution beyond IIT’s Math 454/553.
3
Maximum Matching/Minimum Cover Algorithm 3.2.1 Augmenting path algorithm (for bipartite graphs) Input An X,Y-bigraph G, a partial matching M, unsaturated U X Output One of two possibilities: An augmenting path from U to some y Y A minimum vertex cover Q Maximum Matching/Minimum Cover Algorithm Input An X,Y-bigraph G, a partial matching M (e.g., M= ) Output a maximum matching and a minimum vertex cover Run Algorithm 3.2.1 on M ( ’(G)–M) times, using the augmenting path output to increase M each time until |M|= ’(G) Run Algorithm 3.2.1 once more to produce a minimum vertex cover 3 Contains copyrighted material from Introduction to Graph Theory by Doug West, 2 nd Ed. Not for distribution beyond IIT’s Math 454/553.
4
3.2.1. Augmenting Path Algorithm Framework Algorithm (Augmenting path algorithm) Input An X,Y-bigraph G, a (partial matching) M, and the M-unsaturated vertices U X Idea Explore augmenting paths to all possible vertices, marking explored vertices and their predecessors, and tracking reached vertices S X and T Y Initialization S=U and T= Iteration [Details next slide] 4 Contains copyrighted material from Introduction to Graph Theory by Doug West, 2 nd Ed. Not for distribution beyond IIT’s Math 454/553.
5
3.2.1. Augmenting Path Algorithm Details Algorithm (Augmenting path algorithm) Input An X,Y-bigraph G, a (partial matching) M, and the M-unsaturated vertices U X Initialization S=U and T= Iteration If S is all marked, stop and output M and Q=T (X– S). Otherwise, explore from an unmarked x S. For each y N(x) with xy M: (1)If y is unsaturated, halt and report an augmenting U,y-path (2)If y is saturated, for the unique edge yw M: (1)Update T T {y} (2)Update S S {w} (3)Mark x and iterate 5 Contains copyrighted material from Introduction to Graph Theory by Doug West, 2 nd Ed. Not for distribution beyond IIT’s Math 454/553.
6
Augmenting path algorithm example x1x1 x2x2 x3x3 x4x4 x5x5 y1y1 y2y2 y3y3 y4y4 y5y5 Run 1 Input: M= S=U=X, T= , x=x 1 6 S S S SS Contains copyrighted material from Introduction to Graph Theory by Doug West, 2 nd Ed. Not for distribution beyond IIT’s Math 454/553.
7
Augmenting path algorithm example x1x1 x2x2 x3x3 x4x4 x5x5 y1y1 y2y2 y3y3 y4y4 y5y5 Run 1: y 1 unsaturated. Halt and augment M. 7 T S S S SS Contains copyrighted material from Introduction to Graph Theory by Doug West, 2 nd Ed. Not for distribution beyond IIT’s Math 454/553.
8
Augmenting path algorithm example x1x1 x2x2 x3x3 x4x4 x5x5 y1y1 y2y2 y3y3 y4y4 y5y5 8 Run 2 Input: M={x 1 y 1 } S={x 2, x 3, x 4, x 5 }, T= , x=x 2 S SSS Contains copyrighted material from Introduction to Graph Theory by Doug West, 2 nd Ed. Not for distribution beyond IIT’s Math 454/553.
9
Augmenting path algorithm example x1x1 x2x2 x3x3 x4x4 x5x5 y1y1 y2y2 y3y3 y4y4 y5y5 9 Run 2: From x 2, explore y 1 and its matched neighbor T S S S SS Contains copyrighted material from Introduction to Graph Theory by Doug West, 2 nd Ed. Not for distribution beyond IIT’s Math 454/553.
10
Augmenting path algorithm example x1x1 x2x2 x3x3 x4x4 x5x5 y1y1 y2y2 y3y3 y4y4 y5y5 10 Run 2: From x 1, explore y 2. y 2 is unsaturated: halt and augment M. T S S S SS T Contains copyrighted material from Introduction to Graph Theory by Doug West, 2 nd Ed. Not for distribution beyond IIT’s Math 454/553.
11
Augmenting path algorithm example x1x1 x2x2 x3x3 x4x4 x5x5 y1y1 y2y2 y3y3 y4y4 y5y5 11 Run 3 Input: M={x 1 y 2, x 2 y 1 } S={x 3, x 4, x 5 }, T= , x=x 3 S SS Contains copyrighted material from Introduction to Graph Theory by Doug West, 2 nd Ed. Not for distribution beyond IIT’s Math 454/553.
12
Augmenting path algorithm example x1x1 x2x2 x3x3 x4x4 x5x5 y1y1 y2y2 y3y3 y4y4 y5y5 12 Run 3: From x 3, explore y 3. y 3 unsaturated; halt and report augmenting path. S S S T Contains copyrighted material from Introduction to Graph Theory by Doug West, 2 nd Ed. Not for distribution beyond IIT’s Math 454/553.
13
Augmenting path algorithm example x1x1 x2x2 x3x3 x4x4 x5x5 y1y1 y2y2 y3y3 y4y4 y5y5 13 Run 4 Input: M={x 1 y 2, x 2 y 1, x 3 y 3 } S={x 4, x 5 }, T= , x=x 4 SS Contains copyrighted material from Introduction to Graph Theory by Doug West, 2 nd Ed. Not for distribution beyond IIT’s Math 454/553.
14
Augmenting path algorithm example x1x1 x2x2 x3x3 x4x4 x5x5 y1y1 y2y2 y3y3 y4y4 y5y5 14 Run 4: From x 4, explore y 2,y 3 and their (distinct) matched neighbors. S S S T T S Contains copyrighted material from Introduction to Graph Theory by Doug West, 2 nd Ed. Not for distribution beyond IIT’s Math 454/553.
15
Augmenting path algorithm example x1x1 x2x2 x3x3 x4x4 x5x5 y1y1 y2y2 y3y3 y4y4 y5y5 15 Run 4: From x 1, and x 3, explore to find y 1 via non- matching edges. Explore back up to x 2 via a matching edge. S S S T T S T S Contains copyrighted material from Introduction to Graph Theory by Doug West, 2 nd Ed. Not for distribution beyond IIT’s Math 454/553.
16
Augmenting path algorithm example x1x1 x2x2 x3x3 x4x4 x5x5 y1y1 y2y2 y3y3 y4y4 y5y5 16 Run 4 (continued): x 5 is still unexplored. Explore from x 5 to find unsaturated vertex y 4. Terminate and report an M- augmenting path. S S S S T TT S T Contains copyrighted material from Introduction to Graph Theory by Doug West, 2 nd Ed. Not for distribution beyond IIT’s Math 454/553.
17
Augmenting path algorithm example x1x1 x2x2 x3x3 x4x4 x5x5 y1y1 y2y2 y3y3 y4y4 y5y5 17 Run 5 Input: M={x 1 y 2,x 2 y 1,x 3 y 3,x 5 y 4 } S={x 4 }, T= , x=x 4 S Contains copyrighted material from Introduction to Graph Theory by Doug West, 2 nd Ed. Not for distribution beyond IIT’s Math 454/553.
18
Augmenting path algorithm example x1x1 x2x2 x3x3 x4x4 x5x5 y1y1 y2y2 y3y3 y4y4 y5y5 18 Run 5: From x 4, explore y 2,y 3 and their (distinct) matched neighbors. S S S T T Contains copyrighted material from Introduction to Graph Theory by Doug West, 2 nd Ed. Not for distribution beyond IIT’s Math 454/553.
19
Augmenting path algorithm example x1x1 x2x2 x3x3 x4x4 x5x5 y1y1 y2y2 y3y3 y4y4 y5y5 19 Run 5: From x 1, and x 3, explore to find y 1 via non- matching edges. Explore back up to x 2 via a matching edge. S S S S T TT Contains copyrighted material from Introduction to Graph Theory by Doug West, 2 nd Ed. Not for distribution beyond IIT’s Math 454/553.
20
Augmenting path algorithm example x1x1 x2x2 x3x3 x4x4 x5x5 y1y1 y2y2 y3y3 y4y4 y5y5 20 Termination: No vertex of S is unexplored. Output: maximum matching M={x 1 y 2,x 2 y 1,x 3 y 3,x 5 y 4 } Minimum vertex cover Q=T (X–S) ={x 5,y 1,y 2,y 3 }. S S S S T TT Q Q QQ Contains copyrighted material from Introduction to Graph Theory by Doug West, 2 nd Ed. Not for distribution beyond IIT’s Math 454/553.
21
Proof of Repeated Augmenting Path Algorithm 3.2.2 Theorem Repeatedly applying the Augmenting Path Algorithm to a bipartite graph produces a matching and a vertex cover of equal size. Proof Repeatedly run Algorithm 3.2.1, increasing the matching size by 1 each time, until the first time an augmenting path is not returned. We must argue that the set Q returned by Algorithm 3.2.1 is a vertex cover with size equal to that of the matching M initializing this last run. We must argue that Q=T (X–S) is a vertex cover. It suffices to prove there are no edges of G between S and Y–T. (1)There is no matching edge of M between S and Y–T: There is certainly no matching edge incident to U. (unsaturated) Vertices of S–U only have matching edges to T. (2) There is no non-matching edge of E(G)–M between S and Y–T: Contains copyrighted material from Introduction to Graph Theory by Doug West, 2 nd Ed. Not for distribution beyond IIT’s Math 454/553.
22
Proof of Repeated Augmenting Path Algorithm 3.2.2 Theorem Repeatedly applying the Augmenting Path Algorithm to a bipartite graph produces a matching and a vertex cover of equal size. Proof (continued) (1)There is no matching edge of M between S and Y–T: There is certainly no matching edge incident to U. (unsaturated) Vertices of S–U only have matching edges to T. (2) There is no non-matching edge of E(G)–M between S and Y–T: While exploring vertices in S, all non-matching edges are followed so that the other endpoints are placed in T. (3) Q=T (X-S) has |Q| = |M|: Contains copyrighted material from Introduction to Graph Theory by Doug West, 2 nd Ed. Not for distribution beyond IIT’s Math 454/553.
23
Proof of Repeated Augmenting Path Algorithm 3.2.2 Theorem Repeatedly applying the Augmenting Path Algorithm to a bipartite graph produces a matching and a vertex cover of equal size. Proof (continued) (1)There is no matching edge of M between S and Y–T. (2) There is no non-matching edge of E(G)–M between S and Y–T. (3) Q=T (X–S) has |Q| = |M|: T is involved in exactly T matching edges since these vertices were explored through augmenting paths from S. X–S is saturated; otherwise these vertices would contribute to U. There are no edges from T to X–S because T matches to S–U. Therefore |Q| = |T| + |X–S| = |M|. Contains copyrighted material from Introduction to Graph Theory by Doug West, 2 nd Ed. Not for distribution beyond IIT’s Math 454/553.
24
Weighted Bipartite Matching In weighted bipartite matching, we have a simple bigraph with weighted edges and want a matching with maximum possible total edge weight. Input A simple X,Y-bigraph G and a weight function w:E(G) [0, ) Output A matching M with maximum w(M)= e M w(e) Without loss of generality, we may assume G = K n,n by adding any missing vertices needed to make |X|=|Y| and assigning edge weight 0 to any missing edges. Comments Edge weights of K n,n are encoded in an n n matrix Maximum bipartite matching can be solved by maximum weighted bipartite matching, by assigning edge weight 1 to all edges. We will define weighted covers, which generalize vertex covers. Contains copyrighted material from Introduction to Graph Theory by Doug West, 2 nd Ed. Not for distribution beyond IIT’s Math 454/553.
25
Transversals and (Weighted) Covers 00000 644436 411434 514535 956479 853683 Transversal: A set M of n entries of an n n, matrix, no two in the same column or row. Its weight is the sum of the entries. Cover: A pair of vectors (u,v)=(u 1,…,u n ;v 1,…,v n ) such that every entry w i,j of the matrix satisfies w i,j = u i +v j. u v w(M)=23 w(u,v)=32 Contains copyrighted material from Introduction to Graph Theory by Doug West, 2 nd Ed. Not for distribution beyond IIT’s Math 454/553. v1v1 v2v2 v3v3 v4v4 v5v5 u1u1 u2u2 u3u3 u4u4 u5u5
26
3.2.7 Maximum Transversals and Minimum Covers 3.2.7. Lemma. (Duality of weighted matching and weighted cover problems) For a perfect matching M and a weighted cover (u,v) in a weighted bipartite graph G, c(u,v)>=w(M). Also, c(u,v)=w(M) iff M consists of edges x i y j such that u i +v j =w i,j. In this case, M and (u,v) are optimal. 012 4444 2114 3145 u v w(M)=12 w(u,v)=12 Contains copyrighted material from Introduction to Graph Theory by Doug West, 2 nd Ed. Not for distribution beyond IIT’s Math 454/553.
27
Finding Maximum Transversals and Minimum Covers We know: 1.We can always find a cover by setting u i =max j w i,j for all rows i=1,…,n 2.If we find M, (u,v) with w(M)=c(u,v), by Lemma 3.2.7 we are done. Question But how do we get from Item 1 to Item 2? Answer Compare c(u,v) versus the weights matrix [w i,j ] to Make the equality subgraph of edges for which w i,j =u i +v j Improve (u,v) using a vertex cover of the equality subgraph Iterate until w(M)=c(u,v). Contains copyrighted material from Introduction to Graph Theory by Doug West, 2 nd Ed. Not for distribution beyond IIT’s Math 454/553.
28
The Equality Subgraph 3.2.8 Definition. The equality subgraph G u,v for a weighted cover (u,v) is the spanning subgraph of K n,n whose edges are the pairs x i y j such that w i,j =u i +v j. In the cover, the excess for i,j is u i + v j - w i,j. Contains copyrighted material from Introduction to Graph Theory by Doug West, 2 nd Ed. Not for distribution beyond IIT’s Math 454/553. 00000 641623 750376 823458 634634 846586 u x1x1 x2x2 x3x3 x4x4 x5x5 y1y1 y2y2 y3y3 y4y4 y5y5 v Equality subgraph for (u,v) Matrix entries with w i,j =u i +v j
29
The Equality Subgraph and Excess Matrix Contains copyrighted material from Introduction to Graph Theory by Doug West, 2 nd Ed. Not for distribution beyond IIT’s Math 454/553. 00000 641623 750376 823458 634634 846586 u x1x1 x2x2 x3x3 x4x4 x5x5 y1y1 y2y2 y3y3 y4y4 y5y5 v Equality subgraph for (u,v) Matrix entries with w i,j =u i +v j u v excess matrix for (u,v) 00000 625043 727401 865430 632032 842302
30
3.2.9. Hungarian Algorithm (Maximum Weighted Matching/Minimum Weighted Cover) Algorithm (Hungarian Algorithm) Input An n x n matrix of nonnegative edge weights of K n,n Idea Iteratively adjust the cover (u,v) until the equality subgraph G u,v has a perfect matching Initialization Any cover (u,v), such as u i =max i w i,j and v j =0 Iteration Find a maximum matching M in G u,v. If M is a perfect matching, stop and output M and (u,v) as a maximum weight matching and minimum weight cover. Otherwise: Let = smallest excess in G u,v of an edge from X-R to Y-T. Replace u i u i - for all x i X-R. Replace v j v j + for all y j Y-T. Form the new equality subgraph G u,v and repeat. 30 Contains copyrighted material from Introduction to Graph Theory by Doug West, 2 nd Ed. Not for distribution beyond IIT’s Math 454/553.
31
Hungarian Algorithm Example 00000 641623 750376 823458 634634 846586 u v w(M)=21w(u,v)=35 00000 625043 727401 865430 632032 842302 u v excess matrix TT R x1x1 x2x2 x3x3 x4x4 x5x5 y1y1 y2y2 y3y3 y4y4 y5y5 TT R Equality subgraph vertex cover: Q=R T Add =1 to T, subtract from X–R. Contains copyrighted material from Introduction to Graph Theory by Doug West, 2 nd Ed. Not for distribution beyond IIT’s Math 454/553.
32
Hungarian Algorithm Example 00000 641623 750376 823458 634634 846586 u v w(u,v)=35 TT R Add =1 to T, subtract from X–R. Contains copyrighted material from Introduction to Graph Theory by Doug West, 2 nd Ed. Not for distribution beyond IIT’s Math 454/553. 00110 541623 650376 823458 534634 746586 u v w(u,v)=33 The total cover weight must decrease because new cover weight – old cover weight = (|T| – |X–R|) Note:|T| – |X–R| = |T| – (n – |R|) =|T| + |R| – n < n – n = 0 So:new cover weight – old cover weight < 0.
33
Hungarian Algorithm Example 00000 641623 750376 823458 634634 846586 u v w(u,v)=35 TT R Add =1 to T, subtract from X–R. Contains copyrighted material from Introduction to Graph Theory by Doug West, 2 nd Ed. Not for distribution beyond IIT’s Math 454/553. 00110 541623 650376 823458 534634 746586 u v w(u,v)=33 When the matrix weights are rational, transform the problem by multiplying through by the least common denominator. Then 1 is guaranteed, and the cover weight w(u,v) decreases by at least 1 in each iteration. See the text for the proof when the matrix has an irrational weight.
34
Hungarian Algorithm Example 00110 541623 650376 823458 534634 746586 u v w(M)=21w(u,v)=33 00110 514042 616400 865540 521031 731301 u v excess matrix TT x1x1 x2x2 x3x3 x4x4 x5x5 y1y1 y2y2 y3y3 y4y4 y5y5 TT T Equality subgraph vertex cover: Q=R T T Add =1 to T, subtract from X-R. Contains copyrighted material from Introduction to Graph Theory by Doug West, 2 nd Ed. Not for distribution beyond IIT’s Math 454/553.
35
Hungarian Algorithm Example 00221 441623 550376 723458 434634 646586 u v w(M)=31w(u,v)=31 00221 403042 505400 754540 410031 620301 u v excess matrix TT x1x1 x2x2 x3x3 x4x4 x5x5 y1y1 y2y2 y3y3 y4y4 y5y5 T Matching weight=cover weight. Halt and output M, and (u,v). equality subgraph Contains copyrighted material from Introduction to Graph Theory by Doug West, 2 nd Ed. Not for distribution beyond IIT’s Math 454/553.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.