stable matching problem

{{Short description|Pairing where no unchosen pair prefers each other over their choice}}

In mathematics, economics, and computer science, the stable matching problem {{cite web |author=Tesler, G.|url=https://mathweb.ucsd.edu/~gptesler/154/slides/154_galeshapley_20-handout.pdf|website=mathweb.ucsd.edu|title=Ch. 5.9: Gale-Shapley Algorithm|date= 2020|publisher=University of California San Diego|access-date=26 April 2025|url-status=|archive-url=|archive-date=}}{{cite web|last1=Kleinberg|first1=Jon |last2=Tardos|first2=Éva |url=https://www.cs.princeton.edu/~wayne/kleinberg-tardos/pdf/01StableMatching.pdf|website=www.cs.princeton.edu|title=Algorithmn Design: 1. Stable Matching|date= 2005|publisher=Pearson-Addison Wesley: Princeton University|access-date=26 April 2025|url-status=|archive-url=|archive-date=}}{{cite web |last1=Goel|first1=Ashish |editor1-last=Ramseyer|editor1-first=Geo |url=https://web.stanford.edu/~ashishg/cs261/win21/notes/l5_note.pdf|website=web.stanford.edu|title=CS261 Winter 2018- 2019 Lecture 5: Gale-Shapley Algorith|date= 21 January 2019|publisher=Stanford University|access-date=26 April 2025|url-status=|archive-url=|archive-date=}} 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 bijection from the elements of one set to the elements of the other set. A matching is not stable if:

{{Ordered list|list-style-type=numeric

|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

|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 pair (A, B) which both prefer each other to their current partner under the matching.

The stable marriage problem has been stated as follows:

{{quote|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.}}

The existence of two classes that need to be paired with each other (heterosexual men and women in this example) 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.[http://www.dcs.gla.ac.uk/research/algorithms/stable/ Stable Matching Algorithms] In 2012, the Nobel Memorial Prize in Economic Sciences was awarded to Lloyd S. Shapley and Alvin E. Roth "for the theory of stable allocations and the practice of market design."{{cite web|url=https://www.nobelprize.org/nobel_prizes/economics/laureates/2012/ |title=The Prize in Economic Sciences 2012 |publisher=Nobelprize.org |access-date=2013-09-09}}

An important and large-scale application of stable marriage is in assigning users to servers in a large distributed Internet service.{{cite journal | author= Bruce Maggs and Ramesh Sitaraman | title = Algorithmic nuggets in content delivery | journal= ACM SIGCOMM Computer Communication Review |year=2015|volume=45|issue=3|url = http://www.sigcomm.org/sites/default/files/ccr/papers/2015/July/0000000-0000009.pdf}} 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.

The Gale–Shapley algorithm for stable matching is used to assign rabbis who graduate from Hebrew Union College to Jewish congregations.{{Cite journal |last1=Bodin |first1=Lawrence |last2=Panken |first2=Aaron |date=June 2003 |title=High Tech for a Higher Authority: The Placement of Graduating Rabbis from Hebrew Union College—Jewish Institute of Religion |url=https://pubsonline.informs.org/doi/10.1287/inte.33.3.1.16013 |journal=Interfaces |language=en |volume=33 |issue=3 |pages=1–11 |doi=10.1287/inte.33.3.1.16013 |issn=0092-2102}}

Different stable matchings

{{Main|Lattice of stable matchings}}

In general, there may be many different stable matchings. For example, suppose there are three men (A, B, C) and three women (X, Y, Z) which have preferences of:

: A: YXZ   B: ZYX   C: XZY  

: X: BAC   Y: CBA   Z: ACB

There are three stable solutions to this matching arrangement:

  • men get their first choice and women their third – (AY, BZ, CX);
  • all participants get their second choice – (AX, BY, CZ);
  • women get their first choice and men their third – (AZ, BX, CY).

All three are stable, because instability requires both of the 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. In general, the family of solutions to any instance of the stable marriage problem can be given the structure of a finite distributive lattice,

and this structure leads to efficient algorithms for several problems on stable marriages.{{cite journal

| last = Gusfield | first = Dan | author-link = Dan Gusfield

| doi = 10.1137/0216010

| issue = 1

| journal = SIAM Journal on Computing

| mr = 873255

| pages = 111–128

| title = Three fast algorithms for four problems in stable marriage

| volume = 16

| year = 1987}}

In a uniformly-random instance of the stable marriage problem with {{mvar|n}} men and {{mvar|n}} women, the average number of stable matchings is asymptotically e^{-1}n\ln n.{{cite journal

| last = Pittel | first = Boris

| doi = 10.1137/0402048

| issue = 4

| journal = SIAM Journal on Discrete Mathematics

| mr = 1018538

| pages = 530–549

| title = The average number of stable matchings

| volume = 2

| year = 1989}}

In a stable marriage instance chosen to maximize the number of different stable matchings, this number is an exponential function of {{mvar|n}}.{{cite conference

| last1 = Karlin | first1 = Anna R. | author1-link = Anna Karlin

| last2 = Gharan | first2 = Shayan Oveis

| last3 = Weber | first3 = Robbie

| editor1-last = Diakonikolas | editor1-first = Ilias

| editor2-last = Kempe | editor2-first = David

| editor3-last = Henzinger | editor3-first = Monika | editor3-link = Monika Henzinger

| contribution = A simply exponential upper bound on the maximum number of stable matchings

| doi = 10.1145/3188745.3188848

| mr = 3826305

| pages = 920–925

| publisher = Association for Computing Machinery

| title = Proceedings of the 50th Symposium on Theory of Computing (STOC 2018)

| year = 2018| arxiv = 1711.01032

| isbn = 978-1-4503-5559-9 }}

Counting the number of stable matchings in a given instance is #P-complete.{{cite journal

| last1 = Irving | first1 = Robert W.

| last2 = Leather | first2 = Paul

| doi = 10.1137/0215048

| issue = 3

| journal = SIAM Journal on Computing

| mr = 850415

| pages = 655–667

| title = The complexity of counting stable marriages

| volume = 15

| year = 1986}}

Algorithmic solution

{{Main|Gale–Shapley algorithm}}

File:Gale-Shapley.gif

In 1962, David Gale and Lloyd Shapley proved that, for any equal number in different groups, in the context of college admissions and individuals wanting marriage it is always possible to solve as matched couples to make all resultant pairings / matched factors stable. They presented an algorithm to do so.{{cite journal |first1=D. |last1=Gale |first2=L. S. |last2=Shapley |title=College Admissions and the Stability of Marriage |journal=American Mathematical Monthly |volume=69 |issue= 1|pages=9–14 |year=1962 |jstor=2312726 |doi=10.2307/2312726|url=http://www.dtic.mil/get-tr-doc/pdf?AD=AD0251958 |archive-url=https://web.archive.org/web/20170925172517/http://www.dtic.mil/get-tr-doc/pdf?AD=AD0251958 |url-status=dead |archive-date=September 25, 2017 }}Harry Mairson: "The Stable Marriage Problem", The Brandeis Review 12, 1992 ([http://www1.cs.columbia.edu/~evs/intro/stable/writeup.html online]).

The Gale–Shapley algorithm (also known as the deferred acceptance 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 man 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.

This algorithm is guaranteed to produce a stable marriage for all participants in time O(n^2) where n is the number of men or women.{{cite conference|last1=Iwama|first1=Kazuo|author1-link=Kazuo Iwama (computer scientist)|last2=Miyazaki|first2=Shuichi|contribution=A Survey of the Stable Marriage Problem and Its Variants|year=2008|pages=131–136|doi=10.1109/ICKS.2008.7|title=International Conference on Informatics Education and Research for Knowledge-Circulating Society (ICKS 2008)|publisher=IEEE|isbn=978-0-7695-3128-1|hdl=2433/226940|hdl-access=free}}

Among all possible different stable matchings, it always yields the one that is best for all men among all stable matchings, and worst for all women.{{cite book

| last = Erickson | first = Jeff

| contribution = 4.5 Stable matching

| contribution-url = https://jeffe.cs.illinois.edu/teaching/algorithms/book/04-greedy.pdf

| access-date = 2023-12-19

| date = June 2019

| pages = 170–176

| publisher = University of Illinois

| title = Algorithms}}

It is a truthful mechanism from the point of view of men (the proposing side), i.e., no man can get a better matching for himself by misrepresenting his preferences. Moreover, the GS algorithm is even group-strategy proof for men, i.e., no coalition of men can coordinate a misrepresentation of their preferences such that all men in the coalition are strictly better-off.{{cite journal

| last1 = Dubins | first1 = L. E. | author1-link = Lester Dubins

| last2 = Freedman | first2 = D. A. | author2-link = David A. Freedman

| doi = 10.2307/2321753

| issue = 7

| journal = American Mathematical Monthly

| mr = 628016

| pages = 485–494

| title = Machiavelli and the Gale–Shapley algorithm

| volume = 88

| year = 1981| jstor = 2321753 }} However, it is possible for some coalition to misrepresent their preferences such that some men are better-off and the other men retain the same partner.{{cite conference

| last = Huang | first = Chien-Chung

| editor1-last = Azar | editor1-first = Yossi

| editor2-last = Erlebach | editor2-first = Thomas

| contribution = Cheating by men in the Gale–Shapley stable matching algorithm

| doi = 10.1007/11841036_39

| mr = 2347162

| pages = 418–431

| publisher = Springer

| series = Lecture Notes in Computer Science

| title = Algorithms – ESA 2006, 14th Annual European Symposium, Zurich, Switzerland, September 11–13, 2006, Proceedings

| volume = 4168

| year = 2006| isbn = 978-3-540-38875-3

}}

The GS algorithm is non-truthful for the women (the reviewing side): each woman may be able to misrepresent her preferences and get a better match.

Rural hospitals theorem

{{Main|Rural hospitals theorem}}

The rural hospitals theorem concerns a more general variant of the stable matching problem, like that applying in the problem of matching doctors to positions at hospitals, differing in the following ways from the basic {{mvar|n}}-to-{{mvar|n}} form of the stable marriage problem:

  • Each participant may only be willing to be matched to a subset of the participants on the other side of the matching.
  • The participants on one side of the matching (the hospitals) may have a numerical capacity, specifying the number of doctors they are willing to hire.
  • The total number of participants on one side might not equal the total capacity to which they are to be matched on the other side.
  • The resulting matching might not match all of the participants.

In this case, the condition of stability is that no unmatched pair prefer each other to their situation in the matching (whether that situation is another partner or being unmatched). With this condition, a stable matching will still exist, and can still be found by the Gale–Shapley algorithm.

For this kind of stable matching problem, the rural hospitals theorem states that:

  • The set of assigned doctors, and the number of filled positions in each hospital, are the same in all stable matchings.
  • Any hospital that has some empty positions in some stable matching, receives exactly the same set of doctors in all stable matchings.

Related problems

In stable matching with indifference, some men might be indifferent between two or more women and vice versa.

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 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 (as the NRMP was before 1995){{cite journal|last=Robinson|first=Sara|date=April 2003|title=Are Medical Students Meeting Their (Best Possible) Match?|url=http://www.siam.org/pdf/news/305.pdf|journal=SIAM News|issue=3|page=36|access-date=2 January 2018}} or resident-oriented. This problem was solved, with an algorithm, in the same original paper by Gale and Shapley, in which the stable marriage problem was solved.

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.{{cite book|title=The Stable Marriage Problem: Structure and Algorithms|last1=Gusfield|first1=D.|last2=Irving|first2=R. W.|publisher=MIT Press|year=1989|isbn=0-262-07118-5|page=54}}

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 matching with contracts problem is a generalization of matching problem, in which participants can be matched with different terms of contracts.{{cite journal |first1=John William |last1=Hatfield |first2=Paul |last2=Milgrom |title=Matching with Contracts |journal=American Economic Review |volume=95 |issue=4 |year=2005 |pages=913–935 |jstor=4132699 |doi=10.1257/0002828054825466}} An important special case of contracts is matching with flexible wages.{{cite journal |first1=Vincent |last1=Crawford |first2=Elsie Marie |last2=Knoer |title=Job Matching with Heterogeneous Firms and Workers |year=1981 |journal=Econometrica |volume=49 |issue=2 |pages=437–450 |jstor=1913320 |doi=10.2307/1913320}}

See also

References

{{Reflist|40em}}

Further reading

  • Kleinberg, J., and Tardos, E. (2005) Algorithm Design, Chapter 1, pp 1–12. See companion website for the Text [http://www.aw-bc.com/info/kleinberg/] {{Webarchive|url=https://web.archive.org/web/20110514100625/http://www.aw-bc.com/info/kleinberg/ |date=2011-05-14 }}.
  • {{cite book |author-link=Donald Knuth |last=Knuth |first=D. E. |year=1996 |title=Stable Marriage and Its Relation to Other Combinatorial Problems: An Introduction to the Mathematical Analysis of Algorithms |others=English translation |series=CRM Proceedings and Lecture Notes |publisher=American Mathematical Society }}
  • {{cite journal |last=Pittel |first=B. |year=1992 |title=On likely solutions of a stable marriage problem |journal=The Annals of Applied Probability |volume=2 |issue=2 |pages=358–401 |doi=10.1214/aoap/1177005708 |jstor=2959755 |doi-access=free }}
  • {{cite journal |last=Roth |first=A. E. |year=1984 |title=The evolution of the labor market for medical interns and residents: A case study in game theory |journal=Journal of Political Economy |volume=92 |issue=6 |pages=991–1016 |doi=10.1086/261272 |s2cid=1360205 |url=http://dash.harvard.edu/bitstream/handle/1/29410143/evolut.pdf }}
  • {{cite book | last1=Roth |first1=A. E. |last2=Sotomayor |first2=M. A. O. |year=1990 |title=Two-sided matching: A study in game-theoretic modeling and analysis |publisher=Cambridge University Press |title-link= Two-Sided Matching}}
  • {{cite book | last1=Shoham | first1=Yoav | last2=Leyton-Brown | first2=Kevin | title=Multiagent Systems: Algorithmic, Game-Theoretic, and Logical Foundations | publisher=Cambridge University Press | isbn=978-0-521-89943-7 | url=http://www.masfoundations.org | year=2009 | location=New York}} See Section 10.6.4; [http://www.masfoundations.org/download.html downloadable free online].
  • {{cite book|author1=Schummer, J.|author2=Vohra, R. V.| isbn = 978-0521872829 |chapter=Mechanism design without money| title = Algorithmic Game Theory | editor1-last = Nisan | editor1-first= Noam |year=2007 | chapter-url = http://www.cambridge.org/journals/nisan/downloads/Nisan_Non-printable.pdf | editor2-last = Roughgarden | editor2-first= Tim | editor3-last = Tardos | editor3-first= Eva | editor4-last = Vazirani | editor4-first= Vijay | pages = 255–262}}
  • {{cite book | last1=Gusfield | first1=D. | last2=Irving | first2= R.W. | title=The Stable Marriage Problem: Structure and Algorithms. | publisher=MIT Press | year=1989 | url=https://archive.org/details/stablemarriagepr0000gusf/mode/2up | isbn=0-262-07118-5}}