cs 401 computer algorithms i
play

CS 401: Computer Algorithms I Stable Matching / Representative - PowerPoint PPT Presentation

CS 401: Computer Algorithms I Stable Matching / Representative Problems Xiaorui Sun 1 Last Lecture (summary) Stable matching problem: Given n men and n women, and their preferences, find a stable matching. For a perfect matching M , a pair


  1. CS 401: Computer Algorithms I Stable Matching / Representative Problems Xiaorui Sun 1

  2. Last Lecture (summary) Stable matching problem: Given n men and n women, and their preferences, find a stable matching. For a perfect matching M , a pair m-w is unstable if they prefer each other to their match in M. least favorite favorite least favorite favorite 1 st 2 nd 3 rd 1 st 2 nd 3 rd Xavier Amy Brenda Claire Amy Yuri Xavier Zoran Yuri Brenda Amy Claire Brenda Xavier Yuri Zoran Zoran Amy Brenda Claire Claire Xavier Yuri Zoran Men’s Preference Profile Women’s Preference Profile 2

  3. Last Lecture (summary) Stable matching problem: Given n men and n women, and their preferences, find a stable matching. For a perfect matching M , a pair m-w is unstable if they prefer each other to their match in M. Gale-Shapley algorithm Initialize each person to be free. while (some man is free and hasn't proposed to every woman) { Choose such a man m w = 1 st woman on m 's list to whom m has not yet proposed if ( w is free) assign m and w to be engaged else if ( w prefers m to her fiancé m' ) assign m and w to be engaged, and m' to be free else w rejects m } 3

  4. Questions • Q: Why GS algorithm solves Stable Matching problem? • Q: How to implement GS algorithm efficiently? • Q: If there are multiple stable matchings, which one does GS find? 4

  5. Propose-And-Reject Algorithm [Gale-Shapley’62] Can be improved to O(n) using the fact that • Input: For each man (woman), a list of women (men) ordered by if a man is free, then he hasn’t proposed to every woman yet preference, denoted as pref[m/w, i] (any free man is fine) O ( n 2 ) Initialize each person to be free. time while (some man is free and hasn't proposed to every woman) { Choose such a man m O ( n ) w = 1 st woman on m 's list to whom m has not yet proposed time if ( w is free) assign m and w to be engaged O ( n ) else if ( w prefers m to her fiancé m' ) time assign m and w to be engaged, and m' to be free else w rejects m } • Maintain two arrays wife [ m ] , and husband [ w ] . • set entry to 0 if unmatched Overall: O ( n 4 ) Can be improved to O(n 3 ) • if m matched to w then wife [ m ]= w and husband [ w ]= m time • Maintain a matrix proposed[m, w]. 5 • Set entry to 1 if m has proposed to w , otherwise set to 0

  6. Efficient Implementation We describe O ( n 2 ) time implementation. Representing men and women: Assume men are named 1 , …, n . Assume women are named n+1 , …, 2 n . Free men: Maintain two arrays wife [ m ] , and husband [ w ] . • set entry to 0 if unmatched • if m matched to w then wife [ m ]= w and husband [ w ]= m Maintain a list of free men, e.g., in a queue. Men proposing: For each man, maintain a list of women, ordered by preference pref[m/w, i] . Maintain an array count [ m ] that counts the number of proposals made by man m . 6

  7. Propose-And-Reject Algorithm [Gale-Shapley’62] O ( 1 ) Initialize each person to be free. time while (some man is free and hasn't proposed to every woman) { O ( 1 ) Choose such a man m w = 1 st woman on m 's list to whom m has not yet proposed time if ( w is free) assign m and w to be engaged else if ( w prefers m to her fiancé m' ) assign m and w to be engaged, and m' to be free else w rejects m } 7

  8. A Preprocessing Idea Women rejecting/accepting. Does woman w prefer man m to man m' ? For each woman, create inverse of preference list of men. Constant time access for each query after O ( n ) preprocessing per woman. O ( n 2 ) total preprocessing cost. Amy 1 st 2 nd 3 rd 4 th 5 th 6 th 7 th 8 th Pref 8 3 7 1 4 5 6 2 1 2 3 4 5 6 7 8 Amy Inverse 4 th 8 th 2 nd 5 th 6 th 7 th 3 rd 1 st Amy prefers man 3 to 6, since for i = 1 to n !"#$%&$[()*, ,] = / < 1 = !"#$%&$[()*, 2] inverse[amy, pref[amy, i]] = i 8

  9. Propose-And-Reject Algorithm [Gale-Shapley’62] O ( 1 ) Initialize each person to be free. time while (some man is free and hasn't proposed to every woman) { O ( 1 ) Choose such a man m w = 1 st woman on m 's list to whom m has not yet proposed time if ( w is free) assign m and w to be engaged O ( 1 ) else if ( w prefers m to her fiancé m' ) time assign m and w to be engaged, and m' to be free else w rejects m } Overall: O ( n 2 ) time 9

  10. Implementation Summary We can implement GS algorithm in O ( n 2 ) time. • Problem size: N = 2n 2 words • 2n people each with a preference list of length n Q. Why do we care? A. Usually, the running time is lower-bounded by input length. • GS is the best we can hope for the stable matching problem ( O(N) time). Different implementations of same algorithm may have different running time. 10

  11. Questions • Q: Why GS algorithm solves Stable Matching problem? • Q: How to implement GS algorithm efficiently? • Q: If there are multiple stable matchings, which one does GS find? 11

  12. Understanding the Solution Q. For a given problem instance, there may be several stable matchings. Do all executions of Gale-Shapley yield the same stable matching? If so, which one? An instance with two stable matchings: • A-X, B-Y. • A-Y, B-X. 1 st 2 nd 1 st 2 nd Amy Y X Xavier A B Brenda X Y Yuri B A 12

  13. Man Optimal Assignments Definition: Man m is a valid partner of woman w if there exists some stable matching in which they are matched. Man-optimal assignment: Each man receives the best valid partner (according to his preferences). • Is man-optimal assignment a matching? • Simultaneously best for each and every man. Claim: All executions of GS yield a man-optimal matching, which is a stable matching! 13

  14. Man Optimality S m-w m’-w’ Claim: GS matching S* is man-optimal. . . . Proof: (by contradiction) Suppose some man is paired with someone other than his best valid partner. Men propose in decreasing order of preference Þ some man is rejected by a valid partner. Let m be the man who is the first such rejection, and let w be the women who is first valid partner that rejects him. Let S be a stable matching where w and m are matched. In building S*, when m is rejected, w forms (or reaffirms) engagement with a man, say m’ , whom she prefers to m . Let w’ be the partner of m’ in S . In building S*, m’ is not rejected by any valid partner at the point when m is rejected by w . Thus, m’ prefers w to w’ . But w prefers m’ to m . since this is the first rejection by a valid partner Thus w - m’ is unstable in S . 14

  15. Man Optimality Summary Man-optimality: In version of GS where men propose, each man receives the best valid partner. w is a valid partner of m if there exist some stable matching where m and w are paired Q: Does man-optimality come at the expense of the women? 15

  16. Woman Pessimality Woman-pessimal assignment: Each woman receives the worst valid partner. Claim. GS finds woman-pessimal stable matching S* . Proof. Homework 16

  17. Stable Matching Summary • Stable matching problem: Given n men and n women, and their preferences, find a stable matching. • Gale-Shapley algorithm: Guarantees to find a stable matching for any problem instance. • Q: How to implement GS algorithm efficiently? Different implementations may have different running time • Q: If there are multiple stable matchings, which one does GS find? Proof by contradiction 17

  18. Why this problem is important? In 1962, Gale and Shapley published the paper “College Admissions and the Stability of Marriage” To “The American Mathematical Monthly” 18

  19. Why this problem is important? Alvin Roth modified the Gale-Shapley algorithm and apply it to • National Residency Match Program (NRMP), a system that assigns new doctors to hospitals around the country. (90s) • Public high school assignment process (00s) • Helping transplant patients find a match (2004) (Saved >1,000 people every year!) 19 Reference: https://medium.com/@UofCalifornia/how-a-matchmaking-algorithm-saved-lives-2a65ac448698

  20. Why this problem is important? Some of the problems in this course may seem obscure or even pointless when it was discovered. But their abstraction allows for variety of applications. Shapley and Roth got the Nobel Prize (Economic) in 2012. (David Gale passed away in 2008.) 20

  21. Representative problems 21

  22. Interval Scheduling Input: Set of jobs with start times and finish times Goal: Find maximum cardinality subset of mutually compatible jobs Jobs don’t overlap 22

  23. Weighted Interval Scheduling Input: Set of jobs with start times and finish times Goal: Find maximum weight subset of mutually compatible jobs 23

  24. Bipartite Matching Input: Bipartite graph Goal: Find maximum cardinality matching 24

  25. Independent Set Input: Graph Goal: Find maximum cardinality independent set Subset of nodes such that no two joined by an edge 25

  26. Competitive Facility Location Input: Graph with weight on each node. Game: Two competitive players alternate in selecting nodes. Not allowed to select a node if any of its neighbors have been selected. Goal: Select a maximum weight subset of nodes. Second player can guarantee 20, but not 25 26

  27. Five Representative Problems Common theme: independent set Interval scheduling: n log n greedy algorithm Weighted interval scheduling: n log n dynamic programming algorithm Bipartite matching: n k max-flow based algorithm Independent set: NP-complete Competitive facility location: PSPACE-complete 27

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend