Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "ACS 7101/3 – Advanced Algorithm Design November 2008 Finding the maximum matching of a bipartite graph Final Project."— Presentation transcript:

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

2 ACS 7101 – Advance Data Structures 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 7 8 9 10 11 12 1 2 3 4 5 6 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. November 2008

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

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

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

6 ACS 7101 – Advance Data Structures Finding the maximum matching of a bipartite graph November 2008 G1G1’ : finding j* findLevels.cpp 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

7 ACS 7101 – Advance Data Structures Finding the maximum matching of a bipartite graph November 2008 G1’P findPaths.cpp 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

8 ACS 7101 – Advance Data Structures Finding the maximum matching of a bipartite graph November 2008 PM1 P = M2 findPaths.cpp 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…

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

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

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

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

13 ACS 7101 – Advance Data Structures Finding the maximum matching of a bipartite graph November 2008 PM2 P1 = M3 findPaths.cpp How does the code work: We only evaluate alternate edges 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 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 ………………

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

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

16 ACS 7101 – Advance Data Structures Finding the maximum matching of a bipartite graph November 2008 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

17 ACS 7101 – Advance Data Structures Finding the maximum matching of a bipartite graph November 2008 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 …

18 ACS 7101 – Advance Data Structures Finding the maximum matching of a bipartite graph November 2008 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)

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

20 ACS 7101 – Advance Data Structures Finding the maximum matching of a bipartite graph November 2008 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 What is next:

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


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

Similar presentations


Ads by Google