Many allocation problems require pairing agents from two groups such that no
pair would mutually prefer to be matched to each other instead. This chapter
develops the theory of stable matchings and the Gale–Shapley algorithm that
constructs them.
Motivating Example: Stable peer review assignment at a research conference¶
The Social Perspectives Research Symposium receives five paper submissions and
recruits five expert reviewers. Each paper must be assigned to exactly one reviewer.
To promote high-quality reviews, both authors and reviewers submit ranked preference
lists:
Each author ranks the reviewers based on perceived expertise, familiarity with
the topic, and potential for constructive feedback.
Each reviewer ranks the submissions based on interest, alignment with their
research, and methodological fit.
The participants are:
Authors: A1, A2, A3, A4, A5
Reviewers: R1, R2, R3, R4, R5
For example:
Author A1 has written a paper on representation in environmental activism and ranks
R3, an expert in environmental sociology, as their top choice.
Reviewer R2 specializes in healthcare policy and ranks submission A4 as their first
choice due to its relevance.
Author A5’s paper focuses on queer representation in contemporary fiction, and they
rank R5 highly based on prior work in literature studies.
“R3’s expertise would be invaluable for my analysis.” “A4’s topic fits directly with my current research.” “R5’s previous reviews have been extremely helpful.”
The preferences of the authors are given in Table 1 and the
preferences of the reviewers are given in Table 2.
The organizers aim to compute a stable matching: an assignment where no
author-reviewer pair exists who would both prefer to be assigned to each other over
their current assignments.
A matching game of size N is defined by two disjoint sets S and R of
proposers and reviewers of size N.
Associated to each element of S and R is a preference map:
Here is the Gale-Shapley algorithm, which gives a stable matching for a matching game:
Assign every s∈S and r∈R to be unmatched
Pick some unmatched s∈S, let r be the top of s’s preference list:
If r is unmatched set M(s)=r
If r is matched:
If r prefers s to M−1(r) then set M(s)=r and unmatch the
previous partner M−1(r)
Otherwise s remains unmatched and remove r from s’s preference list.
Repeat step 2 until all s∈S are matched.
Theorem: Unique matching as output of the Gale Shapley algorithm¶
All possible executions of the Gale-Shapley algorithm yield the same stable matching and
in this stable matching every suitor has the best possible partner in any stable matching.
Call a reviewer r a stable partner of a suitor s if M′′(s)=r in some
stable matching M′′. We show that no suitor is ever rejected by a stable
partner during an execution α. Since suitors propose in decreasing order
of preference, this implies that each suitor ends α matched to their most
preferred stable partner, so the outcome does not depend on α.
Suppose, for contradiction, that during α some suitor is rejected by a
stable partner, and consider the first such rejection: reviewer r′ rejects
suitor s, where r′ is a stable partner of s, so M′(s)=r′ for some
stable matching M′. The reviewer r′ rejects s in favour of a suitor s′
whom r′ prefers to s; that is, at that moment r′ holds a proposal from
s′ and prefers s′ to s.
Because this is the first rejection by a stable partner, s′ has not yet been
rejected by any stable partner. As suitors propose in order of preference and
s′ is currently proposing to r′, the reviewer r′ is at least as high in
s′'s list as any reviewer s′ has proposed to so far, and in particular at
least as high as every stable partner of s′. Hence s′ weakly prefers r′ to
M′(s′), and since preferences are strict and M′(s′)=r′ (as M′(r′)=s),
s′ strictly prefers r′ to M′(s′).
Then s′ prefers r′ to M′(s′) and r′ prefers s′ to s=M′(r′), so
(s′,r′) blocks M′, contradicting the stability of M′. No suitor is
therefore rejected by a stable partner, each suitor is matched in M with their
favourite stable reviewer, and since α was arbitrary all executions give
the same matching.
Example: Application of the Gale-Shapley algorithm to the author reviewer game¶
We start by assigning A1,A2,A3,A4,A5 and R1,R2,R3,R4,R5 to be
unmatched.
We pick A1 which has f(A1)=(R3,R1,R4,R5,R2), the top of the preference
list is R3 so we set:
We now pick A4 which has f(A4)=(R2,R3,R5,R1,R4), the top of the
preference list is R2 but R2 is matched (M(A2)=R2). We have g(R2)=(A4,A2,A5,A1,A3) so R2 prefers A4 to their current matching A2. So A2
becomes unmatched and we set:
We now pick A2 (for the second time) which has f(A2)=(R2,R4,R3,R5,R1),
the top of the preference list is R2 but R2 is matched and prefers their
current matching so we remove it from A2’s preference list:
We could pick any unmatched author, we will pick A2 again (for the third
time), A2 has preference list f(A2)=(R4,R3,R5,R1), the top of the
preference list is R4 so we set:
We now pick A5, the final unmatched author, which has f(A5)=(R5,R3,R4,R2,R1), the top of the preference list is R5 but R5 is matched (M(A3)=R5).
We have g(R5)=(A5,A3,A4,A1,A2) so R5 prefers A5 to their current
matching. So we set:
We now pick A3, the one remaining unmatched author, which has f(A3)=(R5,R2,R3,R1,R4), the top of the preference list is R5 but R5 is matched and
prefers their current matching so we remove it from A3’s preference list:
We now pick A3 again as it is still the only unmatched author. The top of the
preference list is R2 but R2 is matched and prefers their current matching
so we remove it from A3’s preference list:
Assume that the result is not true. Let M0 be a suitor-optimal matching
and assume that there is a stable matching M′ such that ∃r such that r prefers s=M0−1(r) to s′=M′−1(r).
Since preferences are strict and M′(s)=r, the suitor s either prefers
M′(s) to M0(s)=r or prefers M0(s)=r to M′(s). The former is
impossible, as suitor-optimality means s has no stable match they prefer to
M0(s). Hence s prefers r to M′(s), and as r prefers s to
M′(r)=s′, the pair (r,s) blocks M′, contradicting its stability.
Every reviewer therefore does at least as badly in M0 as in any stable
matching, so M0 is reviewer-pessimal.
The python Matching library Wilde et al., 2020 implements the Gale-Shapley algorithm as well as a
number of other algorithms for different generalisations of matching games.
The original Gale-Shapley algorithm was presented in Gale & Shapley, 1962, a
rigorous combinatorial treatment of the algorithm is given in Knuth, 1976. Some
refinements to the algorithm are given in Gusfield & Irving, 1989 which is
considered to be the reference text on matching games.
In the original paper Gale & Shapley, 1962 Gale and Shapley present the so called
hospital-resident matching problem which is a matching problem aiming to match
many to one. They do so in the context of College admissions in North America.
In Roth, 1984 presents the problem in the context of hospital resident
assignement. Further to this, Roth considered the problem of kidney exchange in
Roth et al., 2004 as a further matching problem.
In 2012, Lloyd Shapley and Alvin Roth were awarded the Nobel Prize in Economic
Sciences for their contributions to stable matching and market design.
David Gale, who co-authored the foundational 1962 paper introducing the
Gale-Shapley algorithm, was ineligible for the award, having passed away in 2008.
In this chapter we introduced the theory of matching games, motivated by the
practical problem of assigning reviewers to papers at a research conference.
The central concept of stability ensures that no pair of participants would
prefer to deviate from the assignment, making stable matchings attractive in
many real-world settings.
The Gale-Shapley algorithm provides an elegant and efficient solution to the
stable matching problem, always producing a suitor-optimal stable matching.
While stable matchings always exist in the one-to-one setting, extensions to
many-to-one settings (such as hospital-resident assignments) preserve many of
the desirable properties of the original algorithm.
A summary of key concepts introduced in this chapter is given in
Table 3.
Wilde, H., Knight, V., & Gillard, J. (2020). Matching: A python library for solving matching games. Journal of Open Source Software, 5(48), 2169.
Gale, D., & Shapley, L. S. (1962). College admissions and the stability of marriage. The American Mathematical Monthly, 69(1), 9–15.
Knuth, D. E. (1976). Mariages stables et leurs relations avec d’autres problèmes combinatoires. Les Presses de l’Université de Montréal.
Gusfield, D., & Irving, R. W. (1989). The stable marriage problem: structure and algorithms. MIT press.
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(6), 991–1016.
Roth, A. E., Sönmez, T., & Ünver, M. U. (2004). Kidney Exchange. Quarterly Journal of Economics, 119(2), 457–488.