Matching Algorithms and Networks. Algorithms and Networks: Matching2 This lecture Matching: problem statement and applications Bipartite matching Matching.

Slides:



Advertisements
Similar presentations
Bart Jansen 1.  Problem definition  Instance: Connected graph G, positive integer k  Question: Is there a spanning tree for G with at least k leaves?
Advertisements

C&O 355 Lecture 23 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.
Bipartite Matching, Extremal Problems, Matrix Tree Theorem.
1 EE5900 Advanced Embedded System For Smart Infrastructure Static Scheduling.
1 Maximum flow sender receiver Capacity constraint Lecture 6: Jan 25.
Algorithms and Networks
Tutorial 6 of CSCI2110 Bipartite Matching Tutor: Zhou Hong ( 周宏 )
Breadth-First Search of Graphs Prepared by John Reif, Ph.D. Distinguished Professor of Computer Science Duke University Analysis of Algorithms.
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.
1 Weighted Bipartite Matching Lecture 4: Jan Weighted Bipartite Matching Given a weighted bipartite graph, find a matching with maximum total weight.
Finding a Maximum Matching in Non-Bipartite Graphs Alicia Thilani Singham Goodwin /22/2013.
Approximation Algorithms: Combinatorial Approaches Lecture 13: March 2.
Totally Unimodular Matrices Lecture 11: Feb 23 Simplex Algorithm Elliposid Algorithm.
Matchings Lecture 3: Jan 18. Bipartite matchings revisited Greedy method doesn’t work (add an edge with both endpoints free)
Maximum Bipartite Matching
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.
CSE 421 Algorithms Richard Anderson Lecture 27 NP Completeness.
Randomness in Computation and Communication Part 1: Randomized algorithms Lap Chi Lau CSE CUHK.
Steiner trees Algorithms and Networks. Steiner Trees2 Today Steiner trees: what and why? NP-completeness Approximation algorithms Preprocessing.
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,
Maximum Bipartite Matching In a graph G, if no M-augmenting path exists, then M is a maximum matching in G. Idea: Iteratively seek augmenting paths to.
C&O 355 Mathematical Programming Fall 2010 Lecture 17 N. Harvey TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: AA A.
1 Introduction to Approximation Algorithms. 2 NP-completeness Do your best then.
Fixed Parameter Complexity Algorithms and Networks.
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.
Analysis of Algorithms Uri Zwick April 2014 Maximum matching 1 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: AAAAA.
Hungarian Algorithm Vida Movahedi Elderlab, York University June 2007.
1 Introduction to Approximation Algorithms. 2 NP-completeness Do your best then.
Data Structures & Algorithms Graphs
Graph Colouring L09: Oct 10. This Lecture Graph coloring is another important problem in graph theory. It also has many applications, including the famous.
CSE 589 Part VI. Reading Skiena, Sections 5.5 and 6.8 CLR, chapter 37.
1 “Graph theory” Course for the master degree program “Geographic Information Systems” Yulia Burkatovskaya Department of Computer Engineering Associate.
Matching Algorithms and Networks. Algorithms and Networks: Matching2 This lecture Matching: problem statement and applications Bipartite matching Matching.
Graph Algorithms Maximum Flow - Best algorithms [Adapted from R.Solis-Oba]
1 EE5900 Advanced Embedded System For Smart Infrastructure Static Scheduling.
CSEP 521 Applied Algorithms Richard Anderson Lecture 8 Network Flow.
Introduction to Graph Theory
Theory of Computing Lecture 12 MAS 714 Hartmut Klauck.
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:
Indian Institute of Technology Kharagpur PALLAB DASGUPTA Graph Theory: Matchings and Factors Pallab Dasgupta, Professor, Dept. of Computer Sc. and Engineering,
::Network Optimization:: Minimum Spanning Trees and Clustering Taufik Djatna, Dr.Eng. 1.
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.
Minimum Cost Flow Algorithms and Networks. Algorithms and Networks: Minimum Cost Flow2 This lecture The minimum cost flow problem: statement and applications.
TU/e Algorithms (2IL15) – Lecture 8 1 MAXIMUM FLOW (part II)
Hamiltonian Graphs Graphs Hubert Chan (Chapter 9.5)
Hamiltonian Graphs Graphs Hubert Chan (Chapter 9.5)
Algorithms and Networks
Lecture 16 Bipartite Matching
Maximum Flow - Best algorithms
Algorithm Design and Analysis
Lectures on Network Flows
Algorithms and Networks
Chapter 5. Optimal Matchings
Instructor: Shengyu Zhang
Analysis of Algorithms
Richard Anderson Lecture 25 NP-Completeness
CSE 421 Richard Anderson Autumn 2016, Lecture 3
Problem Solving 4.
CSE 421 Richard Anderson Autumn 2015, Lecture 3
Flow Networks and Bipartite Matching
Algorithms (2IL15) – Lecture 7
EE5900 Advanced Embedded System For Smart Infrastructure
Algorithms and Networks
CSE 421, University of Washington, Autumn 2006
Lecture 22 Network Flow, Part 2
CSE 421 Richard Anderson Autumn 2019, Lecture 3
Presentation transcript:

Matching Algorithms and Networks

Algorithms and Networks: Matching2 This lecture Matching: problem statement and applications Bipartite matching Matching in arbitrary undirected graphs: Edmonds algorithm Perfect matchings in regular bipartite graphs –Schrijvers algorithm –Edge coloring and classroom scheduling application Diversion: generalized tic-tac-toe

1 Problem and applications

Algorithms and Networks: Matching4 Matching Set of edges M  E such that no vertex is endpoint of more than one edge. Maximal matching –No e  E with M  {e} also a matching Maximum matching –Matching with |M| as large as possible Perfect matching –|M| = n/2: each vertex endpoint of edge in M.

Algorithms and Networks: Matching5 Cost versions Each edge has cost; look for perfect matching with minimum cost Also polynomial time solvable, but harder

Algorithms and Networks: Matching6 Problems Given graph G, find –Maximal matching: easy (greedy algorithm) –Maximum matching Polynomial time; not easy. Important easier case: bipartite graphs –Perfect matching Special case of maximum matching A theorem for regular bipartite graphs and Schrijver’s algorithm

Algorithms and Networks: Matching7 Applications Personnel assignment –Tasks and competences Classroom assignment Scheduling Opponents selection for sport competitions

Algorithms and Networks: Matching8 Application: matching moving objects Moving objects, seen at two successive time moments Which object came from where?

2 Bipartite matching

Algorithms and Networks: Matching10 Bipartite graphs: using maximum flow algorithms Finding maximum matching in bipartite graphs: –Model as flow problem, and solve it: make sure algorithm finds integral flow. s t Capacities 1

Algorithms and Networks: Matching11 Technique works for variants too Minimum cost perfect matching in bipartite graphs –Model as mincost flow problem b-matchings in bipartite graphs –Function b: V  N. –Look for set of edges M, with each v endpoint of exactly b(v) edges in M.

Algorithms and Networks: Matching12 Steps by Ford-Fulkerson on the bipartite graph M-augmenting path: unmatched becomes in a flow augmentation step

3 Edmonds algorithm: matching in (possibly non-bipartite) undirected graphs

Algorithms and Networks: Matching14 A theorem that also works when the graph is not bipartite Theorem. Let M be a matching in graph G. M is a maximum matching, if and only if there is no M- augmenting path. –If there is an M-augmenting path, then M is not a maximum matching. –Suppose M is not a maximum matching. Let N be a larger matching. Look at N*M = N  M – N  M. Every node in N*M has degree 0, 1, 2: collection of paths and cycles. All cycles alternatingly have edge from N and from M. There must be a path in N*M with more edges from N than from M: this is an augmenting path.

Algorithms and Networks: Matching15 Algorithm of Edmonds Finds maximum matching in a graph in polynomial time

Algorithms and Networks: Matching16 Jack Edmonds

Algorithms and Networks: Matching17 Jack Edmonds

Algorithms and Networks: Matching18 M-blossom Definitions M-alternating walk: –(Possibly not simple) path with edges alternating in M, and not M. M-flower –M-alternating walk that starts in an unmatched vertex, and ends as:

Algorithms and Networks: Matching19 Finding an M-augmenting path or an M-flower – I Let X be the set of unmatched vertices. Let Y be the set of vertices with an edge not in M to a vertex in X. Build digraph D = (V,A) with –A = { (u,v) | there is an x with {u,x}  E-M and {x,v}  M}. Find a shortest walk P from a vertex in X to a vertex in Y of length at least 1. (BFS in D.) Take P’: P, followed by an edge to X. P’ is M-alternating walk between two unmatched vertices.

Algorithms and Networks: Matching20 Finding M-augmenting path or M-flower – II Two cases: P’ is a simple path: it is an M-augmenting path P’ is not simple. Look to start of P’ until the first time a vertex is visited for the second time. –This is an M-flower : Cycle-part of walk cannot be of even size, as it then can be removed and we have a shorter walk in D.

Algorithms and Networks: Matching21 Algorithmic idea Start with some matching M, and find either M-augmenting path or M-blossom. If we find an M-augmenting path: –Augment M, and obtain matching of one larger size; repeat. If we find an M-blossom, we shrink it, and obtain an equivalent smaller problem; recurs.

Algorithms and Networks: Matching22 Shrinking M-blossoms Let B be a set of vertices in G. G/B is the graph, obtained from G by contracting B to a single vertex. –M/B: those edges in M that are not entirely on B.

Example of shrinking a blossom Algorithms and Networks: Matching23 d g b e f c d g b e f c a a

Algorithms and Networks: Matching24 Theorem Theorem: Let B be an M-blossom. Then M is a maximum size matching in G, if and only if M/B is a maximum size matching in G/B. –Proof (in both directions) in following slides.

Proof part 1 (a) Suppose M/B is not a maximum matching in G/B Then there is an M/B-augmenting path P in G/B Case 1: easy: P does not use the `shrinked vertex’ (representing the blossom): –P is also an M-augmenting path in G; so M is not a maximum matching in G Algorithms and Networks: Matching25

Proof part 1 (b) Case 2: P uses the shrinked vertex We use case analysis (next slide) to show that we can build an M-augmenting path As we have an M-augmenting path in G, M is not a maximum matching in G Algorithms and Networks: Matching26

Algorithms and Networks: Matching27 In G/B: In G we have: Notice: we enter with an edge in M and leave with an edge not in M Notice: we enter with an edge in M and leave with an edge not in M

Algorithms and Networks: Matching28 Notice: we enter with an edge in M and leave with an edge not in M Notice: we enter with an edge in M and leave with an edge not in M Last edge before we leave must be in M. From there, go to start This always constructs an M-augmenting path

Proof part 2 (start) First, we change the matching M such that no edge in M enters the blossom: Algorithms and Networks: Matching29

Proof part 2 (end) So, the blossom has an unmatched vertex, and no edge in M enters/leaves the blossom In M/B, the blossom vertex is unmatched Suppose M is not a maximum matching. Then there is an M- augmenting path P in G. 1.If P does not use a vertex in the blossom, then P is also an M/B- augmenting path in G/B. 2.If P uses a vertex in the blossom, then P/B has the blossom vertex as an unmatched endpoint: P/B is an M/B augmenting path in G/B. So G/B has M/B-augmenting path: M/B not maximum matching in G/B. Algorithms and Networks: Matching30 QED

Algorithms and Networks: Matching31 Subroutine Given: Graph G, matching M Question: Find M-augmenting path if it exists. –Let X be the vertices not endpoint of edge in M. –Build D, and test if there is an M-alternating walk P from X to X of positive length. (Using Y, etc.) –If no such walk exists: M is maximum matching. –If P is a path: output P. –If P is not a path: Find M-blossom B on P. Shrink B, and recourse on G/B and M/B. If G/B has no M/B augmenting path, then M is maximum matching. Otherwise, expand M/B-augmenting path to an M-augmenting path.

Algorithms and Networks: Matching32 Edmonds algorithm A maximum matching can be found in O(n 2 m) time. –Start with empty (or any) matching, and repeat improving it with M-augmenting paths until this stops. –O(n) iterations. Recursion depth is O(n); work per recursive call O(m). A perfect matching in a graph can be found in O(n 2 m) time, if it exists.

Algorithms and Networks: Matching33 Improvements Better analysis and data structures gives O(n 3 ) algorithm. Faster is possible: O(n 1/2 m) time. Minimum cost matchings with more complicated structural ideas.

4 Matching in regular bipartite graphs

Algorithms and Networks: Matching35 Regular bipartite graphs Regular = all vertices have the same degree Say d is the degree of all vertices Theorem (proof follows): each regular bipartite graph has a perfect matching Schrijver’s algorithm: finds such a perfect matching quickly Coming: a nice application for scheduling classrooms and lessons

Algorithms and Networks: Matching36 A simple non-constructive proof of a well known theorem Theorem. Each regular bipartite graph has a perfect matching. Proof: –Construct flow model of G. Set flow of edges from s, or to t to 1, and other edges flow to 1/d. –This flow has value n/2, which is optimal. –Ford-Fulkerson will find flow of value n/2; which corresponds to perfect matching.

Algorithms and Networks: Matching37 Perfect matchings in regular bipartite graphs Schrijver’s algorithm to find one: –Each edge e has a weight w(e). –Initially all weights are 1. –Let G w denote the graph formed by the edges of positive weight. –While G w has a circuit Take such a circuit C (which must have even length). Split C into two matchings M and N, with w(M)  w(N). Increase the weight of each edge in M by 1. Decrease the weight of each edge in N by 1.

Algorithms and Networks: Matching38 On the algorithm Let each vertex have degree d. Invariant: the sum of the weights of the incident edges of a vertex is d. At termination: no circuit in G w, and by the invariant, it follows G w must be a perfect matching.

Algorithms and Networks: Matching39 Time to find circuits Finding circuits: –Keep a path P with edges of weight between 1 and d – 1 –Let v be last vertex on P. –v must have edge not on P with weight between 1 and d – 1, say {v,x}. –If x on P: we have a circuit. Apply step on circuit. Remove circuit from P, and work with smaller path. –Otherwise, add {v,x} to P, and repeat O(|C|) per circuit, plus O(n+m) additional overhead.

Algorithms and Networks: Matching40 Time analysis Look at the sum over all edges of w(e) 2. Each improvement over a cycle C increases this sum by at least |C|. Initially m, never larger than nd 2. So, total time O(nd 2 ) = O(dm).

Algorithms and Networks: Matching41 Sum of squares increases by |C|

5 An application of matching in regular bipartite graphs: Edge coloring and classroom schedules

Algorithms and Networks: Matching43 Edge coloring and classroom schedules Teachers Class Some teachers should teach some classes but: –No teacher more than one class at a time –No class more than one lesson at the time –How many hours needed??? JansenPetersenKlaassen 1bX 2aX 2bX X = combination not allowed

Algorithms and Networks: Matching44 Jansen PetersenKlaassen 1bX a1-22-3X 2b2-3X1-2

Algorithms and Networks: Matching45 Edge coloring model Take bipartite graph with vertices for teachers and for classes Look for a coloring of the edges such that no vertex has two incident edges with the same color. What is the minimum number of colors needed? –Lower bound: maximum degree. (Interpretation!) –We can attain the lower bound with help of matchings!!

Algorithms and Networks: Matching46 A theorem Let G be a bipartite graph with maximum degree d. Then G has an edge coloring with d colors. –Step 1: Make G regular by adding vertices and edges. –Step 2: Repeatedly find a matching and remove it.

Algorithms and Networks: Matching47 Making G regular Suppose G has vertex sets V 1 and V 2 with edges only between V 1 and V 2. (Usually called: color classes). If |V 1 | > |V 2 | then add |V 1 | - |V 2 | isolated vertices to |V 2 |. If |V 2 | > |V 1 | then add |V 2 | - |V 1 | isolated vertices to |V 1 |. While not every vertex in V 1  V 2 has degree d: –Find a vertex v in V 1 of degree less than d –Find a vertex w in V 2 of degree less than d –Add the edge {v,w} to the graph. Must exist Must exist

Algorithms and Networks: Matching48 Edge coloring a regular graph Say G’ is regular of degree d. For i = 1 to d do –Find a perfect matching M in G’. –Give all edges in M color i. –Remove all edges in M from G’. (Note that G’ stays regular!)

Algorithms and Networks: Matching49 Final step Take the edge coloring c of G’. Color G in the same way: G is subgraph of G. Time: carrying out d times a perfect matching algorithm in a regular graph: –O(nd 3 ) if we use Schrijver’s algorithm. –Can be done faster by other algorithms.

6 Diversion: multidimensional tic-tac- toe

Algorithms and Networks: Matching51 Trivial drawing strategies in multidimensional tic-tac-toe Tic-tac-toe Generalizations –More dimensions –Larger board size Who has a winning strategy? –Either first player has winning strategy, or second player has drawing strategy

Algorithms and Networks: Matching52 Trivial drawing strategy If lines are long enough: pairing of squares such that each line has a pair If player 1 plays in a pair, then player 2 plays to other square in pair viaaf jbhub cigc duhdf jeegv

Algorithms and Networks: Matching53 Trivial drawing strategies and generalized matchings Bipartite graph: line-vertices and square-vertices; edge when square is part of line Look for set of edges M, such that: –Each line-vertex is incident to two edges in M –Each square-vertex is incident to at most one edge in M There exists such a set of edges M, if and only if there is a trivial drawing strategy (of the described type).

Algorithms and Networks: Matching54 Consequences Testing if trivial drawing strategy exists and finding one if so can be done efficiently (flow algorithm). n by n by …by n tic-tac-toe (d-dimensional) has a trivial drawing strategy if n is at least 2*3 d -1 –A square belongs to at most 3 d -1 lines. –Results from matching theory (see next dia) can be used

Technicalities Take a graph with two vertices per line, and one vertex per square, with an edge if the square belongs to the line Max degree is max(n, 2*3 d -1) This graph has a matching that matches all line vertices – gives the desired strategy –Proof: add edges and vertices to make a regular bipartite graph of degree n and take a perfect matching in this graph Algorithms and Networks: Matching55

7 Conclusions

Algorithms and Networks: Matching57 Conclusion Many applications of matching! Often bipartite… Algorithms for finding matchings: –Bipartite: flow models Bipartite, regular: Schrijver –General: with M-augmenting paths and blossom- shrinking Minimum cost matching can also be solved in polynomial time: more complex algorithm –Min cost matching on bipartite graphs is solved using min cost flow