1 / 98

Combinatorial Algorithms

Combinatorial Algorithms. (Algorithms in Bipartite  Graphs). Outline. Introduction Algorithms in unweighted bipartite graph ( Yehong & Gordon) Maximum matching A simple algorithm Hopcroft -Karp algorithm Stable marriage problem (Wang wei ) Gale–Shapley algorithm

shasta
Download Presentation

Combinatorial Algorithms

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Combinatorial Algorithms (Algorithms in Bipartite Graphs)

  2. Outline • Introduction • Algorithms in unweighted bipartite graph (Yehong & Gordon) • Maximum matching • A simple algorithm • Hopcroft-Karp algorithm • Stable marriage problem (Wang wei) • Gale–Shapley algorithm • Algorithms in weighted bipartite graph (Wang Sheng & Jinyang) • Assignment problem • Hungarian method & Kuhn-Munkres algorithm • Q&A

  3. Introduction • Definition • A graph G = (V, E) is bipartiteif there exists partition V = X ∪ Y with X ∩ Y = ∅ and E ⊆ X × Y. • Bipartite Graph types • Unweighted • Weighted • For every edge e ∈ E , there is a weight w(e) .

  4. Introduction • Example: • There are a set of boys and a set of girls. • Each boy only likes girls and each girl only likes boys. • A common friend wants to match each boy with a girl such that the boy and girl are both happy – but they both will only be happy if the boy likes the girl and the girl likes the boy. • Is it possible for every situation? We can use a bipartite graph to model this problem

  5. Introduction • Problem • Testing bipartiteness • Matching • Maximum matching problem • Perfect matching problem • Stable marriage problem • Maximum weight matching problem

  6. Maximum matching Yehong

  7. Maximum matching • Definition • Matching • A Matching is a subset M ⊆ E such that ∀v ∈ V at most one edge in M is incident upon v • Maximum matching • A Maximum Matching is matching M such that everyother matching M′ satisfies |M′| ≤ |M|. • Unweighted graph: |M|= the number of edges • Weighted graph: |M|= • Perfect Matching • A matching which matches all vertices of the graph

  8. Maximum matching free matched A Matching Not a Matching A Maximum Matching (not perfect) • Definition • We say that a vertex is matched if it is incident to some edge in M. • Otherwise, the vertex is free

  9. Maximum matching • Alternating paths • ( Y1, X2, Y2, X4 ) • Augmenting Path • (Y1, X2, Y2, X4, Y4, X5) • Definition • Alternating Paths • A path is alternating if its edges alternate between Mand E − M. • Augmenting Paths • An alternating path is augmenting if both endpoints are free • Alternating Tree • A tree rooted at some free vertex v in which every path is an alternating path.

  10. Maximum matching • Property of Augmenting Paths • Replacing the M edges by the E − M ones increments size of the matching (Path: Y1, X2, Y2, X4, Y4, X5) Berge's Theorem: A matching M is maximum iff it has no augmenting path (Proof: Lec01 Page 3)

  11. Y1 X1 Y2 X2 Y3 Maximum matching X3 Y4 • A simple algorithm

  12. Y1 Y1 Y1 X1 X1 X1 Y2 Y2 Y2 X2 X2 X2 Y3 Y3 Y3 Maximum matching X3 X3 X3 Y4 Y4 Y4 • A simple algorithm

  13. Y1 Y1 Y1 Y1 X1 X1 X1 X1 Y2 Y2 Y2 Y2 X2 X2 X2 X2 Y3 Y3 Y3 Y3 Maximum matching X3 X3 X3 X3 Y4 Y4 Y4 Y4 • A simple algorithm

  14. Y1 Y1 Y1 X1 X1 X1 Y2 Y2 Y2 X2 X2 X2 Y3 Y3 Y3 Maximum matching X3 X3 X3 Y4 Y4 Y4 • A simple algorithm

  15. Y1 X1 Y2 X2 Y3 Maximum matching X3 Y4 • A simple algorithm • Commonly search algorithm (BFS, DFS) O(E) • At most V times • Complexity: O(VE)

  16. Hopcroft-Karp Algorithm An algorithm to find the maximum matching given a bipartite graphGordon

  17. Introduction • The Hopcroft-Karp algorithm was published in 1973 • It is a matching algorithm that finds a maximum matching in bipartite graphs • The main idea is to augment along a set of vertex-disjoint shortest augment paths simulatenously • The complexity is O(√|V||E|) • In this section, some Theorems and Lemmas from graph theory will be stated without showing the proof.

  18. Definition • We let the set A⊕ B denote the symmetric difference of the set • A ⊕ B = (A ∪ B) – (A ∩ B) • A maximal set of vertex-disjoint minimum length augmenting path is defined as follows : • It is a set of augmenting path • No two path share a same vertex • If the minimum length augmenting path is of length k, then all paths in S are of length k • If p is an augmenting path not in S, then p shares a vertex with some path p’ in S

  19. Algorithm The algorithm of Hopcroftand Kraft is as follows : Given a graph G = (X ∪ Y),E) 1) Let M = {} , 2) Find S = {P1 , P2 , … Pk} 3) While S ≠ {} M = M ⊕ S Find S 4) Output M

  20. Demonstration of algorithm at some stage Let the dark edges represent the edges in a matching M

  21. Demonstration of algorithm at some stage Pink edges represent an augmenting path Deleting them

  22. Demonstration of algorithm at some stage Another augmenting path No more paths

  23. Demonstration of algorithm at some stage Pink edges represent the paths in maximal set S M ⊕ SNote the before and after

  24. Algorithm • Question : How do we know that this algorithm produces the result that we want ? • Theorem 1 (Berge) :A matching M is maximum if and only if there is no augmenting path with respect to M • This theorem guarantees the correctness of the algorithm • We will now prove that the complexity of the algorithm is O(√|V||E|)

  25. Lemma 2 : A maximal set S of vertex-disjoint minimum length augmenting paths can be found in O(|E|) time Proof : Let G = (U ∪ V,E) be the graph that we are working on and M be a matching • First , we construct a “tree-like/directed acyclic graph” graph given G • We start with all the free vertices in U at level 0

  26. Continuation of proof of lemma 2 • Starting at level 2k (even) , the vertices at level 2k+1 are obtained by following free edges from edges at level 2k • Starting at level 2k+1 (odd) , the level at 2k+2 are obtained by following matched edges from vertices at level 2k+1 • Note that the even levels contain vertices from U and odd levels from V U Recall the earlier example : There are 3 levels here V

  27. Continuation of proof of lemma 2 • We continue building the tree until all vertices have been visited or until a free vertex is encountered (say t) • Note that in the latter case, the free vertices are encountered at V • Complexity of this portion of building the “tree” is linear to the size of the edges ( similar to BFS)

  28. Continuation of proof of lemma 2 Dashed line represent edges while the normal lines represent edges in the matching M Example : Free-vertex 0 1 2 3

  29. Continuation of proof of lemma 2 • Now we find a maximal set S of vertex disjoint paths in this “tree” that we constructed • We assign a counter to all vertices after level 0 • This counter represents the number of edges entering the vertex previous level (think of it like an indegree) • Starting at a free vertex v at level t, we trace a path until we reach a free vertex u at level 0

  30. Continuation of proof of lemma 2 • This path is an augmenting path and we add it into S • After which , we add the vertices in this path into a deletion queue • As long as the deletion queue is non empty, we delete the vertex in the queue and from the constructed “tree” • This includes all the edges incident onto it Recall the earlier example

  31. Continuation of proof of lemma 2 • Whenever an edge is deleted , the counter associated with its right endpoint are all decremented • If the counter becomes 0, put the vertex into the deletion queue (there can be no augmenting path from this vertex) • After emptying the deletion queue, if there are still free vertex at level t , it means that an augmenting path must still exist

  32. Continuation of proof of lemma 2 • We continue until there are no more free vertex at level t • This entire process takes linear time , since it is proportional to the number of edges deleted • Therefore this part takes O(|E|) • Total time complexity for both parts is O(|E|)

  33. Continuation of proof of lemma 2 Example : Consider the path : v6 u6 v5 u1 Deletion Queue Counter of v1 decreases by 1

  34. Continuation of proof of lemma 2 Example : 0 0 0 Now consider the path : v3 u3 v1 u2 Deletion Queue

  35. Theorems and Lemmas cited without proof • Lemma 3 : Let M* be a maximum matching, and let M be any matching in G. If the length of the shortest augmenting path with respect to M is k, then |M*| - |M| ≤ (|V|/k) • Lemma 4 : Let k be the length of the shortest augmenting path with respect to M and let S be a maximal set of shortest disjoint augmenting paths with respect to M, then the length of the shortest augmenting path with respect to M⊕S is larger than k

  36. Theorem 5: The Hopcroft-Karp algorithm finds a maximum matching in a bipartite graph in O(√|V||E|) time Proof : • Now we run the algorithm for √|V| and let M be matching after running those rounds • Lemma 4 implies that we have that in each phrase of the algorithm, the length of the shortest augmenting path increases by at least 1 • Therefore the size of the shortest augmenting path must be at least √|V|

  37. Continuation of proof of Theorem 5 • Now from Lemma 3, we have that |M*| - |M| ≤ (|V|/√|V|) = √|V| • In each phrase , we increase the size of the matching by at least 1, so therefore , at most √|V| more phrases needed • Therefore at most 2 √|V| phrases are needed for this entire algorithm. • Therefore with lemma 2, the time complexity of the algorithm is O(√|V| |E|)

  38. Stable Marriage Problem Wang Wei

  39. Terminology • Problem definition: • Given n men and n women, each person has a preference list for all members of the opposite sex; Find a one-to-one match M. • If m(a man) and w (a woman) are matched in M, then m is the partner of w, and vice verse. • Blocking pair in a match M: (m, w), m prefers w than his partner in M, and w prefers mthan her partner. • Stable match: no blocking pair exist.

  40. Stability-checking algorithm • For each man, try to find a woman, with whom they form a blocking pair; if no such woman exist, then the match is stable. • Complexity: O(n2) • Example:http://mathsite.math.berkeley.edu/smp/smp.html

  41. Basic Gale-Shapley algorithm • For man, propose to every women on his preference list until get engaged; • For woman, wait for proposal, accept if free or prefer the proposer than current partner/fiance; otherwise reject the proposal; • Complexity: O(n2)

  42. Theorem 1. • For any given instance of the stable marriage problem, the Gale-Shapley algorithm terminates, and, on termination, the engaged pairs constitute a stable matching. • Termination: • Stability: if m prefers w than his partner , then w must have rejected m, i.e., w prefers her partner to m. (m,w) cannot be a block pairno block pair exists. If GS not terminate, then at least one man is free • To reject a man, the woman must be engaged • He must be rejected by all women • Once a woman is engaged, she will never be free • All women are engaged • All men are engaged

  43. Theorem 2: All possible executions of the Gale-Shapley algorithm(with the men as the proposers) yield the same stable matching, in which, man has the best partner he can have in any stable matching. • Theorem 3: In the man-optimal stable matching, each woman has the worst partner that she can have in any stable matching.

  44. The Hungarian Method Jinyang

  45. Assignment Problem • Suppose we have n resources to which we want to assign to n tasks on a one-to-one basis. Suppose we also know the cost(gain) of assigning a given resource to a given task. We wish to find an optimal assignment–one which minimizes(maximizes) total cost(gain). • Min-Cost or Max-Weight Perfect Matching in Bipartite Graph.

  46. Example • Three students collaborate to finish a project. Their efficiency is different.

  47. Matrix Representation • We will formula this problem in a matrix representation. It is easier to illustrate its key idea and how it works. • We will explain how to implement it into algorithm and show its complexity later. • We will use minimum cost form of the problem. For maximum problem, we just reverse the num.

  48. Matrix Representation

  49. Difficulty

  50. Theorem 1 • If a number is added to or subtracted from all of the entries of any one row or column of a cost matrix, then on optimal assignment for the resulting cost matrix is also an optimal assignment for the original cost matrix. • You have to choose one entry in each row or column any way. So this operation add or reduce the same number for all assignment.

More Related