Lecture 16 Bipartite Matching

Slides:



Advertisements
Similar presentations
Bipartite Matching, Extremal Problems, Matrix Tree Theorem.
Advertisements

Algorithms and Networks
CS 206 Introduction to Computer Science II 11 / 07 / 2008 Instructor: Michael Eckmann.
MAX FLOW APPLICATIONS CS302, Spring 2013 David Kauchak.
Five Problems CSE 421 Richard Anderson Winter 2009, Lecture 3.
Introduction To Algorithms CS 445 Discussion Session 8 Instructor: Dr Alon Efrat TA : Pooja Vaswani 04/04/2005.
Finding a Maximum Matching in Non-Bipartite Graphs Alicia Thilani Singham Goodwin /22/2013.
CSE 421 Algorithms Richard Anderson Lecture 22 Network Flow.
Matchings Lecture 3: Jan 18. Bipartite matchings revisited Greedy method doesn’t work (add an edge with both endpoints free)
Maximum Flows Lecture 4: Jan 19. Network transmission Given a directed graph G A source node s A sink node t Goal: To send as much information from s.
1 Bipartite Matching Lecture 3: Jan Bipartite Matching A graph is bipartite if its vertex set can be partitioned into two subsets A and B so that.
CS 206 Introduction to Computer Science II 03 / 30 / 2009 Instructor: Michael Eckmann.
3/24/03Tucker, Section 4.31 Tucker, Applied Combinatorics, Sec. 4.3, prepared by Jo E-M Bipartite GraphMatching Some Definitions X-Matching Maximal Matching.
WB13 Define the terms bipartite graph,
D1: Matchings.
Approximation Algorithms Motivation and Definitions TSP Vertex Cover Scheduling.
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 12-2: Introduction to Computer Algorithms beyond Search & Sort.
CSE 421 Algorithms Richard Anderson Lecture 24 Network Flow Applications.
Lecture 16 Maximum Matching. Incremental Method Transform from a feasible solution to another feasible solution to increase (or decrease) the value of.
All Pair Shortest Path IOI/ACM ICPC Training June 2004.
MAX FLOW APPLICATIONS CS302, Spring 2012 David Kauchak.
Matching Algorithms and Networks. Algorithms and Networks: Matching2 This lecture Matching: problem statement and applications Bipartite matching Matching.
Bipartite Matching. Unweighted Bipartite Matching.
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.
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 25.
Announcements Finish up Network Flow today Then Review for Final on Monday ◦ HW#5 is due on Monday, let me or the TA’s know if you have trouble starting.
TU/e Algorithms (2IL15) – Lecture 8 1 MAXIMUM FLOW (part II)
IOI/ACM ICPC Training 4 June 2005.
Maximum Flow c v 3/3 4/6 1/1 4/7 t s 3/3 w 1/9 3/5 1/1 3/5 u z 2/2
Bipartite Matching Lecture 8: Oct 7.
Csc 2720 Instructor: Zhuojun Duan
Paths, Trees and Flowers
Algorithms and Networks
Lecture 12 Graph Algorithms
Richard Anderson Lecture 23 Network Flow
Lecture 22 Network Flow, Part 2
What is the next line of the proof?
Redraw this PCB in such a way that no wires cross.
Topological Sort (an application of DFS)
Review: Mini-Quiz Matching
Greedy Algorithms / Interval Scheduling Yin Tat Lee
Various Graph Algorithms
Bipartite Matching and Other Graph Algorithms
Spanning Trees Longin Jan Latecki Temple University based on slides by
CSE 421: Introduction to Algorithms
Lecture 16 Maximum Matching
Instructor: Shengyu Zhang
Edmonds-Karp Algorithm
Maximum Flow c v 3/3 4/6 1/1 4/7 t s 3/3 w 1/9 3/5 1/1 3/5 u z 2/2
Coping With NP-Completeness
Chapter 22: Elementary Graph Algorithms I
Vertex Covers, Matchings, and Independent Sets
Richard Anderson Lecture 30 NP-Completeness
Problem Solving 4.
Flow Networks and Bipartite Matching
COMP171 Depth-First Search.
Topological Sort (an application of DFS)
Algorithms (2IL15) – Lecture 7
EE5900 Advanced Embedded System For Smart Infrastructure
Maximum Flow c v 3/3 4/6 1/1 4/7 t s 3/3 w 1/9 3/5 1/1 3/5 u z 2/2
Spanning Trees Longin Jan Latecki Temple University based on slides by
Lecture 4: Matching Algorithms
Richard Anderson Lecture 5 Graph Theory
Coping With NP-Completeness
Lecture 22 Network Flow, Part 2
Special Graphs: Modeling and Algorithms
Graph Search in C++ Andrew Lindsay.
Lecture 11 Graph Algorithms
Presentation transcript:

Lecture 16 Bipartite Matching

Motivation: Classroom Assignment There are n courses and m classrooms. Because of different requirements (capacity, facility, location etc.) each course can only use a subset of classrooms. For each course, we are given the list of classrooms that it can use. Goal: Find a way to schedule all courses in the classrooms. (each course only need one classroom, and each classroom can only hold one course)

Modeling as a graph problem Edge (i, j): Course i can be scheduled into classroom j Courses Classrooms Solution: A set of edges that do not share any vertices. (a matching)

Maximum Bipartite Matching Given a bipartite graph with n vertices on one part, and m vertices on the other part, Goal: Find a maximum matching in the graph. Bipartite Graph  Courses and classrooms Edge (i, j)  Course i can use classroom j Matching  An assignment of courses to classrooms Maximum matching  Schedule max # of courses

First attempt: Greedy algorithm For each course, if it has a classroom that is not taken by any other course, schedule the course in that classroom. (Simple) Greedy does not work!

Trying to fix the problem How can we fix this problem? Idea: If a classroom is taken, ask its instructor to move to another room. Could you find another room? If yes, then things are fixed. Carlo, 230 A B Rong, 330

Things might become more complicated… D: A, can you find another room? A: let me try… A: B, can you find another room? B: let me try… B: C, can you find another room? C: Yes sure. B  A: I’ve found another room! A  D: I’ve found another room!

Formalizing the “room exchange” idea Augmenting Path: An augmenting path is a path from an unmatched course to an unmatched classroom, that alternates between unmatched edges and matched edges. Path (C, 2), (2, B), (B, 3) is an augmenting path. A B C 1 2 3

“Xor” Operation Given a graph, a matching and an augmenting path, the “xor” operation produces a new matching. All the unmatched edges in the augmenting path is now matched, all the matched edges in the augmenting path is now unmatched. Notation: 𝑀 ′ =𝑀⊕𝑃

Augmenting Path Algorithm Initially matching M = empty While there is an augmenting path in the graph Find the augmenting path P 𝑀=𝑀⊕𝑃 Question: 1. How to find an augmenting path? 2. If we cannot find an augmenting path, does that mean we have found the maximum matching?

Finding an augmenting path Start from an unmatched course. If we are at a course vertex, we need to follow an unmatched edge (to get to a classroom). If we are at a classroom vertex, If it is not matched, we are done! If it is matched, we need to follow the (only) matched edge Can use DFS (or BFS) to do this.

Correctness of the algorithm Theorem: Given a bipartite graph G and a matching M, is there is no augmenting path with respect to this matching M, then M is a maximum matching.

Implementing the algorithm Find_Path(u) Mark u as visited FOR all edges (u,v) //enumerate over classrooms that course u can use IF v is not visited THEN IF v is unmatched or Find_Path(match_room[v]) = true THEN // (if either we found an empty classroom, or the current instructor of // the classroom is able to switch to another room) match_course[u] = v match_course[v] = u // I will take this room RETURN true // I have found a room for course u. RETURN false // I’ve tried all the possible rooms, they are not empty and their instructors // cannot switch to another room, so I cannot find a room for course u. Max_Matching Initially set all nodes to be unmatched. FOR u = 1 to n //enumerate the courses Mark all vertices as unvisited //initialize for the DFS Find_Path(u) //Try to schedule course u.