Optimal stable matching
In the theory of matching markets, an optimal stable matching is a matching that, among all stable matchings, satisfies some criterion of optimality. In the special case in which the matching market is bipartite (e.g. there are men and women, each man should be matched to woman and each woman should be matched to a man), the problem is called optimal stable marriage.[1]
This is a challenging optimization problem, as even in the bipartite case, the number of stable marriages might be exponential in the number of agents.[2][3]
Men-optimal and women-optimal stable marriage
In the bipartite case, the Gale–Shapley algorithm returns a matching that, among all stable matchings, is optimal for the proposing side. That is, if men propose, the outcome is the men-optimal stable marriage; if women propose, the outcome is the women-optimal stable marriage. The run-time of this algorithm is O(m), where m is the total length of the preference lists. In the case of complete preference lists m = n2, so the run-time is O(n2).
There is no conflict within each group: every stable marriage that is better for one man, is better for all men; every stable marriage that is better for one woman, is better for all women. However, there is a total conflict between the sides: the men-optimal stable marriage is the worst for all women, and vice-versa. Hence, researchers have considered optimality criteria that treat both groups in a more balanced way.[1]
Maximizing the total satisfaction
A natural optimization criterion, based on the utilitarian rule, is to maximize the sum of utilities of all agents, men and women alike. Such a matching can be called utilitarian stable matching.
Irving, Leather and Gusfield[4] first consider the special case of rank-utilities --- the utility of each agent is minus the rank of his/her matched partner (e.g. if a man is assigned the woman he likes the best, then his rank is 1, and so his satisfaction is minus 1; if he is assigned his second-best woman, then his satisfaction is minus 2; and so on). They call an algorithm that maximizes the sum of rank-utilities (equivalently, minimizes the sum of ranks) egalitarian, although a more natural name would be rank-utilitarian stable matching. They present an algorithm for computing a rank-utilitarian stable marriage for n men and n women with strict preferences. It runs in time O(m2) = O(n4). The algorithm uses intricate structural properties of the lattice of stable matchings.[4]: Sec.5
A variant of their algorithm computes a utilitarian stable marriage (with general utilities) in time O(m2 log K) = O(n4 log K), where K is the weight of the optimal marriage.[4]: Sec.6 The run-time of their algorithm is dominated by computing the maximum network flow in a network with at most m nodes and at most m edges. They used the Sleator-Tarjan algorithm, a variant of Dinic's algorithm, whose run-time is in O(|V| |E| log |V|) = O(m2 log n). A later algorithm by Orlin (2013) requires only O(|V| |E|) time, which leads to an O(m2) = O(n4) run-time.
Feder[5]: Sec.9 presents two faster algorithms for utilitarian stable matching. The main ingredients driving the speed-up are two new algorithms for maximum network flow on a network with m edges and integer capacities (recall that the classical algorithms run in time O(m n) on a network with m edges an n nodes):
- The first one runs in time , where K is the maximum flow size.
- The second one runs in time , where w is the cut-width of the network (the maximum number of edges in a finite-capacity cut). It is based on iteratively replacing each capacity c with floor(c/2), thus decreasing the maximum flow to at most K/2, until the maximum flow becomes 0. So there are log2K iterations, each of which runs in time O(w m).
The network flow algorithms are used to solve instances of weighted 2-satisfiability, and these in turn are used to compute utilitarian stable matchings. His algorithms for computing a utilitarian stable marriage run in time and respectively, where n is the number of agents, m the total length of all preference lists, and K the weight of the optimal matching. With complete lists m=n2, so the run-times are and respectively. For rank-utilitarian stable marriage (as well as any other case in which K ≤ m), the first algorithm has a better run-time: .
Maximizing the smallest satisfaction
Knuth[2][3] defined a matching as minimum regret if it minimizes the maximum rank that any person receives. Equivalently, it maximizes the minimum utility of an agent, where the utility is defined as minus the rank.[1] Maximizing the minimum utility is the egalitarian rule; hence, such a minimum-regret stable-matching can be called rank-egalitarian stable matching.
A stable marriage maximizing the minimum rank-utiltiy can be computed by reduction to utilitarian stable marriage, but this would require O(n4 log n) arithmetic operations.[4]: Sec.6 The algorithm described by Knuth[2] (which he attributes to Alan Selkow) runs in time O(n4).
Gusfield[6]: sec.5 developed a faster algorithm, that finds a minimum-regret (rank-egalitarian) stable marriage in time O(m) = O(n2). He also presented algorithms for closely related problems:
- Computing every man-woman pair that is contained in at least one stable matching, in time O(n2).
- Finding all "rotations" (transformations from one stable matching to another) in time O(n2).
- Enumerating all stable marriages, in time O(n2 + n|S|), where |S| is the number of stable matchings, and space O(n2).
Lexicographically optimizing the rank-profile
Two different optimization criteria are based on lexicographic optimization of the rank-profile of the matching. The rank-profile of a matching is a vector in which the k-th element counts the number of agents who are matched to their k-th best option.
The first criterion is an adaptation of the rank-maximal matching criterion to stable matchings. A rank-maximal stable matching is a matching that maximizes the number of people who get their best option (1st rank); subject to that, maximizes the number of people who get their second-best option (2nd rank); and so on.
- Irving, Leather and Gusfield[4] show that a rank-maximal stable marriage can be computed by reduction to utilitarian stable marriage: each agent i assigns to his/her k-th best choice, a utility of nn-k. Then, any matching maximizing the sum of utilities, also lexicographically maximizes the rank vector. The run-time is O(m2 log K), where K here is in O(nn), so log K is in O(n log n) and the actual runtime is in O(n m2 log n) = O(n5 log n).[4]: Sec.6 [7]
- Feder[5]: Sec.9 presents a faster algorithm for rank-maximal stable marriage, that does not require exponential weights, and runs in time O(n1/2 m3/2) = O(n3.5).
- Cooper and Manlove[8] present an algorithm for computing a rank-maximal stable marriage. Instead of using exponential weights, they use vector weights. Their algorithm runs in time O(n m2 log n) = O(n5 log n), but the use vector weights allows a substantial decrease in the required memory; in their experiments, the memory requirement is 10 to 100 times smaller.
A second criterion, that can be seen as a dual of the first, is generous stable matching. It minimizes the number of people who get their worst option (n-th rank); subject to that, minimizes the number of people who get their second-worst option; and so on. Note that this is a strictly stronger condition than rank-egalitarian ("minimum regret") stable matching. It could be called lexicographic rank-egalitarian stable matching. It is similar to lexicographic max-min optimization (leximin) of the utility vector, where the utilities are minus the ranks.
- A generous stable marriage can be computed by reduction to utilitarian stable marriage, using exponential weights.[8][clarification needed]
- Cooper and Manlove[8] present an algorithm for computing a generous stable marriage with vector weights instead of exponential weights. Their algorithm runs in time O(min(m,n d)2 d log(n)), where m is the total length of the preference lists and d is the maximum (worst) rank. As d is in O(n) and m is in O(n2), the worst-case run-time is in O(n5 log(n)), as for rank-maximal stable marriage.
Fleiner, Frank and Kirali[9] study stable marriage with strict preferences. They define a condition they call level fair. Each agent assigns to every agent of the other group an integer between 1 and 2*|Est|, where Est is the set of stable edges (edges that appear in some stable matching). Higher level is better. A matching is called level-fair if it minimizes the number of agents with level 1; subject to that, minimizes the number of agents with level 2; and so on. Level-fair stable matchings can be found by reduction to utiltiarian stable matchings with exponential weights, but the authors present a different approach that does not require exponential weights.
Median stable matching
A median stable matching is a stable matching in which each agent is matched to his/her median partner (median taken over all partners of the agent in stable matchings).[8]
Balancing men and women
Irving, Leather and Gusfield[1] define two criteria that explicitly aim to balance the utilities of the two sides of the market - men and women:
- A sex-equal stable matching minimizes the difference between the sum of rank-utilities of all men, and sum of rank-utilities of all women.
- A balanced weighted stable matching minimizes the maximum between the sum of utilities of all men, and the sum of utilities of all women.
Both these problems are NP-hard even in the bipartite case, even in the case of rank utilities.[10][11] But there is a 2-approximation algorithm with run-time O(n2), even for general utilities.
One-to-many and many-to-many optimal stable matching
Utilitarian stable matching
Eirinakis, Magos, Mourtos and Miliotis[12]: Sub.4.3 study optimal stable matchings in the many-to-many ("workers-firms") setting. They assume that each worker-firm pair has a cost, and aim to minimize the total cost of assignments, subject to stability (they define several notions of stability for the many-to-many setting).
Csaji and Sun[13] extend these by allowing each institute (e.g. firm) to define an arbitrary (not necessarily additive) utility function on sets of workers. Such functions can encode e.g. diversity constraints (maximize smallest number of residents per sector), complementarity constraints (maximize couples / siblings matched to the same institute), etc. They prove that, for each institute, the number of different "stable sets" (sets of residents that can be matched to it in a stable matching) is linear in n, and they can be enumerated efficiently. Moreover, each stable set has a unique worst resident. Hence, for any utility function on sets, one can compute in polytime an additive utility function on residents, that yields the same utility for sets. Then, any utilitarian stable matching algorithm can be applied to maximize the sum of utility functions over all institutes.[13]: Sub.5.2
To maximize the smallest utility of an institute, one can run utilitarian stable matching iteratively with an increasing threshold, and modified utility functions that equal 1 when the original utility is at least the threshold and 0 otherwise.[13]: Sub.5.3, Rem.1
The techniques can be extended to two-sided many-to-many matchings, where each agent on one side has arbitrary utilities on subsets of agents on the other side.[13]: Sub.5.5
Leximin stable matching
Narang, Biswas and Narahari[14] study many-to-one matchings, and aim to find a stable matching that is lexicographically max-min optimal for agents on both sides, among the set of stable matchings. Suppose there are n1 agents on the "one" side (e.g. colleges) and n2 agents on the "many" side (e.g. students). Their computational results are:
- For ranked and isometric valuations: with strict preferences - O(n1 n2); with weak preferences - strongly NP-hard when n2=3n1.
- For ranked valuations - with strict preferences - O(n12 n22); with weak preferences - APX-hard.
- For general valuations - with strict preferences - NP-hard; with weak preferences - APX-hard.
- For general isometric valuations with n1=2 (only two colleges): with strict preferences - O(n22); with weak preferences - NP-hard (by reduction from balanced partition: given an instance P, they construct an instance with two colleges with isometric valuations, such that P has a balanced partition iff the leximin-optimal solution allocates a high value to both colleges).
Some of their algorithms are implemented in the fairpyx Python library.[15]
Non-bipartite optimal matching
In the non-bipartite case (the stable roommates problem), the known results are as follows:
- A rank-egalitarian ("minimum regret") stable matching can be found in time O(n2).[16]
- Computing a rank-utilitarian stable matching is NP-hard. Its approximation ratio is the same as that of the minimum vertex cover problem.[10][17]
- Computing a utilitarian stable matching with general utilities is NP-hard, but there is a 2-approximation algorithm with run-time O(n2).[17]
- Computing a rank-maximal or a generous stable matching is NP-hard. Moreover, even finding a stable matching that maximizes the number of agents matched to their top choices, or minimizes the number of agents matched to their d-th choice (without the lexicographic extension), is NP-hard.[8]
References
- ↑ 1.0 1.1 1.2 1.3 Irving, Robert W. (2008) (in en), Optimal Stable Marriage, Springer, Boston, MA, pp. 606–609, doi:10.1007/978-0-387-30162-4_271, ISBN 978-0-387-30162-4, https://link.springer.com/rwe/10.1007/978-0-387-30162-4_271, retrieved 2026-05-12
- ↑ 2.0 2.1 2.2 Knuth, Donald E. (1976) (in French), Mariages stables et leurs relations avec d'autres problèmes combinatoires, Montréal, Quebec: Les Presses de l'Université de Montréal, ISBN 0-8405-0342-3, https://www-cs-faculty.stanford.edu/~knuth/mariages-stables.pdf.
- ↑ 3.0 3.1 Knuth, Donald Ervin (1997) (in en). Stable Marriage and Its Relation to Other Combinatorial Problems: An Introduction to the Mathematical Analysis of Algorithms. American Mathematical Soc.. ISBN 978-0-8218-0603-6. https://books.google.com/books?id=NSnaBwAAQBAJ&dq=Mariages+Stables+Knuth&pg=PR10.
- ↑ 4.0 4.1 4.2 4.3 4.4 4.5 Irving, Robert W.; Leather, Paul; Gusfield, Dan (1987-07-01). "An efficient algorithm for the "optimal" stable marriage". J. ACM 34 (3): 532–543. doi:10.1145/28869.28871. ISSN 0004-5411. https://doi.org/10.1145/28869.28871.
- ↑ 5.0 5.1 Feder, Tomás (1994-03-01). "Network flow and 2-satisfiability" (in en). Algorithmica 11 (3): 291–319. doi:10.1007/BF01240738. ISSN 1432-0541. https://doi.org/10.1007/BF01240738.
- ↑ Gusfield, Dan (1987). "Three Fast Algorithms for Four Problems in Stable Marriage" (in en). SIAM Journal on Computing 16: 111–128. doi:10.1137/0216010. https://epubs.siam.org/doi/10.1137/0216010.
- ↑ Irving, Leather and Gusfield (1987) state a run-time complexity O(n^5 log^2 n). However, Cooper and Manlove (2020) later explain that the actual run-time complexity is O(n^5 log n).
- ↑ 8.0 8.1 8.2 8.3 8.4 Cooper, Frances; Manlove, David (2020-09-11). "Two-sided profile-based optimality in the stable marriage problem". arXiv:1905.06626 [cs.DS].
- ↑ Fleiner, Tamás; Frank, András; Király, Tamás (2024-09-07). "A new approach to bipartite stable matching optimization". arXiv:2409.04885 [cs.GT].
- ↑ 10.0 10.1 Feder, Tomás (1995) (in en). Stable Networks and Product Graphs. American Mathematical Soc.. ISBN 978-0-8218-0347-9. https://books.google.com/books?id=KW3TCQAAQBAJ&dq=Stable+networks+and+product+graphs.&pg=PR5.
- ↑ Kato, Akiko (1993-02-01). "Complexity of the sex-equal stable marriage problem" (in en). Japan Journal of Industrial and Applied Mathematics 10 (1): 1–19. doi:10.1007/BF03167200. ISSN 1868-937X. https://doi.org/10.1007/BF03167200.
- ↑ Eirinakis, Pavlos; Magos, Dimitrios; Mourtos, Ioannis; Miliotis, Panayiotis (May 2012). "Finding All Stable Pairs and Solutions to the Many-to-Many Stable Matching Problem". INFORMS Journal on Computing 24 (2): 245–259. doi:10.1287/ijoc.1110.0449. ISSN 1091-9856. https://pubsonline.informs.org/doi/abs/10.1287/ijoc.1110.0449.
- ↑ 13.0 13.1 13.2 13.3 Csáji, Gergely; Sun, Zhaohong (2026-04-30). "Maximally Diverse Stable Matchings: Optimizing Arbitrary Institutional Objectives". arXiv:2604.27823 [cs.GT].
- ↑ Narang, Shivika; Biswas, Arpita; Narahari, Y. (2022-05-25), On Achieving Leximin Fairness and Stability in Many-to-One Matchings, arXiv, doi:10.48550/arXiv.2009.05823, arXiv:2009.05823, http://arxiv.org/abs/2009.05823, retrieved 2026-05-24
- ↑ ariel-research. "fairpyx/fairpyx/algorithms/Optimization_Matching at main · ariel-research/fairpyx" (in en). https://github.com/ariel-research/fairpyx/tree/main/fairpyx/algorithms/Optimization_Matching.
- ↑ Gusfield, D (1988). "The Structure of the Stable Roommate Problem: Efficient Representation and Enumeration of All Stable Assignments" (in en). SIAM Journal on Computing 17 (4): 742–769. doi:10.1137/0217048. https://epubs.siam.org/doi/10.1137/0217048.
- ↑ 17.0 17.1 Feder, Tomas (1992-10-01). "A new fixed point approach for stable networks and stable marriages" (in en-US). Journal of Computer and System Sciences 45 (2): 233–284. doi:10.1016/0022-0000(92)90048-N. ISSN 0022-0000. https://dx.doi.org/10.1016/0022-0000%2892%2990048-N.
