Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Matching Games

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:

The participants are:

For example:

“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.

Table 1:Preference table for the authors

Author1st2nd3rd4th5th
A1R3R1R4R5R2
A2R2R4R3R5R1
A3R5R2R3R1R4
A4R2R3R5R1R4
A5R5R3R4R2R1

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.

Table 2:Preference table for the reviewers

Reviewer1st2nd3rd4th5th
R1A3A1A5A4A2
R2A4A2A5A1A3
R3A1A5A2A3A4
R4A2A5A3A1A4
R5A5A3A4A1A2

Theory

Definition: Matching Game

A matching game of size NN is defined by two disjoint sets SS and RR of proposers and reviewers of size NN. Associated to each element of SS and RR is a preference map:

f:SRN and g:RSNf:S\to R^N\text{ and }g:R\to S^N

A matching MM is any bijection between SS and RR. If sSs\in S and rRr\in R are matched by MM we denote:

M(s)=rM(s)=r

Example: Author Reviewer as a Matching Game

For Motivating Example: Stable peer review assignment at a research conference the matching game has size N=5N=5, the set of proposers S=(A1,A2,A3,A4,A5)S=(A1, A2, A3, A4, A5) the set of reviewers R=(R1,R2,R3,R4,R5)R=(R1, R2, R3, R4, R5) and the preference maps:

f(A1)=(R3,R1,R4,R5,R2)f(A2)=(R2,R4,R3,R5,R1)f(A3)=(R5,R2,R3,R1,R4)f(A4)=(R2,R3,R5,R1,R4)f(A5)=(R5,R3,R4,R2,R1)g(R1)=(A3,A1,A5,A4,A2)g(R2)=(A4,A2,A5,A1,A3)g(R3)=(A1,A5,A2,A3,A4)g(R4)=(A2,A5,A3,A1,A4)g(R5)=(A5,A3,A4,A1,A2)\begin{align*} f(A1)&=(R3, R1, R4, R5, R2)\\ f(A2)&=(R2, R4, R3, R5, R1)\\ f(A3)&=(R5, R2, R3, R1, R4)\\ f(A4)&=(R2, R3, R5, R1, R4)\\ f(A5)&=(R5, R3, R4, R2, R1)\\ g(R1)&=(A3, A1, A5, A4, A2)\\ g(R2)&=(A4, A2, A5, A1, A3)\\ g(R3)&=(A1, A5, A2, A3, A4)\\ g(R4)&=(A2, A5, A3, A1, A4)\\ g(R5)&=(A5, A3, A4, A1, A2) \end{align*}

One potential mapping is given by:

M(A1)=R3M(A2)=R2M(A3)=R5M(A4)=R1M(A5)=R4\begin{align*} M(A1) &= R3\\ M(A2) &= R2\\ M(A3) &= R5\\ M(A4) &= R1\\ M(A5) &= R4 \end{align*}

Definition: a blocking pair

A pair (s,r)(s,r) is said to block a matching MM if M(s)rM(s)\ne r but ss prefers rr to M(s)M(s) and rr prefers ss to M1(r)M^{-1}(r).

Example: Blocking pair for the author reviewer game

In (4) the pair (A4,R2)(A4, R2) is a blocking pair as A4A4 prefer R2R2 to M(A4)M(A4) and R2R2 prefers A4A4 to M1(R2)M^{-1}(R2).

Definition: a stable matching

A matching MM with no blocking pair is said to be stable.

Example: A stable matching for the author reviewer game

The following is a stable matching for Motivating Example: Stable peer review assignment at a research conference:

M(A1)=R3M(A2)=R4M(A3)=R1M(A4)=R2M(A5)=R5\begin{align*} M(A1) &= R3\\ M(A2) &= R4\\ M(A3) &= R1\\ M(A4) &= R2\\ M(A5) &= R5 \end{align*}

Definition: The Gale-Shapley algorithm

Here is the Gale-Shapley algorithm, which gives a stable matching for a matching game:

  1. Assign every sSs\in S and rRr\in R to be unmatched

  2. Pick some unmatched sSs\in S, let rr be the top of ss’s preference list:

    • If rr is unmatched set M(s)=rM(s)=r

    • If rr is matched:

      • If rr prefers ss to M1(r)M^{-1}(r) then set M(s)=rM(s)=r and unmatch the previous partner M1(r)M^{-1}(r)

      • Otherwise ss remains unmatched and remove rr from ss’s preference list.

  3. Repeat step 2 until all sSs\in 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.

Proof

Call a reviewer rr a stable partner of a suitor ss if M(s)=rM''(s) = r in some stable matching MM''. We show that no suitor is ever rejected by a stable partner during an execution α\alpha. Since suitors propose in decreasing order of preference, this implies that each suitor ends α\alpha matched to their most preferred stable partner, so the outcome does not depend on α\alpha.

Suppose, for contradiction, that during α\alpha some suitor is rejected by a stable partner, and consider the first such rejection: reviewer rr' rejects suitor ss, where rr' is a stable partner of ss, so M(s)=rM'(s) = r' for some stable matching MM'. The reviewer rr' rejects ss in favour of a suitor ss' whom rr' prefers to ss; that is, at that moment rr' holds a proposal from ss' and prefers ss' to ss.

Because this is the first rejection by a stable partner, ss' has not yet been rejected by any stable partner. As suitors propose in order of preference and ss' is currently proposing to rr', the reviewer rr' is at least as high in ss''s list as any reviewer ss' has proposed to so far, and in particular at least as high as every stable partner of ss'. Hence ss' weakly prefers rr' to M(s)M'(s'), and since preferences are strict and M(s)rM'(s') \ne r' (as M(r)=sM'(r') = s), ss' strictly prefers rr' to M(s)M'(s').

Then ss' prefers rr' to M(s)M'(s') and rr' prefers ss' to s=M(r)s = M'(r'), so (s,r)(s', r') blocks MM', contradicting the stability of MM'. No suitor is therefore rejected by a stable partner, each suitor is matched in MM with their favourite stable reviewer, and since α\alpha 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,A5A1, A2, A3, A4, A5 and R1,R2,R3,R4,R5R1, R2, R3, R4, R5 to be unmatched.

We pick A1A1 which has f(A1)=(R3,R1,R4,R5,R2)f(A1)=(R3, R1, R4, R5, R2), the top of the preference list is R3R3 so we set:

M(A1)=R3\begin{align*} M(A1) &= R3 \end{align*}

We now pick A2A2 which has f(A2)=(R2,R4,R3,R5,R1)f(A2)=(R2, R4, R3, R5, R1), the top of the preference list is R2R2 so we set:

M(A1)=R3M(A2)=R2\begin{align*} M(A1) &= R3\\ M(A2) &= R2\\ \end{align*}

We now pick A3A3 which has f(A3)=(R5,R2,R3,R1,R4)f(A3)=(R5, R2, R3, R1, R4), the top of the preference list is R5R5 so we set:

M(A1)=R3M(A2)=R2M(A3)=R5\begin{align*} M(A1) &= R3\\ M(A2) &= R2\\ M(A3) &= R5\\ \end{align*}

We now pick A4A4 which has f(A4)=(R2,R3,R5,R1,R4)f(A4)=(R2, R3, R5, R1, R4), the top of the preference list is R2R2 but R2R2 is matched (M(A2)=R2M(A2)=R2). We have g(R2)=(A4,A2,A5,A1,A3)g(R2)=(A4, A2, A5, A1, A3) so R2R2 prefers A4A4 to their current matching A2A2. So A2A2 becomes unmatched and we set:

M(A1)=R3M(A3)=R5M(A4)=R2\begin{align*} M(A1) &= R3\\ M(A3) &= R5\\ M(A4) &= R2\\ \end{align*}

We now pick A2A2 (for the second time) which has f(A2)=(R2,R4,R3,R5,R1)f(A2)=(R2, R4, R3, R5, R1), the top of the preference list is R2R2 but R2R2 is matched and prefers their current matching so we remove it from A2A2’s preference list:

f(A2)=(R4,R3,R5,R1)f(A2)=(R4, R3, R5, R1)

We could pick any unmatched author, we will pick A2A2 again (for the third time), A2A2 has preference list f(A2)=(R4,R3,R5,R1)f(A2)=(R4, R3, R5, R1), the top of the preference list is R4R4 so we set:

M(A1)=R3M(A2)=R4M(A3)=R5M(A4)=R2\begin{align*} M(A1) &= R3\\ M(A2) &= R4\\ M(A3) &= R5\\ M(A4) &= R2\\ \end{align*}

We now pick A5A5, the final unmatched author, which has f(A5)=(R5,R3,R4,R2,R1)f(A5)=(R5, R3, R4, R2, R1), the top of the preference list is R5R5 but R5R5 is matched (M(A3)=R5M(A3)=R5). We have g(R5)=(A5,A3,A4,A1,A2)g(R5)=(A5, A3, A4, A1, A2) so R5R5 prefers A5A5 to their current matching. So we set:

M(A1)=R3M(A2)=R4M(A4)=R2M(A5)=R5\begin{align*} M(A1) &= R3\\ M(A2) &= R4\\ M(A4) &= R2\\ M(A5) &= R5\\ \end{align*}

We now pick A3A3, the one remaining unmatched author, which has f(A3)=(R5,R2,R3,R1,R4)f(A3)=(R5, R2, R3, R1, R4), the top of the preference list is R5R5 but R5R5 is matched and prefers their current matching so we remove it from A3A3’s preference list:

f(A3)=(R2,R3,R1,R4)f(A3)=(R2, R3, R1, R4)

We now pick A3A3 again as it is still the only unmatched author. The top of the preference list is R2R2 but R2R2 is matched and prefers their current matching so we remove it from A3A3’s preference list:

f(A3)=(R3,R1,R4)f(A3)=(R3, R1, R4)

We pick A3A3 again. The top of the preference list is R3R3 but R3R3 is matched and prefers their current matching so we remove it from A3A3’s preference list:

f(A3)=(R1,R4)f(A3)=(R1, R4)

We pick A3A3 again and match it to R1R1 giving the final matching:

M(A1)=R3M(A2)=R4M(A3)=R1M(A4)=R2M(A5)=R5\begin{align*} M(A1) &= R3\\ M(A2) &= R4\\ M(A3) &= R1\\ M(A4) &= R2\\ M(A5) &= R5\\ \end{align*}

Theorem: Reviewer sub optimality of the Gale Shapley Algorithm

In a suitor-optimal stable matching each reviewer has the worst possible matching.

Proof

Assume that the result is not true. Let M0M_0 be a suitor-optimal matching and assume that there is a stable matching MM' such that \exists rr such that rr prefers s=M01(r)s=M_0^{-1}(r) to s=M1(r)s'=M'^{-1}(r). Since preferences are strict and M(s)rM'(s) \ne r, the suitor ss either prefers M(s)M'(s) to M0(s)=rM_0(s) = r or prefers M0(s)=rM_0(s) = r to M(s)M'(s). The former is impossible, as suitor-optimality means ss has no stable match they prefer to M0(s)M_0(s). Hence ss prefers rr to M(s)M'(s), and as rr prefers ss to M(r)=sM'(r) = s', the pair (r,s)(r,s) blocks MM', contradicting its stability. Every reviewer therefore does at least as badly in M0M_0 as in any stable matching, so M0M_0 is reviewer-pessimal.

Exercises

Programming

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.

import matching
import matching.games

authors = [
    matching.Player("A1"),
    matching.Player("A2"),
    matching.Player("A3"),
    matching.Player("A4"),
    matching.Player("A5"),
]

reviewers = [
    matching.Player("R1"),
    matching.Player("R2"),
    matching.Player("R3"),
    matching.Player("R4"),
    matching.Player("R5"),
]

A1, A2, A3, A4, A5 = authors
R1, R2, R3, R4, R5 = reviewers

A1.set_prefs((R3, R1, R4, R5, R2))
A2.set_prefs((R2, R4, R3, R5, R1))
A3.set_prefs((R5, R2, R3, R1, R4))
A4.set_prefs((R2, R3, R5, R1, R4))
A5.set_prefs((R5, R3, R4, R2, R1))

R1.set_prefs((A3, A1, A5, A4, A2))
R2.set_prefs((A4, A2, A5, A1, A3))
R3.set_prefs((A1, A5, A2, A3, A4))
R4.set_prefs((A2, A5, A3, A1, A4))
R5.set_prefs((A5, A3, A4, A1, A2))

game = matching.games.StableMarriage(authors, reviewers)
print(f"Stable matching: {game.solve()}")
Stable matching: {A1: R3, A2: R4, A3: R1, A4: R2, A5: R5}

Notable Research

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.

Conclusion

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.

Table 3:Summary of key concepts in matching games

ConceptDescription
Matching GameA game where two disjoint sets have preferences over each other
Stable MatchingA matching with no blocking pairs
Blocking PairA pair who would both prefer to be matched to each other over their current assignments
Gale-Shapley AlgorithmAn algorithm that produces a stable matching by iteratively proposing and accepting/rejecting proposals
Suitor-optimalityThe property that each suitor receives the best possible partner across all stable matchings
Reviewer-pessimalityThe property that in suitor-optimal matchings, each reviewer receives the worst acceptable partner

Solutions

References
  1. Wilde, H., Knight, V., & Gillard, J. (2020). Matching: A python library for solving matching games. Journal of Open Source Software, 5(48), 2169.
  2. Gale, D., & Shapley, L. S. (1962). College admissions and the stability of marriage. The American Mathematical Monthly, 69(1), 9–15.
  3. Knuth, D. E. (1976). Mariages stables et leurs relations avec d’autres problèmes combinatoires. Les Presses de l’Université de Montréal.
  4. Gusfield, D., & Irving, R. W. (1989). The stable marriage problem: structure and algorithms. MIT press.
  5. 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.
  6. Roth, A. E., Sönmez, T., & Ünver, M. U. (2004). Kidney Exchange. Quarterly Journal of Economics, 119(2), 457–488.