Skip to main content
Springer logoLink to Springer
. 2020 Feb 6;82(5):1136–1188. doi: 10.1007/s00453-019-00636-y

Stable Matchings with Covering Constraints: A Complete Computational Trichotomy

Matthias Mnich 1,2,, Ildikó Schlotter 3
PMCID: PMC7066313  PMID: 32214574

Abstract

Stable matching problems with lower quotas are fundamental in academic hiring and ensuring operability of rural hospitals. Only few tractable (polynomial-time solvable) cases of stable matching with lower quotas have been identified; most such problems are NP-hard and also hard to approximate (Hamada et al. in Algorithmica 74(1):440–465, 2016). We therefore consider stable matching problems with lower quotas under a relaxed notion of tractability, namely fixed-parameter tractability. By cloning hospitals we focus on the case when all hospitals have upper quota equal to 1, which generalizes the setting of “arranged marriages” first considered by Knuth (Mariages stables et leurs relations avec d’autres problèmes combinatoires, Les Presses de l’Université de Montréal, Montreal, 1976). We investigate how a set of natural parameters, namely the maximum length of preference lists for men and women, the number of distinguished men and women, and the number of blocking pairs allowed determine the computational tractability of this problem. Our main result is a complete complexity trichotomy: for each choice of parameters we either provide a polynomial-time algorithm, or an NP-hardness proof and fixed-parameter algorithm, or NP-hardness proof and W[1]-hardness proof. As corollary, we negatively answer a question by Hamada et al. (Algorithmica 74(1):440–465, 2016) by showing fixed-parameter intractability parameterized by optimal solution size. We also classify all cases of one-sided constraints where only women may be distinguished.

Keywords: Stable marriage, Lower quotas, Fixed-parameter algorithms

Introduction

The Stable Marriage (SM) problem is a fundamental problem first studied by Gale and Shapley [19]. An instance of SM consists of a set M of men, a set W of women, and a preference list for each person ordering members of the opposite sex. We aim to find a stable matching, i.e., a matching for which there exists no pair of a man and a woman who prefer each other to their partners given by the matching; such a pair is called a blocking pair. Gale and Shapley proved [19] that any instance of SM admits at least one stable matching, and gave a polynomial-time algorithm, known as the Gale–Shapley algorithm, to find one. Gale and Shapley also considered the many-to-one extension of SM, known as the Hospitals/Residents (HR) problem. In HR, the two sets H and R that correspond to men and women in the SM problem are residents and hospitals, respectively. Each hospital HH has an upper quota on the number of residents in R that it can accept. For HR it still holds true that a stable matching always exists, and can be found efficiently.

An extension of HR that is motivated by several real-world applications is the Hospitals/Residents with Lower Quota (HRLQ) problem, where hospitals declare both lower and upper quotas which bound the number of residents they can accept; as before, residents rank hospitals and vice versa. Now it is no longer true that a stable assignment always exists. The possible non-existence of stable assignments motivates the design of algorithms that find an assignment with a minimum number of blocking pairs; this is the task of the HRLQ problem. Indeed, the HRLQ problem and its variants have recently gained quite some interest from the algorithmic community  [4, 8, 16, 22, 24, 26, 30, 40, 44, 45]. In his book, Manlove [36, Chapter 5.2] devotes an entire chapter to the algorithmics of different versions of the HRLQ problem.

The reason for this high interest in HRLQ is explained by its importance in several real-world matching markets [17, 18, 42] such as school admission systems, centralized assignment of residents to hospitals, or of cadets to military branches. Lower quotas are a common feature of such admission systems. Their purpose is often to remedy the effects of under-staffing that are explained by the well-known Rural Hospitals Theorem [20]: as an example, governments usually want to assign at least a small number of medical residents to each rural hospital to guarantee a minimum service level. Minimum quotas are also discussed in controlled school choice programs [13, 33, 43] where students are divided into a small number of types, and schools set lower bounds for each type. Such models can represent various forms of affirmative actions taken by schools to, e.g., admit a certain number of minority students [13]. Another example is the German university admission system for admitting students to highly oversubscribed subjects, where a certain percentage of study places is assigned according to high school grades or waiting time [43]. But lower quotas may also arise due to financial considerations: for instance, a business course with too few (tuition-paying) attendees may not be profitable. Certain aspects of airline preferences for seat upgrade allocations can be also modelled by lower quotas [33].

Much of the algorithmic research found that the HRLQ problem (in its different variants) is NP-hard, and thus considered intractable. A common approach then to identify tractable (polynomial-time solvable) cases of HRLQ; this avenue has lead to several beautiful algorithms [16, 26, 45]. However, restricting to polynomial-time solvability necessarily means (if PNP) that some original features of HRLQ must be restricted more or less, which may be undesirable in the application. Another approach aimed at addressing the intractability of HRLQ was the design of approximation algorithms. Unfortunately, it turns out that non-trivial approximation algorithms for HRLQ are highly unlikely to exist: Hamada et al. [24] showed that, unless P=NP, no algorithm with approximation guarantee (|H|+|R|)1-ε can exist for any ε>0 (which they complement by an algorithm with approximation guarantee (|H|+|R|)). In light of their strong inapproximability bounds, Hamada et al. explicitly suggested to consider a more relaxed notion of tractability for HRLQ, namely, fixed-parameter tractability. They particularly asked whether HRLQ is fixed-parameter tractable parameterized by the minimum number b of blocking pairs over all matchings meeting all lower and upper quota requirements.

In this paper we follow this avenue, and study the fixed-parameter tractability of HRLQ. It allows us to provide a fine-grained analysis of HRLQ, and the design of efficient algorithms for NP-hard variants of HRLQ for small parameter values. Our main focus will be the case of HRLQ when each hospital has unit upper quota. The reason is that by the frequently applied method of “cloning” hospitals, stable instances of HRLQ reduce to the case where each hospital has unit upper quota—and thus we can reduce stable instances of HRLQ to the SM setting with lower quotas. In fact, this is equivalent to the special case of SM where only a subset of women (or, equivalently, men) are distinguished by having also a unit lower quota. From now on, we refer to HRLQ with unit upper quotas as SMC (where C means that we have to cover the women/men who have a unit lower quota), to the special case of SMC with one-sided covering constraints, linking SMC and HRLQ, as SMC-1. So formally, in SMC a set W of women and a set M of men are distinguished, and a feasible matching is one where each person in WM gets matched. By the Rural Hospitals Theorem [20] we know that the set of unmatched men and women is the same in all stable matchings, so clearly, feasible stable matchings may not exist. Thus, we define the task in SMC as finding a feasible matching with a minimum number of blocking pairs.

Apart from the recent interest in HRLQ, its reduction SMC also serves as a “modern version” of a classical problem first introduced by Donald Knuth. Knuth [31] considered SM with “arranged marriages”, which are a set X of man-woman pairs that must be matched with each other. He showed that the Gale–Shapley algorithm can be extended to decide the existence of a stable matching still in time O(n2) for n-person instances, but in case of absence of a stable matching, minimizing the number of blocking pairs is NP-hard. Now in SMC, one does not prescribe any more which woman has to marry which man, but only requires certain women and men to marry without dictating their partner. There is a natural Turing reduction from SMC to the variant considered by Knuth. Coarse analysis into polynomial-time solvable and NP-hard cases has been studied by several researchers [1].

Another motivation for studying the SMC problem comes from the following scenario that we dub Control for Stable Marriage. Consider a two-sided market where each participant of the market expresses its preferences over members of the other party, and some central agent (e.g., a government) performs the task of finding a stable matching in the market. It might happen that this central agency wishes to apply a certain control on the stable matching produced: it may favour some participants by trying to assign them a partner in the resulting matching. Such a behaviour might be either malicious (e.g., the central agency may accept bribes and thus favour certain participants) or beneficial (e.g., it may favour those who are at disadvantage, like handicapped or minority participants). However, there might not be a stable matching that covers all participants the agency wants to favour; thus arises the need to produce a matching that is as stable as possible among those that fulfil our constraints—the most natural aim in such a case is to minimize the number of blocking pairs in the produced matching, which yields exactly the SMC problem. Similar control problems have been extensively studied in the area of social choice for voting systems [7, Chapter 7] and recently also for fair division scenarios [2], but have not yet been considered in connection to stable matchings.

Our Results

We provide an extensive algorithmic analysis of the SMC problem and its special case SMC-1. In our analysis, we examine how different aspects of the input influence the tractability of these problems. To this end, we apply the framework of parameterized complexity, which deals with computationally hard problems and focuses on how certain parameters of a problem instance influence its tractability; for background, we refer to the book by Cygan et al. [11]. We aim to design so-called fixed-parameter algorithms, which perform well in practice if the value of the parameter on hand is small (for the precise definitions, see Sect. 2).

The parameters we consider are

  • the number b of blocking pairs allowed,

  • the number |W| of women with covering constraint,

  • the number |M| of men with covering constraint,

  • the maximum length ΔW of women’s preference lists, and

  • the maximum length ΔM of men’s preference lists.

The choice of each of these parameters is motivated by the aforementioned applications. For instance, we seek matchings where ideally no blocking pairs at all or at least only few of them appear, to ensure stability of the matching and happiness of those getting matched. The number of women/men with covering constraints corresponds, for instance, to the number of rural hospitals for which a minimum quota specifically must be enforced, which we can expect to be small among the set of all hospitals accepting medical residents. Finally, preference lists of hospitals and residents can be expected to be small, as each hospital might not rank many more candidates than the number of positions it has to fill, whereas residents might rank only their top choices of hospitals.

We investigate in detail how these parameters influence the complexity of the SMC problem. A parameterized restriction of SMC with respect to the set S={b,|W|,|M|,ΔM,ΔW} means a (possibly parameterized) special case of SMC where each element of S is either restricted to be some constant integer, or regarded as a parameter, or left unbounded. Intuitively, these different choices for the elements of S correspond to their expected “range” in applications, from very small to mid-range to large (compared to the size of the entire system). By considering all combinations, we can flexibly model the whole range of applications mentioned above. We can even cover some cases of master lists, where all men’s preference lists are restrictions of the exact same total order over the women, and likewise all women’s preference lists are restrictions of the exact same total order over the men.

Theorem 1

Any parameterized restriction of SMC with respect to{b,|W|,|M|,ΔM,ΔW} is in P, or NP-hard and fixed-parameter tractable, or NP-hard and W[1]-hard with the given parameterization,1 and is covered by one of the results shown in Table 1.

Table 1.

Summary of our results for Stable Marriage with Covering Constraints

Constants Parameters Complexity
|M|=0, |W|=0 in P (Gale–Shapley algorithm)
|M|=0,|W|,ΔM in P (Theorem 7)
|M|,|W|,ΔM,ΔW in P (Theorem 7)
|M|=0,ΔM2 in P (Theorem 8)
ΔW2,ΔM2 in P (Observation 2)
b in P (Observation 1)
|M|=0,ΔW=2,ΔM3 NP-hard (Theorem 9)
|W|=1,ΔW=2 NP-hard (Theorem 10)
|M|=0,ΔW3,ΔM3,Δ=1   b+|W| W[1]-hard (Theorem 2)
|M|=0,|W|1,ΔW3,Δ=1    b+ΔM W[1]-hard (Theorem 5)
ΔW2 |W|+|M| FPT (Theorem 11)
ΔW2 b FPT (Corollary 3)
ΔW2 |W|+ΔM FPT (Theorem 12)

Here, Δ denotes the maximum length of the preference list of any distinguished person

In particular, SMC is W[1]-hard parameterized by b+|W|, even if there are no distinguished men (i.e., |M|=0), there is a master list over men as well as one over women, ΔM=3, ΔW=3 and each distinguished woman finds only a single man acceptable.

We give a decision diagram in Sect. 7 to show that the presented results indeed cover all restrictions of SMC with respect to {b,|W|,|M|,ΔM,ΔW}. Table 1 summarizes our results on the complexity of SMC. Note that some results are implied directly by the symmetrical roles of men and women in SMC, and thus are not stated explicitly. Here and later, we assume for simplicity that ΔM2 and ΔW2.

As a special case, we answer a question by Hamada et al. [24] who gave an exponential-time algorithm that in time O(|I|b+1) decides for a given instance I of HRLQ whether it admits a feasible matching with at most b blocking pairs;2 the authors asked whether HRLQ is fixed-parameter tractable parameterized by b. As shown by Theorem 1, SMC-1 and therefore also HRLQ is W[1]-hard when parameterized by b, already in a very restricted setting. Thus, the answer to the question by Hamada et al. [24] is negative: SMC-1, and hence HRLQ, admits no fixed-parameter algorithm with parameter b unless FPT=W[1].

Related Work

There is a dynamically growing literature on matching markets with lower quotas [4, 8, 1618, 22, 24, 26, 30, 40, 44, 45]. These papers study several variants of HRLQ, adapting the general model to the various particularities of practical problems. However, there are only a few papers which consider the problem of minimizing the number of blocking pairs [17, 24]. The most closely related work to ours is the paper by Hamada et al. [24]: they prove that the HRLQ problem is NP-hard and give strong inapproximability results; they also consider the SMC-1 problem directly and propose an O(|I|b+1) time algorithm for it.

A different line of research connected to SMC is the problem of arranged marriages, an early extension of SM suggested by Knuth [31]. Here, a set Q of man-woman pairs is distinguished, and we seek a stable matching that contains Q as a subset. Thus, as opposed to SMC, we not only require that each distinguished person is assigned some partner, but instead prescribe its partner exactly. Initial work on arranged marriages [23, 31] was extended by Dias et al. [12] to consider also forbidden marriages, and was further generalized by Fleiner et al. [15] and Cseh and Manlove [10]. Despite the similar flavour of the studied problems, none of these papers have a direct consequence on the complexity of SMC.

Our work also fits into the line of research that addresses computationally hard problems in the area of stable matchings by focusing on instances with bounded preference lists [6, 27, 29, 32, 41] or by applying the more flexible approach of parameterized complexity [1, 3, 5, 37, 38].

Organization After the preliminaries in Sect. 2, we start with the main intractability result in Sect. 3, which answers Hamada et al.’s question. This result shows W[1]-hardness of SMC parameterized by b+|W| even when M= and ΔM=ΔW=3. Thus, we explore three directions to achieve tractability: (i) to lower b to be a constant, (ii) to lower |W| to be a constant, or (iii) to lower either ΔW or ΔM to 2. We cover the cases (i) and (ii) in Sect. 5, and case (iii) in Sect. 6. In addition, Sect. 4 provides polynomial-time approximation results for HRLQ and SMC, used also in the polynomial-time algorithms of Sect. 5.

Preliminaries

An instance I of the Stable Marriage (SM) problem consists of a set M of men and a set W of women. Each person xMW has a preference list L(x) that strictly orders the members of the other party acceptable for x. We thus write L(x) as a vector L(x)=(y1,,yt), denoting that yi is (strictly) preferred by x over yj for each i and j with 1i<jt. A matching M for I is a set of man-woman pairs appearing in each other’s preference lists such that each person is contained in at most one pair of M; some persons may be left unmatched by M. For each person x we denote by M(x) the person assigned by M to x. For a matching M, a man m and a woman w included in each other’s preference lists form a blocking pair if (i) m is either unmatched or prefers w to M(m), and (ii) w is either unmatched or prefers m to M(w). In the Stable Marriage with Covering Constraints (SMC) problem, we are given additional subsets WW and MM of distinguished people that must be matched; a matching M is feasible if it matches everybody in WM. The objective of SMC is to find a feasible matching for I with minimum number of blocking pairs. If only people from one gender are distinguished, then without loss of generality, we assume these to be women; this special case will be denoted by SMC-1.

The many-to-one extension of SMC-1 is the Hospitals/Residents with Lower Quotas (HRLQ) problem whose input consists of a set R of residents and a set H of hospitals that have ordered preferences over the acceptable members of the other party. Each hospital hH has a quota lower bound q_(h) and a quota upper bound q¯(h), which bound the number of residents that can be assigned to h from below and above. One seeks an assignment M that maps a subset of the residents to hospitals that respects acceptability and is feasible, that is, q_(h)|M(h)|q¯(h) for each hospital h. Here, M(h) is the set of residents assigned to some hH by M. We say that a hospital h is under-subscribed if |M(h)|<q¯(h). For an assignment M of an instance of HRLQ, a pair {r,h} of a resident r and a hospital h is blocking if (i) r is unassigned or prefers h to the hospital assigned to r by M, and (ii) h is under-subscribed or prefers r to one of the residents in M(h). The task in HRLQ is to find a feasible assignment with minimum number of blocking pairs.

Some instances of SMC may admit a master list over women, which is a total ordering LW of all women, such that for each man mM, the preference list L(m) is the restriction of LW to those women that m finds acceptable. Similarly, we consider master lists over men.

With each instance I of SMC (or HRLQ) we can naturally associate a bipartite graph GI whose vertex partitions correspond to M and W (or R and H, respectively), and there is an edge between a man mM and a woman wW (or between a resident rR and a hospital hH, respectively) if they appear in each other’s preference lists. We may refer to entities of I as vertices, or a pair of entities as edges, without mentioning GI explicitly. For a graph G, we denote its vertex set by V(G) and its edge set by E(G); furthermore, let dG(v) denote the degree of vertex vV(G) in G. A pathP in G is a series of vertices that contains each vertex at most once, with an edge of G connecting any two consecutive vertices of P. With a slight abuse of the notation, we will often identify paths with their edge sets; we will write PP to express that P is a subpath of P. A matching in G is a set of edges ME(G) such that no vertex in G is adjacent to more than one edges of M; note that a matching in an instance I of SMC indeed corresponds to a matching in the graph GI. For a matching M in G, a path P is called M-alternating, if among any two consecutive edges along P exactly one belongs to M. We will use a few other notions from the theory of matchings about the symmetric difference of matchings, see e.g., the book by Lovász and Plummer [35] for an introduction to this topic.

Parameterized complexity The framework of parameterized complexity deals with computationally hard problems, examining their complexity in a more detailed way than classical complexity theory. In a parameterized problem problem Π, each input instance I is associated with an integer k called the parameter. An algorithm which decides instances I of Π in time f(k)·|I|O(1) for some computable function f is called a fixed-parameter algorithm. Note that the dependence of the polynomial in the run time is constant, but the dependence on the parameter k can be arbitrary (and is typically exponential). However, if the parameter of a given instance is small, then such an algorithm can be useful in practice even if the overall size of the instance is large.

The class of problems admitting fixed-parameter algorithms is denoted by FPT. To argue that a problem is not in FPT, parameterized complexity provides a hardness theory. For two parameterized problems Π1 and Π2, a parameterized reduction from Π1 to Π2 is a function f, computable by a fixed-parameter algorithm, that maps each instance (I1,k1) of Π1 to an instance f(I1,k1)=(I2,k2) of Π2 such that (i) (I1,k1) is a “yes”-instance of Π1 if and only if (I2,k2) is a “yes”-instance of Π2, and (ii) k2g(k1) for some function g. The basic class of parameterized intractability is W[1]: proving a problem Π to be W[1]-hard is strong evidence that ΠFPT. Given some problem Π that is known to be W[1]-hard, a parameterized reduction from Π to some parameterized problem Π implies W[1]-hardness of Π as well.

For more on parameterized complexity, we refer the reader to the book by Cygan et al. [11].

Strong Parameterized Intractability of SMC

This section provides parameterized intractability and inapproximability results for SMC showing the hardness of finding feasible matchings with minimum number of blocking pairs. Namely, we prove SMC-1 to be W[1]-hard parameterized by the number b of blocking pairs we aim for plus the number |W| of distinguished women, even in a very restricted setting.

Theorem 2

SMC-1 is W[1]-hard parameterized by b+|W|, even if there is a master list over men as well as one over women, all preference lists are of length at most 3, and |L(w)|=1 for each woman wW.

Before proving Theorem 2, let us quickly state a simple but useful claim.

Proposition 1

Let M1 and M2 be two matchings in an instance of SMC. Let v0v1vp (with p1) be a maximal path in the symmetric differenc of M1 and M2, denoted by M1M2. Then

  1. P contains an edge that blocks either M1 or M2, and

  2. if i{1,,p-1} is such that vi prefers vi-i to vi+1, then Pi=v0v1vi contains an edge that blocks either M1 or M2.

Proof

We call a person vi a leftist if either i=p, or i{1,,p-1} and vi prefers vi-1 to vi+1. Similarly, we call vi a rightist if either i=0, or i{1,,p-1} and vi prefers vi+1 to vi-1. Observe that any person on P is either a leftist or a rightist. Moreover, the path P, and under the conditions of (b) also the path Pi, must contain an edge {x,y} such that x is a leftist and y is a rightist. Let Mi be the matching that does not contain {x,y} (where i{1,2}). Then both x and y prefer being matched to each other as opposed to their situation in Mi (where they may or may not be matched), proving both (a) and (b).

Proof of Theorem 2

We give a reduction from the W[1]-hard Multicolored Clique parameterized by the size of the solution [14]. Let G be the input graph, with its vertex set partitioned into k sets V1,,Vk; the task is to find a clique of size k in G containing exactly one vertex from each of the sets Vi. We let Ei,j denote those edges that run between Vi and Vj for some 1i<jk. We fix an ordering on the vertices and edges of G that places vertices of Vi before vertices of Vj whenever i<j (the ordering on the edges of G can be chosen arbitrarily). We will write succ(x) to denote the vertex following x in this ordering, and we let vi1 and vi denote the first and last vertices in Vi, respectively. Similarly, we write succ({x,y}) for the edge following {x,y}, and we let ei,j1 and ei,j denote the first and last edges in Ei,j, respectively. We will also write pred(x) and pred({x,y}) for the predecessor of x or {x,y}, respectively. Also, we denote the h-th neighbor of some vertex x as n(xh). For simplicity, we assume that G has no isolated vertices.

We construct an instance I of SMC as follows; see Figs. 1 and 2 for an illustration.

Fig. 1.

Fig. 1

Node selecting gadget Gi in the proof of Theorem 2. Throughout the paper, we use squares for women, circles for men; distinguished persons are denoted by filled squares/circles. The numbering of edges incident to some vertex (or, sometimes, arrows between edges) indicate preferences. Double edges denote edges of the stable matching Ms, and dashed edges are those leaving some gadget

Fig. 2.

Fig. 2

Edge selecting gadget Gi,j in the reduction of Theorem 2

We set the number of blocking pairs allowed for I to be b=2k+k2. Together with the instance I, we will define a stable (but not feasible) matching Ms for I as well. If a woman w of I is matched by Ms, we will denote the man Ms(w) by w^. Some women will need “dummy” partners in their preference lists: we denote the dummy of w by w~. The dummy w~ will always appear as the last item on w’s preference list, and its preference list will always be L(w~)=(w).

For each i and j with 1i<jk, we construct an edge selecting gadget Gi,j that involves women si,j and ti,j, together with women a{x,y}, bxy, and byx for each edge {x,y}Ei,j. All women in Gi,j are matched by Ms except for si,j, and Gi,j contains the man w^ for each of these women w, together with additional dummies b~yx for each {x,y}Ei,j with x preceding y.

For each i{1,,k}, we also construct a node selecting gadgetGi involving women si,ti, and ui1,,uib+1, together with women ax, bx1,,bxdG(x), and cx1,,cxb+1 for each xVi. The men in Gi include w^ for each woman w of Gi except for si, and additional dummies b~x1,,b~xdG(x) and c~xb+1 for each xVi.

We define the following sets of women:

A={axxV(G)}C={cxhxV(G),1hb+1}A={a{x,y}{x,y}E(G)}S={si1ik}{si,j1i<jk}B={bxhxV(G),1hdG(x)}T={ti1ik}{ti,j1i<jk}B={bxy,byx{x,y}E(G)}U={uih1ik,1hb+1}

To define the set W of women in I with covering constraint we let W=STU; note |W|=2k2+2k+k(k2+2k+1). To finish the definition of I, we define the precise structure of these gadgets as well as the connections between them by the preference lists shown in Tables 2 and 3; when not stated otherwise, indices take all possible values. For simplicity, we write bx0=ax, bxdG(x)+1=cx1, and cx0=bxdG(x) for any vertex xV(G).

Table 2.

Preference lists of women and men in node selecting gadgets

L(ax)=(a^succ(x),a^x,b^x1), where xVi\{vi},
L(ax)=(t^i,a^x,b^x1), where x=vi,
L(bxh)=(b^xh,b^xh+1,b~xh), where 1hdG(x),
L(cxh)=(c^xh,c^succ(x)h,c^xh+1), where 1hb, xVi\{vi},
L(cxh)=(c^xh,u^ih,c^xh+1,), where 1hb and x=vi,
L(cxb+1)=(c^xb+1,c^succ(x)h,c~xb+1), where xVi\{vi},
L(cxb+1)=(c^xb+1,u^ib+1,c~xb+1,), where x=vi,
L(si)=(a^x), where x=vi1,
L(ti)=(t^i),
L(uih)=(u^ih),
L(a^x)=(ax,apred(x)), where xVi\{vi1},
L(a^x)=(ax,si), where x=vi1,
L(b^xh)=(bxh-1,bxy,bxh), where y=n(x,h), xVi, yVj and i<j
L(b^xh)=(bxh-1,byx,bxh), where y=n(x,h), xVi, yVj and i>j
L(c^xh)=(cxh-1,cpred(x)h,cxh), where xVi\{vi1},
L(c^xh)=(cxh-1,cxh), where x=vi1,
L(t^i)=(ti,ax), where x=vi,
L(u^ih)=(cxh,uih), where x=vi,
L(w~)=(w), for any dummy woman w~.

Table 3.

Preference lists of women and men in edge selecting gadgets

L(a{x,y})=(a^succ({x,y}),a^{x,y},b^xy), where {x,y}Ei,j\{ei,j,} and x precedes y,
L(a{x,y})=(t^i,j,a^{x,y},b^xy), where {x,y}=ei,j and x precedes y,
L(bxy)=(b^xy,b^xh,b^yx), where y=n(x,h) and x precedes y in V(G),
L(byx)=(b^yx,b^yh,b~yx), where y=n(x,h) and x precedes y in V(G),
L(si,j)=(a^{x,y}), where {x,y}=ei,j1,
L(ti,j)=(t^i,j),
L(a^{x,y})=(a{x,y},apred({x,y})), where {x,y}Ei,j\{ei,j1},
L(a^{x,y})=(a{x,y},si,j), where {x,y}=ei,j1,
L(b^xy)=(a{x,y},bxy), where x precedes y in V(G),
L(b^yx)=(bxy,byx), where x precedes y in V(G),
L(t^i,j)=(ti,j,a{x,y}), where {x,y}=ei,j,
L(w~)=(w), for any dummy woman w~.

Let us define a master list LW over all women as follows. The first women in LW are those in T, in any ordering. They are followed by women in A, ordered according to the reversed ordering over V(G), that is, ax precedes ay exactly if y precedes x. Next follow women of A, ordered according to the reversed ordering over E(G). Next come women in BB. To order them, we first order those in B by putting bxh before by in LW if and only if x precedes y or x=y and h<, then for each edge {x,y}E(G) with x preceding y, y=n(x,h) and x=n(y,) we insert bxy just before bxh, and we insert byx just before by, thus determining the ordering of BB. After women in BB come women of C, with cxh preceding cy exactly if h< or h= and x precedes y. We finish the definition of the master list LW by putting all women in SU at the end of LW in an arbitrary order.

The master list over men is derived from LW by letting w1^ precede w2^ whenever w1 precedes w2 in LW, and adding all dummies at the end in an arbitrary order. It is easy to check that the preference lists given in Tables 2 and 3 are indeed compatible with these master lists. This completes the construction of the instance.

We are going to prove that the constructed instance I admits a feasible assignment with at most b blocking pairs if and only if there is a clique of size k in the graph G.

”: Suppose there is a feasible matching M of men to women with at most b blocking pairs. Let GΔ be the symmetric difference MMs. Notice that for each woman sS, the difference GΔ must contain exactly one maximal path containing s as its endpoint, since the women in S must be matched in M, but are unmatched in Ms. Similarly, no path of GΔ can contain a woman in TU, because these women are matched by Ms to their only possible partners, and they must be matched by M as well, since TU is contained in W. We call a maximal path P in GΔ with an endpoint s in S an improving path. We say that Pstarts at s and ends at its other endpoint, and we refer to the path starting at si (or si,j) as Pi (or Pi,j, respectively).

We define the cost of some path P of GΔ as the number of blocking pairs {m,w} for M involving a woman w that appears on P. By Proposition 1, each improving path contains at least one edge that is blocking for M, because no edge can block Ms. Therefore, each path in GΔ has cost at least 1.

As there are exactly k+k2 improving paths (as all women in S must be matched by M), we get a minimum cost of k+k2. Note also that the total cost of all paths in GΔ cannot exceed b=2k+k2. Claim 1 is therefore crucial.

Claim 1

The following holds for any improving path P of GΔ:

  1. P cannot end at a dummy c~xb+1 for some xV(G).

  2. P contains an edge {a,a^} for some aAA that blocks M.

  3. If P is not disjoint from Gi for some i, then P has cost at least 2.

Proof of Claim 1

To prove (a), suppose for contradiction that P ends at c~xb+1, where xVi. Clearly, P must contain at least one woman from each of the b+1 sets {cvhvVi}, h=1,,b+1. Fix h, and let us consider the last vVi for which cvh is incident to an edge of GΔ. Let w=csucc(v)h if vvi, or otherwise let w=uih. Then the edge {cvh,w^} yields a blocking pair in M, as M(w)=Ms(w)=w^, and thus w^ prefers cvh to w. This reasoning gives us b+1 different blocking pairs for M, one for each index h, contradicting our assumption on M.

To prove (b), let us consider the case when P=Pi for some i; the argument goes the same way for the case where P=Pi,j for some i and j. If P ends at ax for some xVi, then ax forms a blocking pair with a^x in M. If P does not end at a woman in A, then it must contain the edge {ax,bx1} for some x, in which case {ax,a^x} is again blocking in M, showing (b).

To see (c), first observe that if P is not disjoint from Gi, then P ends in Gi, simply because of its property that it contains edges from M and Ms in an alternating fashion. Therefore, the last woman w on P must be in BC. If w=bxh for some bB, then the edge {bxh,b^xh+1} is blocking M, as bxh cannot get its first choice b^xh in M (and b^xh+1 cannot be on P, as that would imply that bxh+1 is on P, contradicting the choice of w). If, by contrast, w=c for some cC, then P must end at w by (a), and then c forms a blocking pair with the third man in its preference list (for whom c is the first choice). In either case, w is involved in a blocking pair, which together with the blocking pair guaranteed by (b) implies that P has cost at least 2.

This completes the proof of Claim 1.

Claim 1 proves that for each i{1,,k} the improving path Pi has cost at least 2. Since all the remaining k2 improving paths have cost at least 1, and the total cost of these paths must be at most b=2k+k2, we get that any path Pi (or Pi,j) must have cost exactly 2 (or 1, respectively). Furthermore, it also follows that no other path of GΔ can enter or start in Gi, for any i, as that would imply that the number of blocking pairs for M is more than b. In addition, it is not hard to see that GΔ does not contain any cycle, because all cycles in the graph underlying I contain two consecutive edges not in Ms. Hence, it follows that the only connected component in GΔ that is not disjoint from Gi is Pi.

To deal with the possible courses the path Pi may take in the graph for some i{1,,k}, let xi denote the vertex in Vi for which {axi,a^xi} is the blocking edge guaranteed by statement (b) of Claim 1. Observe that Pi either ends at axi or contains the edge {axi,b^xi1}. In either case, we say that Piselects xi from Vi; clearly, there can be only one vertex in Vi selected by Pi.

Consider now Pi,j for some 1i<jk. Recall that Pi,j has cost 1. Therefore, statement (b) of Claim 1 proves that the only blocking edge incident to some woman on Pi,j must be {a{x,y},a^{x,y}} for some {x,y}Ei,j. We say that Pi,jselects the edge {x,y}; without loss of generality, let us assume that x precedes y. By statement (c) of Claim 1, we also know that Pi,j cannot leave Gi,j, which means that it can only have cost 1 if it ends at b~yx. In particular, it contains the edges {bxy,b^yx} and {byx,b~yx}. Observe that the edge {bxy,b^xh} where h is such that y=n(x,h) cannot be blocking in M (as this would indicate a cost of 2 for Pi,j), yielding that b^xh must be matched to bxh-1 in M. By the arguments of the previous paragraph, this means that Pi must contain the subpath (ax,b^x1,bx1,,b^xh,bxh). Hence, we obtain that x must be selected by Pi. Similarly, from the fact that the edge {byx,b^y} where x=n(y,) is not blocking in M we get that y must be selected by Pj.

Thus, we obtain that if an edge is selected by Pi,j for some i and j, then its endpoints must be selected by Pi and Pj. As this must hold for each pair of indices with 1i<jk, we obtain that there must be k2 edges in G whose endpoints are among the k selected vertices. This can only happen if these edges are the edges of a clique of size k.

”: Suppose now that G has a clique of size k formed by the vertices x1,,xk, with xiVi for each i{1,,k}. Instead of directly defining the required matching M that is feasible and admits at most b blocking pairs, we give MsM as the union of paths Pi for i{1,,k}, and paths Pi,j for 1i<jk, defined as follows.

We set Pi as the path

Pi=(si,a^vi1,avi1,,a^xi,axi,b^xi1,bxi1,,b^xidG(xi),bxidG(xi),b~xidG(xi)).

Similarly, we define

Pi,j=(si,j,a^ei,j1,aei,j1,,a^{xi,xj},a{xi,xj},b^xixj,bxixj,b^xjxi,bxjxi,b~xjxi).

It is straightforward to verify that the blocking pairs for M are then the k edges {axi,a^xi}, i{1,,k}, the k edges {bxidG(xi),cxi1}, and the k2 edges {a{xi,xj},a^{xi,xj}}, 1i<jk. The feasibility of M is trivial; this completes the proof of Theorem 2.

A fundamental hypothesis about the complexity of NP-hard problems is the Exponential Time Hypothesis (ETH), which stipulates that algorithms solving all Satisfiability instances in subexponential time cannot exist [28]. Assuming ETH, the fundamental Clique problem parameterized by solution size k was shown not to admit any algorithm giving the correct answer in time f(k)·no(k) for all n-vertex instances and any computable function f [9, Thm. 5.4]. The known reduction from Clique to Multicolored Clique does not change the parameter [14]. Finally, in the proof of Theorem 2, an instance of Multicolored Clique with solution size k is reduced to an instance of SMC-1 with parameter b=O(k2).

Corollary 1

Assuming ETH, SMC-1 cannot be solved in time f(b)·no(b) for any computable function f, even if there is a master list over men and over women, all preference lists have length at most 3, and each woman in W finds only a single man acceptable.

Polynomial-Time Approximation

Here we first provide a polynomial-time algorithm that yields an approximation for HRLQ with factor (ΔR-1)q_Σ, where ΔR is the maximum length ΔR of residents’ preference lists and q_Σ is the total sum of all lower quotas. Then we use this result to propose an exact polynomial-time algorithm for HRLQ for the case where both ΔR and q_Σ are constant. Recall that in HRLQ, our objective is to find an assignment that satisfies all quota lower and upper bounds and minimizes the number of blocking pairs.

Theorem 3

Let I be an instance of HRLQ. Let ΔR denote the maximum length of residents’ preference lists, and let q_Σ denote the sum of lower quota bounds taken over all hospitals in I. There is an algorithm that in polynomial time either outputs a feasible assignment for I with at most (ΔR-1)q_Σ blocking pairs, involving only q_Σ residents, or concludes that no feasible assignment exists.

Proof

Let H denote the set of hospitals with positive lower quotas. We start by finding an assignment Mq that assigns q_(h) residents to each hospital hH, and has the following property: graphic file with name 453_2019_636_Figa_HTML.jpg Such an assignment can be obtained as follows. We start from an arbitrary assignment M that assigns q_(h) residents to each hH (if no such assignment exists, then we can stop and reject); such an assignment, if existent, can be found in polynomial time by an algorithm of Hopcroft and Karp [25]. Then we greedily re-assign residents to hospitals of H, one-by-one: at each step, we take a hospital hH, and if there exists a resident r not assigned to any other hospital in H that h prefers to the least preferred resident r in M(h), then we replace r with r in M(h). If this step cannot be applied anymore, then we arrive at an assignment Mq with the desired property ().

Given Mq, we reduce the upper quotas of each hospital hH by q_(h), set all lower quotas to 0, and delete all residents in R:=Mq(H). We then find a stable assignment Ms in the resulting instance I; note that I is an instance of HR, so we can find Ms in polynomial time [19]. Finally, we output Mout=MsMq. Clearly, Mout is feasible. Also, any blocking pair that Mout admits must involve either a hospital from H or a resident from R=Mq(H) by the stability of Ms with respect to I. Observe that if some hH is involved in some blocking pair {r,h} of Mout, then we must have rR. To see this, recall that each resident that is preferred by h to its least preferred resident in Mq(h) must be in R because of property (), and furthermore, h is under-subscribed in Mout (within I) if and only if h is under-subscribed in Ms (within I). Therefore, we can conclude that each blocking pair for Mout must involve some resident in R; observe that |R|hHq_(h)=q_Σ. Since each resident in R is incident to at most ΔR-1 edges not in Mout, we also have that Mout admits at most (ΔR-1)|R|(ΔR-1)q_Σ blocking pairs.

If both ΔR and q_Σ are constant, then Theorem 3 implies that HRLQ becomes polynomial-time solvable. Indeed, we can use the following simple strategy, depending on the number b of blocking pairs allowed: if b(ΔR-1)q_Σ, then we apply Theorem 3 directly; if b<(ΔR-1)q_Σ, then we use the algorithm by Hamada et al. [24] running in time O(|I|b+1) which is polynomial, since b is upper-bounded by a constant.

Corollary 2

If both the maximum length ΔR of residents’ preference lists and the total sum q_Σ of all lower quotas is constant, then HRLQ is polynomial-time solvable.

Another application of Theorem 3 is an approximation algorithm that works regardless of whether ΔR or q_Σ is a constant. In fact, the algorithm of Theorem 3 can be turned into a (ΔR-1)q_Σ-factor approximation algorithm as follows. First, we find a stable assignment Ms for I in polynomial time using the extension of the Gale–Shapley algorithm for the Hospitals/Residents problem. If Ms is not feasible, then by the Rural Hospitals Theorem [20], we know that any feasible assignment for I must admit at least one blocking pair; hence, the algorithm presented in Theorem 3 clearly yields an approximation with (multiplicative and also additive) factor (ΔR-1)q_Σ.

To close this section, we also state an analogue of Theorem 3 that deals with SMC: it can handle covering constraints on both sides, but assumes that all quota upper bounds are 1.

Theorem 4

There is an algorithm that in polynomial time either outputs a feasible matching for an instance I of SMC with at most (ΔW-1)|M|+(ΔM-1)|W| blocking pairs, or concludes that I admits no feasible matching.

Proof

The proof uses the same ideas as those used in our proof for Theorem 3, so the reader may skip the proof below, which we only include for completeness.

We start by finding an arbitrary matching M that covers each distinguished person (if no such matching exists, then we can stop and reject); such a matching, if existent, can be found in polynomial time by standard flow techniques. We assume, without loss of generality, that each edge in M is incident to some distinguished person. Let us define X=WM, and let U be the set of those persons xX whose partner M(x) is also in X.

We proceed by modifying M into a matching Mq that covers X and has the following property: graphic file with name 453_2019_636_Figb_HTML.jpg Such an assignment can be obtained as follows. We greedily assign partners to the men and women in X\U, one-by-one: at each step, we take a person xX\U, and if x forms a blocking pair (with respect to the current matching) with some y that is not the partner of a distinguished person, then we replace the partner of x with y: we add the edge {x,y} to the matching, and delete all the other edges incident to x or y. Observe that the obtained matching is still feasible. If this step cannot be applied anymore, then we arrive at a matching Mq with the desired property (); note also that each edge in Mq is incident to some distinguished person.

Given Mq, we delete all men and women covered by Mq. We then find a stable matching Ms in the resulting instance I; note that I is an instance of Stable Marriage, so we can find Ms in polynomial time [19]. Finally, we output Mout=MsMq. Clearly, Mout is feasible. Also, any blocking pair that Mout admits must involve a person covered by Mq due to the stability of Ms with respect to I.

We claim that any blocking pair {x,y} involves a person whose partner by Mq is distinguished, so either Mq(x)X or Mq(y)X. We can assume that x is covered by Mq (because this holds for at least one of x and y). To see the claim, first note that if x is not distinguished, then Mq(x) must be distinguished, because each edge of Mq contains a distinguished person. Second, if xX, then either xU (in which case Mq(x)X) or Mq(y)X because of property (). Therefore, we can conclude that each blocking pair for Mout must involve the partner of some distinguished resident. The partners of distinguished women can be incident to at most |W|(ΔM-1) blocking pairs, and similarly, the partners of distinguished men can be incident to at most |M|(ΔW-1) blocking pairs, proving the theorem.

SMC with Bounded Number of Distinguished Persons or Blocking Pairs

In Theorem 2 we proved W[1]-hardness of SMC-1 for the case where ΔM=ΔW=3, with parameter b+|W|. Here we investigate those instances of SMC and SMC-1 where the length of preference lists may be unbounded, but either b, or the number of distinguished persons is constant.

First, if the number b of blocking pairs allowed is constant, then SMC can be solved by simply running the extended Gale–Shapley algorithm after guessing and deleting all blocking pairs. This complements the result by Hamada et al. [24].

Observation 1

SMC can be solved in time O(|I|b+1), where b denotes the number of blocking pairs allowed in the input instance I.

In Theorem 5 we prove hardness of SMC-1 even if only one woman must be covered. If we require preferences to follow master lists, then a slightly weaker version of Theorem 5, where |W|=2, still holds.

Theorem 5

SMC-1 is W[1]-hard parameterized by b+ΔM, even if W={s}, ΔW=3, and |L(s)|=1.

Proof

We present a reduction based on the one from Multicolored Clique given in the proof of Theorem 2. Given some graph G and an integer k as inputs, we are going to re-use the instance I constructed in the proof of Theorem 2. Recall that I has a feasible matching with at most b=k2+2k blocking pairs if and only if G has a clique of size k. Recall also that the set of women that must be covered in I is STU; here we denote this set by WI. We define a modified instance I of SMC as follows. For each wWI, we create a forcing gadget Fw which apart from w contains the newly introduced women aw,bw,cw,dw and men aw,bw,cw,dw. We also add the distinguished woman s, who must be covered in I, and the unique man t in L(s). See Fig. 3 for an illustration.

Fig. 3.

Fig. 3

Illustration depicting the forcing gadget Fw in the proof of Theorem 5

Let n(w) denote the unique man acceptable for some wWI in I. Additionally, we let Y={aw,cwwWI}, and we write [Y] for an arbitrarily fixed ordering of the elements of Y. The preferences of the newly introduced men and women, as well as the modified preferences of those agents that find them acceptable, is given below. Here, again, indices take all possible values, and w can be any woman in WI. We let I contain all other women and men defined in I, having the same preferences as in I.

L(s)=(t),L(t)=([Y],s),L(aw)=(bw,t,aw),L(aw)=(aw,dw),L(bw)=(cw,bw),L(bw)=(bw,w,aw),L(cw)=(dw,t,cw),L(cw)=(cw,bw),L(dw)=(aw,dw),L(dw)=(dw,w,cw),L(w)=(n(w),bw,dw).

We will show that I has a feasible matching with at most b blocking pairs if and only if I has such a matching; this clearly proves the theorem.

First observe that any feasible matching M for I contains the edge {s,t}. Thus, if some woman y in Y is not matched by M to her first choice, then {y,t} is blocking in M. Consider now Fw for some wWI. It is straightforward to check that if M(w)n(w), then there are at least two blocking pairs incident to a woman in Fw. Indeed, assume first that {t,aw} is the only blocking pair in Fw; this quickly implies M(cw)=dw and M(aw)=aw, which in turn leads to {dw,dw} blocking M, a contradiction. Second, assume that {t,aw} does not block M; from this follows M(aw)=bw and we have that {bw,w} is a blocking pair for M. Now either {t,cw} is blocking (in which case our claim holds), or we get M(cw)=dw, which implies that {dw,w} blocks M, again a contradiction.

Now, let Wi be the women in Gi that must be covered in I, i.e., Wi={si,ti,ui1,,uib+1}. Consider the number βi of blocking pairs for M that involve a woman either in the gadget Gi or in a gadget Fw for some wWi. On the one hand, if some wWi is not matched by M to n(w), then βi2 because of the blocking pairs in Fw. On the other hand, if each wWi is matched by M to n(w), then using the arguments of the proof for Theorem 2, we again know βi2 because of the blocking pairs in Gi. Also, βi=2 can only be achieved if (i) M(ti)=n(ti), as otherwise {ti,n(ti)} would be blocking for M, in addition to the two blocking pairs in Fti, and (ii) M(uih)=n(uih) for each h{1,,b+1}, as otherwise we would have M(si)=n(si) (so as to avoid having four blocking pairs due to women in Fuih and Fsi), implying at least one blocking pair in Gi in addition to those in Fuih.

Analogously, let βi,j denote the number of blocking pairs for M that involve a woman either in the gadget G{i,j} or in a gadget Fw for some w{si,j,ti,j}. Then either βi,j2, or we know that M(w)=n(w) for both women w{si,j,ti,j}; in this case, from the proof of Theorem 2 we get βi,j1. However, supposing that M has at most b=2k+k2 blocking pairs, it follows that βi=2 and βi,j=1 must hold for each i{1,,k} and each ij with 1i<jk, respectively.

Along the same lines as in the proof of Theorem 2, it can also be verified that βi,j=1 for each pair of indices ij can only be achieved if MMs contains a path in each gadget Gi. From M(w)=n(w) for each wWi\{si} we get that such a path contains at least one blocking pair. This implies M(si)=n(si), as otherwise we would end up with βi3 because of the blocking pairs incident to women of Fsi.

Altogether, we have proved that M(w)=n(w) for each wWI. Hence, the restriction of M to I yields a feasible matching for I that admits at most b blocking pairs.

For the other direction, suppose that I has a feasible matching M. Then it is easy to see that adding the edges {aw,bw}, {bw,cw}, {cw,dw}, and {dw,aw} for each wWI together with the edge {s,t} to M yields a feasible matching for I that contains exactly the same number of blocking pairs in I as M does in I.

Theorem 6

SMC-1 is W[1]-hard parameterized by b+ΔM, even if there is a master list over men as well as one over women, |W|=2, ΔW3, and |L(w)|=1 for each wW.

Proof

The proof is very similar to the one for Theorem 5, so we will only sketch it. Again, we are going to re-use the instance I constructed in the proof of Theorem 2, and construct a modified instance I of SMC, adding only two new women z1 and z2 and two men m1 and m2 to I. We append z1 and z2, in this order, to the master list over women, and similarly, we append m1 and m2 to the master list over men. We define the women to be covered in I as z1 and z2.

Again, we denote the set of women to be covered in I by WI, and we denote by n(w) the unique man acceptable for some wWI in I. The preferences of the newly introduced men and women, as well as the modified preferences of those agents that find them acceptable, is given below (here, [WI] denotes the ordering of WI given by the master list). We let I contain all other women and men defined in I, having the same preferences as in I.

L(z1)=(m1),L(m1)=([WI],z1),L(z2)=(m2),L(m2)=([WI],z2),L(w)=(n(w),m1,m2)wWI.

Arguing analogously as before in the proof of Theorem 5, one can show that I has a feasible matching with at most b blocking pairs if and only if I has such a matching; this suffices to prove the theorem.

To contrast our intractability results, we show next that if each of the four parameters |W|, |M|, ΔW, and ΔM is constant, then SMC becomes polynomial-time solvable. Our algorithm relies on the observation that in this case, the number of blocking pairs in an optimal solution is at most (ΔM-1)|W|+(ΔW-1)|M| by Theorem 4. Note that for instances of SMC-1, Theorem 7 yields a polynomial-time algorithm already if both |W| and ΔM are constant.

Theorem 7

SMC can be solved in time O(|I|(ΔM-1)|W|+(ΔW-1)|M|+1).

Proof

By Theorem 4, there is a matching with at most bmax=(ΔM-1)|W|+(ΔW-1)|M| blocking pairs. Hence, if the number b of blocking pairs allowed is at least bmax, then we can simply run the algorithm of Theorem 4. Otherwise, we can use Observation 1, which gives us the required run time.

Importantly, restricting only three of the values |W|, |M|, ΔW, and ΔM to be constant does not yield tractability for SMC, showing that Theorem 7 is tight in this sense. Indeed, Theorem 5 implies immediately that restricting the maximum length of the preference lists on only one side still results in a hard problem: SMC remains W[1]-hard with parameter b+ΔM, even if ΔW=3, |W|=1, and |M|=0. On the other hand, Theorem 2 shows that the problem remains hard even if ΔW=ΔM=3 and |M|=0.

SMC with Preference Lists of Length at Most Two

In this section we investigate the computational complexity of SMC where the maximum length of preference lists is bounded by 2 on one side. This restriction leads to important tractable special cases: we obtain both polynomial-time algorithms and fixed-parameter tractability results for various parameterizations.

Let I be an instance of SMC with underlying graph G. Let Ms be a stable matching in I, and let M0 and W0 denote the set of distinguished men and women, respectively, unmatched by Ms. Furthermore, let M0 and W0 denote the set of all men and women, respectively, unmatched by Ms. A path P in G is called an augmenting path, if MsP is a matching, and either both endpoints of P are in M0W0, or one endpoint of P is in M0W0, and its other endpoint is not distinguished. This definition ensures that for an augmenting path P, the set of distinguished men and women that are matched in MsP strictly contains the set of distinguished men and women matched in Ms.3 We will call an augmenting path Pmasculine or feminine if it contains a man in M0 or a woman in W0, respectively; if P is both masculine and feminine, then we call it neutral. If P is not neutral, then we say that it starts at the (unique) person from M0W0 it contains, and ends at its other endpoint.

Covering Constraints on One Side

Here we deal with the SMC-1 problem where only women need to be covered. We first give a polynomial-time algorithm for SMC-1 when each man finds at most two women acceptable, and then show NP-hardness of SMC-1 for instances where each woman finds at most two men acceptable. We start by considering the special case of SMC-1 where ΔM2.

Theorem 8

There is a polynomial-time algorithm for the special case ofSMC-1 where each man finds at most two women acceptable.

High-Level Description The main observation behind Theorem 8 is that if ΔM2, then any two augmenting paths starting from different women in W0 are almost disjoint, namely they can only intersect at their endpoints. Thus, we can modify the stable matching Ms by selecting augmenting paths starting from each woman in W0 in an almost independent fashion: intuitively, we simply need to take care not to choose paths sharing an endpoint—a task which can be managed by finding a bipartite matching in an appropriately defined auxiliary graph. To ensure that the number of blocking pairs in the output is minimized, we will assign costs to the augmenting paths. Roughly speaking, the cost of an augmenting path P determines the number of blocking pairs introduced when modifying Ms along P (though certain special edges need not be counted); hence, our problem reduces to finding a bipartite matching with minimum weight in the auxiliary graph.

To present the algorithm of Theorem 8 in detail, we start with the following properties of augmenting paths which are easy to prove using that ΔM2:

Proposition 2

Suppose ΔM2. Let P1 and P2 be augmenting paths starting at women w1 and w2, respectively.

  1. If w1w2, then P1 and P2 are either vertex-disjoint, or they both end at some mM0, with V(P1)V(P2)={m}.

  2. If there is an edge {m,w} of G (with mM and wW) connecting P1 and P2, then mM0 and P1 or P2 must end at m.

  3. If w1=w2 and P is the maximal common subpath of P1 and P2 starting at w1, then either V(P1)V(P2)=V(P), or P1 and P2 both end at some mM0 and V(P1)V(P2)=V(P){m}.

With a set P of edges (typically a set of augmenting paths) where MsP is a matching, we associate a cost, which is the number of blocking pairs that MsP admits. A pair {m,w} for some mM and wW is special, if mM0 and w is the second (less preferred) woman in L(m). As it turns out, such edges can be ignored during certain steps of the algorithm; thus, we define the special cost of P as the number of non-special blocking pairs in MsP.

Lemma 1

For vertex-disjoint augmenting paths P1 and P2 with cost c1 and c2, respectively, the cost of P1P2 is at most c1+c2. Further, if the cost of P1P2 is less than c1+c2, then the following holds for {i1,i2}={1,2}: there is a special edge {m,w} with Pi1 ending at m and w appearing on Pi2; moreover, {m,w} is blocking in MsPi2, but not in Ms(P1P2).

Proof

First observe that if some edge {m,w} has a common vertex with only one of the paths P1 and P2, say P1, then {m,w} is blocking in MsP1 if and only if it is blocking in Ms(P1P2).

Consider now the case when {m,w} connects P1 and P2. By Proposition 2, this implies that one of the paths, say P1, ends at mM0 (and w lies on P2). Clearly, {m,w} is not blocking in MsP1, by the stability of Ms. If, on the one hand, w is the first choice of m, then {m,w} is blocking in MsP2 exactly if it is blocking in Ms(P1P2). If, on the other hand, {m,w} is special, then it cannot be blocking in Ms(P1P2), but it might be blocking in MsP2. Putting all these facts together, the lemma follows immediately.

We are ready to provide the algorithm, in a sequence of four steps.

Step 1: Computing all augmenting paths By Proposition 2, if we delete M0 from the union of all augmenting paths starting at some wW0, then we obtain a tree. Furthermore, these trees are mutually vertex-disjoint for different starting vertices of W0. This allows us to compute all augmenting paths in linear time, e.g., by an appropriately modified version of a depth-first search algorithm (so that only augmenting paths are considered). During this process, we can also compute the special cost of each augmenting path in a straightforward way.

Step 2: Constructing an auxiliary graph Using the results of the computation of Step 1, we construct an edge-weighted single bipartite graph Gpath=(U,V;E) as follows. To define the vertices of Gpath we set U:=W0 and V:=M0{wwW0}, so for each woman wW0 we create a corresponding new vertex w. The edge set E contains an edge {w,w} for each wU, as well as an edge {w,m} whenever wU, mM0 and there exists an augmenting path with endpoints w and m. We define the weight of an edge {w,w} as the minimum special cost cwmin of any augmenting path starting at w and not ending in M0, and we define the weight of an edge {w,m} with wU and mM0 as the minimum special cost of any augmenting path with endpoints w and m.

Step 3: Computing a minimum weight matching We compute a matching MP in Gpath covering U and having minimum weight; this can be done in polynomial time by, e.g., the Hungarian method [34]. Observe that the matching MP corresponds to a set of augmenting paths P={PwwW0} that are mutually vertex-disjoint by Proposition 2. Recall that the special cost of Pw is the weight of the edge in MP incident to w.

Step 4: Eliminating blocking special edges In this step, we modify P iteratively. We start by setting Pact=P. At each iteration we modify Pact as follows. We check whether there exists a special edge {m,w} that is blocking in MsPact. If yes, then notice that m is not matched in MsPact, because {m,w} is special and thus mM0. Let P be the path of Pact containing w. We modify Pact by truncating P to its subpath between its starting vertex and w, and appending to it the edge {m,w}. This way, {m,w} becomes an edge of the matching MsPact. The iteration stops when there is no special edge blocking MsPact. Note that once a special edge ceases to be blocking in MsPact, it cannot become blocking again during this process, so the algorithm performs at most |M0| iterations. For each wW0, let Pw denote the augmenting path in Pact covering w at the end of Step 4; we define P={PwwW0} and output the matching MsP.

This completes the description of the algorithm; we now provide its analysis.

Lemma 2

Msol:=MsP is a feasible matching for I, and the number of blocking pairs for Msol is at most the weight of MP.

Proof

Consider the situation when the iteration in Step 4 deals with a special edge {m,w} blocking in Pact. Notice that since w is the second woman in L(m) (by the definition of a special edge), and since {w,m} is blocking in MsPact, we know that m is unmatched in MsPact, that is, m does not lie on any of the augmenting paths in Pact. From this follows that the augmenting paths in Pact, and hence in P, remain mutually vertex-disjoint. Therefore, Msol is indeed a matching. As it covers W0, and no augmenting path ends at a woman in W\W0, matching Msol is feasible.

Clearly, Step 4 ensures that there are no blocking special edges in Msol. Note that when the algorithm modifies Pw for some wW0, at most one new blocking pair may arise with respect to MsPact, and from the stability of M and Proposition 2 it follows that such an edge must be a special edge (incident to the man at which Pw ends before its modification). This means that Step 4 gets rid of all blocking special edges without introducing any non-special blocking edges. Hence, we obtain that the cost of Pw is at most the special cost of Pw, for each wW0. By Lemma 1, the number of blocking pairs that Msol admits is at most the sum of the costs of all augmenting paths in P; this finishes the proof.

To show that our algorithm is correct and Msol is optimal, by Lemma 2 it suffices to prove that the weight of MP is at most the number of blocking pairs in Mopt, where Mopt denotes an optimal solution in I. To this end, we are going to define a matching covering W0 in Gpath whose weight is at most the number of blocking pairs in Mopt.

Clearly, MsMopt contains an augmenting path Qw covering w for each wW0. If some Qw ends at a man mM0, then clearly no other path in MsMopt can end at m. So let us take the matching MQ in Gpath that includes all pairs {m,w} where Qw ends at mM0 for some wW0. Also, we put {w,w} into MQ if Qw does not end at a man of M0. Note that MQ is indeed a matching.

It remains to show that the weight of MQ is at most the number of blocking pairs in Mopt. By definition, the weight of MQ is at most the sum of the special costs of the paths Qw for every wW0. By Lemma 1, any non-special blocking pair in MsQw remains a blocking pair in Ms(wW0Qw), and hence in Mopt as well. Hence, there is a matching in Gpath with weight at most the number of blocking pairs in an optimal solution, implying the correctness of our algorithm. As the algorithm runs in polynomial time, Theorem 8 follows.

By contrast to Theorem 8, if men may have preference lists of length 3, then SMC-1 (and hence SMC) is NP-hard even if each woman finds at most two men acceptable.

Theorem 9

SMC-1 is NP-hard even if ΔW=2 and ΔM=3.

Proof

We give a reduction from the NP-hard Vertex Cover problem, asking whether the input graph G has a vertex cover of size at most k. We order the vertices of G arbitrarily, and denote the h-th neighbor of some vertex x by n(xh) for any h{1,,dG(x)}.

Let us construct an instance I of SMC as follows; see Fig. 4 for an illustration. For each vertex xV(G) we construct a node gadgetGx which contains women sx, ax0,,axdG(x), cx1 and cx2, and men bx0,,bxdG(x), and dx. For each edge {x,y}E(G) we also construct an edge gadgetG{x,y} involving women s{x,y}, axy and ayx, and men bxy and byx. Furthermore, there are two edges in the underlying graph connecting G{x,y} to Gx and Gy, namely {axy,bxh} and {ayx,by} where y=n(x,h) and x=n(y,).

Fig. 4.

Fig. 4

Illustration of a node gadget Gx and an edge gadget G{x,y} constructed in the proof of Theorem 9. Double edges denote edges of a stable matching for I, and dashed edges are those leaving some gadget. The example depicted assumes y=n(x,2)

The preference lists of I are given in Table 4. Let the set of women with covering constraints be

W=xV(G){sx,ax0,,axdG(x)-1}{x,y}E(G){s{x,y}},

and set the number of blocking pairs allowed to be |V(G)|+k. We are going to prove that I admits a feasible matching with at most |V(G)|+k blocking pairs if and only if there is a vertex cover of size k in the graph G.

Table 4.

Preference lists of women and men in the proof of Theorem 9

L(sx)=(bx0,dx),
L(bx0)=(ax0,sx),
L(bxh)=(axh,axy,axh-1) where 1hdG(x) and y=n(x,h),
L(axh)=(bxh+1,bxh) where 0h<dG(x),
L(axdG(x))=(bxdG(x)),
L(cxh)=(dx), where h{1,2},
L(dx)=(cx1,cx2,sx),
L(s{x,y})=(bxy,byx) where x precedes y,
L(bxy)=(axy,s{x,y}),
L(axy)=(bxy,bxh) where y=n(x,h).

When not stated otherwise, indices take all possible values

”: Let M be a feasible matching with at most |V(G)|+k blocking pairs. We say that the cost of some gadget Gx (or G{x,y}) is the number of edges blocking M which are incident to some man of Gx (or G{x,y}, respectively.) We will prove that the set S of vertices x for which Gx has cost at least 2 is a vertex cover of G.

First, let us consider some x for which M(sx)=dx. In this case, both cx1 and cx2 form a blocking pair for M with dx, implying xS. Second, let us consider some x with M(sx)=bx0. Since each axh with 0h<dG(x) must be matched by M (because it is contained in W), we obtain M(axh)=bxh+1 for each such h. Hence, axdG(x) and bxdG(x) form a blocking pair for M. Moreover, if the woman axy is unmatched in M for some y, then {axy,bxh} is also a blocking pair in M (where y=n(x,h)), and implies a cost of at least 2 for Gx. Therefore, we can observe that if xS, then axy must be matched by M to bxy for each neighbor y of x in G.

However, for any {x,y}E(G), M must match s{x,y} either to bxy or to byx (because s{x,y} is contained in W), which means that xS or yS. This proves that S is indeed a vertex cover for G. Moreover, the number of vertices in S can be at most k, since each Gx with xS has cost at least 2, each Gx with xS has cost at least 1, and the total cost of all gadgets cannot exceed our budget |V(G)|+k.

”: Given a vertex cover S of size at most k for G, we define a matching M with the desired properties. Namely, for each xS we set M(sx)=dx and M(axh)=bxh for each h{0,,dG(x)}. In this case, cx1,cx2 are unmatched by M, both forming a blocking pair with dx. By contrast, all of the men bx0,,bxdG(x) get their first choices.

Next, for each xV(G)\S we set M(sx)=bx0, M(cx1)=dx, and M(axh)=bxh+1 for each h{0,,dG(x)-1}. Note that axdG(x) is unmatched by M, and thus forms a blocking pair with bxdG(x). Observe also that dx is not contained in any blocking pair.

Finally, for some {x,y}E(G), let us assume yS (since S is a vertex cover, it contains x or y). We set M(s{x,y})=byx and M(axy)=bxy. Note that axy gets her first choice, so it cannot be involved in a blocking pair. Although ayx is unmatched by M, we know that it cannot form a blocking pair with by where x=n(y,), because yS and hence by is assigned her first choice by M. Thus, no man or woman of some edge gadget participates in a blocking pair, and therefore we obtain that the total number of blocking pairs for M is exactly |V(G)|+k.

Since M is feasible, the theorem follows.

Covering Constraints on Both Sides

Let us now investigate the complexity of SMC with covering constraints both for men and women. If we restrict the maximum length of preference lists on both sides to be at most 2, SMC becomes linear-time solvable. To see this, observe that by max(ΔW,ΔM)2, the underlying graph G must be a collection of paths and cycles. Thus, we can process the connected components of G one by one. Applying dynamic programming on each component K, we can determine the minimum number bK of blocking pairs for any matching that is feasible for K, together with a matching MK for K that admits bK blocking pairs. If K is a path, then this can be done in a straightforward manner, traversing the edges of K one by one in linear time. If K is a cycle, then we can pick any edge e of K, guess whether it is contained in MK, or blocks MK, or neither of the two; we can then process the remainder of K (which is a path) taking into account our guess for e. To compute the minimum number of blocking pairs that a feasible matching admits in our instance, we can simply sum up the values bK over each connected component K of G. Hence, we arrive at the following.

Observation 2

Instances of SMC with max(ΔW,ΔM)2 are linear-time solvable.

Recall that the case where ΔW=2 and ΔM=3 is NP-hard by Theorem 9, even if there are no distinguished men to be covered. However, switching the roles of men and women in Theorem 8, we obtain that if there are no women to be covered, then ΔW2 guarantees polynomial-time solvability for SMC. This raises the natural question whether SMC with ΔW2 can be solved efficiently if the number of distinguished women is bounded. Next we show that this is unlikely, as the problem turns out to be NP-hard for |W|=1.

Theorem 10

SMC is NP-hard, even if ΔW=2, |W|=1 and there is only one man m with |L(m)|>3.

Proof

We present a reduction from the following special case of Exact-3-Cover. We are given a set U={u1,,un}, a family S of subsets S1,,Sm of U, each having size 3, such that each element of U occurs in at most three sets of S. The task is to decide whether there exists a collection of n/3 sets in S whose union covers U; such a collection of subsets is called an exact cover for U. This problem is NP-complete [21, GT2]. We construct an equivalent instance I of SMC as follows.

The set W of women in I contains the women sj, pj1, pj2, pj3, and qj for each j{1,,m}, women x and y, as well as two women ai,j,bi,j for each element ui contained in Sj for each j{1,,m}. The men defined in I are p^j1, p^j2, p^j3q^j, and tj for each j{1,,m}, a man ci for each uiU, a man b^i,j for each element ui contained in Sj for each j{1,,m}, plus one additional man y^. (The pairs {w,w^} form a stable matching in I.) The only distinguished woman in I is x, and the set of distinguished men is M={cii=1,,n}{tjj=1,,m}. The preferences of each person are as shown in Table 5. Note that since each subset Sj contains three elements, and each element ui is contained in at most three subsets from S, we get that all men except for y^ have a preference list of length at most 3, as promised. To finish the construction, we set the number of allowed blocking pairs to be b=2m+2n/3+1.

Table 5.

Preference lists of women and men in the proof of Theorem 10

L(x)=(y^),
L(y)=(y^),
L(sj)=(p^j3,y^),
L(pj1)=(p^j1,tj),
L(pjh)=(p^jh-1,p^jh) for h{2,3},
L(qj)=(q^j,tj),
L(ai,j)=(b^i,j,p^jh) for the unique h{1,2,3} that satisfies i=ind(j,h),
L(bi,j)=(b^i,j,ci),
L(y^)=(y,s1,s2,,sm,x),
L(tj)=(pj1,qj),
L(p^jh)=(pjh,ai,j,pjh+1) for h{1,2} and i=ind(j,h),
L(p^j3)=(pj3,ai,j,sj) where i=ind(j,3),
L(q^j)=(qj),
L(b^i,j)=(bi,j,ai,j),
L(ci)=([Bi]) where Bi={bi,juiSj} and [Bi] is some fixed ordering of Bi

We denote by ind(j,h) the index i for which ui is the h-th element in Sj. When not stated otherwise, indices take all possible values

We claim that I admits a feasible matching with at most b blocking pairs if and only if (U,S) is a “yes”-instance of Exact-3-Cover.

”: Suppose that M is a feasible matching for I with at most b blocking pairs. Clearly, as x is distinguished, M must contain the edge {x,y^}. Thus, {y,y^} is blocking in M. Second, since tj is distinguished for each j{1,,m}, we get that M matches tj either to qj or to pj1, which in turn implies that either {qj,q^j} or {pj1,p^j1} blocks M, leading to m additional blocking pairs for M. Third, consider now any man ci, i{1,,n}: as ci is distinguished, we know M(ci)=bi,j for some j such that Sj contains ui. In this case, {bi,j,b^i,j} is also a blocking pair for M, yielding n blocking pairs of such form. Thus, if bU denotes the number of blocking pairs among the edges {bi,j,b^i,j} for indices i and j with uiSj, then we get bUn. This adds up to m+bU+1m+n+1 blocking pairs so far.

Let us define the set Ej of those edges that are incident to sj, p^j3p^j2, or p^j1, but not to pj1 for some j{1,,m} ; note that these sets are pairwise disjoint, and none of them contains any of the (possibly) blocking edges mentioned in the previous paragraph.

Let k be the number of indices j for which Ej contains no blocking pairs for M; we call such indices (and the subsets Sj corresponding to them) selected. The m-k non-selected indices clearly correspond to at least m-k blocking pairs for M (each contained in Ej for some j).

Suppose now that j is selected. Then, since {sj,y^} is not blocking, we get M(sj)=p^j3, since y^ prefers sj to its partner x. This implies that M(pj3)=p^j2, as otherwise {pj3,p^j3} would be blocking in M. Similarly, from this we obtain M(pj2)=p^j1. Moreover, for each h{1,2,3}, to ensure that {p^jh,ai,j} does not block M where ui is the h-th element of Sj, we must have M(ai,j)=b^i,j. Hence, {bi,j,b^i,j} must be blocking in M. Since this holds for each h{1,2,3} and each selected j, we get bU3k.

Summing up the blocking pairs identified so far, we know that M admits at least 1+m+(m-k)+max(n,3k) blocking pairs. Using that this must be upper-bounded by b=1+m+n+(m-n/3), it is easy to show that only k=n/3 is possible. This yields that there exist exactly n/3 selected indices, and for all such indices j all the edges {bi,j,b^i,j} for which uiSj are blocking with respect to M. Moreover, we also must have bU=n, as otherwise the number of blocking pairs would exceed b.

However, observe that for each i{1,,n}, there must exist some j with uiSj for which the pair {bi,j,b^i,j} is blocking in M (because ci is distinguished), implying that for each uiU there must exist some selected Sj that contains ui. Since there are exactly n/3 selected sets in S, we get that they form an exact covering of U.

”: Suppose that (U,S) is a “yes”-instance of Exact-3-Cover. Let J be the set of indices describing a solution, meaning that the subsets SjS with jJ form an exact covering of U; clearly, |J|=n/3. We define σ(i) as the unique index j in J for which uiSj. We define a feasible matching M for I with exactly b blocking pairs as follows (indices take all possible values, if not stated otherwise).

M(y^)=x,M(tj)=pj1ifjJ,M(tj)=qjifjJ,M(p^jh)=pjh+1ifjJ,h{1,2},M(p^j3)=sjifjJ,M(ci)=bi,σ(i),M(b^i,σ(i))=ai,σ(i),M(w^)=wifwWand neitherM(w)norM(w^)is defined yet.

It is easy to check that M indeed is feasible, and the blocking pairs it admits are exactly the pairs {y,y^}, {bi,σ(i),b^i,σ(i)} for each i{1,,n}, {pj1,p^j1} for each jJ, {qj,q^j} for each jJ, and {sj,y^} for each jJ. This proves the lemma.

Contrasting Theorem 10, we establish fixed-parameter tractability of the case ΔW2 with three different parameterizations. Considering our five parameters, the relevant cases (whose tractability or intractability does not follow from our results obtained so far) are as follows, assuming ΔW2 throughout. Since letting the number b of blocking pairs and the number |W| of distinguished women to be unbounded (while assuming ΔW2) results in NP-hardness by Theorem 9, in order to obtain fixed-parameter tractability, we need to take either b or |W| as a parameter. However, taking only|W| as a parameter is not likely to result in tractability, as the case |W|=1 is still NP-hard by Theorem 10. Thus we need to take either |M| or ΔM as an additional parameter. Altogether, this results in the following parameterizations of the SMC problem, each case subject to the assumption ΔW2:

  • taking b as the parameter,

  • taking |W|+|M| as the parameter, and

  • taking |W|+ΔM as the parameter.

We show fixed-parameter tractability for each three of these parameterizations. The first two parameterizations can be dealt with an algorithm whose properties are stated in Theorem 11 (see also Corollary 3), while the third parameterization will be considered by Theorem 12.

Theorem 11

There is a fixed-parameter algorithm for the special case of SMC where each woman finds at most two men acceptable (i.e., ΔW2), parameterized by the number |W0|+|M0| of distinguished men and women left unmatched by some stable matching.

Let Mopt denote an optimal solution for our instance I such that MsMopt contains the minimum number of edges; recall that Ms is a fixed stable matching for I. Without loss of generality, we can further assume that there does not exist another optimal solution M such that (i) M has the same number of common edges with Ms as Mopt, and (ii) for each man m, either M(m)=Mopt(m) or m prefers M(m) to Mopt(m).4 Indeed, as long as such a “superior” matching M exists, we can simply pick that instead of Mopt, until this is no longer possible. This way, we eventually end up with an optimal matching that satisfies our requirement.

We denote by b the number of blocking pairs in Mopt.

High-Level Description Let us remark first that simply guessing the optimal partners for each woman in W0 and then using the polynomial-time algorithm presented in Sect. 6.1 (after exchanging the roles of men and women) does not work, since that algorithm heavily relies on the assumption that we start with a stable matching. In fact, the main difficulty to overcome is that feminine and masculine augmenting paths may “interact” in the sense that certain blocking pairs introduced by a feminine augmenting path can be “eliminated” (i.e., made non-blocking again) by an appropriately chosen masculine path. Therefore, we apply the following strategy. In Phase I, we find all feminine paths (as well as all cycles) in MsMopt, and in Phase II we proceed with choosing the masculine paths carefully. Note that in Phase I it does not suffice to find a cheapest set of feminine augmenting paths, since we may not be able to eliminate as many blocking pairs afterwards as it is possible after an optimal choice of feminine paths. Instead, we need to find the exact feminine augmenting paths (and cycles) present in MsMopt; this can be accomplished by guessing certain properties of Mopt.

In Phase II, the main obstacle is that we do not know which blocking edges should be eliminated in an optimal solution, nor can we guess these edges efficiently. We deal with this problem by guessing the sets of those men in M0 whose augmenting paths in MsMopt contribute to the elimination of a blocking pair; this information allows us to find these masculine paths. Finally, we apply the algorithm of Theorem 8.

For the detailed description of our algorithm, we need a couple of simple observations and some additional notation. We begin with the following implications of the fact that each woman finds at most two men acceptable.

Proposition 3

Suppose ΔW2. Let P1 and P2 be two augmenting paths.

  1. If P1 and P2 start at some wW0 through the same edge, then one of them is a subpath of the other.

  2. If P1 and P2 start at different women w1 and w2, respectively, and P1 and P2 are not disjoint, then the set of their common vertices induces a suffix of either P1 or P2 (or both); their first common vertex is a man.

  3. If P1 and P2 are disjoint and e is an edge incident to both, then one of the paths starts or ends at a women w, and e connects w with a man on the other path.

Observations (a) and (b) of Proposition 3 immediately suggest that feminine paths are easy to find, since once we decide which edge to start with, all possible augmenting paths lead in the same direction; the only difficulty arises in deciding when to stop. Observation (c) describes the limited ways in which two augmenting path can interact; we next look closer at such interactions.

We say that an edge f={m,w} of G (with mM and wW) is dependent if it connects two different connected components K1 and K2 of MsMopt and, in addition, it holds that MsK1 admits more blocking pairs than Ms(K1K2). We will say that f, and with a slight abuse of the notation, also K1relies on K2. We say that

  • f has type A, if w is the endpoint of K2 (which is a path), f connects w with a man m on K1 that prefers Ms(m) to w, and w to Mopt(m), and w is unmatched by Ms and prefers Mopt(w) to m;

  • f has type B, if w is the endpoint of K1 (which is a path), unmatched by Mopt, and f connects w with a man m on K2 that prefers Mopt(m) to w, and w to Ms(m).

See Fig. 5 for an illustration of the above definitions.

Fig. 5.

Fig. 5

Illustration of a dependent edge f, running between two connected components K1 and K2 of MsMopt where K1 relies on K2. Double lines here denote edges of Ms, single lines denote edges of Mopt, and f is drawn with a dashed line

Lemma 3

Let K be the set of connected components of MsMopt, and let HK and KK\H. Then any edge f that is blocking in MsH but is not blocking in Ms(HK) connects K with a connected component of H, is a dependent edge relying on K, and has either type A or type B.

Proof

Let f be an edge that blocks MsH but does not block Ms(HK). Since Ms is stable, f must have an endpoint in a connected component of H, because it blocks MsH. However, as it ceases to be blocking in Ms(HK), it also must have an endpoint in K. Let w and m be the woman and the man connected by f, respectively. We distinguish now between two cases.

First, let us assume that w is contained in K. Since m is not contained in K, and w can only be connected to two men, it follows that the degree of w in K is at most (and hence exactly) 1. Since each connected component of MsMopt is either a cycle or a path, this implies that K is a path with w being one of its endpoints.

Since f blocks MsH and the partner of m under MsH is Mopt(m), we know that m prefers w to Mopt(m). But as Ms is stable, m must prefer Ms(m) to w.

Notice now that w is unmatched either in Ms or in Mopt. However, as f blocks MsH (where w is matched as in Ms) but does not blockMs(HK) (where w is matched as in Mopt), it must be the case that w is matched by Mopt but is unmatched in Ms. Further, as f is not blocking in Ms(HK) even though m prefers w to Mopt(m), we get that w prefers Mopt(w) to m. This proves that f has type A.

Second, let us assume that w is contained in a connected component K of H. As in the previous case, we quickly get that K must be a path, with w being an endpoint of K. Since f blocks MsH, we know that w is matched by Ms but is unmatched by Mopt. The stability of Ms implies also that w prefers Ms(w) to m.

Regarding m, the fact that f blocks MsH implies that m prefers w to Ms(m). However, since f ceases to be blocking in Ms(HK), we get that m prefers Mopt(m) to w. This proves that f has type B.

We are now ready to present our algorithm, which is a branching algorithm: throughout its course, we make several “guesses” for which all possibilities have to be explored. When certain guesses turn out to be trivially wrong, such guesses are discarded, and we might not explicitly mention this in the algorithm. (In Step 1, we describe such issues in detail for illustration, but later we omit them.) Phases I and II consist of Steps 1-5 and Steps 6-8, respectively.

Step 1: Guessing the first edges of feminine augmenting paths First, for each wW0 with |L(w)|=2, we guess the edge of Mopt incident to w. This results in at most 2|W0| possibilities, all of which must be explored. Naturally, we discard those guesses where the edges {w,Mopt(w)}, wW0, do not form a matching. From now on we assume that we know Mopt(w) for each wW0.

Additionally, we delete those edges {m,w} for which wW0 and w prefers Mopt(w) to m. Such edges are neither needed in Mopt, nor can they block any matching that contains all the edges {w,Mopt(w)}, wW0, guessed in this step.

Before proceeding to Step 2, we state an important lemma about augmenting paths.

Lemma 4

Each connected component of MsMopt that is not a cycle is an augmenting path. Further, assume that Step 1 has already been performed, and K1 and K2 are connected components of MsMopt such that K1 relies on K2 via a dependent edge f. Then

  1. if f has type A, then K2 is a masculine path and not a feminine path;

  2. if f has type B, then K1 is a feminine path and not a masculine path, and K2 is either a cycle or a feminine path.

Proof

We begin by proving the first sentence of the lemma. Let us first suppose that Q is a connected component of MsMopt that is not a cycle (thus is a path) but is not an augmenting path. The feasibility of Mopt implies that if Q has a distinguished person p as its endpoint, then p must be unmatched by Ms. This means that Q can only be non-augmenting if neither of its endpoints is distinguished. This implies that MQ:=MoptQ is a feasible matching. Recall that b is the number of blocking pairs Mopt admits. If MQ admits at most b blocking pairs as well, then this contradicts the choice of Mopt, because there are strictly less edges in MsMQ than in MsMopt.

Hence, MoptQ admits at least b+1 blocking pairs. Since Q is a maximal path in MsMopt and Ms is stable, Proposition 1 implies that there must be an edge along Q that blocks Mopt. Obviously, there is no edge on Q that blocks Ms, since Ms is stable. Hence, modifying Mopt by switching the edges of Ms and Mopt along Qdecreases the number of blocking edges among the edges ofQ. However, the same operation increases the total number of blocking pairs (from b to at least b+1), thus we get that there must exist at least two edges that become blocking only as a result of this switch along Q. In other words, there exist at least two edges that are blocking in MoptQ but are not blocking in Mopt. By Lemma 3 we obtain that these edges must be dependent edges relying on Q.5 By the definition of a type A edge, at most one type A edge can rely on Q (as only one endpoint of Q can be a woman unmatched by Ms, and this woman may be incident to at most one edge outside Q), so we get that at least one of these dependent edges relying on Q must have type B.

Let us call the man endpoint of a type B dependent edge a joiner; by the previous paragraph, Q contains at least one joiner. Our aim is to fix an “outer-most” joiner m on Q. However, for technical reasons we also have to take into account a special case where some man m lying on Q, called the looper for Q, fulfils the following properties: (i) one endpoint of Q is a woman w that is adjacent to m in G but prefers Ms(w) to m, and (ii) m prefers w to Ms(m) but prefers Mopt(m) to w.6 Now, we choose a man m that is either a joiner or the looper for Q so that the following holds: if m splits Q into two subpaths Q1 and Q2 with Q1 containing Mopt(m), then V(Q1)\{m} contains neither joiners nor the looper for Q.

Case for a Joiner First, let us assume that m is a joiner. In this case, there might be several women who form a dependent edge of type B with m, so let w denote the one that is most preferred by m. Let f be the edge {m,w}, and let P be the path of MsMopt that has w as its endpoint. We illustrate these concepts in Fig. 6.

Fig. 6.

Fig. 6

The joiner m splits Q into subpaths Q1 and Q2. Here and in later figures, double lines denote edges of Ms. Single lines denote edges of Mopt, and dashed lines are for dependent edges

We claim that Mf=Mopt(Q1{f})=(MoptQ1){f} is an optimal solution. Observe that MsMf can be obtained from MsMopt by deleting Q and substituting P by the path P+f+Q2 where the plus sign means concatenation. Let x denote the endpoint of Q1 that is not m. First, Mf is clearly feasible, since x is not distinguished (by our assumption that Q is non-augmenting). Next, suppose that some edge e is blocking in Mf but is not blocking in Mopt. It is easy to see that by our choice of  we cannot be incident to w or m. As only vertices in Q1{f} are matched differently in Mf as in Mopt, we obtain that one endpoint of e must lie on Q1. Using the stability of Ms, we also get that the other endpoint of e must lie either on a connected component of MsMopt other than Q or on Q2. In the former case, Lemma 3 implies7 that e is a dependent edge. By our choice of m, e cannot be of type B, hence by Lemma 3, e must have type A, and thus it is incident to x which must be a woman not covered by Ms. In the latter case, supposing that the man endpoint m of e lies on Q1 we quickly get that it must be the looper for Q. To see this, first note that the only woman that m can be adjacent to on Q2 must be the common endpoint of Q2 and Q (by ΔW2); let w denote this woman. Second, since e blocks Mf but it does not block Mopt, we know that m prefers w to Ms(m), but prefers Mopt(m) to w. Third, since m prefers w to Ms(m), the stability of Ms implies that w is matched by Ms and w prefers Ms(w) to m. Hence, m is indeed the looper for Q, contradicting our choice of m. Thus, we know that it must be the woman endpoint of e that lies on Q1. Since the two endpoints of Q1 are mM and x, by ΔW2 we obtain that the woman endpoint of e lying on Q1 can only be x, which therefore must be a woman not covered by Ms. In either case, we can conclude that there can only exist at most one such edge e (because x has degree at most 2 in G). So the number of edges that are blocking in Mf but not blocking in Mopt is at most one.

Furthermore, since f is a dependent edge of type B, by definition we know that m prefers y=Mopt(m) to Ms(m), and hence, y must prefer Ms(y) to m (as otherwise {m,y} would be blocking in Ms, which is not possible). Note that, in particular, Ms(y) exists and Q1 contains at least two edges. By Proposition 1, Q1 must contain at least one edge that blocks Mopt, and this edge is not blocking in Mf, simply because any edge of Q1 that blocks Mopt but be an edge contained in Ms and hence in Mf. Thus, the number of edges blocking Mf cannot be more than b. Hence, Mf is an optimal solution such that there are less edges in MsMf than in MsMopt, a contradiction. This proves the first statement of the lemma for the case of m being a joiner.

Case for a Looper Let us now assume that m=m is the looper for Q. In this case let f be the edge connecting m to the woman endpoint w of Q that is matched by Ms; it is easy to see that w is the endpoint of Q2 as well. See Fig. 7 for an illustration. Let us again define Mf=Mopt(Q1{f}). As in the previous case, it is immediate that Mf is feasible. Arguing similarly as before and using that Q1 does not contain any joiners, we get that any edge that blocks Mf but does not block Mopt can only be a type A dependent edge incident to the (woman) endpoint x of Q1 that is not m. Hence, there can be at most one edge blocking Mf but not Mopt. From this point on, we can use the same reasoning as in the previous case to arrive at the conclusion that Mf is an optimal solution that has more edges common with Ms than Mopt, a contradiction. This proves the first statement of our lemma.

Fig. 7.

Fig. 7

The looper m of Q splits Q into subpaths Q1 and Q2

Let us prove (b) now. Suppose that K1 and K2 are two connected components of MsMopt such that K1 relies on K2 via an edge f={w,m} of type B. By the definition of a type B edge, we know that K1 is a path with an endpoint that is a woman covered by Ms, so its other endpoint is either a woman not covered by Ms, or a man covered by Ms. Thus, K1 cannot be a masculine path, so by the first statement of the lemma, it is feminine. It remains to show that if K2 is a path, then it is feminine. Assume for contradiction that K2 is a non-feminine path Q in MsMopt and some other path P in MsMopt relies on Q via a type B edge f. In this case we can argue exactly as above to show that there must exist an optimal matching Mf (defined the same way as we did while proving the first statement of the lemma) for which MsMf contains less edges than MsMopt, a contradiction.

To show (a), suppose that K1 and K2 are two connected components of MsMopt such that K1 relies on K2 via an edge f={w,m} of type A. By the definition of a type A edge, the woman endpoint w of f is unmatched in Ms, and K2 is a path that has w as an endpoint. Also, m is the second choice of w and Mopt(w) is the first choice of w. Hence wW0 is not possible, as in that case the edge f would have been deleted in Step 1 of the algorithm. Furthermore, since K2 is an Ms-alternating path with an endpoint in W0, the other endpoint of K2 cannot be a woman in W0. Hence, K2 is not a feminine augmenting path. Since we already know that K2 is an augmenting path, (a) follows.

By Lemma 4, each connected component in MsMopt that is a path must be an augmenting path; we let Pxopt denote the augmenting path in MsMopt that contains some xW0M0 as an endpoint.

Consider now any woman wW0. Let us define a candidate path for w as an augmenting path that starts through the edge {w,Mopt(w)}. Observe that Pwopt itself is a candidate path for w. Furthermore, although we cannot determine Pxopt directly, Proposition 3 implies that there exists a unique maximal candidate path Aw for w that contains Pwopt as a subpath. We can compute Aw easily: starting from the edge {w,Mopt(w)}, we can build Aw by adding edges of Ms and edges not in Ms in an alternating manner, always appending a new edge to the last vertex of the current subpath of Aw. Observe that after an addition of an edge of Ms, the resulting subpath of Aw ends at a woman, and thus ΔW2 implies that there exists at most one edge that we can add to our path. This shows the uniqueness of Aw.

Step 2: Finding cycles in MsMopt We make one more guess for each wW0 by guessing whether Pwopt relies on some cycle of MsMopt or not; this again yields 2|W0| possibilities. If Pwopt relies on some cycle C, then by Proposition 3, both Pwopt and C can be found in time O(|Pwopt|+|C|) as follows. We compute the longest possible candidate path Aw for w. Since Pwopt relies on cycle C, the last person on Aw must be a woman x incident to an edge {x,m} for which m is already on Aw. Then the subpath of Aw between m and x together with the edge {x,m} form the cycle C. For an illustration, see Fig. 8.

Fig. 8.

Fig. 8

Step 2 of the algorithm for Theorem 11, for finding cycles in MMopt

Lemma 5

Assuming that the guesses made by the algorithm are correct, all cycles in MsMopt and all paths relying on some cycle in MsMopt are found in Step 2.

Proof

Let C be a cycle in MsMopt. By the stability of Ms, no edge of C blocks the matching MoptC. Since MoptC has more edges in common with Ms than Mopt does, we know by the choice of Mopt that there must be an edge incident to C that is blocking in MoptC but is not blocking in Mopt. By Lemma 3, such an edge must be a dependent edge e relying on C. This proves that there are no cycles in MsMopt without augmenting paths relying on them.

By Lemma 4 we know that dependent edges of type A rely on (masculine) paths,8 so e must have type B. From this, Lemma 4 yields that all paths relying on a cycle must be feminine paths. Hence, Step 2 indeed finds all paths that rely on some cycle, together with the cycles that these paths rely upon, which (as pointed out above) means that Step 2 finds all cycles of MsMopt, proving our claim.

Step 3: Finding neutral paths In this step, for each wW0 we guess whether w lies on a neutral path in MsMopt, yielding at most 2|W0| possibilities. Clearly, if w lies on a neutral path, then by Proposition 3, Pwopt is the maximal candidate path starting with the edge {w,Mopt(w)}, that is, Pwopt=Aw.

Step 4: Finding feminine paths relying on other feminine paths In this step, we find all feminine paths that rely on some other feminine path; note that feminine paths that do not depend on other feminine paths will be taken care of by Step 5.

In Step 4, we first guess for each wW0 whether Pwopt relies on another feminine path, and if so, we also guess on which one. This means at most |W0| possibilities for each wW0, a total of |W0||W0| possibilities.

Supposing that, according to our guesses, Pwopt relies on Pyopt for some w and y in W0, we can find Pwopt easily as follows. Consider the maximal candidate paths Aw and Ay for w and y, respectively. We know that Pwopt and Pyopt are disjoint, but supposing that our guesses were made correctly, Lemma 4 implies that they are connected by a dependent edge f of type B relying on Pyopt. Hence, Aw contains Pwopt, followed by the dependent edge f connecting Pwopt and Pyopt, followed possibly by a suffix of Pyopt. Thus, by Proposition 3Aw and Ay must share the man endpoint m of f as their first common vertex, and they coincide after m. Therefore, Pwopt can be obtained by deleting all edges incident to or occurring after m on Aw. This way, f and Pwopt can be found in O(|Pwopt|+|Pyopt|) time.

Notice that this method only enables us to locate Pwopt but not Pyopt; we only know that Pyopt must contain the man m incident to f, but we do not know where Pyopt ends. To remind us that Pyopt contains m, we store m as an obligatory man for y.

Step 5: Finding all remaining feminine paths In this step, we find all feminine paths that rely neither on a cycle, nor on another feminine path. To do so, we will use a surprisingly simple method. Intuitively, it makes sense to construct augmenting paths to be as short as possible, since the longer such a path gets, the more opportunities arise for a blocking pair to appear along the way. This intuition is almost entirely correct, if no other path (or cycle) relies on the augmenting path Pwopt we are looking for: it turns out that Pwopt is either indeed the shortest possible, or if this is not the case, then we can “get rid of” only one blocking pair by constructing a longer augmenting path—and this, too, we can keep as short as it is possible, by stopping whenever we encounter a decrease in the number of blocking pairs along the augmenting path. In the case when some other path relies on Pwopt, we need to be somewhat more careful, and take into account the obligatory men defined in Step 4.

After this high-level explanation, let us define Step 5 formally. Let Wr be the set of those women wW0 for which Pwopt has not been found yet (that is, where Pwopt is not neutral, and it does not rely on any other path or cycle in MsMopt). Let us fix any woman wWr. With any candidate path Q for w, we associate a matching MQ=(MoptPwopt)Q; we can think of MQ as the matching that results from replacing Pwopt with Q in the symmetrical difference of Ms and the solution. Let us state a few useful properties of candidate paths and their associated matchings.

Proposition 4

The following holds for any candidate path Q for w:

  1. MsQ is a matching.

  2. MQ is a feasible matching.

  3. Q must be one of the following two forms:
    • (i)
      Q ends at a man in M0, in which case Q=Aw=Pwopt, or
    • (ii)
      Q ends at a non-distinguished woman.

Proof

Recall that the definition of an augmenting path (see the beginning of Sect. 6) directly requires that MsQ be a matching, proving (a). This immediately implies that if Q ends at a man, then this man cannot be matched by Ms, from which Q=Aw and thus Q=Pwopt follows. Using again the definition of an augmenting path, we get that the last person on Q is not distinguished (because Pwopt is not neutral by Step 3), showing (c).

To see that MQ is a matching, let K-w denote the union of all connected components of MsMopt except for Pwopt. Then MoptPwopt=MsK-w is a matching. But as K-w is vertex-disjoint from Q, from (a) we get that MQ=(MsK-w)Q must be a matching too. The properties of Q described in (c) show also that MQ is feasible.

Now, we define two candidate paths for w as follows:

  • First, we let Qw1 be the shortest candidate path for w that contains all obligatory men for w. In particular, if there are no obligatory men for w, then Qw1 is the shortest candidate path for w; see Fig. 9 for an illustration.

  • Second, let Qw2 be the shortest candidate path containing Qw1 such that MsQw2 admits less blocking pairs than MsQw1. Such a path, however, may not exist, in which case we leave Qw2 undefined.

Fig. 9.

Fig. 9

An example of the paths Qw1 for three women w{w1,w2,w3}Wr, as defined in Step 5. The man miobl for each i{1,2,3} is the last obligatory man for wi on the maximal augmenting path Awi. In cases where there is no obligatory man for wi, one can identify miobl with Mopt(wi) to get an appropriate figure

Lemma 6

If Pwopt does not rely on any other path or cycle in MsMopt, then either Pwopt=Qw1 or Pwopt=Qw2.

Proof

First observe that for any wWr, if the guesses made by the algorithm are correct, then Pwopt contains Qw1 as a subpath. To see this, recall that if the guesses made in Step 4 of the algorithm are correct, then Pwopt indeed must contain all obligatory men for w. Since Pwopt is a candidate path for w, it indeed must contain Qw1.

Next, suppose that PwoptQw1, and consider the matching M1:=MQw1. By Proposition 4, M1 is a feasible matching, and PwoptQw1 implies that Qw1 ends at a non-distinguished woman x.

Claim 2

Let Q be a candidate path for w such that Qw1QPwopt. If e is an edge blocking in M1 but not blocking in MQ, then e is adjacent to x.

Proof of Claim 2

Suppose for contradiction that e is not incident to x. First note that e must be adjacent to a person in V(Q)\V(Qw1), as all other persons (except for x) have the same partner in M1 as in MQ. Second, as Ms is stable, at least one endpoint of e must be matched differently in M1 than in Ms. Thus, e must connect a person in V(Q)\V(Qw1) either (i) with a connected component of K-w, denoting the union of all connected components of MsMopt except for Pwopt, or (ii) with Qw1.

In case (i), e must be blocking in MsK-w (as e blocks M1). As e is not blocking in MQ=Ms(K-wQ), it is not blocking in Mopt=Ms(K-wPwopt) either (because any person in V(Q)\V(Qw1) has the same partner in MQ as in Mopt, except possibly for the last person on Q who might be left unmatched in MQ). Therefore, Lemma 3 implies that e is a dependent edge relying on Pwopt. By Lemma 4, only feminine paths may rely on Pwopt. However, in Step 4 we have stored the man endpoint of all edges that connect Pwopt with a feminine path relying on Pwopt as an obligatory man, so assuming correct guesses in Step 4, e must have an obligatory man as its endpoint. But Qw1 contains all the obligatory men for w, which contradicts our assumption of case (i).

In case (ii), let we and me be the woman and man endpoint of e, respectively; we assumed wex. By ΔW2, we can only be adjacent to both V(Q)\V(Qw1) and V(Qw1) if either we=w, or Q and also Pwopt ends at we. In the former case, meV(Pwopt)\V(Qw1), yielding M1(me)=Ms(me). As e blocks M1, me prefers w to Ms(me); however, w is not matched in Ms, so this means that e blocks Ms as well, a contradiction. In the latter case, me lies on Qw1, yielding M1(me)=Mopt(me). As e blocks M1, me prefers we to Mopt(me); however, we is not matched by Mopt, so this means that e blocks Mopt as well, a contradiction. Hence the claim follows.

Let c1 denote the number of blocking pairs with respect to M1 that are incident to a man or woman on Qw1.

Claim 3

If Q is a candidate path for w such that Qw1QPwopt, and c is the number of blocking pairs with respect to MQ that are incident to a man or woman on Q, then cc1-1.

Proof of Claim 3

By Claim 2, cc1-2 can only happen if both edges incident to x are blocking in M1, and none of them is blocking in MQ. However, this cannot happen, as we are going to show now. Let m1=Ms(x) and m2=Mopt(x) be the two men in x’s preference list; note that Qw1 contains m1 but not m2. If both {x,m1} and {x,m2} are blocking in M1, then m1 prefers x to Mopt(m1), and m2 either prefers x to Ms(m2) or m2 is unmatched by Ms. Therefore the stability of Ms implies that x prefers m1 to m2, as otherwise {x,m2} would block Ms. But this shows that {x,m1} is a blocking pair in Mopt and thus in MQ as well, proving our claim.

Now, let copt denote the number of blocking pairs with respect to Mopt that are incident to a man or woman on Pwopt. By our assumption Qw1Pwopt, we get copt<c1, as otherwise M1 would also be an optimal solution which would contradict our choice of Mopt (as MsM1 contains less edges than MsMopt). Hence, Claim 3 implies copt=c1-1.

By the definition of Qw2, we know that Qw1Qw2Pwopt, and Proposition 4 yields that M2:=MQw2 is a feasible solution. The definition of Qw2 and Claim 3 together imply that the number of blocking pairs with respect to M2 that are incident to a man or woman on Qw2 is exactly c1-1. Hence, M2 is an optimal solution. Therefore, MsM2 cannot contain less edges than MsMopt, because assuming otherwise would contradict our choice of Mopt. From this, Qw2=Pwopt follows.

According to Lemma 6, we can find all remaining feminine paths inMsMopt by guessing for each wWr whether Pwopt equals Qw1 or Qw2. This means at most 2|W0| guesses; the computations needed for each guess take linear time.

Step 6: Computing elimination paths. Let F be the union of cycles, feminine and neutral paths found in Steps 1 to 5. When searching for masculine paths, we will have to deal with edges that might be type A dependent edges in the optimum solution. We call an edge volatile if it connects a woman in W0 with her second choice. The importance of this definition is shown by the following two lemmas.

Lemma 7

Let f be an edge that is blocking in MsF, but not blocking in Mopt. Then f is volatile, its woman endpoint is contained on a non-feminine path of MsMopt, and its man-endpoint is contained in F.

Proof

Observe that since f does not block Mopt, there must exists a connected component Q of MsMopt not in F such that f does not block Ms(FQ). Clearly, Q is a masculine but not feminine augmenting path by the definition of F. Lemma 3 then implies that f is a dependent edge relying on Q, and Lemma 4 yields also that f has type A and Q is masculine and not feminine. The remaining statements follow from the definition of a type A edge.

Lemma 8

If f is a volatile edge incident to some non-feminine path in MsMopt, then f is not blocking in Mopt.

Proof

Recall that Mopt is an optimal solution for which MsMopt has as few edges as possible, and there does not exist another optimal solution M such that (i) M has the same number of common edges with Ms as Mopt, and (ii) for each man  m, either M(m)=Mopt(m) or m prefers M(m) to Mopt(m).

Suppose for the sake of contradiction, that f is a volatile edge incident to a masculine path Pxopt in MsMopt for some xM0, and f blocks Mopt. Let m and w be the man and woman connected by f.

Since m is the second choice of w and f is blocking in Mopt, we know that Mopt does not cover w. However, any woman on a masculine augmenting path is matched by Mopt with a man adjacent to her on this path, so w does not lie on Pxopt. Therefore, m lies on Pxopt.

Define P as the subpath of Pxopt from x to m plus the edge f. Consider now Mf=Mopt(PxoptP); Mf is a matching because wW0. Clearly, Mf is feasible, since Pxopt is not a neutral path.

Claim 4

If f is an edge that blocks Mf but does not block Mopt, then Pxopt ends at a woman y, and f is a volatile edge incident to y.

Proof of Claim 4

Let w and m be the woman and man connected by f. The only persons that are matched differently in Mf than in Mopt are those in (V(Pxopt)\V(P)){m,w}; recall that f={m,w} with wW0. Since both m and w are better off in Mf than in Mopt, and f blocks Mf but not Mopt, we get that one endpoint of f must be in V(Pxopt)\V(P).

Suppose first that mV(Pxopt)\V(P). Then Mf(m)=Ms(m) and since f blocks Mf, we know that m prefers w to Ms(m). But Ms is stable, so w prefers Ms(w) to m, and in particular is matched by Ms. As f blocks Mf, we get that Mf(w)Ms(w). Hence, as ww (because wW0 but wW0), it must be the case that Mf(w)=Mopt(w) and w is on a connected component of K-x, denoting the union of all connected components of MsMopt other than Pxopt. This implies that f is blocking in MsK-x as well. Since f is not blocking in Mopt=Ms(K-xPxopt), Lemma 3 implies that f must be a dependent edge relying on Pxopt. Note that since mV(Pxopt), f cannot be of type A (by the definition of a type A edge), so it must be of type B. However, Lemma 4 tells us that a type B edge relies either on a cycle or on a feminine path, but as Pxopt is neither of the two, we arrive at a contradiction.

Thus, we get wV(Pxopt)\V(P). Observe that m=m is not possible, because it would imply f={m,Mopt(m)} contradicting the assumption that f blocks Mf (note that m prefers w to Mopt(m) because f blocks Mopt). From this we obtain that f cannot be contained in Pxopt: we have fMf by definition, and fMopt is also not possible, since in that case mV(Pxopt)\V(P) would imply m=m. Thus, by ΔW2 we know that w=y, and since f blocks Mf but not Mopt, we also get that m must be the second choice of w. Hence f is volatile, proving our claim.

By Claim 4, there can be at most one edge that is blocking in Mf but not in Mopt. Since f is an edge that blocks Mopt but not Mf, we get that Mf is an optimal matching. Moreover, either Mf has more common edges with Ms than Mopt, or m is the last man on Pxopt, in which case every man has the same partner in Mf as in Mopt except for m who is better off in Mf than in Mopt. This contradicts our choice of Mopt.

For any volatile edge f we can decide in linear time if there exists a masculine augmenting path disjoint from F that contains the woman endpoint w of f, but not f itself. Indeed, we can build such a path starting from w by taking edges not in Ms and edges in Ms in an alternating manner; by ΔW2 and since we need to start with an edge different from f, we always have at most one possibility to pick our next edge. This process may or may not result in a masculine augmenting path, but if it does, then the path is unique, proving the following claim.

Proposition 5

Let f be a volatile edge. If there exists a masculine augmenting path disjoint from F that contains the woman endpoint w of f but not f itself, then this path is unique; we denote it by Qfelim.

Let f be a volatile edge that is blocking in MsF. We say that a set Pf of masculine augmenting paths eliminates f if (i) Qfelim exists and QfelimPf, and (ii) for any path QPf, if there is a volatile blocking edge f in MsQ, then Qfelim exists and is contained in Pf. We refer to the (inclusion-wise) minimal set of masculine paths eliminating f as the elimination paths for f, and denote it by Pfelim. Further, we refer to the starting vertices of these paths as the elimination set for f. The next lemma illuminates the role of elimination paths.

Lemma 9

If f is an edge blocking in MsF but not blocking in Mopt, then MsMopt contains all paths in Pfelim.

Proof

By Lemma 7, the woman endpoint w of f lies on a masculine path. By Proposition 5, this path can only be Qfelim, and thus Qfelim must be contained in MsMopt. For an inductive reasoning, assume that Q is a masculine path in Pfelim that is contained in MsMopt and f is a volatile edge that is blocking in MsQ. We claim that Qfelim is contained in MsMopt, which by induction proves our lemma.

To see our claim, note that by Lemma 8, f cannot be blocking in Mopt. Since the woman endpoint of f is unmatched by Ms, it can only be blocking in MsQ if its man endpoint lies on Q. Thus, since f is not blocking in Mopt (but is blocking in MsQ), it must be the case that its woman endpoint lies on a masculine path in MsMopt. Since such a path can only be Qfelim by Proposition 5, we get that QfelimPfelim and the lemma follows.

Step 7: Guessing relevant elimination sets inMopt We call an edge relevant in Mopt, if it is a volatile edge blocking MsF, but it does not block Mopt. By Lemma 9, if f is a relevant edge in Mopt, then MsMopt must contain all paths in Pfelim. Since there may be several volatile edges blocking in MsF, we cannot determine the relevant ones among them by simply guessing them. Instead, we only guess the elimination sets for all relevant edges. Clearly, these sets must be pairwise disjoint subsets of M0, so guessing them results in at most (|M0|+1)|M0| possibilities. Let us denote by R1,,R the guessed elimination sets.

Step 8: Computing cheapest elimination paths For each set RiM0 with i=1,, that, according to our guesses made in Step 7, forms the elimination set for a volatile edge relevant in Mopt, we determine some volatile edge f incident to F that is blocking in MsF and whose elimination set is exactly Ri. Namely, we pick an edge f among all such edges in a way that the number of blocking pairs in Ms(FPfelim) is as small as possible. Let fi be the volatile edge chosen this way, and let Pelim=1iPfielim.

Step 9: Computing remaining masculine paths We define Mr=M0\(R1R) as the set of distinguished men that are neither covered by Ms nor contained in any of the sets R1,,R. For each such m we are going to compute an augmenting path Pm disjoint from F such that the number of edges that block Ms(FmMrPr) but not MsF is minimized. We set Pr={PmmMr}.

To compute Pr, we use the algorithm of Theorem 8 with some modifications.

Step 9.1 We compute all augmenting paths that start at a man mMr and are disjoint from F. For each such augmenting path P we define a set C(P) containing those edges that block Ms(FP) but not MsF, and are either non-volatile or have a woman endpoint in F; we define the contributing cost of P as |C(P)|.

Step 9.2 We construct the auxiliary graph Gpath=(U,V;E) as follows: we set U=Mr and V=W0{mmMr}. The edge set E contains an edge {m,m} for each mU, as well as an edge {m,w} whenever mU, wW0 and there exists an augmenting path disjoint from F with endpoints m and w. We define the weight of an edge {m,m} as the minimum contributing cost cmmin of any augmenting path starting at m and not ending in W0, and we define the weight of an edge {m,w} with mU and wW0 as the minimum contributing cost of any augmenting path with endpoints m and w, disjoint from F.

Step 9.3 We compute a minimum weight matching MP in Gpath covering U the same way as in the algorithm of Theorem 8; let P denote the set of augmenting paths corresponding to the edges of the matching MP. Note that the paths in P are pairwise disjoint, by the construction of Gpath and because MP is a matching in Gpath.

Step 9.4 We eliminate all volatile edges that block Ms(FP) but not MsF and are not incident to F. We modify P iteratively. We start by setting Pact=P. At each iteration we modify Pact as follows. We check whether there exists a volatile edge {m,w} with wW0 that is not incident to F, and blocks Ms(FPact) but not MsF. If yes, then notice that w is not matched in Ms(FPact), because m is the second choice for w. Let P be the path of Pact containing w. We modify Pact by truncating P to its subpath between its starting vertex and m, and appending to it the edge {m,w}. This way, {m,w} becomes an edge of the matching Ms(FPact). The iteration stops when there is no volatile edge disjoint from F blocking Ms(FPact) but not MsF. Note that once a volatile edge ceases to be blocking in Ms(FPact), it cannot become blocking again during this process, so the algorithm performs at most |W0| iterations. For each mMr, let Pm denote the augmenting path in Pact covering m at the end of this step; we set Pr:={PmmMr}.

Step 9.5 Finally, we output the matching Mout=Ms(FPelimPr).

It is straightforward to verify that the number of guesses made are bounded by a function of |W0|+|M0|, and all computations in a branch can be performed in time polynomial in the size |I| of the instance, yielding a fixed-parameter algorithm with parameter |W0|+|M0|. It remains to prove the correctness of the proposed algorithm.

To this end, we first prove a simple observation.

Proposition 6

Suppose ΔW2. Let M be a matching and KM the set of connected components in MsM. Let also H1 and H2 be two disjoint subsets of KM. Then there is no edge that blocks both MsH1 and MsH2

Proof

Suppose that e blocks both M1:=MsH1 and M2:=MsH2; by the stability of Ms, e connects a person a1 in H1 with a person a2 in H2. Since e blocks M1, we know that a2 prefers a1 to its situation in Ms. Since e blocks M2, we also get that a1 prefers a2 to its situation in Ms. This contradicts the stability of Ms.

Next, let us prove that Step 9 works as promised.

Lemma 10

For each mMr let Pm be an augmenting path disjoint from F and starting at m, and let Pr={PmmMr}. Then the number of edges that block Ms(FPr) but not MsF is at most the number of edges that block Ms(FPr) but not MsF.

Proof

Let c be the number of edges that block Ms(FPr) but not MsF. Then Claim 5 implies that there can be at most c edges in mMrC(Pm).

Claim 5

If e is an edge such that eC(Pm) for some mMr, then e blocks Ms(FPr) but not MsF.

Proof

Let m and w be the man and woman connected by e. By eC(Pm) it does not block MsF, so we only need to show that e blocks Ms(FPr). Suppose for contradiction that e does not block Ms(FPr). Then it must clearly be adjacent to some path Px, xMr. By ΔW2 we know that w is the endpoint of one of these paths, wW0, and since e blocks Ms(FPm) but not Ms(FPr) we also get that m must be the less preferred choice of w; this yields that e is volatile. However, as e is not incident to F (because it connects Pm and Px), this contradicts eC(Pm).

Let m1 and m2 be two distinct men in Mr; we will show C(Pm1)C(Pm2)=. Assuming otherwise, let e be an edge in C(Pm1)C(Pm2). Then e does not block MsF but blocks both Ms(FPm1) and Ms(FPm2). Hence e connects Pm1 with Pm1, and thus blocks MsPm1 and MsPm2 as well, contradicting Proposition 6. Thus,

mMrC(Pm)=mMr|C(Pm)|c.

Then, by the definition of edge-weights in Gpath, we get that there exists a matching M in Gpath with weight at most mMr|C(Pm)|c that covers U=Mr. Thus, the matching computed by the algorithm in Step 9.3 has weight at most c as well, yielding that the set Pr of augmenting path corresponding to this matching is such that mMr|C(Pm)|c, that is, their total contribution cost is at most c. From this, Claim 6 below implies that there can be at most c edges that block Ms(FPr) but not MsF.

Claim 6

If an edge e blocks Ms(FPr) but not MsF, then eC(Pm) for some mMr.

Proof

Let m and w be the man and woman connected by e. Clearly, e is adjacent to some path in Pr.

First, suppose that e is adjacent to only one path Pm where mMr. Then e must block Ms(FPm) as well. In that case, to prove eC(Pm) we only need to show that either w is in F or is e is non-volatile. Suppose for contradiction that e is volatile and w is not in F. However, as a result of Step 9.4, there can be no volatile edge that blocks Ms(FPr), unless it is incident to F. Hence, we must have that m is in F, and since e blocks Ms(FPm), we get that m prefers w to its partner in Ms(FPm), which is the same partner he has in MsF. However, this yields that e blocks MsF as well: since wW0 and w is not in F, she is unmatched in MsF. Hence, we arrive at a contradiction, proving eC(Pm).

Second, suppose that e connects two paths Pm1 and Pm2 where m1 and m2 are distinct men in Mr. By ΔW2, we know that w is an endpoint of one of these paths; without loss of generality, we may assume that w is an endpoint of Pm1. Since Pm1 is a masculine augmenting path, we get wW0. Now, we know that e blocks Ms(FPm1Pm2), so it must also block Ms(FPm2), because w is unmatched in Ms(FPm2) and m has the same partner in Ms(FPm2) as in Ms(FPm1Pm2). Again, e cannot be volatile as a result of Step 9.4, yielding that e is contained in C(Pm2).

This proves the optimality of Pr as stated by the lemma.

Next we state the following useful lemma.

Lemma 11

Let f be a volatile edge blocking in MsF, Q an elimination path in Pfelim, and Q a non-feminine augmenting path not contained in Pfelim, disjoint from F. Let e be an edge. Then e blocks Ms(QQ) if and only if it blocks MsQ or MsQ.

Proof

First observe that the statement of the lemma is obviously true for any edge e that is incident to at most one of Q and Q. So suppose that e connects Q with Q. Since both Q and Q are masculine augmenting paths and ΔW2, by Proposition 3 we know that e connects the woman endpoint w of one of these paths with a man m on the other path; moreover, w must be unmatched by Ms as it is the endpoint of a masculine augmenting path. Let Qw be the path (either Q or Q) that contains w, and let Qm be the one containing m. By wW0 and the stability of Ms, e cannot be blocking in MsQw.

Now, if e blocks Ms(QmQw), then it blocks MsQm as well, since m prefers w to its partner in MsQm and w is unmatched in MsQm.

It remains to show that if e blocks MsQm, then it also blocks Ms(QwQm). Supposing otherwise, it must be the case that (i) m prefers w to its partner in MsQm, but (ii) w prefers its partner in MsQw to m. Consequently, e is a volatile edge.9 We distinguish two cases.

Case (A)Qw=Q. Then Q must be the unique masculine augmenting path containing the woman endpoint of e but not e itself, that is, Q=Qeelim. Hence, since e is a volatile edge blocking MsQ and QPfelim, by the definition of elimination paths we get QPfelim as well, a contradiction.

Case (B)Qm=Q. Then Q contains the man endpoint of e. However, again by the definition of elimination paths, as Q is a path of Pfelim, the man endpoint of e must be contained either in F (if e=f) or another path of Pfelim that triggered the addition of Q into Pfelim; both possibilities contradict our conditions on Q.

Now we are ready to show that our algorithm is correct.

Proof of Theorem 11

To prove the correctness of the proposed algorithm, we first show that if all our guesses are true, then the paths and cycles in F are exactly the feminine paths and the cycles of MsMopt. The correctness of Step 2 is stated by Lemma 5. From the description of our algorithm, it should be clear that the correctness of Steps 3 and 4 follows directly from Proposition 3 and Lemma 4. Lemma 6 guarantees the correctness of Step 5, which proves that in Steps 1–5 the algorithm indeed finds all cycles and feminine paths of MsMopt.

Next, let us argue that Mout is indeed a matching. For this, apart from the correctness of Steps 1–5, we need that the masculine paths in MsMout are disjoint from F. Further, we also need that paths in Pelim are disjoint from all remaining masculine paths. To see this, observe that any path P in Pelim ends at a woman wW0 which is connected by a volatile edge (not on P) to either F or to another path in Pelim. Hence, w cannot lie on any masculine path other than P by Proposition 5. Thus, Mout is a matching. Its feasibility is implied by the correctness of Steps 1–5, and the definition of augmenting paths.

It remains to argue that Mout admits at most as many blocking pairs as Mopt. First, Lemma 7 implies that all edges blocking in MsF are either relevant volatile edges in Mopt, or they are also blocking in Mopt. Furthermore, if fiopt is a relevant volatile edge with elimination set Ri for some i{1,,}, then by Lemma 9 we know that all elimination paths in Pfioptelim must be contained in MsMopt. As F is the set of feminine augmenting paths and cycles of MsMopt, in Step 8 the algorithm is bound to find some volatile edge fi (though not necessarily fiopt) that is blocking in MsF and whose elimination set is Ri. Furthermore, by our choice of fi, there are at most as many blocking pairs in Ms(FPfielim) as there are in Ms(FPfioptelim).

Let the contribution of a volatile edge e, denoted by C(e), be the set of edges that block Ms(FPeelim) but not MsF; we extend this notion to any set E of volatile edges with pairwise disjoint elimination sets by defining the contribution C(E) of E as the set of edges that block Ms(FeEPeelim) but not MsF. By our choice of fi, we know |C(fi)||C(fiopt)|.

We are going to show

|C({fi1i})||C({fiopt1i})|,

which implies that Ms(F1iPfielim) has at most as many blocking pairs as Ms(F1iPfioptelim) does. To prove this, it suffices to prove the following claim.

Claim 7

Let F{f} be a set of volatile edges with pairwise disjoint elimination sets, F. Then |C(f)|+|C(F)|=|C(F{f})|.

Proof

We need to prove that any edge e blocks Ms(FPfelimfFPfelim) but not MsF if and only if it blocks exactly one of Ms(FPfelim) and Ms(FfFPfelim) but not MsF. So let us assume that e does not block MsF.

Notice that if e is incident to only one of Pfelim and fFPfelim, then our claim is immediate. So suppose that e connects a path QPfelim with a path QfFPfelim. Observe that it suffices to show that e blocks Ms(QQ) if and only if it blocks exactly one of MsQ and MsQ, because e cannot be incident to any connected component of FPfelimfFPfelim other than Q and Q. Now the claim follows directly from Lemma 11 and Proposition 6.

It remains to consider the blocking pairs contributed by the paths Propt:={PmoptmMr}.

Claim 8

If e is an edge that blocks Ms(FPropt) but not MsF, then e blocks Mopt but not MoptPropt.

Proof

Recall that by definition Mopt=Ms(FPropt1iPfioptelim) and MoptPropt=Ms(F1iPfioptelim), so if e does not have an endpoint in 1iPfioptelim, then the claim follows immediately.

So suppose that e is incident to a path QPfioptelim for some i{1,,}. As e blocks Ms(FPropt) but not MsF, the other endpoint of e must be contained in a path Pmopt for some mMr. Since Q and Pmopt are the only connected components of MsMopt that e is adjacent to, the condition of our claim yields that e blocks MsPmopt, and we need to show that e blocks Ms(QPmopt) but not MsQ. To see this, first notice that by Proposition 6, edge e cannot block MsQ, because Q and Pmopt are disjoint. Second, as e blocks MsPmopt, Lemma 11 implies that it must block Ms(QPmopt) as well, proving our claim.

Let cr be the number of those edges that block Mopt but not MoptPropt. Then Claim 8 implies that there are at most cr edges that block Ms(FPropt) but not MsF. Since Steps 9.1–9.4 calculate a set Pr={PmmMr} of augmenting paths that minimizes the number of edges that block Ms(FPr) but not MsF, we know that there are at most cr such edges. This in turn shows that there can be at most cr edges that block Mout but not MoutPr, as implied by Claim 9. This proves the optimality of Mout.

Claim 9

If e is an edge that blocks Mout but not MoutPr, then e blocks Ms(FPr) but not MsF.

Proof

Since Mout=Ms(FPrPelim) and MoutPr=Ms(FPelim), we have that if e does not have an endpoint in Pelim, then the claim follows immediately.

So suppose that e is incident to a path QPfielim for some i{1,,}. As e blocks Mout but not MoutPr, the other endpoint of e must be contained in a path Pm for some mMr. Since Q and Pm are the only connected components of MsMout that e is adjacent to, the condition of our claim yields that e blocks Ms(QPm) but not MsQ, and we only need to show that e blocks MsPm, which is directly implied by Lemma 11, proving our claim.

This finishes our proof of correctness for Theorem 11.

As each augmenting path contains at least one edge that blocks Mopt, the number of blocking pairs admitted by Mopt is at least (|W0|+|M0|)/2. Thus, we get Corollary 3.

Corollary 3

The special case of SMC where each woman finds at most two men acceptable (i.e., ΔW2) is fixed-parameter tractable for parameter b.

It remains to deal with the third among the parameterizations we have to consider. So let us turn our attention to the complexity of the SMC with ΔW2 where we take |W|+ΔM as the parameter.

Theorem 12

There is a fixed-parameter algorithm for the special case of SMC where each woman finds at most two men acceptable (i.e., ΔW2), and the parameter is |W|+ΔM, the number of distinguished women plus the maximum length of men’s preference lists.

It turns out that Theorem 12 can be proved by a modified version of the algorithm described above to prove Theorem 11. In fact, we start with applying Steps 1 to 6. However, we can no longer apply Step 7, because now |M| can be unbounded, and thus guessing the elimination sets would not yield a fixed-parameter tractable algorithm. To circumvent this problem, we rely on an observation stated by Lemma 12 which shows that “almost all” volatile edges that are blocking in MsF are relevant edges, and thus have to be eliminated. This allows us to efficiently guess the set of relevant volatile edges, leading us to a fixed-parameter tractable algorithm. Hence, instead of guessing only the elimination sets (that is, the man endpoints of the elimination paths) we can now guess the exact set of edges that the optimal solution eliminates, so in fact the modified algorithm can be viewed as a more simple approach.

Let Evol denote the set of all volatile blocking edges in MsF, and let {m,w}Evol for some man m. We say that {m,w} is loose, if

  • both Ms and Mopt assign a partner to m,

  • m prefers Ms(m) to w, and w to Mopt(m), and

  • Mopt(m) is not distinguished.

Lemma 12

All loose edges in Evol are relevant, and at most (ΔM-1)|W| edges in Evol are not loose.

Proof

First suppose that {m,w} for some man m is loose. Since {m,w} is volatile, we have that m is the less preferred man acceptable to w, and since {m,w} is blocking in MsF, we know that w is unmatched in MsF.

For the sake of contradiction, let us suppose that {m,w} is not relevant, meaning that it is still blocking in Mopt. In this case, w must be unmatched in Mopt too. We define a matching M obtained from Mopt by modifying only the partner of m to be M(m)=w and, i.e., M=(Mopt\{{m,Mopt(m)}}){{w,m}}. Observe that M is indeed a matching, because w was unmatched in Mopt. It is also feasible, because only Mopt(m) becomes unmatched by this modification, and Mopt(m) is not distinguished (by the definition of a loose edge). Furthermore, while {m,w} is not blocking in M, the only edge that might be blocking in M but not in Mopt is the edge adjacent to Mopt(m) but not to m, if existent (because both m and w are better off in M than in Mopt). Hence, M is also an optimal matching. It should also be clear that it has the same number of common edges with Ms as Mopt. Note also that each man has the same partner in M as in Mopt except for m who is better off in M than in Mopt. This contradicts our choice of Mopt, proving that {m,w} must indeed be relevant.

To prove the second part of the lemma, let us consider any edge {m,w}Evol with mM. Again, w must be unmatched in the matching MsF, since otherwise {m,w} would not block it (because m is the less preferred man in w’s preference list). By contrast, {m,w} cannot block Ms, which can be explained in three different ways, giving rise to the following three cases:

  • Case A: {m,w}Ms,

  • Case B: {m,w}Ms, but Ms(w) exists and is preferred by w to m, or

  • Case C: {m,w}Ms, but Ms(m) exists and is preferred by m to w.

In Case A, by {m,w}Ms, the edge {m,w} must be contained in an augmenting path of MsF, with w being an endpoint (since w is not matched in MsF). In Case B, Ms matches w to its first choice, say x, so the edge {w,x} must be contained in an augmenting path of MsF, with w being an endpoint. Thus, in both cases we know that w is an endpoint of a feminine augmenting path of F. However, Cases A and B exclude each other, because in Case A the augmenting path ending at w contains the edge connecting w to her second choice, while in Case B it connects w to her first choice. Since there are at most |W| feminine augmenting paths, it follows that the number of such edges {m,w}Evol where the conditions of Cases A or B hold is at most |W|.

In Case C, let us first observe that m gets matched in MsF. Indeed, if this were not the case, then m would be the man endpoint of a feminine augmenting path, with the last edge contained in Ms; however, this is not possible (simply because feminine paths start with women and with edges not in Ms). Because F is a collection of connected components of MsMopt, with m contained in F, it is clear that the partner of m in MsF is the same as his partner in Mopt. Thus, Mopt(m) exists, and since {m,w} blocks MsF, we know that m prefers w to Mopt(m). Therefore, either {m,w} is a loose edge, or Mopt(m) is distinguished; in the latter case, we say that {m,w}belongs to this distinguished woman.

Now, observe that all edges belonging to some woman zW are adjacent to Mopt(z), and Mopt(z) is adjacent to at least two edges not belonging to z: namely, the edges {Mopt(z),z} and {Mopt(z),Ms(Mopt(z))}. Hence, at most ΔM-2 edges may belong to z, implying that there are at most (ΔM-2)|W| edges in total belonging to distinguished women. Taking into account all three cases, we get that there are at most (ΔM-1)|W| edges in Evol that are not loose.

Let us now describe our algorithm proving Theorem 12 in detail. This algorithm starts with Steps 1 to 6 (as given for Theorem 11), and then applies Steps 7 and 8 below. The last step of our algorithm is Step 9 from the algorithm for Theorem 11.

Step7: Guessing the relevant edges To determine which edges among those volatile edges that block MsF are relevant, we first compute the set Eloose of all loose edges in Evol. Notice that when checking some edge {m,w}Evol, we already know Mopt(m): since m lies on a path or cycle of F, it gets matched in MsF to the same woman as in Mopt. Therefore, checking whether {m,w} is loose is straightforward.

After determining all loose edges (which are all relevant by Lemma 12), we guess the remaining set of relevant edges in Evol\Eloose. By Lemma 12, this yields at most 2(ΔM-1)|W| possibilities, and in the branch where our guess is correct, we obtain the set Erel of all relevant volatile edges blocking in MsF.

Step8: Computing cheapest elimination path This step is a simplification of Step 8 of the algorithm for Theorem 11. By Lemma 9, for each fErel the elimination paths in Pfelim (determined in Step 6) are all contained in MsMopt; let Pelim=fErelPfelim.

Step9: Computing remaining masculine paths Let Mr denote the set of distinguished men in M0 not covered by any of the elimination paths in Pelim. For each mMr we compute an augmenting path Pm disjoint from F such that the number of edges that block Ms(FPr) but not MsF is minimized, where Pr is the union of all paths Pm, mMr. We accomplish this with the exact same method as in Step 9 of the algorithm for Theorem 11. Finally, we output the matching Mout=Ms(FPelimPr).

Note that the number of guesses made in Steps 1 to 6 are bounded by a function of |W0|, and the guesses made in Step 7 result in at most 2(ΔM-1)|W| possibilities. Since all computations in a branch can be performed in time polynomial in the size |I| of the instance, we obtain a fixed-parameter algorithm with parameter |W|+ΔM. It remains to prove its correctness.

Proof of Theorem 12

The proof is a straightforward adaptation of our proof for Theorem 11. The only difference is that instead of finding some elimination paths that eliminate the necessary number of relevant volatile edges blocking in MsF, our algorithm now directly finds all of the relevant edges among those volatile edges that block MsF, together with the corresponding elimination paths; this is a consequence of Lemma 12 and the definition of Step 7. As Step 8 can also be viewed as a simplification of Step 8 as defined for the algorithm for Theorem 11, it can be verified that the exact same arguments that prove the correctness of Step 8 in our algorithm for Theorem 11 also imply the correctness of Step 8 for our algorithm for Theorem 12 in a straightforward manner.

Discussion

We provided a systematic study of the computational complexity of Stable Marriage with Covering Constraints. Our main result is a complete computational complexity trichotomy into polynomial-time solvable cases, NP-hard and fixed-parameter tractable cases, and NP-hard and W[1]-hard cases, for all possible combinations of five natural parameters:

  • |M|: the number of distinguished men,

  • |W|: the number of distinguished women,

  • ΔM: the maximum length of preference lists for men,

  • ΔW: the maximum length of preference lists for women, and

  • b: the number of blocking pairs allowed.

As a special case, we solved a problem by Hamada et al. [24].

Figure 10 provides a decision diagram showing that our results indeed fully determine the computational complexity of SMC with respect to the set S={b,|W|,|M|,ΔM,ΔW} of possible parameters. Going through this decision diagram should convince the reader that any parameterized restriction of SMC with respect to the set S is classified as either polynomial-time solvable (P) or NP-hard, and in the latter case, either fixed-parameter tractable (FPT), or W[1]-hard with the given parameterization (if any). In particular, when we provide parameterized results, this means that the parameterized restriction of SMC in question is NP-hard without parameterization.

Fig. 10.

Fig. 10

Decision diagram for determining the complexity of SMC. We remark that if a certain restriction of SMC where one of the values vS is a constant k proves to be NP-hard or W[1]-hard with some parameterization, then it is easy to see that the same hardness result also holds for the case where vk (and all other assumptions are the same). We refer to the “reflection” of a result by adding the postfix ‘R’ to its name (so Theorem xR denotes the reflection of Theorem x); here by reflection we mean the statement obtained by switching the roles of men and women

Given the strong polynomial-time inapproximability bounds, as well as the parameterized intractability results of this paper, we pose as an open question whether fixed-parameter approximation algorithms can beat either of these obstacles for solving SMC.

Another challenge for future research is to investigate possible adaptations of the proposed algorithms to the Hospitals/Residents model (note that, naturally, all our hardness results for SMC-1 apply to the HRLQ problem), or to a setting where ties are allowed in the preference lists.

Acknowledgements

Open Access funding provided by Projekt DEAL. We thank the anonymous reviewers for their remarks which greatly helped to improve the paper; we are grateful for their patience and their rigorous reading of earlier drafts.

Footnotes

1

Restrictions without any parameters are simply classified as polynomial-time solvable or NP-hard.

2

Hamada et al. claim only a run time O((|W||M|)b+1), but their algorithm can easily be implemented to run in time O(|I|b+1).

3

We remark that our concept of an augmenting path is analogous, but not identical, to the standard notion of an augmenting path in general matching theory. According to the standard definition, an augmenting path for a given matching M is an M-alternating path P such that MP is a matching containing more edges than M. In our case, however, instead of increasing the number of edges in the matching, we aim for a path which can be used to increase the number of distinguished men and women that are matched.

4

Note that there may be optimal solutions that are incomparable to Mopt in the sense that they are preferred by some of the men while not preferred by some other men, but the existence of such a matching is of no importance to us: we can pick any optimal matching that fulfils our requirement above.

5

Formally, we need to apply Lemma 3 with setting H to contain all connected component of MsMopt except for Q, and setting K as Q.

6

Note that there cannot exist two loopers for Q, because only one woman endpoint of Q can be matched by Ms and such a woman can only be connected to at most one man on Q other than its partner in Ms.

7

Again, we need to apply Lemma 3 with setting H to contain all connected component of MsMopt except for Q, and setting K as Q.

8

We remark that it is still possible that C itself relies on a masculine path via a dependent edge of type A, but such edges do not play a role in Step 2.

9

This case is analogous with e being a type A edge; however, the paths Q and Q here need not be paths of MsMopt.

A preliminary version of the results presented in here appeared at the Proceedings of the 10th International Symposium on Algorithmic Game Theory [39]. Research of M. Mnich supported by ERC Starting Grant 306465 (BeyondWorstCase) and DFG Grant MN 59/4-1. Research of I. Schlotter supported by the Hungarian National Research Fund (OTKA Grants Nos. K-108383 and K-108947).

Publisher's Note

Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

Contributor Information

Matthias Mnich, Email: matthias.mnich@tuhh.de.

Ildikó Schlotter, Email: ildi@cs.bme.hu.

References

  • 1.Arulselvan A, Cseh Á, Groß M, Manlove DF, Matuschke J. Matchings with lower quotas: algorithms and complexity. Algorithmica. 2018;8(1):185–208. doi: 10.1007/s00453-016-0252-6. [DOI] [Google Scholar]
  • 2.Aziz, H., Schlotter, I., Walsh, T.: Control of fair division. In: IJCAI 2016, pp. 67–73. IJCAI/AAAI Press (2016)
  • 3.Aziz, H., Seedig, H.G., von Wedel, J.K.: On the susceptibility of the deferred acceptance algorithm. In: AAMAS 2015, pp. 939–947 (2015)
  • 4.Biró P, Fleiner T, Irving RW, Manlove DF. The college admissions problem with lower and common quotas. Theor. Comput. Sci. 2010;411(34–36):3136–3153. doi: 10.1016/j.tcs.2010.05.005. [DOI] [Google Scholar]
  • 5.Biró P, Irving RW, Schlotter I. Stable matching with couples: an empirical study. ACM J. Exp. Algorithmics. 2011;16:1.2:1.1–1.2:1.27. [Google Scholar]
  • 6.Biró P, Manlove DF, McDermid EJ. “Almost stable” matchings in the roommates problem with bounded preference lists. Theor. Comput. Sci. 2012;432:10–20. doi: 10.1016/j.tcs.2012.01.022. [DOI] [Google Scholar]
  • 7.Brandt F, Conitzer V, Endriss U, Lang J, Procaccia AD. Handbook of Computational Social Choice. New York: Cambridge University Press; 2016. [Google Scholar]
  • 8.Cechlárová K, Fleiner T. Pareto optimal matchings with lower quotas. Math. Soc. Sci. 2017;88(C):3–10. doi: 10.1016/j.mathsocsci.2017.03.007. [DOI] [Google Scholar]
  • 9.Chen, J., Huang, X., Kanj, I.A., Xia, G.: Linear FPT reductions and computational lower bounds. In: STOC 2004, pp. 212–221 (2004)
  • 10.Cseh Á, Manlove DF. Stable marriage and roommates problems with restricted edges: complexity and approximability. Discrete Optim. 2016;20:62–89. doi: 10.1016/j.disopt.2016.03.002. [DOI] [Google Scholar]
  • 11.Cygan M, Fomin FV, Kowalik Ł, Lokshtanov D, Marx D, Pilipczuk M, Pilipczuk M, Saurabh S. Parameterized Algorithms. Cham: Springer; 2015. [Google Scholar]
  • 12.Dias VM, da Fonseca GD, de Figueiredo CM, Szwarcfiter JL. The stable marriage problem with restricted pairs. Theor. Comput. Sci. 2003;306(1–3):391–405. doi: 10.1016/S0304-3975(03)00319-0. [DOI] [Google Scholar]
  • 13.Ehlers L, Hafalir IE, Yenmez MB, Yildirim MA. School choice with controlled choice constraints: hard bounds versus soft bounds. J. Econ. Theory. 2014;153:648–683. doi: 10.1016/j.jet.2014.03.004. [DOI] [Google Scholar]
  • 14.Fellows MR, Hermelin D, Rosamond F, Vialette S. On the parameterized complexity of multiple-interval graph problems. Theor. Comput. Sci. 2009;410(1):53–61. doi: 10.1016/j.tcs.2008.09.065. [DOI] [Google Scholar]
  • 15.Fleiner T, Irving RW, Manlove DF. Efficient algorithms for generalised stable marriage and roommates problems. Theor. Comput. Sci. 2007;381:162–176. doi: 10.1016/j.tcs.2007.04.029. [DOI] [Google Scholar]
  • 16.Fleiner T, Kamiyama N. A matroid approach to stable matchings with lower quotas. Math. Oper. Res. 2016;41(2):734–744. doi: 10.1287/moor.2015.0751. [DOI] [Google Scholar]
  • 17.Fragiadakis D, Iwasaki A, Troyan P, Ueda S, Yokoo M. Strategyproof matching with minimum quotas. ACM Trans. Econ. Comput. 2016;4(1):6:1–6:40. doi: 10.1145/2841226. [DOI] [Google Scholar]
  • 18.Fragiadakis D, Troyan P. Improving matching under hard distributional constraints. Theor. Econ. 2017;12:863–908. doi: 10.3982/TE2195. [DOI] [Google Scholar]
  • 19.Gale D, Shapley LS. College admissions and the stability of marriage. Am. Math. Mon. 1962;69(1):9–15. doi: 10.1080/00029890.1962.11989827. [DOI] [Google Scholar]
  • 20.Gale D, Sotomayor M. Some remarks on the stable matching problem. Discrete Appl. Math. 1985;11(3):223–232. doi: 10.1016/0166-218X(85)90074-5. [DOI] [Google Scholar]
  • 21.Garey M, Johnson DS. Computers and Intractability: A Guide to the Theory of NP-Completeness. New York: W. H. Freeman and Co.; 1979. [Google Scholar]
  • 22.Goto M, Iwasaki A, Kawasaki Y, Kurata R, Yasuda Y, Yokoo M. Strategyproof matching with regional minimum and maximum quotas. Artif. Intell. 2016;235:40–57. doi: 10.1016/j.artint.2016.02.002. [DOI] [Google Scholar]
  • 23.Gusfield D, Irving RW. The Stable Marriage Problem: Structure and Algorithms. Cambridge: MIT Press; 1989. [Google Scholar]
  • 24.Hamada K, Iwama K, Miyazaki S. The hospitals/residents problem with lower quotas. Algorithmica. 2016;74(1):440–465. doi: 10.1007/s00453-014-9951-z. [DOI] [Google Scholar]
  • 25.Hopcroft JE, Karp RM. An n5/2 algorithm for maximum matchings in bipartite graphs. SIAM J. Comput. 1973;2(4):225–231. doi: 10.1137/0202019. [DOI] [Google Scholar]
  • 26.Huang, C.C.: Classified stable matching. In: SODA 2010, pp. 1235–1253 (2010)
  • 27.Immorlica, N., Mahdian, M.: Marriage, honesty, and stability. In: SODA 2005, pp. 53–62 (2005)
  • 28.Impagliazzo R, Paturi R, Zane F. Which problems have strongly exponential complexity? J. Comput. Syst. Sci. 2001;63(4):512–530. doi: 10.1006/jcss.2001.1774. [DOI] [Google Scholar]
  • 29.Irving RW, Manlove D, O’Malley G. Stable marriage with ties and bounded length preference lists. J. Discrete Algorithms. 2009;7:213–219. doi: 10.1016/j.jda.2008.09.003. [DOI] [Google Scholar]
  • 30.Kamiyama N. A note on the serial dictatorship with project closures. Oper. Res. Lett. 2013;41(5):559–561. doi: 10.1016/j.orl.2013.07.006. [DOI] [Google Scholar]
  • 31.Knuth DE. Mariages stables et leurs relations avec d’autres problèmes combinatoires. Montreal: Les Presses de l’Université de Montréal; 1976. [Google Scholar]
  • 32.Kojima F, Pathak PA, Roth AE. Matching with couples: stability and incentives in large markets. Q. J. Econ. 2013;128(4):1585–1632. doi: 10.1093/qje/qjt019. [DOI] [Google Scholar]
  • 33.Kominers SD, Sönmez T. Matching with slot-specific priorities: theory. Theor. Econ. 2016;11(2):683–710. doi: 10.3982/TE1839. [DOI] [Google Scholar]
  • 34.Kuhn HW. The Hungarian method for the assignment problem. Nav. Res. Logist. Q. 1955;2:83–97. doi: 10.1002/nav.3800020109. [DOI] [Google Scholar]
  • 35.Lovász L, Plummer M. Matching Theory. Amsterdam: North-Holland; 2009. [Google Scholar]
  • 36.Manlove DF. Algorithmics of Matching Under Preferences. Singapore: World Scientific Publishing; 2013. [Google Scholar]
  • 37.Marx D, Schlotter I. Parameterized complexity and local search approaches for the stable marriage problem with ties. Algorithmica. 2010;58(1):170–187. doi: 10.1007/s00453-009-9326-z. [DOI] [Google Scholar]
  • 38.Marx D, Schlotter I. Stable assignment with couples: parameterized complexity and local search. Discrete Optim. 2011;8:25–40. doi: 10.1016/j.disopt.2010.07.004. [DOI] [Google Scholar]
  • 39.Mnich Matthias, Schlotter Ildikó. Algorithmic Game Theory. Cham: Springer International Publishing; 2017. Stable Marriage with Covering Constraints–A Complete Computational Trichotomy; pp. 320–332. [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 40.Monte D, Tumennasan N. Matching with quorums. Econ. Lett. 2013;120(1):14–17. doi: 10.1016/j.econlet.2013.03.007. [DOI] [Google Scholar]
  • 41.Roth AE, Peranson E. The redesign of the matching market for American physicians: some engineering aspects of economic design. Am. Econ. Rev. 1999;89:748–780. doi: 10.1257/aer.89.4.748. [DOI] [PubMed] [Google Scholar]
  • 42.Veskioja, T.: Stable marriage problem and college admission. Ph.D. thesis, Department of Informatics, Tallinn University of Technology (2005)
  • 43.Westkamp A. An analysis of the German university admissions system. Econ. Theory. 2013;53(3):561–589. doi: 10.1007/s00199-012-0704-4. [DOI] [Google Scholar]
  • 44.Yokoi, Y.: Envy-free matchings with lower quotas. In: ISAAC 2017, Leibniz International Proceedings in Informatics, vol. 92, pp. 67:1–67:12 (2017)
  • 45.Yokoi Y. A generalized polymatroid approach to stable matchings with lower quotas. Math. Oper. Res. 2017;42:238–255. doi: 10.1287/moor.2016.0802. [DOI] [Google Scholar]

Articles from Algorithmica are provided here courtesy of Springer

RESOURCES