Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Stable Marriage Problem

Similar presentations


Presentation on theme: "The Stable Marriage Problem"— Presentation transcript:

1 The Stable Marriage Problem
Algorithms and Networks 2014/2015 Hans L. Bodlaender Johan M. M. van Rooij

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

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.

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. Co

5 Contents of this lecture
Stable marriage problem. Gale-Shapley algorithm. Man-optimal and woman-optimal stable marriages. Stable roommates problem. The Stable Marriage Problem

6 Stable marriage problem
Algorithms and Networks Stable marriage problem

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…

8 Result Gale-Shapley algorithm: always finds a stable matching.
Input: list of men, women, and their preference list. Output: stable matching.

9 Does this terminate? How fast? Does this give a stable matching?
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 next woman on his list. Questions: Does this terminate? How fast? Does this give a stable matching?

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. Co

11 Termination and number of steps
Observations: Once a woman is matched, she stays matched. Her partner can change though. If her partner changes, she will always get a more preferable partner. The women to whom a man proposes will get worse (in his opinion) during the execution of algorithm. 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. The computed set is a matching. The algorithm uses at most n2 steps/proposals. Each man proposes to each women at most once.

12 The matching is stable Suppose the computed matching is not stable.
There exist (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’’.

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 Ann: Bert Arie Bert: Betty Ann Betty: Arie Bert

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: S is a stable matching (not clear from the definition). The algorithm produces a Man-optimal stable matching. 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).

15 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.

16 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 there best possible stable partner. All woman have there worst possible stable partner.

17 Stable roommates problem
Algorithms and Networks Stable roommates problem

18 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.

19 Not always a stable matching for the stable roommates
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.

20 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 list, 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.

21 Phase 1: proposing In the 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: proposer := current person. proposer proposes to his best choice by whom he is not (yet) rejected. if rejected, goto 2. if accepted by someone without a proposal: done for this person. else proposer := person who just got rejected, goto 2.

22 Phase 1: example on the blackboard
Algorithm: Apply the following for each person once: proposer := current person. proposer proposes to his best choice by whom he is not (yet) rejected. if rejected, goto 2. if accepted by someone without a proposal: done for this person. else proposer := person who just got rejected, goto 2.

23 The Stable Marriage Problem
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 x is rejected by y 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. 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, and hence has been rejected by w earlier, contradicting that this is the first rejection by a stable roommate. The Stable Marriage Problem

24 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: x cannot have a better stable roommate than y. 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.

25 Filtering for phase 1 Phase 1 finishes with either:
Some person being rejected by all others. There is no stable matching (by the previous lemma). 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.

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

27 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, : 6. 2: 6, 3, 5, 1, : 3, 5, 4. 3: 4, 5, 1, 6, : 5, 2. 4: 2, 6, 5, 1, : 2, 5. 5: 4, 2, 3, 6, : 4, 2, 3. 6: 5, 1, 4, 2, : 1.

28 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.

29 Definition: 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) 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)

30 Definition: 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) 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.

31 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.

32 Second lemma on all-or-nothing cycles
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.

33 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 in S’ partner 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.

34 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. 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.

35 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.

36 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, ...

37 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.

38 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.

39 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.

40 Algorithms and Networks
SOME FINAL COMMENTS

41 Final comments Stable marriage problem Stable roommates 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.


Download ppt "The Stable Marriage Problem"

Similar presentations


Ads by Google