Jump to content

Stable roommates problem: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Addbot (talk | contribs)
m Bot: Migrating 1 interwiki links, now provided by Wikidata on d:q3406260
MichaelExe (talk | contribs)
included discussion of stable tables in the algorithm description and O(n^2) implementation details; expanded the example; one more reference + further reading
Tag: nowiki added
Line 1: Line 1:
In [[mathematics]], especially in the fields of [[game theory]] and [[combinatorics]], the '''stable roommate problem (SRP)''' is the problem of finding a '''stable matching''' — a [[Matching (graph theory)|matching]] in which there is no pair of elements, each from a different matched set, where each member of the pair prefers the other to their match. This is different from the [[stable marriage problem]] in that the stable roommates problem does not require that a set is broken up into male and female subsets. Any person can prefer anyone in the same set.
In [[mathematics]], [[economics]] and [[computer science]], particularly in the fields of [[combinatorics]], [[game theory]] and [[algorithms]], the '''stable roommate problem (SRP)''' is the problem of finding a '''stable matching''' — a [[Matching (graph theory)|matching]] in which there is no pair of elements, each from a different matched set, where each member of the pair prefers the other to their match. This is different from the [[stable marriage problem]] in that the stable roommates problem does not require that a set is broken up into male and female subsets. Any person can prefer anyone in the same set.


It is commonly stated as:
It is commonly stated as:
Line 13: Line 13:
An efficient algorithm was given in {{harv|Irving|1985}}. The algorithm will determine, for any instance of the problem, whether a stable matching exists, and if so, will find such a matching.
An efficient algorithm was given in {{harv|Irving|1985}}. The algorithm will determine, for any instance of the problem, whether a stable matching exists, and if so, will find such a matching.


Irving's algorithm has O(''n''<sup>2</sup>) complexity, provided suitable data structures are used to facilitate manipulation of the preference lists and identification of rotations (see below).
Irving's algorithm has O(''n''<sup>2</sup>) complexity, provided suitable data structures are used to facilitate manipulation of the preference lists and identification of rotations.


The algorithm consists of two phases. In the first phase, participants ''propose'' to each other, in a manner similar to that of the Gale Shapley algorithm for the [[stable marriage problem]]. Participants propose to each person on their preference list, in order, continuing to the next person if and when their current proposal is rejected. A participant rejects a proposal if he already holds, or subsequently receives, a proposal from someone he prefers. In this first phase, one participant might be rejected by all of the others, an indicator that no stable matching is possible. Otherwise, Phase 1 ends with each person holding a proposal from one of the others – this situation can be represented as a set ''S'' of ordered pairs of the form (''p'',''q''), where ''q'' holds a proposal from ''p'' – we say that ''q'' is ''p'''s current ''favorite''. In the case that this set represents a matching, i.e., (''q'',''p'') is in ''S'' whenever (''p'',''q'') is, the algorithm terminates with this matching, which is bound to be stable.
The algorithm consists of two phases. In Phase 1, participants ''propose'' to each other, in a manner similar to that of the Gale Shapley algorithm for the [[stable marriage problem]]. Participants propose to each person on their preference list, in order, continuing to the next person if and when their current proposal is rejected. A participant rejects a proposal if he already holds, or subsequently receives, a proposal from someone he prefers. In this first phase, one participant might be rejected by all of the others, an indicator that no stable matching is possible. Otherwise, Phase 1 ends with each person holding a proposal from one of the others.


If ''q'' holds a proposal from ''p'', then we remove from ''q''<nowiki>'</nowiki>s list all the ''x'' after ''p'', and symmetrically, for each of those ''x'', we remove ''q'' from ''x''<nowiki>'</nowiki>s list, so that ''q'' is first in ''p''<nowiki>'</nowiki>s list; and ''p'', last in ''q''<nowiki>'</nowiki>s, since ''q'' and ''x'' cannot be partners in any stable matching. The resulting reduced set of preference lists together is called the Phase 1 table. In this table, if any reduced list is empty, then there is no stable matching. Otherwise, the Phase 1 table is a ''stable table''. A stable table, by definition, is the set of preference lists together (the original table) with some entries removed, satisfying the following three conditions (where reduced list means a list in the stable table):
Otherwise the algorithm enters Phase 2, in which the set ''S'' is repeatedly changed by the application of so-called rotations. Suppose that (''p'',''q'') is in the set ''S'' but (''q'',''p'') is not. For each such ''p'' we identify his current ''second favorite'' to be the first successor of ''q'' in ''p'''s preference list who would reject the proposal that he holds in favor of ''p''. A ''rotation'' relative to ''S'' is a sequence (''p''<sub>0</sub>,''q''<sub>0</sub>), (''p''<sub>1</sub>,''q''<sub>1</sub>),. . ., (''p''<sub>''k''-1</sub>,''q''<sub>''k''-1</sub>) such that (''p''<sub>''i''</sub>,''q''<sub>''i''</sub>) is in ''S'' for each ''i'', and ''q''<sub>''i''+1</sub> is ''p''<sub>''i''</sub>'s current second favorite (where ''i'' + 1 is taken modulo ''k''). If, such a rotation (''p''<sub>0</sub>,''q''<sub>0</sub>), . . . , (''p''<sub>2''k''</sub>,''q''<sub>2''k''</sub>), of odd length, is found such that ''p''<sub>''i''</sub> = ''q''<sub>''i''+''k''+1</sub> for all ''i'' (where ''i'' + ''k'' + 1 is taken modulo 2''k'' + 1), this is what is referred to as an ''odd party'', which is also an indicator that there is no stable matching. Otherwise, application of the rotation involves replacing the pairs (''p''<sub>''i''</sub>,''q''<sub>''i''</sub>), in S by the pairs (''p''<sub>''i''</sub>,''q''<sub>''i''+1</sub>), (where ''i'' + 1 is again taken modulo ''k'').

(i) ''p'' is first on ''q''<nowiki>'</nowiki>s reduced list if and only if ''q'' is last on ''p''<nowiki>'</nowiki>s </br>
(ii) ''p'' is not on ''q''<nowiki>'</nowiki>s reduced list if and only if ''q'' is not on ''p''<nowiki>'</nowiki>s if and only if ''q'' prefers the last person on his list to ''p''; or ''p'', the last person on his list to ''q'' </br>
(iii) no reduced list is empty </br>

Stable tables have several important properties, which are used to justify the remainder of the procedure:

1. Any stable table must be a subtable of the Phase 1 table, where subtable is defined in the obvious sense, i.e. that the preference lists of the subtable are those of the supertable with some individuals removed from each other's lists.

2. In any stable table, if every reduced list contains ''exactly'' one individual, then pairing each individual with the single person on his list gives a stable matching.

3. If the stable roommates problem instance has a stable matching, then there is a stable matching contained in any one of the stable tables.

4. Any stable subtable of a stable table, and in particular any stable subtable that specifies a stable matching as in 2, can be obtained by a sequence of ''rotation eliminations'' on the stable table.

These rotation eliminations comprise Phase 2 of Irving's algorithm.

By 2, if each reduced list of the Phase 1 table contains exactly one individual, then this gives a matching.

Otherwise, the algorithm enters Phase 2. A ''rotation'' in a stable table ''T'' is defined as a sequence (''x''<sub>0</sub>, ''y''<sub>0</sub>), (''x''<sub>1</sub>, ''y''<sub>1</sub>), ..., (''x''<sub>k-1</sub>, ''y''<sub>k-1</sub>) such that the ''x''<sub>i</sub> are distinct, ''y''<sub>i</sub> is first on ''x''<sub>i</sub>'s reduced list (or ''x''<sub>i</sub> is last on ''y''<sub>i</sub>'s reduced list) and ''y''<sub>i+1</sub> is second on ''x''<sub>i</sub>'s reduced list, for i = 0, ..., k-1 where the indices are taken modulo k. It follows that in any stable table with a reduced list containing at least two individuals, such a rotation always exists. To find it, start at such a ''p''<sub>0</sub> containing at least two individuals in his reduced list, and define recursively ''q''<sub>i+1</sub> to be the second on ''p''<sub>i</sub>'s list and ''p''<sub>i+1</sub> to be the last on ''q''<sub>i+1</sub>'s list, until this sequence repeats some ''p''<sub>j</sub>, at which point a rotation is found: it is the sequence of pairs starting at the first occurrence of (''p''<sub>j</sub>, ''q''<sub>j</sub> and ending at the pair before the last occurrence. The sequence of ''p''<sub>i</sub> up until the ''p''<sub>j</sub> is called the ''tail'' of the rotation. The fact that it's a stable table in which this search occurs guarantees that each ''p''<sub>i</sub> has at least two individuals on his list.

To eliminate the rotation, ''y''<sub>i</sub> rejects ''x''<sub>i</sub> so that ''x''<sub>i</sub> proposes to ''y''<sub>i+1</sub>, for each ''i''. To restore the stable table properties (i) and (ii), for each ''i'', all successors of ''x''<sub>i-1</sub> are removed from ''y''<sub>i</sub>'s list, and ''y''<sub>i</sub> is removed from their lists. If a reduced list becomes empty during these removals, then there is no stable matching. Otherwise, the new table is again a stable table, and either already specifies a matching since each list contains exactly one individual or there remains another rotation to find and eliminate, so the step is repeated.


Phase 2 of the algorithm can now be summarized as follows:
Phase 2 of the algorithm can now be summarized as follows:


<source lang="java">
<source lang="java">
S = output of Phase 1;
T = Phase 1 table;
while (true) {
while (true) {
identify a rotation r in S;
identify a rotation r in T;
if (r is an odd party)
eliminate r from T;
if some list in T becomes empty,
return null; (there is no stable matching)
return null; (no stable matching can exist)
else
else if (each reduced list in T has size 1)
apply r to S;
if (S is a matching)
return the matching M = {{x, y} | x and y are on each other's lists in T}; (this is a stable matching)
return S; (guaranteed to be stable)
}
}
</source>
</source>

To achieve an O(''n''<sup>2</sup>) running time, a ranking matrix whose entry at row ''i'' and column ''j'' is the position of the ''j''th individual in the ''i''th's list; this takes O(''n''<sup>2</sup>) time. With the ranking matrix, checking whether an individual prefers one to another can be done in constant time by comparing their ranks in the matrix. Furthermore, instead of explicitly removing elements from the preference lists, the indices of the first, second and last on each individual's reduced list are maintained. The first individual that is ''unmatched'' , i.e. has at least two in his reduced lists, is also maintained. Then, in Phase 2, the sequence of ''p''<sub>i</sub> "traversed" to find a rotation is stored in a list, and an array is used to mark individuals as having been visited, as in a standard [[depth-first search]] [[graph traversal]]. After the elimination of a rotation, we continue to store only its tail, if any, in the list and as visited in the array, and start the search for the next rotation at the last individual on the tail, and otherwise at the next unmatched individual if there is no tail. This reduces repeated traversal of the tail, since it is largely unaffected by the elimination of the rotation.



===Example===
===Example===
The following are the preference lists for a Stable Roommates instance involving 6 participants ''p''<sub>1</sub>, ''p''<sub>2</sub>, ''p''<sub>3</sub>, ''p''<sub>4</sub>, ''p''<sub>5</sub>, ''p''<sub>6</sub>.


The following are the preference lists for a Stable Roommates instance involving 6 participants 1, 2, 3, 4, 5, 6.
''p''<sub>1</sub> : {{pad|1em}} ''p''<sub>3</sub> {{pad|1em}} ''p''<sub>4</sub> {{pad|1em}} ''p''<sub>2</sub> {{pad|1em}} ''p''<sub>6</sub> {{pad|1em}} ''p''<sub>5</sub> <br />

''p''<sub>2</sub> : {{pad|1em}} ''p''<sub>6</sub> {{pad|1em}} ''p''<sub>5</sub> {{pad|1em}} ''p''<sub>4</sub> {{pad|1em}} ''p''<sub>1</sub> {{pad|1em}} ''p''<sub>3</sub> <br />
''p''<sub>3</sub> : {{pad|1em}} ''p''<sub>2</sub> {{pad|1em}} ''p''<sub>4</sub> {{pad|1em}} ''p''<sub>5</sub> {{pad|1em}} ''p''<sub>1</sub> {{pad|1em}} ''p''<sub>6</sub> <br />
1 : {{pad|1em}} 3 {{pad|1em}} 4 {{pad|1em}} 2 {{pad|1em}} 6 {{pad|1em}} 5 <br />
''p''<sub>4</sub> : {{pad|1em}} ''p''<sub>5</sub> {{pad|1em}} ''p''<sub>2</sub> {{pad|1em}} ''p''<sub>3</sub> {{pad|1em}} ''p''<sub>6</sub> {{pad|1em}} ''p''<sub>1</sub> <br />
2 : {{pad|1em}} 6 {{pad|1em}} 5 {{pad|1em}} 4 {{pad|1em}} 1 {{pad|1em}} 3 <br />
''p''<sub>5</sub> : {{pad|1em}} ''p''<sub>3</sub> {{pad|1em}} ''p''<sub>1</sub> {{pad|1em}} ''p''<sub>2</sub> {{pad|1em}} ''p''<sub>4</sub> {{pad|1em}} ''p''<sub>6</sub> <br />
3 : {{pad|1em}} 2 {{pad|1em}} 4 {{pad|1em}} 5 {{pad|1em}} 1 {{pad|1em}} 6 <br />
''p''<sub>6</sub> : {{pad|1em}} ''p''<sub>5</sub> {{pad|1em}} ''p''<sub>1</sub> {{pad|1em}} ''p''<sub>3</sub> {{pad|1em}} ''p''<sub>4</sub> {{pad|1em}} ''p''<sub>2</sub>
4 : {{pad|1em}} 5 {{pad|1em}} 2 {{pad|1em}} 3 {{pad|1em}} 6 {{pad|1em}} 1 <br />
5 : {{pad|1em}} 3 {{pad|1em}} 1 {{pad|1em}} 2 {{pad|1em}} 4 {{pad|1em}} 6 <br />
6 : {{pad|1em}} 5 {{pad|1em}} 1 {{pad|1em}} 3 {{pad|1em}} 4 {{pad|1em}} 2


A possible execution of Phase 1 consists of the following sequence of proposals and rejections, where → represents ''proposes to'' and &times; represents ''rejects''.
A possible execution of Phase 1 consists of the following sequence of proposals and rejections, where → represents ''proposes to'' and &times; represents ''rejects''.


''p''<sub>1</sub> &rarr; ''p''<sub>3</sub> <br />
1 &rarr; 3 <br />
''p''<sub>2</sub> &rarr; ''p''<sub>6</sub> <br />
2 &rarr; 6 <br />
''p''<sub>3</sub> &rarr; ''p''<sub>2</sub> <br />
3 &rarr; 2 <br />
''p''<sub>4</sub> &rarr; ''p''<sub>5</sub> <br />
4 &rarr; 5 <br />
''p''<sub>5</sub> &rarr; ''p''<sub>3</sub>; {{pad|1em}} ''p''<sub>3</sub> &times; ''p''<sub>1</sub> <br />
5 &rarr; 3; {{pad|1em}} 3 &times; 1 <br />
''p''<sub>1</sub> &rarr; ''p''<sub>4</sub> <br />
1 &rarr; 4 <br />
''p''<sub>6</sub> &rarr; ''p''<sub>5</sub>; {{pad|1em}} ''p''<sub>5</sub> &times; ''p''<sub>6</sub> <br />
6 &rarr; 5; {{pad|1em}} 5 &times; 6 <br />
''p''<sub>6</sub> &rarr; ''p''<sub>1</sub>
6 &rarr; 1


So Phase 1 ends with the following reduced preference lists:
So Phase 1 ends with the set ''S'' = {(''p''<sub>1</sub>,''p''<sub>4</sub>), (''p''<sub>2</sub>,''p''<sub>6</sub>), (''p''<sub>3</sub>,''p''<sub>2</sub>), (''p''<sub>4</sub>,''p''<sub>5</sub>), (''p''<sub>5</sub>,''p''<sub>3</sub>), (''p''<sub>6</sub>,''p''<sub>1</sub>)}.



In Phase 2, the rotation ''r''<sub>1</sub> = (''p''<sub>1</sub>,''p''<sub>4</sub>), (''p''<sub>3</sub>,''p''<sub>2</sub>) is first identified. This is because ''p''<sub>2</sub> is ''p''<sub>1</sub>'s second favorite, and ''p''<sub>4</sub> is the second favorite of ''p''<sub>3</sub>. Applying ''r''<sub>1</sub> gives the new set ''S'' = {(''p''<sub>1</sub>,''p''<sub>2</sub>), (''p''<sub>2</sub>,''p''<sub>6</sub>), (''p''<sub>3</sub>,''p''<sub>4</sub>), (''p''<sub>4</sub>,''p''<sub>5</sub>), (''p''<sub>5</sub>,''p''<sub>3</sub>), (''p''<sub>6</sub>,''p''<sub>1</sub>)}. Next, the rotation ''r''<sub>2</sub> = (''p''<sub>1</sub>,''p''<sub>2</sub>), (''p''<sub>2</sub>,''p''<sub>6</sub>), (''p''<sub>4</sub>,''p''<sub>5</sub>) is identified, and application of ''r''<sub>2</sub> gives ''S'' = {(''p''<sub>1</sub>,''p''<sub>6</sub>), (''p''<sub>2</sub>,''p''<sub>5</sub>), (''p''<sub>3</sub>,''p''<sub>4</sub>), (''p''<sub>4</sub>,''p''<sub>2</sub>), (''p''<sub>5</sub>,''p''<sub>3</sub>), (''p''<sub>6</sub>,''p''<sub>1</sub>)}. Finally, the rotation ''r''<sub>3</sub> = (''p''<sub>2</sub>,''p''<sub>5</sub>), (''p''<sub>3</sub>,''p''<sub>4</sub>) is identified, application of which gives ''S'' = {(''p''<sub>1</sub>,''p''<sub>6</sub>), (''p''<sub>2</sub>,''p''<sub>4</sub>), (''p''<sub>3</sub>,''p''<sub>5</sub>), (''p''<sub>4</sub>,''p''<sub>2</sub>), (''p''<sub>5</sub>,''p''<sub>3</sub>), (''p''<sub>6</sub>,''p''<sub>1</sub>)}. This is a matching, and is guaranteed to be stable.
1 : {{pad|1em}} <del>3</del> {{pad|1em}} 4 {{pad|1em}} 2 {{pad|1em}} 6 {{pad|1em}} <del>5</del> <br />
2 : {{pad|1em}} 6 {{pad|1em}} 5 {{pad|1em}} 4 {{pad|1em}} 1 {{pad|1em}} 3 <br />
3 : {{pad|1em}} 2 {{pad|1em}} 4 {{pad|1em}} 5 {{pad|1em}} <del>1</del> {{pad|1em}} <del>6</del> <br />
4 : {{pad|1em}} 5 {{pad|1em}} 2 {{pad|1em}} 3 {{pad|1em}} 6 {{pad|1em}} 1 <br />
5 : {{pad|1em}} 3 {{pad|1em}} <del>1</del> {{pad|1em}} 2 {{pad|1em}} 4 {{pad|1em}} <del>6</del> <br />
6 : {{pad|1em}} <del>5</del> {{pad|1em}} 1 {{pad|1em}} <del> 3</del> {{pad|1em}} 4 {{pad|1em}} 2


In Phase 2, the rotation ''r''<sub>1</sub> = (1,4), (3,2) is first identified. This is because 2 is 1's second favorite, and 4 is the second favorite of 3. Eliminating ''r''<sub>1</sub> gives:

1 : {{pad|1em}} <del>3</del> {{pad|1em}} <del>4</del> {{pad|1em}} 2 {{pad|1em}} 6 {{pad|1em}} <del>5</del> <br />
2 : {{pad|1em}} 6 {{pad|1em}} 5 {{pad|1em}} 4 {{pad|1em}} 1 {{pad|1em}} <del>3</del> <br />
3 : {{pad|1em}} <del>2</del> {{pad|1em}} 4 {{pad|1em}} 5 {{pad|1em}} <del>1</del> {{pad|1em}} <del>6</del> <br />
4 : {{pad|1em}} 5 {{pad|1em}} 2 {{pad|1em}} 3 {{pad|1em}} 6 {{pad|1em}} <del>1</del> <br />
5 : {{pad|1em}} 3 {{pad|1em}} <del>1</del> {{pad|1em}} 2 {{pad|1em}} 4 {{pad|1em}} <del>6</del> <br />
6 : {{pad|1em}} <del>5</del> {{pad|1em}} 1 {{pad|1em}} <del> 3</del> {{pad|1em}} <del>4</del> {{pad|1em}} 2

Next, the rotation ''r''<sub>2</sub> = (1,2), (2,6), (4,5) is identified, and its elimination yields:

1 : {{pad|1em}} <del>3</del> {{pad|1em}} <del>4</del> {{pad|1em}} <del>2</del> {{pad|1em}} 6 {{pad|1em}} <del>5</del> <br />
2 : {{pad|1em}} <del>6</del> {{pad|1em}} 5 {{pad|1em}} 4 {{pad|1em}} <del>1</del> {{pad|1em}} <del>3</del> <br />
3 : {{pad|1em}} <del>2</del> {{pad|1em}} 4 {{pad|1em}} 5 {{pad|1em}} <del>1</del> {{pad|1em}} <del>6</del> <br />
4 : {{pad|1em}} <del>5</del> {{pad|1em}} 2 {{pad|1em}} 3 {{pad|1em}} <del>6</del> {{pad|1em}} <del>1</del> <br />
5 : {{pad|1em}} 3 {{pad|1em}} <del>1</del> {{pad|1em}} 2 {{pad|1em}} <del>4</del> {{pad|1em}} <del>6</del> <br />
6 : {{pad|1em}} <del>5</del> {{pad|1em}} 1 {{pad|1em}} <del> 3</del> {{pad|1em}} <del>4</del> {{pad|1em}} <del>2</del>

Hence 1 and 6 are matched. Finally, the rotation ''r''<sub>3</sub> = (2,5), (3,4) is identified, and its elimination gives:

1 : {{pad|1em}} <del>3</del> {{pad|1em}} <del>4</del> {{pad|1em}} <del>2</del> {{pad|1em}} 6 {{pad|1em}} <del>5</del> <br />
2 : {{pad|1em}} <del>6</del> {{pad|1em}} <del>5</del> {{pad|1em}} 4 {{pad|1em}} <del>1</del> {{pad|1em}} <del>3</del> <br />
3 : {{pad|1em}} <del>2</del> {{pad|1em}} <del>4</del> {{pad|1em}} 5 {{pad|1em}} <del>1</del> {{pad|1em}} <del>6</del> <br />
4 : {{pad|1em}} <del>5</del> {{pad|1em}} 2 {{pad|1em}} <del>3</del> {{pad|1em}} <del>6</del> {{pad|1em}} <del>1</del> <br />
5 : {{pad|1em}} 3 {{pad|1em}} <del>1</del> {{pad|1em}} <del>2</del> {{pad|1em}} <del>4</del> {{pad|1em}} <del>6</del> <br />
6 : {{pad|1em}} <del>5</del> {{pad|1em}} 1 {{pad|1em}} <del> 3</del> {{pad|1em}} <del>4</del> {{pad|1em}} <del>2</del>

Hence the matching {{1, 6}, {2,4}, {3, 5}} is stable.


==Applications==
==Applications==
Line 66: Line 127:
*{{citation | title=An efficient algorithm for the "stable roommates" problem | journal = Journal of Algorithms | volume=6 | year=1985 | pages=577–595 | first1=Robert W. | last1=Irving | doi=10.1016/0196-6774(85)90033-1 | issue=4 }}
*{{citation | title=An efficient algorithm for the "stable roommates" problem | journal = Journal of Algorithms | volume=6 | year=1985 | pages=577–595 | first1=Robert W. | last1=Irving | doi=10.1016/0196-6774(85)90033-1 | issue=4 }}
*{{citation | title=The Stable Roommates Problem with Ties | first1=Robert W. | last1=Irving | first2=David F. | last2=Manlove | journal=Journal of Algorithms | volume=43 | pages=85–105 | year=2002 | url=http://eprints.gla.ac.uk/11/01/SRT.pdf | doi=10.1006/jagm.2002.1219 | issue=1 }}
*{{citation | title=The Stable Roommates Problem with Ties | first1=Robert W. | last1=Irving | first2=David F. | last2=Manlove | journal=Journal of Algorithms | volume=43 | pages=85–105 | year=2002 | url=http://eprints.gla.ac.uk/11/01/SRT.pdf | doi=10.1006/jagm.2002.1219 | issue=1 }}
*{{citation | title=The Stable Marriage Problem: Structure and Algorithms | journal = MIT Press | year=1989 | first1=Daniel M. | last1=Gusfield | first2=Robert W. | last2=Irving }}

==Further Reading==
*{{citation | title=An efficient algorithm for the "stable roommates" problem | journal = Theoretical Computer Science | volume=381 | year=2007 | pages=162–176 | first1=Tamás | last1=Fleiner| first2=Robert W. | last2=Irving| first3=David F. | last3=Manlove| doi=10.1016/j.tcs.2007.04.029 | issue=1-3 }}


{{game theory}}
{{game theory}}

Revision as of 23:37, 26 November 2013

In mathematics, economics and computer science, particularly in the fields of combinatorics, game theory and algorithms, the stable roommate problem (SRP) is the problem of finding a stable matching — a matching in which there is no pair of elements, each from a different matched set, where each member of the pair prefers the other to their match. This is different from the stable marriage problem in that the stable roommates problem does not require that a set is broken up into male and female subsets. Any person can prefer anyone in the same set.

It is commonly stated as:

In a given instance of the Stable Roommates problem (SRP), each of 2n participants ranks the others in strict order of preference. A matching is a set of n disjoint (unordered) pairs of participants. A matching M in an instance of SRP is stable if there are no two participants x and y, each of whom prefers the other to his partner in M. Such a pair is said to block M, or to be a blocking pair with respect to M.

Solution

Unlike the stable marriage problem, the stable roommates may not, in general, have a solution. For a minimal counterexample, consider 4 people A, B, C and D such that the rankings are:

A:(B,C,D), B:(C,A,D), C:(A,B,D), D:(A,B,C)

In this ranking, each of A,B,C is the most favorite of someone. In any solution, one of A,B,C must be paired with D and the other 2 with each other (for example AD and BC) yet D's partner and the one for whom D's partner is most favorite would each prefer to be with each other. In this example, AC is a more favorable pairing.

Algorithm

An efficient algorithm was given in (Irving 1985). The algorithm will determine, for any instance of the problem, whether a stable matching exists, and if so, will find such a matching.

Irving's algorithm has O(n2) complexity, provided suitable data structures are used to facilitate manipulation of the preference lists and identification of rotations.

The algorithm consists of two phases. In Phase 1, participants propose to each other, in a manner similar to that of the Gale Shapley algorithm for the stable marriage problem. Participants propose to each person on their preference list, in order, continuing to the next person if and when their current proposal is rejected. A participant rejects a proposal if he already holds, or subsequently receives, a proposal from someone he prefers. In this first phase, one participant might be rejected by all of the others, an indicator that no stable matching is possible. Otherwise, Phase 1 ends with each person holding a proposal from one of the others.

If q holds a proposal from p, then we remove from q's list all the x after p, and symmetrically, for each of those x, we remove q from x's list, so that q is first in p's list; and p, last in q's, since q and x cannot be partners in any stable matching. The resulting reduced set of preference lists together is called the Phase 1 table. In this table, if any reduced list is empty, then there is no stable matching. Otherwise, the Phase 1 table is a stable table. A stable table, by definition, is the set of preference lists together (the original table) with some entries removed, satisfying the following three conditions (where reduced list means a list in the stable table):

(i) p is first on q's reduced list if and only if q is last on p's
(ii) p is not on q's reduced list if and only if q is not on p's if and only if q prefers the last person on his list to p; or p, the last person on his list to q
(iii) no reduced list is empty

Stable tables have several important properties, which are used to justify the remainder of the procedure:

1. Any stable table must be a subtable of the Phase 1 table, where subtable is defined in the obvious sense, i.e. that the preference lists of the subtable are those of the supertable with some individuals removed from each other's lists.

2. In any stable table, if every reduced list contains exactly one individual, then pairing each individual with the single person on his list gives a stable matching.

3. If the stable roommates problem instance has a stable matching, then there is a stable matching contained in any one of the stable tables.

4. Any stable subtable of a stable table, and in particular any stable subtable that specifies a stable matching as in 2, can be obtained by a sequence of rotation eliminations on the stable table.

These rotation eliminations comprise Phase 2 of Irving's algorithm.

By 2, if each reduced list of the Phase 1 table contains exactly one individual, then this gives a matching.

Otherwise, the algorithm enters Phase 2. A rotation in a stable table T is defined as a sequence (x0, y0), (x1, y1), ..., (xk-1, yk-1) such that the xi are distinct, yi is first on xi's reduced list (or xi is last on yi's reduced list) and yi+1 is second on xi's reduced list, for i = 0, ..., k-1 where the indices are taken modulo k. It follows that in any stable table with a reduced list containing at least two individuals, such a rotation always exists. To find it, start at such a p0 containing at least two individuals in his reduced list, and define recursively qi+1 to be the second on pi's list and pi+1 to be the last on qi+1's list, until this sequence repeats some pj, at which point a rotation is found: it is the sequence of pairs starting at the first occurrence of (pj, qj and ending at the pair before the last occurrence. The sequence of pi up until the pj is called the tail of the rotation. The fact that it's a stable table in which this search occurs guarantees that each pi has at least two individuals on his list.

To eliminate the rotation, yi rejects xi so that xi proposes to yi+1, for each i. To restore the stable table properties (i) and (ii), for each i, all successors of xi-1 are removed from yi's list, and yi is removed from their lists. If a reduced list becomes empty during these removals, then there is no stable matching. Otherwise, the new table is again a stable table, and either already specifies a matching since each list contains exactly one individual or there remains another rotation to find and eliminate, so the step is repeated.

Phase 2 of the algorithm can now be summarized as follows:

	T = Phase 1 table;
	while (true) {
	    identify a rotation r in T;
	    eliminate r from T;
	    if some list in T becomes empty,
		return null; (no stable matching can exist)
	    else if (each reduced list in T has size 1)
		return the matching M = {{x, y} | x and y are on each other's lists in T}; (this is a stable matching)
	}

To achieve an O(n2) running time, a ranking matrix whose entry at row i and column j is the position of the jth individual in the ith's list; this takes O(n2) time. With the ranking matrix, checking whether an individual prefers one to another can be done in constant time by comparing their ranks in the matrix. Furthermore, instead of explicitly removing elements from the preference lists, the indices of the first, second and last on each individual's reduced list are maintained. The first individual that is unmatched , i.e. has at least two in his reduced lists, is also maintained. Then, in Phase 2, the sequence of pi "traversed" to find a rotation is stored in a list, and an array is used to mark individuals as having been visited, as in a standard depth-first search graph traversal. After the elimination of a rotation, we continue to store only its tail, if any, in the list and as visited in the array, and start the search for the next rotation at the last individual on the tail, and otherwise at the next unmatched individual if there is no tail. This reduces repeated traversal of the tail, since it is largely unaffected by the elimination of the rotation.


Example

The following are the preference lists for a Stable Roommates instance involving 6 participants 1, 2, 3, 4, 5, 6.

1 :   3   4   2   6   5
2 :   6   5   4   1   3
3 :   2   4   5   1   6
4 :   5   2   3   6   1
5 :   3   1   2   4   6
6 :   5   1   3   4   2

A possible execution of Phase 1 consists of the following sequence of proposals and rejections, where → represents proposes to and × represents rejects.

1 → 3
2 → 6
3 → 2
4 → 5
5 → 3;   3 × 1
1 → 4
6 → 5;   5 × 6
6 → 1

So Phase 1 ends with the following reduced preference lists:


1 :   3   4   2   6   5
2 :   6   5   4   1   3
3 :   2   4   5   1   6
4 :   5   2   3   6   1
5 :   3   1   2   4   6
6 :   5   1   3   4   2


In Phase 2, the rotation r1 = (1,4), (3,2) is first identified. This is because 2 is 1's second favorite, and 4 is the second favorite of 3. Eliminating r1 gives:

1 :   3   4   2   6   5
2 :   6   5   4   1   3
3 :   2   4   5   1   6
4 :   5   2   3   6   1
5 :   3   1   2   4   6
6 :   5   1   3   4   2

Next, the rotation r2 = (1,2), (2,6), (4,5) is identified, and its elimination yields:

1 :   3   4   2   6   5
2 :   6   5   4   1   3
3 :   2   4   5   1   6
4 :   5   2   3   6   1
5 :   3   1   2   4   6
6 :   5   1   3   4   2

Hence 1 and 6 are matched. Finally, the rotation r3 = (2,5), (3,4) is identified, and its elimination gives:

1 :   3   4   2   6   5
2 :   6   5   4   1   3
3 :   2   4   5   1   6
4 :   5   2   3   6   1
5 :   3   1   2   4   6
6 :   5   1   3   4   2

Hence the matching {{1, 6}, {2,4}, {3, 5}} is stable.

Applications

References

  • Irving, Robert W. (1985), "An efficient algorithm for the "stable roommates" problem", Journal of Algorithms, 6 (4): 577–595, doi:10.1016/0196-6774(85)90033-1
  • Irving, Robert W.; Manlove, David F. (2002), "The Stable Roommates Problem with Ties" (PDF), Journal of Algorithms, 43 (1): 85–105, doi:10.1006/jagm.2002.1219
  • Gusfield, Daniel M.; Irving, Robert W. (1989), "The Stable Marriage Problem: Structure and Algorithms", MIT Press

Further Reading

  • Fleiner, Tamás; Irving, Robert W.; Manlove, David F. (2007), "An efficient algorithm for the "stable roommates" problem", Theoretical Computer Science, 381 (1–3): 162–176, doi:10.1016/j.tcs.2007.04.029