Finding the maximum matching of a bipartite graph

Slides:



Advertisements
Similar presentations
ACS 7101/3 – Advanced Algorithm Design November 2008 Finding the maximum matching of a bipartite graph Final Project.
Advertisements

Analysis of programs with pointers. Simple example What are the dependences in this program? Problem: just looking at variable names will not give you.
Yangjun Chen 1 Bipartite Graphs What is a bipartite graph? Properties of bipartite graphs Matching and maximum matching - alternative paths - augmenting.
Implementation of Graph Decomposition and Recursive Closures Graph Decomposition and Recursive Closures was published in 2003 by Professor Chen. The project.
Matchings Lecture 3: Jan 18. Bipartite matchings revisited Greedy method doesn’t work (add an edge with both endpoints free)
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.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Data Structures Stacks.
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 No.01 Data Structures Dr. Sohail Aslam
ECE 103 Engineering Programming Chapter 61 Abstract Data Types Herbert G. Mayer, PSU CS Status 6/4/2014 Initial content copied verbatim from ECE 103 material.
VB Games: Preparing for Memory Brainstorm controls & events Parallel structures (again), Visibility, LoadPicture, User-defined procedures, Do While/Loop,busy.
1 CSC 222: Computer Programming II Spring 2004 See online syllabus at: Course goals:
All Pair Shortest Path IOI/ACM ICPC Training June 2004.
Bipartite Matching. Unweighted Bipartite Matching.
CS223 Advanced Data Structures and Algorithms 1 Maximum Flow Neil Tang 3/30/2010.
Homework - hints Problem 1. Node weights  Edge weights
Stacks A stack is a linear data structure that can be accessed only at one of its ends for storing and retrieving data LIFO (Last In First Out) structure.
C Programming Day 2. 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/LA07/003 Version No. 1.0 Union –mechanism to create user defined data types.
© Oxford University Press All rights reserved. Data Structures Using C, 2e Reema Thareja.
Chapter 3 Lists, Stacks, Queues. Abstract Data Types A set of items – Just items, not data types, nothing related to programming code A set of operations.
Implementing stacks Prof. Ramin Zabih
Priority Queues and Heaps Tom Przybylinski. Maps ● We have (key,value) pairs, called entries ● We want to store and find/remove arbitrary entries (random.
STACKS & QUEUES for CLASS XII ( C++).
Stack ADT (Abstract Data Type) N …
Run-Time Environments Chapter 7
Stacks II David Lillis School of Computer Science and Informatics
Lecture 6 of Computer Science II
C++ Programming:. Program Design Including
IOI/ACM ICPC Training 4 June 2005.
Data Structures Using C, 2e
Queues.
Data Structures Binary Trees 1.
Data Structure and Algorithms
UNIT-3 LINKED LIST.
Datastructure.
Sequences 8/1/2018 4:38 AM Linked Lists Linked Lists.
EEL 4854 IT Data Structures Linked Lists
Stacks and Queues.
Bipartite Graphs What is a bipartite graph?
Lecture 16 Bipartite Matching
Hashing Exercises.
Lectures on Network Flows
Stack.
Discussion Section 3 HW1 comments HW2 questions
Stack Data Structure, Reverse Polish Notation, Homework 7
CC 215 Data Structures Graph Searching
Arrays, For loop While loop Do while loop
Discussion section #2 HW1 questions?
Arrays and Linked Lists
Data Structures – Stacks and Queus
B- Trees D. Frey with apologies to Tom Anastasio
Linked Lists.
B- Trees D. Frey with apologies to Tom Anastasio
Lectures on Graph Algorithms: searching, testing and sorting
Lists CSE 373 Data Structures.
CSE 373 Data Structures Lecture 16
Cs212: Data Structures Computer Science Department Lecture 6: Stacks.
B- Trees D. Frey with apologies to Tom Anastasio
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.
How to use hash tables to solve olympiad problems
By Yogesh Neopaney Assistant Professor Department of Computer Science
Data Structures & Algorithms
Lists CSE 373 Data Structures.
Important Problem Types and Fundamental Data Structures
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
17CS1102 DATA STRUCTURES © 2018 KLEF – The contents of this presentation are an intellectual and copyrighted property of KL University. ALL RIGHTS RESERVED.
Verifying Dijktra’s algorithm in Jahob
Assignment #2 (Assignment due: Nov. 06, 2018) v1 v2 v3 v4 v5
LINEAR DATA STRUCTURES
Presentation transcript:

Finding the maximum matching of a bipartite graph ACS 7101/3 – Advanced Algorithm Design Finding the maximum matching of a bipartite graph Final Project November 2008

Finding the maximum matching of a bipartite graph From an initial matching We want to find the maximum matching 1 2 3 4 5 6 1 2 3 4 5 6 7 8 9 10 11 12 7 8 9 10 11 12 preconditions: The graph stored in a text file is represented by positive integer numbers. The nodes must be consecutive and no node should be represented with a number bigger than the total number of nodes. This code is designed for a balanced bipartite graph. Notes: Since we are using positive integers to name each node, we are not going to use the index 0 of the array. ACS 7101 – Advance Data Structures November 2008

Finding the maximum matching of a bipartite graph The general procedure is: M1 G1 G1’ P M1 P = M2 M2 G2 G2’ P1 & P2 M2 P1 P2 = M3 In this example M3 is the maximum matching ACS 7101 – Advance Data Structures November 2008

Finding the maximum matching of a bipartite graph We start with the graph stored in a text file as pairs u, v Store the file in memory using an Array of Objects Graph.txt 1 7 2 8 2 9 3 9 3 10 4 10 11 … 1 2 3 4 5 6 7 8 9 10 11 12 ACS 7101 – Advance Data Structures November 2008

Finding the maximum matching of a bipartite graph M1 G1 count the nodes readFile.cpp randomMatching.cpp or exampleMatching.cpp initialize rest of the Array G1 G1 is a directed graph ACS 7101 – Advance Data Structures November 2008

Finding the maximum matching of a bipartite graph G1 G1’ : finding j* Level 0: (first half)‏ if M = 0 => L = 0 while j* != 0 Level k odd (we want to go down on the directed graph)‏ for the first half assign k to all the nodes minus the one pointed by pm in the list Level k even (we want to go up)‏ for the second half assign k to all the matching node Note: when L = current level and M = 0 => j* = L findLevels.cpp ACS 7101 – Advance Data Structures November 2008

Finding the maximum matching of a bipartite graph G1’ P Use a stack to keep track of the path Starting at Level 0: Push (i)‏ Read the list while it doesn’t belong to a path (P = 0) AND is not pointed by pm while level(j) is greater than 0 and <= j*, AND it doesn't belong to a path AND it does belong to a matching: push(j); level ++; 1 2 3 4 5 6 7 8 9 10 11 12 findPaths.cpp ACS 7101 – Advance Data Structures November 2008

Finding the maximum matching of a bipartite graph P M1 P = M2 If we found a free node then we found a path => empty the stack, set P to 1, while doing the symmetric difference and updating the matching… findPaths.cpp ACS 7101 – Advance Data Structures November 2008

Finding the maximum matching of a bipartite graph P M2 P1 = M3 Idea behind the symmetric difference: 3 edges in the path: (1, 7)‏ (7, 6)‏ (6, 12)‏ 1 2 3 4 5 6 1 2 3 4 5 6 M2 P1 7 8 9 10 11 12 7 8 9 10 11 12 Edge (1, 7)‏ In M2 doesn’t belong to a match match (A[1].M = 0 AND A[7].M = 1)‏ M3 1 2 3 4 5 6 7 8 9 10 11 12 findPaths.cpp ACS 7101 – Advance Data Structures November 2008

Finding the maximum matching of a bipartite graph P M2 P1 = M3 Idea behind the symmetric difference: 3 edges in the path: (1, 7)‏ (7, 6)‏ (6, 12)‏ 1 2 3 4 5 6 1 2 3 4 5 6 M2 P1 7 8 9 10 11 12 7 8 9 10 11 12 Edge (1, 7)‏ In M2 doesn’t belong to a match match (A[1].M = 0 AND A[7].M = 1)‏ M3 1 2 3 4 5 6 7 8 9 10 11 12 findPaths.cpp ACS 7101 – Advance Data Structures November 2008

Finding the maximum matching of a bipartite graph P M2 P1 = M3 Idea behind the symmetric difference: 3 edges in the path: (1, 7)‏ (7, 6)‏ (6, 12)‏ 1 2 3 4 5 6 1 2 3 4 5 6 M2 P1 7 8 9 10 11 12 7 8 9 10 11 12 Edge (7, 6)‏ Is a matching in M2 ignore (A[7].M = 1 AND A[6].M = 1)‏ M3 1 2 3 4 5 6 7 8 9 10 11 12 findPaths.cpp ACS 7101 – Advance Data Structures November 2008

Finding the maximum matching of a bipartite graph P M2 P1 = M3 Idea behind the symmetric difference: 3 edges in the path: (1, 7)‏ (7, 6)‏ (6, 12)‏ 1 2 3 4 5 6 1 2 3 4 5 6 M2 P1 7 8 9 10 11 12 7 8 9 10 11 12 Edge (6, 12)‏ In M2 doesn’t belong to a match match (A[6].M = 1 AND A[12].M = 0)‏ M3 1 2 3 4 5 6 7 8 9 10 11 12 findPaths.cpp ACS 7101 – Advance Data Structures November 2008

Finding the maximum matching of a bipartite graph P M2 P1 = M3 How does the code work: We only evaluate alternate edges Edge (1, 7)‏ In M2 doesn’t belong to a match match (A[1].M = 0 AND A[7].M = 1) A[1].M = 1 AND A[7].M = 1 … Edge (6, 12)‏ In M2 doesn’t belong to a match match (A[6].M = 1 AND A[12].M = 0)‏ A[6].M = 1 AND A[12].M = 1 findPaths.cpp ACS 7101 – Advance Data Structures November 2008

Finding the maximum matching of a bipartite graph P M2 P1 = M3 After repeating the process: M3 1 2 3 4 5 6 7 8 9 10 11 12 findPaths.cpp ACS 7101 – Advance Data Structures November 2008

Finding the maximum matching of a bipartite graph writeGraph.txt 1 7 Match 2 8 Match 2 9 3 9 3 10 Match … 7 1 Match 6 2 Match The final step is to write al the pairs (u, v) back into a text file including the matching edges found ACS 7101 – Advance Data Structures November 2008

Finding the maximum matching of a bipartite graph List of files coded: main.cpp linkedListBG.h graph.txt array.cpp readFile.cpp display.cpp randomMatching.cpp exampleMatching.cpp findLevels.cpp findPaths.cpp writeFile.cpp ACS 7101 – Advance Data Structures November 2008

Finding the maximum matching of a bipartite graph Improvements to be done before testing it with bigger graphs: Change “pos” to an auxiliary pointer Store repeated calls to linked list in a variable Check end of list (now is done with count() should be checking if the pointer points to null)‏ error control: Open file List is empty … Finish the random initial matching ACS 7101 – Advance Data Structures November 2008

Finding the maximum matching of a bipartite graph Problems encounter during the process: The implementation was not clear in the book How to store the graph in memory How to mark the matching edges How to find the levels How to find the symmetric difference C++ language All the above plus First time working with array of objects ever Plus linked lists and pointers (everywhere) ACS 7101 – Advance Data Structures November 2008

Finding the maximum matching of a bipartite graph Positive actions during the process : C++ Hello world Books – exercises coding pseudo codes and assignment 2 design Discussions with professor brainstorming the Structure writing the document ACS 7101 – Advance Data Structures November 2008

Finding the maximum matching of a bipartite graph What is next: Fix everything mentioned before Create a function to generate a random graph Test the code in an incremental way starting maybe with 50 nodes and increment it up to 20.000 nodes ACS 7101 – Advance Data Structures November 2008

Finding the maximum matching of a bipartite graph Questions? ACS 7101 – Advance Data Structures November 2008