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 ). 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
Ranked matchings 1 st 2 nd 3 rd 4 th 1 st 2 nd 3 rd 4 th Applicant Job a 3 4 2 1 1 a c b d b 1 4 2 3 2 d c b a c 2 3 1 4 3 b a d c d 3 1 2 4 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
Unstable matching 1 st 2 nd 3 rd 4 th 1 st 2 nd 3 rd 4 th Applicant Job a 3 4 2 1 1 a c b d b 1 4 2 3 2 d c b a c 2 3 1 4 3 b a d c d 3 1 2 4 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
Unstable matching 1 st 2 nd 3 rd 4 th 1 st 2 nd 3 rd 4 th Applicant Job a 3 4 2 1 1 a c b d b 1 4 2 3 2 d c b a c 2 3 1 4 3 b a d c d 3 1 2 4 4 c d a b Example: Matching 1 d , 2 b , 3 a , 4 c and pair 1 c 1 prefers c over their current match, d . c prefers 1 over their current match, 4 . 1 c is an unstable pair . If we switched to 1 c and 4 d , 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
Unstable matching 1 st 2 nd 3 rd 4 th 1 st 2 nd 3 rd 4 th Applicant Job a 3 4 2 1 1 a c b d b 1 4 2 3 2 d c b a c 2 3 1 4 3 b a d c d 3 1 2 4 4 c d a b Example: Matching 1 d , 2 b , 3 a , 4 c and pair 3 b 3 prefers b over their current match, a . However, b prefers their current match, 2 , over 3 . So 3 b is not an unstable pair. Prof. Tesler Ch. 5.9: Gale-Shapley Algorithm Math 154 / Winter 2020 6 / 32
Unstable matching 1 st 2 nd 3 rd 4 th 1 st 2 nd 3 rd 4 th Applicant Job a 3 4 2 1 1 a c b d b 1 4 2 3 2 d c b a c 2 3 1 4 3 b a d c d 3 1 2 4 4 c d a b Do you see any other unstable pairs for matching 1 d , 2 b , 3 a , 4 c ? Answers: 1 b ; 1 c ; 2 c Prof. Tesler Ch. 5.9: Gale-Shapley Algorithm Math 154 / Winter 2020 7 / 32
Unstable matching 1 st 2 nd 3 rd 4 th 1 st 2 nd 3 rd 4 th Applicant Job a 3 4 2 1 1 a c b d b 1 4 2 3 2 d c b a c 2 3 1 4 3 b a d c d 3 1 2 4 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
Stable Roommates Problem 1 st 2 nd 3 rd Person 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 K n . This is a matching in an ordinary graph, vs. our job application scenario was a matching in a bipartite graph K n , n . Prof. Tesler Ch. 5.9: Gale-Shapley Algorithm Math 154 / Winter 2020 9 / 32
Stable Roommates Problem 1 st 2 nd 3 rd Person 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
Job application scenario again 1 st 2 nd 3 rd 4 th 1 st 2 nd 3 rd 4 th Applicant Job a 3 4 2 1 1 a c b d b 1 4 2 3 2 d c b a c 2 3 1 4 3 b a d c d 3 1 2 4 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
Gale-Shapley Algorithm 1 st 2 nd 3 rd 4 th 1 st 2 nd 3 rd 4 th Applicant Job a 3 4 2 1 1 a c b d b 1 4 2 3 2 d c b a c 2 3 1 4 3 b a d c d 3 1 2 4 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
Gale-Shapley Algorithm 1 st 2 nd 3 rd 4 th 1 st 2 nd 3 rd 4 th Applicant Job a 3? 4 2 1 1 a c b? d b 1? 4 2 3 2 d c? b a c 2? 3 1 4 3 b a? x d c d 3 x 1 2 4 4 c d a b Provisional matching: 3 a , 1 b , 2 c . 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
Gale-Shapley Algorithm 1 st 2 nd 3 rd 4 th 1 st 2 nd 3 rd 4 th Applicant Job a 3? 4 2 1 1 a c b? d x b 1? 4 2 3 2 d c? b a c 2? 3 1 4 3 b a? x d c d 3 x 1 x 2 4 4 c d a b Provisional matching: 3 a , 1 b , 2 c . 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
Gale-Shapley Algorithm 1 st 2 nd 3 rd 4 th 1 st 2 nd 3 rd 4 th Applicant Job a 3? 4 2 1 1 a c b? x d b 1? 4 2 3 2 d? x c b a c 2 x 3 1 4 3 b a? x d c d 3 x 1 x 2? 4 4 c d a b Provisional matching: 3 a , 1 b , 2 d . 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
Gale-Shapley Algorithm 1 st 2 nd 3 rd 4 th 1 st 2 nd 3 rd 4 th Applicant Job a 3? 4 2 1 1 a c b? x d b 1? 4 2 3 2 d? c x b a c 2 x 3 x 1 4 3 b a? d x c x d x 3 x 1 2? 4 4 c d a b Provisional matching: 3 a , 1 b , 2 d . 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
Gale-Shapley Algorithm 1 st 2 nd 3 rd 4 th 1 st 2 nd 3 rd 4 th Applicant Job a 3? 4 2 1 1 a c? x b x d b x 1 4 2 3 2 d? x c b a c 2 x 3 x 1? 4 3 b a? x d c x d x 3 x 1 2? 4 4 c d a b Provisional matching: 3 a , 1 c , 2 d . 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
Gale-Shapley Algorithm 1 st 2 nd 3 rd 4 th 1 st 2 nd 3 rd 4 th Applicant Job 3? c? a 4 2 1 1 a b x x d b x 1 4? 2 3 2 d? c x b a c 2 x 3 x 1? 4 3 b a? d x c x d x 3 x 1 2? 4 4 c d a b? Provisional matching: 3 a , 1 c , 2 d , 4 b . Round 7: Applicants: No applicant is unmatched! Companies: Every current “maybe” becomes “yes”! Output: Matching 1 c , 2 d , 3 a , 4 b Prof. Tesler Ch. 5.9: Gale-Shapley Algorithm Math 154 / Winter 2020 18 / 32
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
Recommend
More recommend