Chapter 26 of CLSR Bipartite Matching By Dr. M. Sakalli, Sources: Levitin and many other CSE, Marmara Univ. May/2009.

Slides:



Advertisements
Similar presentations
Stable Matching Problems with Constant Length Preference Lists Rob Irving, David Manlove, Gregg OMalley University Of Glasgow Department of Computing Science.
Advertisements

Piyush Kumar (Lecture 3: Stable Marriage) Welcome to COT5405.
Chapter 10 IterativeImprovement Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Bipartite Matching, Extremal Problems, Matrix Tree Theorem.
Greedy Algorithms Greed is good. (Some of the time)
Graph Matching prepared and Instructed by Shmuel Wimer Eng. Faculty, Bar-Ilan University March 2014Graph Matching1.
Bioinformatics III1 We will present an algorithm that originated by Ford and Fulkerson (1962). Idea: increase the flow in a network iteratively until it.
Algorithms and Networks
Midterm <  70 3.
Chapter 10: Iterative Improvement The Maximum Flow Problem The Design and Analysis of Algorithms.
Maurizio Patrignani seminar on the paper on the single-source unsplittable flow problem authored by Yefim Dinitz Naveen Garg Michel X. Goemans FOCS ‘98.
A. Levitin “Introduction to the Design & Analysis of Algorithms,” 3rd ed., Ch. 10 ©2012 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
Chapter 26 of CLSR Maximum Network Flow by me Dr. M. Sakalli Ch26 of CSLR and many other sources. Marmara Univ. Picture taken from without permission.
Lectures on Network Flows
Finding a Maximum Matching in Non-Bipartite Graphs Alicia Thilani Singham Goodwin /22/2013.
Yangjun Chen 1 Bipartite Graphs What is a bipartite graph? Properties of bipartite graphs Matching and maximum matching - alternative paths - augmenting.
1 Discrete Structures & Algorithms Graphs and Trees: II EECE 320.
Yangjun Chen 1 Bipartite Graph 1.A graph G is bipartite if the node set V can be partitioned into two sets V 1 and V 2 in such a way that no nodes from.
Lecture 11. Matching A set of edges which do not share a vertex is a matching. Application: Wireless Networks may consist of nodes with single radios,
Lecture 11. Matching A set of edges which do not share a vertex is a matching. Application: Wireless Networks may consist of nodes with single radios,
Week 11 - Friday.  What did we talk about last time?  Exam 2 post mortem  Cycle detection  Connectivity.
Chapter 10: Iterative Improvement Simplex Method The Design and Analysis of Algorithms.
Theory of Computing Lecture 10 MAS 714 Hartmut Klauck.
The Stable Marriage Problem
Maximum Flow Chapter 26.
CSE, IIT KGP Matchings and Factors. CSE, IIT KGP Matchings A matching of size k in a graph G is a set of k pairwise disjoint edges.A matching of size.
Section 2.1 “Matching in bipartite graphs” in Graph Theory Handout for reading seminar.
Chapter 10 IterativeImprovement. Iterative Improvement Algorithm design technique for solving optimization problems b Start with a feasible solution b.
All Pair Shortest Path IOI/ACM ICPC Training June 2004.
Bipartite Matching. Unweighted Bipartite Matching.
Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices.
The Stable Marriage Problem
Matching Algorithms and Networks. Algorithms and Networks: Matching2 This lecture Matching: problem statement and applications Bipartite matching Matching.
Assignments and matchings Chapter 12 Presented by Yorai Geffen.
Matching Lecture 19: Nov 23.
Network Flows Chun-Ta, Yu Graduate Institute Information Management Dept. National Taiwan University.
and 6.855J March 6, 2003 Maximum Flows 2. 2 Network Reliability u Communication Network u What is the maximum number of arc disjoint paths from.
Graph Algorithms Maximum Flow - Best algorithms [Adapted from R.Solis-Oba]
CSCI 256 Data Structures and Algorithm Analysis Lecture 2 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.
Market Design and Analysis Lecture 2 Lecturer: Ning Chen ( 陈宁 )
Introduction to Graph Theory
Prof. Swarat Chaudhuri COMP 382: Reasoning about Algorithms Fall 2015.
C&O 355 Lecture 19 N. Harvey TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: A A A A A A A A A A.
Iterative Improvement for Domain-Specific Problems Lecturer: Jing Liu Homepage:
Chapter 10 IterativeImprovement Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Indian Institute of Technology Kharagpur PALLAB DASGUPTA Graph Theory: Matchings and Factors Pallab Dasgupta, Professor, Dept. of Computer Sc. and Engineering,
1 Graphs Chapters 10.1 and 10.2 University of Maryland Chapters 10.1 and 10.2 Based on slides by Y. Peng University of Maryland.
Hamiltonian Graphs Graphs Hubert Chan (Chapter 9.5)
Maximum Flow Chapter 26.
IOI/ACM ICPC Training 4 June 2005.
V15: Max-Flow Min-Cut V15 continues chapter 12 in Gross & Yellen „Graph Theory“ Theorem [Characterization of Maximum Flow] Let f be a flow in a.
Stable Matching.
Stable Marriage Problem
Introduction to the Design and Analysis of Algorithms
Chapter 10 Iterative Improvement
Maximum Flow Chapter 26.
Hamiltonian Graphs Graphs Hubert Chan (Chapter 9.5)
Bipartite Graphs What is a bipartite graph?
Algorithms and Networks
Maximum Flow - Best algorithms
Algorithm Design and Analysis
Lectures on Network Flows
Chapter 5. Optimal Matchings
Various Graph Algorithms
Graphs Chapters 10.1 and 10.2 Based on slides by Y. Peng University of Maryland.
Planarity Testing.
Bipartite Graph 1. A graph G is bipartite if the node set V can be partitioned into two sets V1 and V2 in such a way that no nodes from the same set are.
Algorithms (2IL15) – Lecture 7
Bipartite Matching By Dr. M
Week 10 - Wednesday CS221.
Presentation transcript:

Chapter 26 of CLSR Bipartite Matching By Dr. M. Sakalli, Sources: Levitin and many other CSE, Marmara Univ. May/2009

Bipartite Matching Example –given a community with n men and m women Assume we have a way to determine which couples (man/woman) are compatible for marriage –E.g. (Joe, Susan) or (Fred, Susan) but not (Frank, Susan) Problem: Maximize the number of marriages –Neither polygamy nor polyandry are allowed.. Each vertex can be assigned only one vertex of the other group. –solve this problem by creating a flow network out of a bipartite graph

A Bipartite Graph It is an undirected graph G=(V, E) in which V can be partitioned into two (disjoint) sets V 1 and V 2 such that (u, v)  E implies either u  V 1 and v  V 2 or vice versa. V 1 (blue)V 2 (yellow).That is, all edges go between the two sets V 1 and V 2 but are not allowed within V 1 (blue) and V 2 (yellow). A bipartite graph is 2-colorable: the vertices can be colored in two colors so that every edge has its vertices colored differently. A B C D X Y Z A B C D X Y Z Matching between x and c, and z and d. A B C D X Y Z Optimal matching

Bipartite graph: a graph whose vertices can be partitioned into two disjoint sets V and U, not necessarily of the same size, so that every edge connects a vertex in V to a vertex in U. A graph is bipartite if and only if it does not have a cycle of an odd length. 2-Colorable, iff contains no odd length cycle. Suppose V and U are opposite set of genders.. A matching in a graph is a subset of its edges with the property that no two edges share a vertex. A maximum (or maximum cardinality) matching A maximum (or maximum cardinality) matching is a matching with the largest number of edges –always exists –not always unique V U 6 12

Hall's condition (1931): If there exists a perfect matching, then it must be true that for any subset of the women the number of men that they collectively like must be at least as large as the number of women in the subset so that every person is happy. If this is not true then a perfect matching is impossible. Hall proved that this obvious necessary condition is also sufficient to ensure a perfect matching. Hall's Theorem: Given a bipartite graph G=(V, E) with vertex classes X and Y, G has a perfect matching if and only if for every subset S of X, |adj(S)|  |S|, where adj(S) denotes the set of vertices adjacent to some vertex of S. Hall’s condition does not yield an algorithm directly, since checking the condition would require examining all 2 n subsets of X.

Algorithm: Successive improvements, like Dijkstra’s algorithm (relaxation). –Suppose M is an initial matching, M  G and M  M’. Iterate to improve M to M’, if an augmentation path is feasible, if not then M=M’  G. –Search for such an augmentation path: Starting with an unmatched partner V  M of the smaller set, and similarly ending at an unmatched partner such that every second edge  M, but the initial E  M. An alternating path, relative to the M, because it alternates the current edges to the edges not in the current matching M, therefore augmenting-path with respect to M. –augmenting-path always provides an improvement in the # of total matches, since unmatched are additionally matched. –An augmenting path of a bipartite graph must have an add length path. Since all odd-numbered edges are E 2i+1  M, while all even- numbered ones are E 2i  M, we increase the number of E (matching vertices) by one if replace the edge of E 2i  M with the edge of E 2i+1  M, where 0  i  n. The result is an improved M’, |M’|=|M|+1 which is odd numbered and also proof the Lemma to be given...

Lemma 1. Suppose that G=(V,E) is a bipartite graph with vertex classes X and Y, and M is a matching in G. If there exists an augmenting path from an unmatched vertex x in X to an unmatched vertex y in Y, then there exists a matching M' with cardinality |M| + 1. Example below, if AP search would have started from the unmatched vertex 7, and proceed to 7-2, it would not have been resulted with an unmatched vertex having an only one path, and removal of the match is going leave it completely isolated, which could not be acceptable unless the number of vertices |U|> |V|. Besides that, search must end at the opposite set with an unmatched vertex. This means, the maximum match is a perfect match which happens when |U|=|V|. Start from an unmatched but having a single path, either of the vertices 11, 4, 6. –Theorem A matching M is maximum if and only if there exists no augmenting path with respect to M ? V U V U 6 12

Augmenting Path Method (template) Start with some initial matching –e.g., the empty set Find an augmenting path and augment the current matching along that path –e.g., using bfs like traversal starting simultaneously from all the free vertices of the smaller set. AP is odd in length. When no augmenting path can be found, terminate and return the last matching which must be the case of maximum cardinality.

BFS-based Augmenting Path Algorithm Initialize queue Q with all free vertices in one of the sets (say V) While Q is not empty, delete front vertex w and label every unlabeled vertex u adjacent to w as follows: Case 1 (w is in V) If u is free, augment the matching along the path ending at u by moving backwards until a free vertex in V is reached. After that, erase all labels and reinitialize Q with all the vertices in V that are still free If u is matched (not with w), label u with w and enqueue u Case 2 (w is in U) Label its matching mate v with w and enqueue v After Q becomes empty, return the last matching, which is maximum.

Aggregate pairwise happiness of collective marriage.. Σ(c i ).. Best collective coupling y’=argmax y (Σ(c i )) Maximum-weight perfect bipartite match (assignment problem, exactly solvable in O(n 3 ) Hungarian algorithm.. Relaxation: We know the scores.. Measure edge features.. Complex feature vectors. Then instead of parameterizing features use MLE method.. c i =f(x i : θ) Probability of a match given a g, p(y|x; θ)=e ( -g(x, θ)) where y is a match for graph x.. Most likely match y’=argmax y (  (x, y), θ) idea to construct data (  (x, y), θ) =Σ i (c iy(i) ) which suggests that  (x, y) =Σ i (  iy(i) ) c iy(i) =

Augmentation along path 1, 2 Augmentation along path 2,6,1,7 Augmentation along the paths 3, 8, 4, 9, 5, V U V U V U Queue: 1 2 3, AP from 6 Queue: AP from 7 Queue: 2 3 Queue: 3, AP from 10 Queue: V U Maximum match, no remaining vertices to be matched

Notes on Maximum Matching Algorithm Each iteration (except the last) matches two free vertices (one each from V and U). Therefore, the number of iterations cannot exceed  n/2  + 1, where n is the number of vertices in the graph. The time spent on each iteration is in O(n+m), where m is the number of edges in the graph. Hence, the time efficiency is in O(n(n+m))Each iteration (except the last) matches two free vertices (one each from V and U). Therefore, the number of iterations cannot exceed  n/2  + 1, where n is the number of vertices in the graph. The time spent on each iteration is in O(n+m), where m is the number of edges in the graph. Hence, the time efficiency is in O(n(n+m)) This can be improved to O(n(n+m)) by combining multiple iterations to maximize the number of edges added to matching M in each searchThis can be improved to O(n(n+m)) by combining multiple iterations to maximize the number of edges added to matching M in each search Finding a maximum matching in an arbitrary graph is much more difficult, but the problem was solved in 1965 by Jack Edmonds.Finding a maximum matching in an arbitrary graph is much more difficult, but the problem was solved in 1965 by Jack Edmonds.

Stable Marriage Problem There is a set Y = {m 1,…,m n } of n men and a set X = {w 1,…,w n } of n women. Each one has a ranking list of the opposite gender, (with no ties in these lists). A marriage matching M is a set of n pairs (m i, w j ). A pair (m, w) is said to be a blocking pair for matching M if man m and woman w are not matched in M but prefer each other to their mates in M. A marriage matching M is called stable if there is no blocking pair for it; otherwise, it’s called unstable. The stable marriage problem is to find a stable marriage matching for men’s and women’s given preferences.

Instance of the Stable Marriage Problem An instance of the stable marriage problem can be specified either by two sets of preference lists or by a ranking matrix, as in the example below. men’s preferences women’s preferences 1 st 2 nd 3 rd 1 st 2 nd 3 rd Bob: Lea Ann SueAnn: Jim Tom Bob Jim: Lea Sue Ann Lea : Tom Bob Jim Tom: Sue Lea Ann Sue: Jim Tom Bob ranking matrix Ann Lea Sue {(Bob, Ann) (Jim, Lea) (Tom, Sue)} is unstable Bob 2,3 1,2 3,3 {(Bob, Ann) (Jim, Lea) (Tom, Sue)} is unstable {(Bob, Ann) (Jim, Sue) (Tom, Lea)} is stable Jim 3,1 1,3 2,1 {(Bob, Ann) (Jim, Sue) (Tom, Lea)} is stable Tom3,2 2,1 1,2 Stable because even if the algorithm is iterated once more the result will not change (due to the preferences of the proposed parties)!!.. Algorithm ends when the stability is achieved. In which case there is no a blocking pair.

Stable Marriage Algorithm (Gale-Shapley) Step 0 Start with all the men and women being free Step 1 While there are free men, arbitrarily select one of them and do the following: Proposal The selected free man m proposes to w, the next woman on his preference list Response If w is free, she accepts the proposal to be matched with m. If she is not free, she compares m with her current mate. If she prefers m to him, she accepts m’s proposal, making her former mate free; otherwise, she simply rejects m’s proposal, leaving m free Step 2 Return the set of n matched pairs

Example Bob proposed to Lea Lea accepted Jim proposed to Lea Lea rejected Jim proposed to Sue Sue accepted Tom proposed to Sue Sue rejected Tom proposed to Lea Lea replaced Bob with Tom Bob proposed to Ann Ann accepted Free men: Bob, Jim, Tom Free men: Jim, Tom Free men: Tom

Analysis of the Gale-Shapley Algorithm The algorithm terminates after no more than n 2 iterations with a stable marriage output The stable matching produced by the algorithm is always gender- optimal: each man gets the highest rank woman on his list under any stable marriage. One can obtain the woman-optimal matching by making women propose to men A man (woman) optimal matching is unique for a given set of participant preferences The stable marriage problem has practical applications such as matching medical-school graduates with hospitals for residency training

Solution Using Max Flow Add a supersource, supersink, make each undirected edge directed with a flow of 1 Question of min-cut A B C D X Y Z A B C D X Y Z s t Since the input is 1, flow conservation prevents multiple matchings