Stable matching problem explained
In mathematics, economics, and computer science, the stable matching problem [1] [2] [3] 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:
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: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.[4] 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."[5]
One application of stable matching can be found in the client-server model, where content delivery networks send users as fast as possible to their servers in a version of the travelling salesman problem. Content delivery networks have to balance the traffic going into servers while also having to find servers close to the user to reduce loading time.[6]
The Gale–Shapley algorithm for stable matching is used to assign rabbis who graduate from Hebrew Union College to Jewish congregations.[7]
Different stable matchings
See main article: 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.[8]
In a uniformly-random instance of the stable marriage problem with men and women, the average number of stable matchings is asymptotically
.
[9] In a stable marriage instance chosen to maximize the number of different stable matchings, this number is an
exponential function of .
[10] Counting the number of stable matchings in a given instance is
- P-complete
.
[11] Algorithmic solution
See main article: Gale–Shapley algorithm. 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.[12] [13]
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.
where
is the number of men or women.
[14] 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.[15]
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.[16] 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.[17] 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
See main article: 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 -to- 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)[18] 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.[12]
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.[19]
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.[20] An important special case of contracts is matching with flexible wages.[21]
The popular matching problem seeks a matching
such that no other matching
exists with more people happier with
than with
. For non-bipartite inputs, it is
NP-complete to determine whether a popular matching exists.
[22] See also
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/ .
- Book: Knuth, D. E. . Donald Knuth . 1996 . Stable Marriage and Its Relation to Other Combinatorial Problems: An Introduction to the Mathematical Analysis of Algorithms . English translation . CRM Proceedings and Lecture Notes . American Mathematical Society .
- Pittel . B. . 1992 . On likely solutions of a stable marriage problem . . 2 . 2 . 358–401 . 10.1214/aoap/1177005708 . 2959755 . free .
- Roth . A. E. . 1984 . The evolution of the labor market for medical interns and residents: A case study in game theory . . 92 . 6 . 991–1016 . 10.1086/261272 . 1360205 .
- Book: Roth . A. E. . Sotomayor . M. A. O. . 1990 . Two-sided matching: A study in game-theoretic modeling and analysis . . Two-Sided Matching.
- Book: Shoham . Yoav . Leyton-Brown . Kevin . Multiagent Systems: Algorithmic, Game-Theoretic, and Logical Foundations . . 978-0-521-89943-7 . 2009 . New York. See Section 10.6.4; downloadable free online.
- Book: Schummer, J.. Vohra, R. V.. 978-0521872829 . Mechanism design without money. Algorithmic Game Theory . Nisan . Noam . 2007 . http://www.cambridge.org/journals/nisan/downloads/Nisan_Non-printable.pdf . Roughgarden . Tim . Tardos . Eva . Vazirani . Vijay . 255–262.
- Book: Gusfield . D. . Irving . R.W. . The Stable Marriage Problem: Structure and Algorithms. . . 1989 . 0-262-07118-5.
External links
Notes and References
- Web site: Tesler, G.. Ch. 5.9: Gale-Shapley Algorithm. mathweb.ucsd.edu. 2020. University of California San Diego. 26 April 2025.
- Web site: Kleinberg. Jon . Tardos. Éva . Algorithmn Design: 1. Stable Matching. www.cs.princeton.edu. 2005. Pearson-Addison Wesley: Princeton University. 26 April 2025.
- Web site: Goel. Ashish . Ramseyer. Geo . CS261 Winter 2018- 2019 Lecture 5: Gale-Shapley Algorithm. web.stanford.edu. 21 January 2019. Stanford University. 26 April 2025.
- http://www.dcs.gla.ac.uk/research/algorithms/stable/ Stable Matching Algorithms
- Web site: The Prize in Economic Sciences 2012 . Nobelprize.org . 2013-09-09.
- . Algorithmic nuggets in content delivery . ACM SIGCOMM Computer Communication Review . 2015. 45. 3.
- Bodin . Lawrence . Panken . Aaron . June 2003 . High Tech for a Higher Authority: The Placement of Graduating Rabbis from Hebrew Union College—Jewish Institute of Religion . Interfaces . en . 33 . 3 . 1–11 . 10.1287/inte.33.3.1.16013 . 0092-2102. subscription .
- Gusfield . Dan . Dan Gusfield . 10.1137/0216010 . 1 . . 873255 . 111–128 . Three fast algorithms for four problems in stable marriage . 16 . 1987.
- Pittel . Boris . 10.1137/0402048 . 4 . . 1018538 . 530–549 . The average number of stable matchings . 2 . 1989.
- Karlin . Anna R. . Anna Karlin . Gharan . Shayan Oveis . Weber . Robbie . Diakonikolas . Ilias . Kempe . David . Henzinger . Monika . Monika Henzinger . A simply exponential upper bound on the maximum number of stable matchings . 10.1145/3188745.3188848 . 3826305 . 920–925 . Association for Computing Machinery . Proceedings of the 50th Symposium on Theory of Computing (STOC 2018) . 2018. 1711.01032 . 978-1-4503-5559-9 .
- Irving . Robert W. . Leather . Paul . 10.1137/0215048 . 3 . . 850415 . 655–667 . The complexity of counting stable marriages . 15 . 1986.
- D. . Gale . L. S. . Shapley . College Admissions and the Stability of Marriage . . 69 . 1. 9–14 . 1962 . 2312726 . 10.2307/2312726. https://web.archive.org/web/20170925172517/http://www.dtic.mil/get-tr-doc/pdf?AD=AD0251958 . dead . September 25, 2017 . subscription .
- [Harry Mairson]
- Iwama. Kazuo. Kazuo Iwama (computer scientist). Miyazaki. Shuichi. A Survey of the Stable Marriage Problem and Its Variants. 2008. 131–136. 10.1109/ICKS.2008.7. International Conference on Informatics Education and Research for Knowledge-Circulating Society (ICKS 2008). IEEE. 978-0-7695-3128-1. 2433/226940. free.
- Book: Erickson, Jeff
. 4.5 Stable matching . https://jeffe.cs.illinois.edu/teaching/algorithms/book/04-greedy.pdf . 2023-12-19 . June 2019 . 170–176 . University of Illinois . Algorithms.
- Dubins . L. E. . Lester Dubins . Freedman . D. A. . David A. Freedman . 10.2307/2321753 . 7 . . 628016 . 485–494 . Machiavelli and the Gale–Shapley algorithm . 88 . 1981. 2321753 .
- Huang . Chien-Chung . Azar . Yossi . Erlebach . Thomas . Cheating by men in the Gale–Shapley stable matching algorithm . 10.1007/11841036_39 . 2347162 . 418–431 . Springer . Lecture Notes in Computer Science . Algorithms – ESA 2006, 14th Annual European Symposium, Zurich, Switzerland, September 11–13, 2006, Proceedings . 4168 . 2006. 978-3-540-38875-3 .
- Robinson. Sara. April 2003. Are Medical Students Meeting Their (Best Possible) Match?. SIAM News. 3. 36. 2 January 2018.
- Book: The Stable Marriage Problem: Structure and Algorithms. Gusfield. D.. Irving. R. W.. MIT Press. 1989. 0-262-07118-5. 54.
- John William . Hatfield . Paul . Milgrom . Matching with Contracts . . 95 . 4 . 2005 . 913–935 . 4132699 . 10.1257/0002828054825466.
- Vincent . Crawford . Elsie Marie . Knoer . Job Matching with Heterogeneous Firms and Workers . 1981 . . 49 . 2 . 437–450 . 1913320 . 10.2307/1913320.
- Gupta . Sushmita . Misra . Pranabendu . Saurabh . Saket . Zehavi . Meirav . March 2021 . 10.1145/3442354 . 2 . ACM Transactions on Computation Theory . Popular matching in roommates setting is NP-hard . 13. 1803.09370 .