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

cs 401 computer algorithms i
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

CS 401: Computer Algorithms I

Stable Matching / Representative Problems

Xiaorui Sun

1

slide-2
SLIDE 2

Last Lecture (summary)

Stable matching problem: Given n men and n women, and their preferences, find a stable matching.

2

For a perfect matching M, a pair m-w is unstable if they prefer each other to their match in M.

Zoran Amy Claire Brenda Yuri Brenda Claire Amy Xavier Amy Claire Brenda 1st 2nd 3rd

Men’s Preference Profile

Claire Xavier Zoran Yuri Brenda Xavier Zoran Yuri Amy Yuri Zoran Xavier 1st 2nd 3rd

Women’s Preference Profile

favorite least favorite favorite least favorite

slide-3
SLIDE 3

Last Lecture (summary)

Stable matching problem: Given n men and n women, and their preferences, find a stable matching. Gale-Shapley algorithm

3

For a perfect matching M, a pair m-w is unstable if they prefer each other to their match in M.

Initialize each person to be free. while (some man is free and hasn't proposed to every woman) { Choose such a man m w = 1st 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 }

slide-4
SLIDE 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

slide-5
SLIDE 5

Propose-And-Reject Algorithm [Gale-Shapley’62]

5

Initialize each person to be free. while (some man is free and hasn't proposed to every woman) { Choose such a man m w = 1st 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 }

  • 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 matrix proposed[m, w].
  • Set entry to 1 if m has proposed to w, otherwise set to 0

O(n2) time O(n) time

  • Input: For each man (woman), a list of women (men) ordered by

preference, denoted as pref[m/w, i] Overall: O(n4) time O(n) time Can be improved to O(n) using the fact that if a man is free, then he hasn’t proposed to every woman yet (any free man is fine) Can be improved to O(n3)

slide-6
SLIDE 6

Efficient Implementation

We describe O(n2) time implementation. Representing men and women:

Assume men are named 1, …, n. Assume women are named n+1, …, 2n.

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

slide-7
SLIDE 7

Propose-And-Reject Algorithm [Gale-Shapley’62]

7

Initialize each person to be free. while (some man is free and hasn't proposed to every woman) { Choose such a man m w = 1st 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 }

O(1) time O(1) time

slide-8
SLIDE 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(n2) total preprocessing cost.

8

for i = 1 to n inverse[amy, pref[amy, i]] = i

Pref 1st 8 2nd 7 3rd 3 4th 4 5th 1 5 2 6 6th 7th 8th Inverse 4th 2nd 8th 6th 5th 7th 1st 3rd 1 2 3 4 5 6 7 8 Amy Amy

Amy prefers man 3 to 6, since !"#$%&$[()*, ,] = / < 1 = !"#$%&$[()*, 2]

slide-9
SLIDE 9

Propose-And-Reject Algorithm [Gale-Shapley’62]

9

Initialize each person to be free. while (some man is free and hasn't proposed to every woman) { Choose such a man m w = 1st 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 }

O(1) time O(1) time Overall: O(n2) time O(1) time

slide-10
SLIDE 10

Implementation Summary

We can implement GS algorithm in O(n2) time.

  • Problem size: N=2n2 words
  • 2n people each with a preference list of length n
  • 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

  • Q. Why do we care?
  • A. Usually, the running time is lower-bounded by input length.
slide-11
SLIDE 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

slide-12
SLIDE 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.

12 Yuri Xavier B A 1st A B 2nd X Brenda Amy Y 1st Y X 2nd

slide-13
SLIDE 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

slide-14
SLIDE 14

Man Optimality

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. Thus w-m’ is unstable in S.

14

m’-w’ m-w

S

. . . since this is the first rejection by a valid partner

slide-15
SLIDE 15

Man Optimality Summary

Man-optimality: In version of GS where men propose, each man receives the best valid partner. Q: Does man-optimality come at the expense of the women?

15

w is a valid partner of m if there exist some stable matching where m and w are paired

slide-16
SLIDE 16

Woman Pessimality

Woman-pessimal assignment: Each woman receives the worst valid partner.

  • Claim. GS finds woman-pessimal stable matching S*.
  • Proof. Homework

16

slide-17
SLIDE 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

slide-18
SLIDE 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

slide-19
SLIDE 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!)

Reference: https://medium.com/@UofCalifornia/how-a-matchmaking-algorithm-saved-lives-2a65ac448698

19

slide-20
SLIDE 20

Why this problem is important?

20

Shapley and Roth got the Nobel Prize (Economic) in 2012. (David Gale passed away in 2008.)

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.

slide-21
SLIDE 21

21

Representative problems

slide-22
SLIDE 22

Interval Scheduling

Input: Set of jobs with start times and finish times Goal: Find maximum cardinality subset of mutually compatible jobs

22

Jobs don’t overlap

slide-23
SLIDE 23

Weighted Interval Scheduling

Input: Set of jobs with start times and finish times Goal: Find maximum weight subset of mutually compatible jobs

23

slide-24
SLIDE 24

Bipartite Matching

Input: Bipartite graph Goal: Find maximum cardinality matching

24

slide-25
SLIDE 25

Independent Set

Input: Graph Goal: Find maximum cardinality independent set

25

Subset of nodes such that no two joined by an edge

slide-26
SLIDE 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.

26

Second player can guarantee 20, but not 25

slide-27
SLIDE 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: nk max-flow based algorithm Independent set: NP-complete Competitive facility location: PSPACE-complete

27