Chapter 5.9 Stable Matchings: The Gale Shapley Algorithm Prof. - - PowerPoint PPT Presentation

chapter 5 9 stable matchings the gale shapley algorithm
SMART_READER_LITE
LIVE PREVIEW

Chapter 5.9 Stable Matchings: The Gale Shapley Algorithm Prof. - - PowerPoint PPT Presentation

Chapter 5.9 Stable Matchings: The Gale Shapley Algorithm Prof. Tesler Math 154 Winter 2020 Prof. Tesler Ch. 5.9: Gale-Shapley Algorithm Math 154 / Winter 2020 1 / 32 Ranked matchings Consider n people (set A ) applying to n jobs (set B ).


slide-1
SLIDE 1

Chapter 5.9 Stable Matchings: The Gale Shapley Algorithm

  • Prof. Tesler

Math 154 Winter 2020

  • Prof. Tesler
  • Ch. 5.9: Gale-Shapley Algorithm

Math 154 / Winter 2020 1 / 32

slide-2
SLIDE 2

Ranked matchings

Consider n people (set A) applying to n jobs (set B). Each person makes a ranked list of which jobs they prefer, and each company has a ranked list of all the applicants. ALL people rank ALL jobs and vice-versa. A central clearinghouse forms a perfect matching between A & B:

Each person gets exactly one job and each job is filled by exactly one person. Always possible since everyone applies to every job and |A| = |B|.

  • Prof. Tesler
  • Ch. 5.9: Gale-Shapley Algorithm

Math 154 / Winter 2020 2 / 32

slide-3
SLIDE 3

Ranked matchings

Applicant 1st 2nd 3rd 4th a 3 4 2 1 b 1 4 2 3 c 2 3 1 4 d 3 1 2 4 Job 1st 2nd 3rd 4th 1 a c b d 2 d c b a 3 b a d c 4 c d a b Applicants: a, b, c, d Jobs: 1, 2, 3, 4 Applicants rank their preference for all of the jobs, and companies rank all applicants.

  • Prof. Tesler
  • Ch. 5.9: Gale-Shapley Algorithm

Math 154 / Winter 2020 3 / 32

slide-4
SLIDE 4

Unstable matching

Applicant 1st 2nd 3rd 4th a 3 4 2 1 b 1 4 2 3 c 2 3 1 4 d 3 1 2 4 Job 1st 2nd 3rd 4th 1 a c b d 2 d c b a 3 b a d c 4 c d a b For a matching M, an unstable pair is x ∈ A, y ∈ B where xy aren’t matched, but they each prefer each other over who they’re matched to in M. A matching is unstable if there are any unstable pairs, and stable if there aren’t.

  • Prof. Tesler
  • Ch. 5.9: Gale-Shapley Algorithm

Math 154 / Winter 2020 4 / 32

slide-5
SLIDE 5

Unstable matching

Applicant 1st 2nd 3rd 4th a 3 4 2 1 b 1 4 2 3 c 2 3 1 4 d 3 1 2 4 Job 1st 2nd 3rd 4th 1 a c b d 2 d c b a 3 b a d c 4 c d a b

Example: Matching 1d, 2b, 3a, 4c and pair 1c

1 prefers c over their current match, d. c prefers 1 over their current match, 4. 1c is an unstable pair. If we switched to 1c and 4d, then 1 and c would both be happier. Would 4 and d be happier? No! They’re both switched to lower-ranked choices.

  • Prof. Tesler
  • Ch. 5.9: Gale-Shapley Algorithm

Math 154 / Winter 2020 5 / 32

slide-6
SLIDE 6

Unstable matching

Applicant 1st 2nd 3rd 4th a 3 4 2 1 b 1 4 2 3 c 2 3 1 4 d 3 1 2 4 Job 1st 2nd 3rd 4th 1 a c b d 2 d c b a 3 b a d c 4 c d a b

Example: Matching 1d, 2b, 3a, 4c and pair 3b

3 prefers b over their current match, a. However, b prefers their current match, 2, over 3. So 3b is not an unstable pair.

  • Prof. Tesler
  • Ch. 5.9: Gale-Shapley Algorithm

Math 154 / Winter 2020 6 / 32

slide-7
SLIDE 7

Unstable matching

Applicant 1st 2nd 3rd 4th a 3 4 2 1 b 1 4 2 3 c 2 3 1 4 d 3 1 2 4 Job 1st 2nd 3rd 4th 1 a c b d 2 d c b a 3 b a d c 4 c d a b Do you see any other unstable pairs for matching 1d, 2b, 3a, 4c? Answers: 1b; 1c; 2c

  • Prof. Tesler
  • Ch. 5.9: Gale-Shapley Algorithm

Math 154 / Winter 2020 7 / 32

slide-8
SLIDE 8

Unstable matching

Applicant 1st 2nd 3rd 4th a 3 4 2 1 b 1 4 2 3 c 2 3 1 4 d 3 1 2 4 Job 1st 2nd 3rd 4th 1 a c b d 2 d c b a 3 b a d c 4 c d a b We saw a switch that made one pair happier than their original match, although the other pair involved got worse in this instance. It’s not obvious whether or not there are any stable matchings.

  • Prof. Tesler
  • Ch. 5.9: Gale-Shapley Algorithm

Math 154 / Winter 2020 8 / 32

slide-9
SLIDE 9

Stable Roommates Problem

Person 1st 2nd 3rd a b c d b c a d c a b d d a b c n people (n even) need to be matched in pairs as roommates. Each person makes a ranked list of the other n − 1 people. Putting them in pairs gives a perfect matching of Kn. This is a matching in an ordinary graph, vs. our job application scenario was a matching in a bipartite graph Kn,n.

  • Prof. Tesler
  • Ch. 5.9: Gale-Shapley Algorithm

Math 154 / Winter 2020 9 / 32

slide-10
SLIDE 10

Stable Roommates Problem

Person 1st 2nd 3rd a b c d b c a d c a b d d a b c Consider the matching M: ab, cd.

b prefers c over their current match, a. c prefers b over their current match, d. b and c ditch their initial roommates and become roommates, forcing ad together, resulting in bc, ad. So M is unstable.

But matching bc, ad has unstable pair ac, and matching ca, bd has unstable pair ab.

Just permute the roles of a, b, c in the above. d is very unpopular, while a, b, c ranked each other in a circle.

The roommates problem may or may not have a stable matching.

  • Prof. Tesler
  • Ch. 5.9: Gale-Shapley Algorithm

Math 154 / Winter 2020 10 / 32

slide-11
SLIDE 11

Job application scenario again

Applicant 1st 2nd 3rd 4th a 3 4 2 1 b 1 4 2 3 c 2 3 1 4 d 3 1 2 4 Job 1st 2nd 3rd 4th 1 a c b d 2 d c b a 3 b a d c 4 c d a b In the job application scenario, we will see there is always a stable matching! The Gale-Shapley Algorithm (1962) gives a solution. We’ll have multiple rounds of people applying to one job at a time, and the companies making provisional (but not final) decisions.

  • Prof. Tesler
  • Ch. 5.9: Gale-Shapley Algorithm

Math 154 / Winter 2020 11 / 32

slide-12
SLIDE 12

Gale-Shapley Algorithm

Applicant 1st 2nd 3rd 4th a 3 4 2 1 b 1 4 2 3 c 2 3 1 4 d 3 1 2 4 Job 1st 2nd 3rd 4th 1 a c b d 2 d c b a 3 b a d c 4 c d a b Round 1: Each applicant applies to their first choice job.

a and d apply to 3; b applies to 1; c applies to 2.

Each company that receives applications this round replies “maybe” to the applicant they most prefer, and “no” to the others.

3 says “maybe” to a and “no” to d. 1 says “maybe” to b. 2 says “maybe” to c. 4 has no applicants yet, so no decisions yet.

  • Prof. Tesler
  • Ch. 5.9: Gale-Shapley Algorithm

Math 154 / Winter 2020 12 / 32

slide-13
SLIDE 13

Gale-Shapley Algorithm

Applicant 1st 2nd 3rd 4th a 3? 4 2 1 b 1? 4 2 3 c 2? 3 1 4 d x 3 1 2 4 Job 1st 2nd 3rd 4th 1 a c b? d 2 d c? b a 3 b a? x d c 4 c d a b Provisional matching: 3a, 1b, 2c. Round 2: Each unmatched applicant applies to their top remaining choice.

d applies to 1.

Each company considers their current match (if any) and any new applicants; then says “maybe” to its top choice among those and “no” to the others (possibly including the previous “maybe”).

Since 1 prefers current match b over d, they say “no” to d.

  • Prof. Tesler
  • Ch. 5.9: Gale-Shapley Algorithm

Math 154 / Winter 2020 13 / 32

slide-14
SLIDE 14

Gale-Shapley Algorithm

Applicant 1st 2nd 3rd 4th a 3? 4 2 1 b 1? 4 2 3 c 2? 3 1 4 d x 3 x 1 2 4 Job 1st 2nd 3rd 4th 1 a c b? x d 2 d c? b a 3 b a? x d c 4 c d a b Provisional matching: 3a, 1b, 2c. Round 3: Applicants: d applies to 2. Companies: Since 2 prefers d to its current match c, they change their decision on c to “no”, and say “maybe” to d.

  • Prof. Tesler
  • Ch. 5.9: Gale-Shapley Algorithm

Math 154 / Winter 2020 14 / 32

slide-15
SLIDE 15

Gale-Shapley Algorithm

Applicant 1st 2nd 3rd 4th a 3? 4 2 1 b 1? 4 2 3 c x 2 3 1 4 d x 3 x 1 2? 4 Job 1st 2nd 3rd 4th 1 a c b? x d 2 d? x c b a 3 b a? x d c 4 c d a b Provisional matching: 3a, 1b, 2d. Round 4: Applicants: c applies to 3. Companies: 3 prefers its current match a over c, so they say “no” to c.

  • Prof. Tesler
  • Ch. 5.9: Gale-Shapley Algorithm

Math 154 / Winter 2020 15 / 32

slide-16
SLIDE 16

Gale-Shapley Algorithm

Applicant 1st 2nd 3rd 4th a 3? 4 2 1 b 1? 4 2 3 c x 2 x 3 1 4 d x 3 x 1 2? 4 Job 1st 2nd 3rd 4th 1 a c b? x d 2 d? x c b a 3 b a? x d x c 4 c d a b Provisional matching: 3a, 1b, 2d. Round 5: Applicants: c applies to 1. Companies: 1 prefers c to its current match b, so they say “maybe” to c and “no” to b.

  • Prof. Tesler
  • Ch. 5.9: Gale-Shapley Algorithm

Math 154 / Winter 2020 16 / 32

slide-17
SLIDE 17

Gale-Shapley Algorithm

Applicant 1st 2nd 3rd 4th a 3? 4 2 1 b x 1 4 2 3 c x 2 x 3 1? 4 d x 3 x 1 2? 4 Job 1st 2nd 3rd 4th 1 a c? x b x d 2 d? x c b a 3 b a? x d x c 4 c d a b Provisional matching: 3a, 1c, 2d. Round 6: Applicants: b applies to 4. Companies: 4 has no match yet, so they say “maybe” to b.

  • Prof. Tesler
  • Ch. 5.9: Gale-Shapley Algorithm

Math 154 / Winter 2020 17 / 32

slide-18
SLIDE 18

Gale-Shapley Algorithm

Applicant 1st 2nd 3rd 4th a 3? 4 2 1 b x 1 4? 2 3 c x 2 x 3 1? 4 d x 3 x 1 2? 4 Job 1st 2nd 3rd 4th 1 a c? x b x d 2 d? x c b a 3 b a? x d x c 4 c d a b? Provisional matching: 3a, 1c, 2d, 4b. Round 7: Applicants: No applicant is unmatched! Companies: Every current “maybe” becomes “yes”! Output: Matching 1c, 2d, 3a, 4b

  • Prof. Tesler
  • Ch. 5.9: Gale-Shapley Algorithm

Math 154 / Winter 2020 18 / 32

slide-19
SLIDE 19

Gale-Shapley Algorithm

Interpretation of yes/no/maybe

Imagine your disappointment at being told “maybe” and having it changed to “no”. And the discussion that would occur to try to get the other side to make a final decision / change their rankings / . . . For the Gale-Shapley Algorithm to actually work, applicants and companies submit their preference lists to a central clearinghouse. The clearinghouse runs the algorithm. They don’t inform the applicants and companies about the provisional decisions each round; they only report the final result at the end.

  • Prof. Tesler
  • Ch. 5.9: Gale-Shapley Algorithm

Math 154 / Winter 2020 19 / 32

slide-20
SLIDE 20

Gale-Shapley Algorithm

Algorithm terminates in finite time, with a perfect matching

As the algorithm proceeds:

Once a company makes a match, they never become unmatched

  • again. They only “trade up” for a higher-ranked applicant.

So the size of the matching never goes down. Whereas applicants may go back and forth between matched and unmatched.

The size of the matching increases each time a company w/o a provisional matching receives an application. Each of the n2 possible applications xy (x ∈ A, y ∈ B) is made at most once, and eventually, every company receives an application, so the matching achieves size n in n2 rounds. Once the matching size reaches n, there are no unmatched applicants, so it terminates.

  • Prof. Tesler
  • Ch. 5.9: Gale-Shapley Algorithm

Math 154 / Winter 2020 20 / 32

slide-21
SLIDE 21

Gale-Shapley Algorithm

Output is a stable matching

Let M be the Gale-Shapley matching. Consider a pair xy (x ∈ A, y ∈ B) that’s not in M. In M, x is matched to y′ y and y is matched to x′ x. Case 1: Person x did not apply to job y during the algorithm.

Since applicants apply to jobs in consecutively decreasing order of preference, then y is ranked worse than y′. So x would not want to switch to y, so xy is not an unstable pair.

Case 2: Person x did apply to job y during the algorithm.

y rejected x due to being matched to higher ranked applicant x′. In subsequent rounds, y may have been re-matched to an applicant x′′ it prefers even more than x′; but then y prefers x′′ over x as well.

Either way, xy is not an unstable pair.

  • Prof. Tesler
  • Ch. 5.9: Gale-Shapley Algorithm

Math 154 / Winter 2020 21 / 32

slide-22
SLIDE 22

Stable matchings may not be unique

Applicant 1st 2nd 3rd 4th a 3 4 2 1 b 1 4 2 3 c 2 3 1 4 d 3 1 2 4 Job 1st 2nd 3rd 4th 1 a c b d 2 d c b a 3 b a d c 4 c d a b This has three stable matchings: 1a, 2d, 3b, 4c 1c, 2d, 3a, 4b — the solution we got 1c, 2d, 3b, 4a I found these by checking all n! = 4! = 24 perfect matchings.

  • Prof. Tesler
  • Ch. 5.9: Gale-Shapley Algorithm

Math 154 / Winter 2020 22 / 32

slide-23
SLIDE 23

Which side does the Gale-Shapley algorithm benefit most?

Applicant 1st 2nd 3rd 4th a 3 4 2 1 b x 1 4 2 3 c x 2 x 3 1 4 d x 3 x 1 2 4 Job 1st 2nd 3rd 4th 1 a c x b x d 2 d x c b a 3 b a x d x c 4 c d a b As the Gale-Shapley algorithm proceeds: The applicants’ provisional matches move left-to-right (best to worst) through their lists (also crossing out rejects along the way). The companies’ provisional matches go right-to-left (worst to best) through their lists (possibly crossing out some lower ranked applicants later). Which side benefits from this?

  • Prof. Tesler
  • Ch. 5.9: Gale-Shapley Algorithm

Math 154 / Winter 2020 23 / 32

slide-24
SLIDE 24

Which side does the Gale-Shapley algorithm benefit most?

Applicant 1st 2nd 3rd 4th a 3 4 2 1 b 1 4 2 3 c 2 3 1 4 d 3 1 2 4 Job 1st 2nd 3rd 4th 1 a c b d 2 d c b a 3 b a d c 4 c d a b Three stable matchings: 1a, 2d, 3b, 4c; 1c, 2d, 3a, 4b; 1c, 2d, 3b, 4a A valid match for x ∈ A is any y ∈ B where xy appears in at least

  • ne stable matching. Valid matches for y ∈ B are defined similarly.

Valid matches for a: 1, 3, 4 b: 3, 4 c: 4, 1 d: 2 Valid matches for 1: a, c 2: d 3: b, a 4: c, b, a

  • Prof. Tesler
  • Ch. 5.9: Gale-Shapley Algorithm

Math 154 / Winter 2020 24 / 32

slide-25
SLIDE 25

Which side does the Gale-Shapley algorithm benefit most?

Applicant 1st 2nd 3rd 4th a 3 4 2 1 b 1 4 2 3 c 2 3 1 4 d 3 1 2 4 Job 1st 2nd 3rd 4th 1 a c b d 2 d c b a 3 b a d c 4 c d a b Three stable matchings: 1a, 2d, 3b, 4c; 1c, 2d, 3a, 4b; 1c, 2d, 3b, 4a Reorder the valid matches in order of preference. Valid matches for a: 3, 4, 1 b: 4, 3 c: 1, 4 d: 2 Valid matches for 1: a, c 2: d 3: b, a 4: c, a, b

  • Prof. Tesler
  • Ch. 5.9: Gale-Shapley Algorithm

Math 154 / Winter 2020 25 / 32

slide-26
SLIDE 26

Which side does the Gale-Shapley algorithm benefit most?

Gale-Shapley matching: 1c, 2d, 3a, 4b Valid matches for a: 3, 4, 1 b: 4, 3 c: 1, 4 d: 2 Valid matches for 1: a, c 2: d 3: b, a 4: c, a, b Applicants got their top choice among the valid matches. Companies got their worst choice among the valid matches!

  • Prof. Tesler
  • Ch. 5.9: Gale-Shapley Algorithm

Math 154 / Winter 2020 26 / 32

slide-27
SLIDE 27

Switch roles of A and B in G-S algorithm

Applicant 1st 2nd 3rd 4th a 3 4 2 1 b 1 4 2 3 c 2 3 1 4 d 3 1 2 4 Job 1st 2nd 3rd 4th 1 a c b d 2 d c b a 3 b a d c 4 c d a b Switch the roles of A and B. In each round, companies make provisional offers to applicants, with applicants replying “maybe” to their best offer so far and “no” to their other offers so far. Round 1: Companies: Offers 1a, 2d, 3b, 4c. Applicants: Each has just one offer, so replies “maybe.” Round 2: Companies: All companies have provisional matches, so no company makes an offer, so it terminates.

  • Prof. Tesler
  • Ch. 5.9: Gale-Shapley Algorithm

Math 154 / Winter 2020 27 / 32

slide-28
SLIDE 28

Switch roles of A and B in G-S algorithm

Matching: 1a, 2d, 3b, 4c Valid matches for a: 3, 4, 1 b: 4, 3 c: 1, 4 d: 2 Valid matches for 1: a, c 2: d 3: b, a 4: c, a, b Each company got their best valid match, and each applicant got their worst valid match.

  • Prof. Tesler
  • Ch. 5.9: Gale-Shapley Algorithm

Math 154 / Winter 2020 28 / 32

slide-29
SLIDE 29

Proving G-S assigns each applicant their best valid match

Assume by way of contradiction that someone gets a job that’s not their best valid match. Since people apply to jobs in decreasing order of preference, someone was rejected by their best valid match. Let xy be the first such rejection in the G-S algorithm: y is the best valid match for x, but y rejects x in favor of x′. Let M1 be the provisional matching when y rejects x; M2 be a stable matching with xy; y′ be matched to x′ in M2. x′ must prefer y to y′:

If x′ prefers y′, they would have applied to y′ before applying to y; and since x′ is now matched in M1 to y, it means y′ rejected x′. But y rejecting x was the first rejection by a valid match.

So x′ y is unstable for M2, contradicting that M2 is stable. Proving G-S gives each company their worst valid match is similar.

  • Prof. Tesler
  • Ch. 5.9: Gale-Shapley Algorithm

Math 154 / Winter 2020 29 / 32

slide-30
SLIDE 30

National Resident Matching Program

The National Resident Matching Program is an organization that matches medical school students to hospital residencies, using a version of the Gale-Shapley algorithm. In 2019: over 40K applicants matched to over 30K positions at

  • ver 5000 institutions.

These are further broken down by medical specialties.

  • Prof. Tesler
  • Ch. 5.9: Gale-Shapley Algorithm

Math 154 / Winter 2020 30 / 32

slide-31
SLIDE 31

National Resident Matching Program

Applicants rank their top 20 hospitals/positions rather than all of

  • them. (They can rank more for additional fees.)

Hospitals may have multiple positions. Say a hospital has 3:

The first 3 applicants initially get “maybe.” Any subsequent applicant who the hospital prefers over any current provisional match is given a “maybe” while the hospital’s current lowest ranked match is changed to “no”.

At the end:

There will be unmatched applicants and unmatched positions. The matching is stable.

The original implementation (1950s) favored hospitals’ rankings. In the late 1990s, it was switched to favor applicants’ rankings.

  • Prof. Tesler
  • Ch. 5.9: Gale-Shapley Algorithm

Math 154 / Winter 2020 31 / 32

slide-32
SLIDE 32

Applications of the Gale-Shapley Algorithm

Marriage proposals. Matching medical students to internships. Matching students to high schools / colleges. Matching organ donors with patients. In 2012, Lloyd Shapley and Alvin Roth won the Nobel Memorial Prize in Economic Sciences, for applications of the algorithm in Economics.

  • Prof. Tesler
  • Ch. 5.9: Gale-Shapley Algorithm

Math 154 / Winter 2020 32 / 32