The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm...

49
1 The Stable Marriage Problem Algorithms and Networks 2016/2017 Johan M. M. van Rooij Hans L. Bodlaender

Transcript of The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm...

Page 1: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

1

The Stable Marriage Problem

Algorithms and Networks 2016/2017

Johan M. M. van Rooij

Hans L. Bodlaender

Page 2: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

2

A prize winning algorithm

Lloyd Shapley, Nobel Prize Winner 2012 in economics.

Obtained the prize for a number of contributions, one being the Gale-Shapley algorithm, discussed today.

Photo Bengt Nyman

http://en.wikipedia.org/wiki/File:Lloyd_Shapley_2_2012.jpg

Page 3: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

3

The stable marriage problem

There are n men and n women all unmarried. Each has a preference list on the persons of the opposite sex.

Does there exist and can we find a stable marriage (stable matching): a matching between men and women, such that there is no man and woman who both prefer each other above their partner in the matching?

Origin: assignment of medical students to hospitals (for internships).

Students list hospitals in order of preference.

Hospitals list students in order of preference.

Page 4: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

4

Example

Arie: Ann Cindy Betty

Bert: Betty Ann Cindy

Carl: Betty Ann Cindy

Ann: Bert Carl Arie

Betty: Carl Bert Arie

Cindy: Bert Carl Arie

Stable matching: (Arie, Cindy), (Bert, Ann), (Carl, Betty).

Matching (Arie, Cindy), (Bert, Betty), (Carl, Ann) is not stable.

Carl and Betty prefer each other above given partner: they form a Blocking pair.

Page 5: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

5

Contents of this lecture

Stable marriage problem.

Gale-Shapley algorithm.

Man-optimal and woman-optimal stable marriages.

Stable roommates problem.

Introduction.

Next week:

An algorithm for the stable roommates problem.

Page 6: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

6

STABLE MARRIAGE PROBLEM

Stable Marriage & Roommates - Algorithms and Networks

Page 7: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

7

Problem: greedy algorithm does not need to terminate

Greedy or ‘Soap-Series’ Algorithm:

While there is a blocking pair

Do Switch the blocking pair

Greedy “local search” approach does not need to terminate:

Can go on for ever!

So, we need something else…

Page 8: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

8

Result

Gale-Shapley algorithm: always finds a stable matching.

Input: list of men, women, and their preference list.

Output: stable matching.

Page 9: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

9

The algorithm

Fix some ordering on the men.

Repeat until everyone is matched.

Let Y be the first unmatched man in the ordering.

Now Y will ‘propose’ to the women X highest on Y’s preference list to whom he has not proposed before.

If X has no partner, or feels that she is better off with Y than with her current partner, she accepts and X and Y become matched. This possibly turns a man Z to be unmatched.

Otherwise X turns down Y and Y will continue proposing to the next woman on his list.

Questions: Does this terminate? How fast?

Does this give a stable matching?

Page 10: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

10

A demonstration on the blackboard

Example:

Arie: Ann Cindy Betty

Bert: Betty Ann Cindy

Carl: Betty Ann Cindy

Ann: Bert Carl Arie

Betty: Carl Bert Arie

Cindy: Bert Carl Arie

Gale-Shapley Algorithm:

Repeat until everyone is matched:

Let Y be the first unmatched man.

Y will ‘propose’ to the women X highest on Y’s preference list to whom he has not proposed before.

If X has no partner, or feels that she is better off with Y than with her current partner, she accepts and X and Y become matched (possibly leaving man Z).

Otherwise X turns down Y and Y will continue proposing to next woman on his list.

Page 11: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

11

Termination and number of steps

Observations:

1. Once a woman is matched, she stays matched. Her partner can change though.

2. If her partner changes, she will always get a more preferable partner.

3. The women to whom a man proposes will get worse (in his opinion) during the execution of algorithm.

4. If a man becomes free again, then there is a woman to whom he has not yet proposed. There must be a free woman due to a counting argument, and

he cannot have proposed to her by the first observation.

5. The computed set is a matching.

6. The algorithm uses at most n2 steps/proposals. Each man proposes to each women at most once.

Proof: the matching is stable.

Page 12: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

12

The matching is stable

Suppose the computed matching is not stable.

There exist a blocking pair: (X,Y), (X’,Y’) where:

• Y prefers X’ over X

• X’ prefers Y over Y’.

Ys last proposal was to X (by definition of the algorithm).

Did Y propose to X’ during the execution of the algorithm?

No? Then Y does not prefer X’ over X – contradiction.

Yes? Then X’ rejected Y in favour of man Y’’.

• Y’’ Y’! Otherwise, contradiction with that X’ prefers Y over Y’.

Since X’ ends up with Y’ we know that she prefers Y’ over Y’’.

But wait: X’ prefers Y over Y’ and Y’ over Y’’, thus Y over Y’’.

• Contradiction: she rejected Y in favour of Y’’.

Page 13: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

13

More than one stable matching?

Conclusion:

A stable matching always exists and can be found in polynomial time.

How well are the men/women off in the stable matching produced by the Gale-Shapley algorithm?

What if the woman would propose?

Are there alternative stable matchings?

Example: (preference lists)

Arie: Ann Betty

Bert: Betty Ann

Ann: Bert Arie

Betty: Arie Bert

Page 14: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

14

Man-optimal stable matchings

Theorem:

All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }.

Corollaries:

1. S is a stable matching (not clear from the definition).

2. The algorithm produces a Man-optimal stable matching.

3. The algorithm produces the worst stable matching from the perspective of the women.

Page 15: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

15

Proof of Corollary 3

Theorem:

All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }.

Corollary:

3. The algorithm produces the worst stable matching from the perspective of the women. Suppose that in S woman X is matched to Y while Y is not her

worst possible stable partner.

Then there is a stable matching S’ in which she is matched to Y’ that is worse than Y (let Y have partner X’ in S’).

Since X is the best stable partner of Y (in S) and X’ is a stable partner of Y (in S’), we know that Y prefers X to X’.

Contradiction: S’ is not stable, blocking pair (X,Y).

Page 16: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

16

Proof of Theorem

Theorem:

All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }.

Suppose it is not true, then some man Y is rejected by a stable partner X during the execution of the algorithm.

Consider the first time this happens: X rejects Y in favour of Y’.

Because men propose in order of preference, and this is the first such rejection, X is Ys best stable partner.

Since X is a stable partner for Y, there is a stable matching S’ where X and Y are matched. Here Y’ is matched to X’ X.

Since we consider the first rejection of a stable partner, Y’ has not been rejected yet by a stable partner: thus, Y’ prefers X over X’.

Then S’ is not stable: X prefers Y’ over Y, Y’ prefers X over X’.

Contradiction.

Page 17: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

17

Stable marriage: conclusions

A stable matching always exists and can be found in O(n2) time using the Gale-Shapley algorithm.

The Gale-Shapley algorithm produces a stable matching where:

All men have their best possible stable partner.

All woman have their worst possible stable partner.

Page 18: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

18

STABLE ROOMMATES PROBLEM

Stable Marriage & Roommates - Algorithms and Networks

Page 19: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

19

Stable roommates

Given:

A set of people that must share two-person rooms.

Each person has a preference list with all possible roommates.

Question:

Does there exist (and can we find) a stable matching: an assignment of roommates, such that there are no two people who both prefer each other above their current roommate.

Page 20: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

20

Not always a stable matching for the stable roommates problem

Consider the following instance: Arie: Carl Bert Dirk

Bert: Arie Carl Dirk

Carl: Bert Arie Dirk

Dirk: can be anything

Each matching is unstable e.g., (Arie,Bert)(Carl,Dirk) has {Carl,Arie} as blocking pair.

Page 21: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

21

The Stable Roommates Problem

Algorithms and Networks 2016/2017

Johan M. M. van Rooij

Hans L. Bodlaender

Page 22: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

22

Contents of this lecture

Last week: Stable marriage problem.

Gale-Shapley algorithm.

Man-optimal and woman-optimal stable marriages.

Introduction to stable roommates problem.

This week:

An algorithm for the stable roommates problem.

Page 23: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

23

Stable roommates

Given:

A set of people that must share two-person rooms.

Each person has a preference list with all possible roommates.

Question:

Does there exist (and can we find) a stable matching: an assignment of roommates, such that there are no two people who both prefer each other above their current roommate.

Last week, we have seen that such a stable roommates assignment does not need to exists.

Page 24: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

24

Not always a stable matching for the stable roommates problem

Consider the following instance: Arie: Carl Bert Dirk

Bert: Arie Carl Dirk

Carl: Bert Arie Dirk

Dirk: can be anything

Each matching is unstable e.g., (Arie,Bert)(Carl,Dirk) has {Carl,Arie} as blocking pair.

This problem appears a bit more complicated than the stable marriage problem.

Page 25: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

25

Testing stable roommates

In the next slides, we give an algorithm to find a stable roommates assignment or decide that no such assignment exists.

The algorithm will filter preference lists, removing options that will never lead to stable assignments.

Some form of constraint propagation.

Algorithm outline:

Phase 1: proposing and filtering.

Phase 2: removing all-or-nothing cycles.

Phase 3: find empty preference lists, or output solution.

Page 26: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

26

Phase 1: proposing

Proposing phase: people propose to others to be roommates.

During the algorithm each person:

Has at most one outstanding proposal.

Keeps the best proposal he has received so far and rejects others.

Algorithm:

Apply the following for each person once:

1. proposer := current person.

2. proposer proposes to his best choice by whom he is not (yet) rejected.

3. if rejected by this person: goto 2.

4. if accepted by someone without a proposal: done for this person.

5. else proposer := person who just got rejected, goto 2.

Page 27: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

27

Phase 1: example on the blackboard

Example:

1: 4, 6, 2, 5, 3.

2: 6, 3, 5, 1, 4.

3: 4, 5, 1, 6, 2.

4: 2, 6, 5, 1, 3.

5: 4, 2, 3, 6, 1.

6: 5, 1, 4, 2, 3.

Algorithm:

Apply the following for each

person once:

1. proposer := current person.

2. proposer proposes to his best choice by whom he is not (yet) rejected.

3. if rejected, goto 2.

4. if accepted by someone without a proposal: done for this person.

5. else proposer := person who just got rejected, goto 2.

Page 28: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

28

A lemma on rejections

Lemma:

If y rejects x in phase 1 of the algorithm, then x and y cannot be partners in a stable matching.

Page 29: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

29

A lemma on rejections

Lemma:

If y rejects x in phase 1 of the algorithm, then x and y cannot be partners in a stable matching.

Suppose that y rejects x in favour of z while x and y are roommates in some stable matching S.

W.l.o.g. assume that this is the first such rejection while running the algorithm. We consider both types of rejection (z proposing to y or x proposing to y) and note that z must have proposed to y in both cases (now or earlier respectively).

Let z be matched to w in S. Since S is stable, and y prefers z to x, z must prefer w over y.

But then, z has proposed to w earlier than he did to y, and hence has been rejected by w earlier, contradicting that this is the first rejection by a stable roommate.

Page 30: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

30

Best or worst stable roommates

Lemma:

If y rejects x in phase 1 of the algorithm, then x and y cannot be partners in a stable matching.

Corollaries:

If, in phase 1 of the algorithm, x proposes to y:

1. x cannot have a better stable roommate than y.

2. y cannot have a worse stable roommate than x.

Page 31: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

31

Best or worst stable roommates

Lemma:

If y rejects x in phase 1 of the algorithm, then x and y cannot be partners in a stable matching.

Corollaries:

If, in phase 1 of the algorithm, x proposes to y:

1. x cannot have a better stable roommate than y.

2. y cannot have a worse stable roommate than x.

(1.) follows directly by the lemma. For (2.):

Let S be a stable assignment, where y is matched to z while y prefers x over z, and where x is matched to any person w.

y prefers x to z, and by (1.) x prefers y to w: contradiction to S being stable.

Page 32: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

32

Filtering for phase 1

Phase 1 finishes with either:

1. Some person being rejected by all others.

There is no stable matching (by the previous lemma).

2. Everyone holds a proposal from someone and has a made a proposal to someone that has not been rejected.

In the second case we can delete entries from the preference lists that never lead to a stable assignment.

If y holds a proposal from x then we remove from y’s preference list:

All those who rejected y.

All those to whom y prefers x (x was worst possible matching).

All those who hold a proposal from a person whom they prefer to y.

Page 33: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

33

Filtering for phase 1

If y holds a proposal from x then we remove from y’s preference list:

All those who rejected y.

All those to whom y prefers x (x was worst possible matching).

All those who hold a proposal from a person whom they prefer to y.

The example

1: 4, 6, 2, 5, 3. Proposals held in bold black.

2: 6, 3, 5, 1, 4. Rejected in phase 1 in red.

3: 4, 5, 1, 6, 2. Worse than proposal in purple.

4: 2, 6, 5, 1, 3. Eliminated because the other holds

5: 4, 2, 3, 6, 1. a better proposal in green.

6: 5, 1, 4, 2, 3.

Page 34: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

34

The result of phase 1 filtering

If y holds a proposal from x then we remove from y’s preference list:

All those who rejected y.

All those to whom y prefers x (x was worst possible matching).

All those who hold a proposal from a person whom they prefer to y.

The example The filtered example

1: 4, 6, 2, 5, 3. 1: 6.

2: 6, 3, 5, 1, 4. 2: 3, 5, 4.

3: 4, 5, 1, 6, 2. 3: 5, 2.

4: 2, 6, 5, 1, 3. 4: 2, 5.

5: 4, 2, 3, 6, 1. 5: 4, 2, 3.

6: 5, 1, 4, 2, 3. 6: 1.

Page 35: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

35

Properties after filtering

Proposals after filtering:

Everyone holds a proposal, and the proposal is from the last person on his list.

Everyone is first on someone’s list, namely the person where he holds a proposal from.

Other properties after filtering:

x appears on y’s list, if and only if, y appears on x’s list.

x is first on y’s list, if and only if, y appears last on x’s list.

if x has only y on his list, then y has only x on his list and they must be together in a stable roommates assignment if such an assignment exists.

Now we are ready for phase 2.

Page 36: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

36

Definition: all-or-nothing cycle

Definition:

An all-or-nothing cycle is a sequence of persons a1,a2,...,ar such that:

The second person in ai’s current preference list is the first person in ai+1’s preference list, and we will call this person bi+1, the best match for ai+1. (all indices modulo r)

a1: b1, b2, ...

a2: b2, b3, ... ai is the i-the person on the cycle.

a3: b3, b4, ... bi is ai’s best remaining roommate.

a4: b4, b5, ... bi+1 is second on ai’s list.

....

(modulo r)

Page 37: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

37

Definition: all-or-nothing cycle

Definition:

An all-or-nothing cycle is a sequence of persons a1,a2,...,ar such that:

The second person in ai’s current preference list is the first person in ai+1’s preference list, and we will call this person bi+1, the best match for ai+1. (all indices modulo r)

The example after phase 1

1: 6. All-or-nothing cycle: 3, 4.

2: 3, 5, 4. a1 = 3.

3: 5, 2. b2 = 2. a1: b1, b2, ...

4: 2, 5. a2 = 4. a2: b2, b1, ...

5: 4, 2, 3. b1 = 5.

6: 1.

Page 38: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

38

First lemma on all-or-nothing cycles

Lemma: (this is why we call it an all-or-nothing cycle)

Let a1,a2,...,ar be an all-or-nothing cycle relative to a set of filtered preference lists, and let bi be the first person on ai’s preference list. In any stable assignment:

either ai and bi are roommates for all i,

or ai and bi are roommates for no value of i.

Page 39: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

39

First lemma on all-or-nothing cycles

Lemma: (this is why we call it an all-or-nothing cycle)

Let a1,a2,...,ar be an all-or-nothing cycle relative to a set of filtered preference lists, and let bi be the first person on ai’s preference list. In any stable assignment:

either ai and bi are roommates for all i,

or ai and bi are roommates for no value of i.

Suppose that for some i, ai and bi are partners in a stable matching S that is part of the filtered preference lists.

Since bi is first on ai’s filtered list, ai is last on bi’s filtered list.

Since bi is second on ai-1’s list, ai-1 is present on bi’s filtered list.

So, for S to be stable, ai-1 must be matched to the only person he prefers to bi, namely bi-1.

By induction and taking i modulo r, the result follows.

Page 40: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

40

Second lemma on all-or-nothing cycles

Lemma:

Let a1,a2,...,ar be an all-or-nothing cycle relative to a set of filtered preference lists, and let bi be the first person on ai’s preference list.

If there is a stable assignment S in which (all) ai and bi are partners, then there is another one in which they are not.

We may assume all ai to be different from all bi: no aj = bk.

If so, then not all ai can have their best partner bi, as aj = bk has its worst remaining partner as ak has his best (and aj has more than one option because it is on the all-or-nothing cycle).

Claim: Let S’ be the matching where ai is partnered to bi+1 (his second best choice), and any person that is not any ai or bi is partnered as in S. We claim that S’ is stable.

Lemma follows if we prove this claim.

Page 41: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

41

Proof of the claim

Claim:

Let S’ be the matching where ai is partnered to bi+1 (his second best choice), and any person that is not any ai or bi is partnered as in S. We claim that S’ is stable.

Each bi gets a better partner in S’ than in S, where he gets his worst possible remaining partner, so any instability must involve some ai (otherwise S not stable). Let ai prefer x to bi+1. Then:

Either x = bi (ai’s partner in S), then clearly bi prefers ai-1 to ai.

Or, x is no longer on ai’s reduced preference list. In this case, x currently holds a better proposal than ai, otherwise x would still be on ai’s list. And because x’s current proposal is his worst remaining option, he clearly prefers his partner in S’ to ai.

Page 42: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

42

Filtering for phase 2

Given an all-or-nothing cycle a1,a2,...,ar relative to a set of filtered preference lists, we filter the preference lists by:

Letting each bi reject the current proposal from ai.

Let each ai consequently propose to bi+1.

Removing all items further back on bi+1’s list than ai (these are now worse than bi+1’s current proposal.

The example with one phase-2 filtering step

1: 6. 1: 6.

2: 3, 5, 4. a1 = 3. 2: 3.

3: 5, 2. b2 = 2. 3: 2. Stable assignment:

4: 2, 5. a2 = 4. 4: 5. (1,6), (2,3), (4,5).

5: 4, 2, 3. b1 = 5. 5: 4.

6: 1. 6: 1.

Page 43: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

43

Phase 2 filtering maintains the properties

Proposals after filtering:

Everyone holds a proposal, and the proposal is from the last person on his list.

Everyone is first on someone’s list, namely the person where he holds a proposal from.

Other properties after filtering:

x appears on y’s list, if and only if, y appears on x’s list.

x is first on y’s list, if and only if, y appears last on x’s list.

if x has only y on his list, then y has only x on his list and they must be together in a stable roommates assignment if such an assignment exists.

Page 44: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

44

Finding an all-or-nothing cycle

An all-or-nothing cycle is a sequence of persons a1,a2,...,ar such that:

The second person in ai’s current preference list is the first person in ai+1’s preference list, and we will call this person bi+1, the best match for ai+1. (all indices modulo r)

Property of filtered instances:

Everyone is first on someone’s list: the person where he holds a proposal from.

Let p1 be any person who’s current preference list contains more than one person.

Let qi := the second person on pi’s filtered list.

Let pi+1 := the last person on qi’s filtered list (qi first on pi+1).

Repeat until this cycles, then ai = ps+i-1, where ps is the first pi to be repeated in the sequence.

a1: b1, b2, ...

a2: b2, b1, ...

Page 45: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

45

Phase 3: find empty lists or output solution

After phase 1, apply phase 2 filtering exhaustively.

If at some point a reduced preference list is empty, then there is no stable roommates assignment.

Filtering keeps at least one stable roommates assignment.

If a reduced set of preference lists has exactly one person on each list, then the lists specify a stable assignment.

Identical to ‘proof of the claim’. If some y prefers person x over his current partner, then by filtering x must prefer the last person on his list over y.

Page 46: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

46

Example where phase 2 results in an empty list

Example Example after phase 1 filtering

1: 2, 6, 4, 3, 5. 1: 2, 3.

2: 3, 5, 1, 6, 4. 2: 3, 1.

3: 1, 6, 2, 5, 4. 3: 1, 2.

4: 5, 2, 3, 6, 1. 4: 5, 6.

5: 6, 1, 3, 4, 2. 5: 6, 4.

6: 4, 2, 5, 1, 3. 6: 4, 5.

All-or-nothing cycle: 1, 2, 3

a1 = 1, b2 = 3.

a2 = 2, b3 = 1.

a3 = 3, b1 = 2.

If the bi reject their current proposal, lists become empty.

Page 47: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

47

Stable Roommates Problem

We have shown a three phase algorithm for the stable roommates problem.

The algorithm filters preference list, removing options that will never lead to stable assignments.

Some form of constraint propagation.

Three phases:

Phase 1: proposing and filtering.

Phase 2: removing all-or-nothing cycles.

Phase 3: find empty preference lists, or output solution.

Page 48: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

48

SOME FINAL COMMENTS

Stable Marriage & Roommates - Algorithms and Networks

Page 49: The Stable Marriage Problem - Utrecht University · All executions of the Gale-Shapley algorithm result in the set S = { (Y, best partner of Y in any stable matching) }. Corollary:

49

Final comments

Stable marriage problem Stable matching always exists.

Man-optimal (or woman-optimal) matchings can be found using the Gale-Shapley algorithm.

Stable roommates problem. Stable matchings do not always exists.

Testing whether one exists, and finding one can be done using the given three-phase algorithm.

Much further work has been done, e.g.: Random / Fair stable matchings.

Many variants of stable matching are also solvable (indifferences, groups, forbidden pairs, …).

What happens if some participants lie about their preferences?

Stable roommates with indifferences: NP-complete.