Stable marriage problem

From Infogalactic: the planetary knowledge core
(Redirected from Gale–Shapley algorithm)
Jump to: navigation, search

In mathematics, economics, and computer science, the stable marriage problem (also stable matching problem or SMP) is the problem of finding a stable matching between two equally sized sets of elements given an ordering of preferences for each element. A matching is a mapping from the elements of one set to the elements of the other set. A matching is stable whenever it is not the case that both the following conditions hold.

  1. There is an element A of the first matched set which prefers some given element B of the second matched set over the element to which A is already matched, and
  2. B also prefers A over the element to which B is already matched.

In other words, a matching is stable when there does not exist any match (A, B) by which both A and B are individually better off than they would be with the element to which they are currently matched.

The stable marriage problem has been stated as follows:

Given n men and n women, where each person has ranked all members of the opposite sex in order of preference, marry the men and women together such that there are no two people of opposite sex who would both rather have each other than their current partners. When there are no such pairs of people, the set of marriages is deemed stable.

Note that the requirement that the marriages be heterosexual distinguishes this problem from the stable roommates problem.

Applications

Algorithms for finding solutions to the stable marriage problem have applications in a variety of real-world situations, perhaps the best known of these being in the assignment of graduating medical students to their first hospital appointments.[1] In 2012, the Nobel Prize in Economics was awarded to Lloyd S. Shapley and Alvin E. Roth "for the theory of stable allocations and the practice of market design."[2]

An important and large-scale application of stable marriage is in assigning users to servers in a large distributed Internet service.[3] Billions of users access web pages, videos, and other services on the Internet, requiring each user to be matched to one of (potentially) hundreds of thousands of servers around the world that offer that service. A user prefers servers that are proximal enough to provide a faster response time for the requested service, resulting in a (partial) preferential ordering of the servers for each user. Each server prefers to serve users that it can with a lower cost, resulting in a (partial) preferential ordering of users for each server. Content delivery networks that distribute much of the world's content and services solve this large and complex stable marriage problem between users and servers every tens of seconds to enable billions of users to be matched up with their respective servers that can provide the requested web pages, videos, or other services.[3]

Solution

File:Gale-Shapley.gif
Animation showing an example of the Gale–Shapley algorithm

In 1962, David Gale and Lloyd Shapley proved that, for any equal number of men and women, it is always possible to solve the SMP and make all marriages stable. They presented an algorithm to do so.[4][5]

The Gale–Shapley algorithm involves a number of "rounds" (or "iterations"). In the first round, first a) each unengaged man proposes to the woman he prefers most, and then b) each woman replies "maybe" to her suitor she most prefers and "no" to all other suitors. She is then provisionally "engaged" to the suitor she most prefers so far, and that suitor is likewise provisionally engaged to her. In each subsequent round, first a) each unengaged man proposes to the most-preferred woman to whom he has not yet proposed (regardless of whether the woman is already engaged), and then b) each woman replies "maybe" if she is currently not engaged or if she prefers this guy over her current provisional partner (in this case, she rejects her current provisional partner who becomes unengaged). The provisional nature of engagements preserves the right of an already-engaged woman to "trade up" (and, in the process, to "jilt" her until-then partner). This process is repeated until everyone is engaged.

The runtime complexity of this algorithm is O(n^2) where n is number of men or women.[6]

This algorithm guarantees that:

Everyone gets married 
At the end, there cannot be a man and a woman both unengaged, as he must have proposed to her at some point (since a man will eventually propose to everyone, if necessary) and, being proposed to, she would necessarily be engaged (to someone) thereafter.
The marriages are stable 
Let Alice be a woman and Bob be a man who are both engaged, but not to each other. Upon completion of the algorithm, it is not possible for both Alice and Bob to prefer each other over their current partners. If Bob prefers Alice to his current partner, he must have proposed to Alice before he proposed to his current partner. If Alice accepted his proposal, yet is not married to him at the end, she must have dumped him for someone she likes more, and therefore doesn't like Bob more than her current partner. If Alice rejected his proposal, she was already with someone she liked more than Bob.

Algorithm

function stableMatching {
    Initialize all m ∈ M and w ∈ W to free
    whilefree man m who still has a woman w to propose to {
       w = first woman on m’s list to whom m has not yet proposed
       if w is free
         (m, w) become engaged
       else some pair (m', w) already exists
         if w prefers m to m'
            m' becomes free
           (m, w) become engaged 
         else
           (m', w) remain engaged
    }
}

Optimality of the solution

While the solution is stable, it is not necessarily optimal from all individuals' points of view. The traditional form of the algorithm is optimal for the initiator of the proposals and the stable, suitor-optimal solution may or may not be optimal for the reviewer of the proposals. An example is as follows:

There are three suitors (A,B,C) and three reviewers (X,Y,Z) which have preferences of:

A: YXZ   B: ZYX   C: XZY   X: BAC   Y: CBA   Z: ACB

There are 3 stable solutions to this matching arrangement:

suitors get their first choice and reviewers their third (AY, BZ, CX)
all participants get their second choice (AX, BY, CZ)
reviewers get their first choice and suitors their third (AZ, BX, CY)

All three are stable because instability requires both participants to be happier with an alternative match. Giving one group their first choices ensures that the matches are stable because they would be unhappy with any other proposed match. Giving everyone their second choice ensures that any other match would be disliked by one of the parties. The algorithm converges in a single round on the suitor-optimal solution because each reviewer receives exactly one proposal, and therefore selects that proposal as its best choice, ensuring that each suitor has an accepted offer, ending the match. This asymmetry of optimality is driven by the fact that the suitors have the entire set to choose from, but reviewers choose between a limited subset of the suitors at any one time.

Stable Marriage with indifference

In the classical version of the problem, each person must rank the members of the opposite sex in strict order of preference. However, in a real-world setting, a person may prefer two or more persons as equally favorable partner. Such tied preference is termed as indifference. Below is such an instance where m_2 finds tie between w_3 \& w_1 and w_2 finds tie between m_1 \& m_2.

m_1[\  w_2\ w_1\ w_3 \ ] \ \ \ \ \ \ w_1[\ m_3\ m_2\ m_1 \ ]

m_2[\left( w_3\ w_1 \right) w_2] \ \ \ \ \ \ w_2[\left( m_1\ m_2\right) m_3 ]

m_3[\  w_1\ w_2\ w_3 \ ] \ \ \ \ \ \ w_3[\ m_2\ m_3\ m_1 \ ]

If tied preference lists are allowed then the stable marriage problem will have below three notions of stability which are discussed in the below sections.

A matching will be called weakly stable unless there is a couple each of whom strictly prefers the other to his/her partner in the matching. Robert W. Irving[7] has extended Gale–Shapley algorithm as below to provide such weakly stable matching in O(n^2) time where n is size of stable marriage problem . Ties in men and women's preference list are broken arbitrary. Preference lists are reduced as algorithm proceeds.

Assign each person to be free;
	while (some man m is free) do
	begin
		w := first woman on m’s list;
		m proposes, and becomes engaged, to w;
		if (some man m' is engaged to w) then
		    assign m' to be free;
		for each (successor m'' of m on w’s list) do
			delete the pair (m'', w)
	end;
	output the engaged pairs, which form a stable matching

A matching is super-stable if there is no couple each of whom either strictly prefers the other to his/her partner or is indifferent between them. Robert W. Irving[7] has modified the above algorithm to check whether such super stable matching exists and outputs matching in O(n^2) time if it exists. Below is the pseudo-code.

assign each person to be free;
repeat
	while (some man m is free) do
	  for each (woman w at the head of m’s list) do
	  begin
	  m proposes, and becomes engaged, to w;
		for each (strict successor m' of m on w’s list) do
		begin
			if (m' is engaged) to w then
			   break the engagement;
			delete the pair (m'. w)
		end
	  end
	for each (woman w who is multiply engaged) do
	begin
		break all engagements involving W;
		for each (man m at the tail of w’s list) do
		  delete the pair (m. w)
    end;
until (some man’s list is empty) or (everyone is engaged);
if everyone is engaged then
	the engagement relation is a super-stable matching
else
	no super-stable matching exists

A matching is strongly stable if there is no couple x, y such that x strictly prefers y to his/her partner and y either strictly prefers x to his/her partner or is indifferent between them. Robert W. Irving[7] has provided the algorithm which checks if such strongly stable matching exists and outputs the matching if exists. The algorithm computes perfect matching between set of men and women thus finding critical set of men who are engaged to multiple women. Since such engagements are never stable so all such pairs are deleted and proposal sequence will be repeated again until some man's preference list becomes empty in which no strongly stable matching exists or strongly stable matching is obtained. Below is the pseudo-code finding strongly stable matching.It runs in O(n^4) time which is explained in the Lemma 4.6 of .[7]

Assign each person to be free;
repeat
	while (some man m is free) do
	  for each (woman w at the head of m's list) do
	  begin
	  m proposes, and becomes engaged, to w;
		for each (strict successor m' of m on w’s list) do
		begin
			if (m' is engaged) to w then
			   break the engagement;
			delete the pair (m'. w)
		end
	  end
    if (the engagement relation does not contain a perfect matching) then	
    begin
	    find the critical set Z of men;
	    for each (woman w who is engaged to a man in Z) do
	    begin
	        break all engagements involving w;	
  	        for each man m at the tail of w’s list do
	            delete the pair (m, w)
	    end;
    end;
until (some man’s list is empty) or (everyone is engaged);
if everyone is engaged then
	the engagement relation is a super-stable matching
else
	no super-stable matching exists

Similar problems

The assignment problem seeks to find a matching in a weighted bipartite graph that has maximum weight. Maximum weighted matchings do not have to be stable, but in some applications a maximum weighted matching is better than a stable one.

The stable roommates problem is similar to the stable marriage problem, but differs in that all participants belong to a single pool (instead of being divided into equal numbers of "men" and "women").

The hospitals/residents problem — also known as the college admissions problem — differs from the stable marriage problem in that the "women" can accept "proposals" from more than one "man" (e.g., a hospital can take multiple residents, or a college can take an incoming class of more than one student). Algorithms to solve the hospitals/residents problem can be hospital-oriented (female-optimal) or resident-oriented (male-optimal).

The hospitals/residents problem with couples allows the set of residents to include couples who must be assigned together, either to the same hospital or to a specific pair of hospitals chosen by the couple (e.g., a married couple want to ensure that they will stay together and not be stuck in programs that are far away from each other). The addition of couples to the hospitals/residents problem renders the problem NP-complete.[8]

The matching with contracts problem is a generalization of matching problem, in which participants can be matched with different terms of contracts.[9] An important special case of contracts is matching with flexible wages.[10]

Implementation in software package

  • R: The Gale-Shapley algorithm (also referred to as Deferred-Acceptance algorithm) for the stable marriage and the hospitals/residents problem is available as part of the matchingMarkets package.[11][12]

See also

References

  1. Stable Matching Algorithms
  2. Lua error in package.lua at line 80: module 'strict' not found.
  3. 3.0 3.1 Lua error in package.lua at line 80: module 'strict' not found.
  4. Lua error in package.lua at line 80: module 'strict' not found.
  5. Harry Mairson: "The Stable Marriage Problem", The Brandeis Review 12, 1992 (online).
  6. Lua error in package.lua at line 80: module 'strict' not found.
  7. 7.0 7.1 7.2 7.3 Lua error in package.lua at line 80: module 'strict' not found.
  8. Lua error in package.lua at line 80: module 'strict' not found.
  9. Lua error in package.lua at line 80: module 'strict' not found.
  10. Lua error in package.lua at line 80: module 'strict' not found.
  11. Lua error in package.lua at line 80: module 'strict' not found.
  12. Lua error in package.lua at line 80: module 'strict' not found.

Textbooks and other important references not cited in the text

  • Dubins, L., and Freedman, D. (1981) "Machiavelli and the Gale–Shapley algorithm", American Mathematical Monthly 88(7), 485–494.
  • Kleinberg, J., and Tardos, E. (2005) Algorithm Design, Chapter 1, pp 1–12. See companion website for the Text [1].
  • Knuth, D. E. (1976). Mariages stables. Montreal: Les Presses de I'Universite de Montreal.
  • Roth, A. E. (1984). "The evolution of the labor market for medical interns and residents: A case study in game theory", Journal of Political Economy 92: 991–1016.
  • Roth, A. E., and Sotomayor, M. A. O. (1990) Two-sided matching: A study in game-theoretic modeling and analysis Cambridge University Press.
  • Lua error in package.lua at line 80: module 'strict' not found. See Section 10.6.4; downloadable free online.
  • Lua error in package.lua at line 80: module 'strict' not found..

External links