570 likes | 703 Views
Assignments and matchings. Chapter 12 Presented by Yorai Geffen. Overview. Definitions Bipartite ( דו צדדי ) cardinality matching problem Bipartite weighted matching problem Stable Marriage Problem Nonbipartite cardinality matching problem Bipartite Matching Algorithm
E N D
Assignments and matchings Chapter 12 Presented by Yorai Geffen
Overview • Definitions • Bipartite (דו צדדי) cardinality matching problem • Bipartite weighted matching problem • Stable Marriage Problem • Nonbipartite cardinality matching problem • Bipartite Matching Algorithm • Nonbipartite Matching Algorithm • Summary
Definitions • Matching: Subgraph with the property that every node in the subgraph has degree zero or one. • Simple Network:Every node in the network, except the source (s) and sink (t) nodes, has at most one incoming arc or at most one outgoing arc.
Bipartite cardinality matching problem • Bipartite matching problem: Given undirected graph . Our target to find a matching with maximum edges. • We transform it to a maximum flow problem
Transformation to max flow problem • Direction: Pointing nodes in to nodes in • New nodes: • New edges: points to all nodes in and all nodes in points to • Capacity: Each arc in the network • Simple network: One incoming arc to , one outgoing arc from
Solution and time complexity • Matching of cardinality k in = flow of value k in • Proof on board… • The unit capacity maximum flow algorithm establishes a maximum flow in unit capacity simple networks in time. [Chapter 8, Theorem 8.2, page 254]
Bipartite weighted matching problem AKA The Assignment Problem • Bipartite network , with • Arc weights • If directed, require • If undirected, make it directed from to
Transformation to min cost flow • Objective function: • Possible solutions: Successive Shortest Path Algorithm, Hungarian Algorithm, Relaxation Algorithm, Cost Scaling Algorithm
Successive Shortest Path Algorithm • Reminder: Augments shortest paths from a node with excess supply to a node with unfulfilled demand. • Time: where is the upper bound of the supply, and denotes the time needed to solve a shortest path problem with nonnegative arc costs bounded by . • Applied on the matching problem, each iteration augments 1 unit of flow assigning to one node in
Relaxation Algorithm • Relaxed constraints: Allows any node in to be assigned multiple times. • Assign to with min cost • In each iteration, choose over-assigned node in run shortest path in residual network, update potentials and augment path to an unassigned node . • Each assigns one more node in , and never makes more unassigned, so within iterations it will end to a feasible assignment. • Maintains optimality conditions. • Overall time:
Stable Marriage Problem • men and women. • Each man ranks each woman by perference and vice versa (high means favored). • A (man,woman) pair is unstable if they’re not married, but prefer each other • A perfect matching (marriage) is stable if it does not contain any unstable pairs.
Stable Marriage Problem cont. • Input: Two preferences matrices. • W.L.O.G we assume each rank is an integer between 1 to . • We use the matrices to construct priority list for each person (decreasing order). Can be constructed in time.
Stable Marriage iterative greedy algorithm AKA Propose-and-reject Algorithm • LIST = • m.current_woman = m’s top priority • Until LIST = do: • For each m in LIST: • mproposes to w = m.current_woman • If w is unassigned and not engaged, then she’s now engaged to m. • If w is engaged, she chooses her preferred one and rejects the other • Rejected man r chooses the next on his priority list to be r.current_woman • Add\Remove man from LIST accordingly to engaged\rejected
Analysis • Correctness: On board. • Complexity: • At each iteration, a woman receiving a proposal: either (1) receiving her first proposal (once per woman), (2) rejects some proposal (at most times). Therefore steps per woman. • In total, steps ( women). • Cannot be better: it is linear in the input data length.
Comments • There could be several stable matchings. • A pair (i,j) is stable partners if some stable match matches man i with woman j. • Algorithms property: Each man obtains his best possible stable partner. • We refer to such a matching as man-optimal.
Man-optimal proof (1) • Lemma: In the propose-and-reject algorithm, a woman never rejects a stable partner. • Proof: • the constructed matching by the algorithm. • Suppose the lemma is false. • The first time a woman rejects a stable partner. • Continue on board…
Man-optimal proof (2) • Lemma:The propose-and-reject algorithm constructs a man-optimal stable matching. • Proof: • Immediate after the previous lemma: • The preferred stable-partner of a man will not reject him, as by previous lemma.
Nonbipartitecardinality matching problem – notations(1) • – a node’s adjacency list • A matching of graph is a subset of arcs with the property that no two arcs of are incident to the same node • The arcs of are matched arcs, while the others are unmatched arcs. • Nodes incident to matched arcs are matched nodes, else unmatched.
Nonbipartite cardinality matching problem – notations(2) • A path is an alternating path in if every consecutive pair of arcs in the path contains one matched and one unmatched arc. • Odd\Even alternating path – as the number of arcs in the path. • Alternating Cycle is an alternating path which starts and finishes on the same node.
Nonbipartite cardinality matching problem – notations(3) • Augmenting path– odd alternating path where the first and last nodes in the path are unmatched. • By switching the matches we augment the cardinality by 1. • Symmetric difference of sets -
Properties (1) • If is a matching and is an augmenting path in , then is a matching of cardinality + 1. Moreover, in the matching, all the matched nodes in remain matched and two additional nodes, namely the first and last nodes of P, are matched. (augmentation) • Explanation:
Properties (2) • If and are two matchings, their symmetric difference defines the subgraphwith the property that every component is one of the six types shown here:
Augmenting Path Theorem • Theorem: If a node p is unmatched in a matching M, and this matching contains no augmenting path that starts at node p, then node p is unmatched in some maximum matching. • Proof: • Let be a maximum matching. Assume p matched in , otherwise done. • Look at One of six figures. Yet p is unmatched in , so only (d) and (e) are possible, when p is the starting node on the left. • No augmenting path rules out (d). So must be (e). • also maximum matching and p is unmatched. • Thus such a maximum matching exists.
Bipartite Matching Algorithm • is a maximum matching, by the previous theorem. • At each iteration, number of unmatched nodes reduces by 1 (either by matching or deleting).
Finding an augmenting path from node p • Search algorithm to identify all reachable nodes by alternating paths from p. If it finds an unmatched node reachable from p, we found the path. Else it does not exist. • Complicated: Straight forward solves it for bipartite case, but it fails for thenonbipartite case.
The straightforward approach • Search tree from p to others via alternating path. • p – the root node (remember: p is unmatched) • The search tree – an alternating tree. • Nodes in the alternating tree – labeled, else unlabeled. Each labeled node is even or odd depending on the unique path from p. • If odd and unmatched – it is an augmenting path. • LIST of labeled nodes, examined one by one. • Assign label to its adjacencies (if unlabeled).
Complexity • Time: • Search and augment executed at most n times • Augment takes time. • Search takes time. • Examining an odd node takes – just the matching arc. • Examining an even node takes , all its neighbors.
Correctness of the search method • If we find an augmenting path, it exists. • If we fail to find, can we conclude one does not?
Unique label property • A graph is said to possess a unique label property with respect to a given matching and a root node p if the search procedure assigns a unique label to every labeled node (i.e., even or odd) irrespective of the order in which it examines labeled nodes. • Use: If a graph poses this property, then if an augmenting path exists, the search will find it. • Proof: Take an augmenting path, label in its order. So all other orders should be labeled the same.
Unique label property cont. • Bipartite networks satisfy this property. • If the root is in then every labeled node in will receive an even label, and every labeled node in will receive an odd label. • This is why the algorithmworks in bipartite networks. • Nonbipartite networks might not satisfy the unique label property, and therefore the search algorithm might fail to detect an augmenting path even though the network contains one.
Nonbipartitenetwork counter example • Path 1-2-3-4-5 6 is given odd Augmenting path • Path 1-2-3-7-8-5 6 is not even scanned (not part of a unique matched arc to 5). Thus the algorithm fails. • We can connect node 5 to the root by both an odd-length and an even-length alternating path.
Solution? • Allow nodes to have both an even and odd labels, and scan it accordingly. • Fails:
Difficulty • By assigning just one label to each node, we might overlook an augmenting path. • By assigning two labels, we might falsely believe that we have found an augmenting path. • Why? What is the cause? • Certain subgraphs called flowers, composed of particular types of paths and odd cycles.
Flowers and Blossoms • A flowerin respect to a matching and a root node p, is a subgraph with two components: • Stem – An even length alternating path that starts at p and terminates at some node w. If p = w, we say that the stem is empty. • Blossom – An odd length alternating cycle that starts and terminates at the terminal node w of a stem, and has no other node in common with the stem. We refer to node w as the base of the blossom.
Properties (1) • A stem spans 2i nodes and contains i matched arcs for some integer i 0. • A blossom spans 2k + 1 nodes and contains k matched arcs for some integer k 1. The matched arcs match all nodes of the blossom except its base. • The base of a blossom is an even node.
Properties (2) • Every node i in the blossom (except its base) is reachable from the root p (or from the base of the blossom w) through two distinct alternating paths; one has even length and the other has odd length.
Even nodes in blossom • In a blossom – each node can receive both even and odd labels. • We would prefer to give even labels to the nodes for the following reason: • Even-labeled nodes - we can label nodes outside the blossom (all unmatched arcs incident to nodes in the blossom). • Odd-labeled nodes - we label only the nodes in the blossom (matched arcs).
Intuition • If we assign all nodes in a blossom with even, the search algorithm will find an augmenting path. • All nodes in blossom are matched, except its base. • Can be reached with either an even or odd path. • If stem is not empty – the base is matched too.
Contracting a blossom (1) • Popular approach: Shrink blossom to single node. • Blossom B = turns to a node b (pseudonode – always even): • Neighbors: • Update neighbors: • To recover information we form a circular doubly linked list of its nodes, and deleted them and all their arcs from the network (another update).
Contracting a blossom (2) • The result network the contracted network.
Nonbipartite Matching Algorithm • Search procedure assigns even or odd labels. • Algorithm will identify the possibility to assign even\odd to an odd\even respectively. • When discovering we can assign different label than what node i already has, we suspend the search. Trace back the indices of these paths until the first common node. That node is the base, and the nodes traced are the blossom. • Then we contract it to a pseudonode. • If we find a path containing a pseudonodes, we expand them one by one until none are in the path (pseudonode can contain other pseudonodes)
Correctness (1) • Lemma, If contains an augmenting path starting at the root node p (or the pseudonode containing p) with respect to the matching, then the original network contains an augmenting path starting at the root p with respect to the matching . • Proof: • If does not contain a node b, then is valid in .
Correctness (2) • Lemma,if contains an augmenting path from node p to node q with respect to a matching , then contains an augmenting path from node p (or the pseudonode containing p) to node q with respect to the matching . • Proof: • P in from p to q. Only unmatched nodes in . • If P has not node in common with a Blossom B, then P is also a path in the contracted network – nothing to prove. So assume it has nodes in common. • Case 1 – stem is empty:
Correctness (2) cont. • Proof (cont.): • Case 2 –B has nonempty stem. • - even alternating path from p to w (base of B). • - p matched, w unmatched. • contains augmenting path in so in too. w,q are the only unmatched nodes in , so must contain an augmenting path between them. • matching of contracted graph in respect to . • In , B has an empty stem, so case 1 applies, and we have an augmenting path after contracting the nodes of the blossom. • So contains an augmenting path with respect to the matching . But since and have the same cardinality, must also contain an augmenting path with respect to the matching . This conclusion completes the proof of the lemma.