Stable marriage and roommates problems with restricted edges: complexity and approximability

In the stable marriage and roommates problems, a set of agents is given, each of them having a strictly ordered preference list over some or all of the other agents. A matching is a set of disjoint pairs of mutually accepted agents. If any two agents mutually prefer each other to their partner, then they block the matching, otherwise, the matching is said to be stable. In this paper we investigate the complexity of finding a solution satisfying additional constraints on restricted pairs of agents. Restricted pairs can be either forced or forbidden. A stable solution must contain all of the forced pairs, while it must contain none of the forbidden pairs. Dias et al. gave a polynomial-time algorithm to decide whether such a solution exists in the presence of restricted edges. If the answer is no, one might look for a solution close to optimal. Since optimality in this context means that the matching is stable and satisfies all constraints on restricted pairs, there are two ways of relaxing the constraints by permitting a solution to: (1) be blocked by some pairs (as few as possible), or (2) violate some constraints on restricted pairs (again as few as possible). Our main theorems prove that for the (bipartite) stable marriage problem, case (1) leads to NP-hardness and inapproximability results, whilst case (2) can be solved in polynomial time. For the non-bipartite stable roommates instances, case (2) yields an NP-hard problem. In the case of NP-hard problems, we also discuss polynomially solvable special cases, arising from restrictions on the lengths of the preference lists, or upper bounds on the numbers of restricted pairs.


Introduction
In the classical Stable Marriage problem (sm) [1], a bipartite graph is given, where one colour class symbolises a set of men U and the other colour class stands for a set of women W . Man u and woman w are connected by edge uw if they find one another mutually acceptable. Each participant provides a strictly ordered preference list of the acceptable agents of the opposite gender. An edge uw blocks matching M if it is not in M , but each of u and w is either unmatched or prefers the other to their partner. A stable matching is a matching not blocked by any edge. From the seminal paper of Gale and Shapley [1], we know that the existence of such a stable solution is guaranteed and one can be found in linear time. Moreover, the solutions form a distributive lattice [2]. The two extreme points of this lattice are called the man-and woman-optimal stable matchings [1]. These assign each man/woman their best partner reachable in any stable matching. Another interesting and useful property of stable solutions is the so-called Rural Hospitals Theorem. Part of this theorem states that if an agent is unmatched in one stable matching, then all stable solutions leave him unmatched [3].
One of the most widely studied extensions of sm is the Stable Roommates problem (sr) [1,4], defined on general graphs instead of bipartite graphs. The notion of a blocking edge is as defined above (except that it can now involve any two agents in general), but several results do not carry over to this setting. For instance, the existence of a stable solution is not guaranteed any more. On the other hand, there is a linear-time algorithm to find a stable matching or report that none exists [4]. Moreover, the corresponding variant of the Rural Hospitals Theorem holds in the roommates case as well: the set of matched agents is the same for all stable solutions [5]. We summarise this observation as follows: Theorem 1.1 (Gusfield and Irving [5]). Given an instance of sr, the same set of agents is matched in all stable matchings.
Both sm and sr are widely used in various applications. In markets where the goal is to maximise social welfare instead of profit, the notion of stability is especially suitable as an optimality criterion [6]. For sm, the oldest and most common area of applications is employer allocation markets [7]. On one side, job applicants are represented, while the job openings form the other side. Each application corresponds to an edge in the bipartite graph. The employers rank all applicants to a specific job offer and similarly, each applicant sets up a preference list of jobs. Given a proposed matching M of applicants to jobs, if an employer-applicant pair exists such that the position is not filled or a worse applicant is assigned to it, and the applicant received no contract or a worse contract, then this pair blocks M . In this case the employer and applicant find it mutually beneficial to enter into a contract outside of M , undermining its integrity. If no such blocking pair exists, then M is stable. Stability as an underlying concept is also used to allocate graduating medical students to hospitals in many countries [8]. sr on the other hand has applications in the area of P2P networks [9].
Forced and forbidden edges in sm and sr open the way to formulate various special requirements on the sought solution. Such edges now form part of the extended problem instance: if an edge is forced, it must belong to a constructed stable matching, whilst if an edge is forbidden, it must not. In certain market situations, a contract is for some reason particularly important, or to the contrary, not wished by the majority of the community or by the central authority in control. In such cases, forcing or forbidding the edge and then seeking a stable solution ensures that the wishes on these specific contracts are fulfilled while stability is guaranteed. Henceforth, the term restricted edge will be used to refer either to a forbidden edge or a forced edge. The remaining edges of the graph are referred as unrestricted edges.
Note that simply deleting forbidden edges or fixing forced edges and searching for a stable matching on the remaining instance does not solve the problem of finding a stable matching with restricted edges. Deleted edges (corresponding to forbidden edges, or those adjacent to forced edges) can block that matching. Therefore, to meet both requirements on restricted edges and stability, more sophisticated methods are needed.
The attention of the community was drawn very early to the characterisation of stable matchings that must contain a prescribed set of edges. In the seminal book of Knuth [2], forced edges first appeared under the term arranged marriages. Knuth presented an algorithm that finds a stable matching with a given set of forced edges or reports that none exists, given an instance of sm. This method runs in O(n 2 ) time, where n denotes the number of vertices in the graph. Gusfield and Irving [5] provided an algorithm for sm based on rotations that terminates in O(|Q| 2 ) time, following O(n 4 ) pre-processing time, where Q is the set of forced edges. This latter method is favoured over Knuth's if multiple forced sets of small cardinality are proposed.
Forbidden edges appeared only in 2003 in the literature, and were first studied by Dias et al. [10]. In their paper, complete bipartite graphs were considered, but the methods can easily be extended to incomplete preference lists. Their main result was the following (in the following theorem, and henceforth, m is the total number of edges in the graph). Theorem 1.2 (Dias et al. [10]). The problem of finding a stable matching in an sm instance with forced and forbidden edges or reporting that none exists is solvable in O(m) time.
While Knuth's method relies on basic combinatorial properties of stable matchings, the other two algorithms make use of rotations. We refer the reader to [5] for background on these. The problem of finding a stable matching with forced and forbidden edges in an sm instance can easily be formulated as a weighted stable matching problem (that is, we seek a stable matching with minimum weight, where the weight of a matching M is the sum of the weights of the edges in M ). Let us assign all forced edges weight −1, all forbidden edges weight 1, and all remaining edges weight 0. A stable matching satisfying all constraints on restricted edges exists if and only if there is a stable matching of weight −|Q| in the weighted instance, where Q is the set of forced edges. With the help of rotations, minimum weight stable matchings can be found in polynomial time [11][12][13][14] (see the final paragraph of Section 2 for more details on the role played by each of these references).
Since finding a weight-minimal stable matching in sr instances is an NP-hard task [12], it follows that solving the problem with forced and forbidden edges requires different methods from the aforementioned weighted transformation. Fleiner et al. [15] showed that any sr instance with forbidden edges can be converted into another stable matching problem involving ties that can be solved in O(m) time [16] and the transformation has the same time complexity as well. Forced edges can easily be eliminated by forbidding all edges adjacent to them, therefore we can state the following result. Theorem 1.3 (Fleiner et al. [15]). The problem of finding a stable matching in an sr instance with forced and forbidden edges or reporting that none exists is solvable in O(m) time.
As we have seen so far, answering the question as to whether a stable solution containing all forced and avoiding all forbidden edges exists can be solved efficiently in the case of both sm and sr. We thus concentrate on cases where the answer to this question is no. What kind of approximate solutions exist then and how can we find them?
Our contribution. Since optimality is defined by two criteria, it is straightforward to define approximation from those two points of view. In case BP, all constraints on restricted edges must be satisfied, and we seek a matching with the minimum number of blocking edges. In case CV, we seek a stable matching that violates the fewest constraints on restricted edges. The optimisation problems that arise from each of these cases are defined formally in Section 2.
In Section 3, we consider case BP: that is, all constraints on restricted edges must be fulfilled, while the number of blocking edges is minimised. We show that in the sm case, this problem is computationally hard and not approximable within n 1−ε for any ε > 0, unless P = NP. We also discuss special cases for which this problem becomes tractable. This occurs if the maximum degree of the graph is at most 2 or if the number of blocking edges in the optimal solution is a constant. We point out a striking difference in the complexity of the two cases with only forbidden and only forced edges: the problem is polynomially solvable if the number of forbidden edges is a constant, but by contrast it is NP-hard even if the instance contains a single forced edge. We also prove that when the restricted edges are either all forced or all forbidden, the optimisation problem remains NP-hard even on very sparse instances, where the maximum degree of a vertex is 3.
Case CV, where the number of violated constraints on restricted edges is minimised while stability is preserved, is studied in Section 4. It is a rather straightforward observation that in sm, the setting can be modelled and efficiently solved with the help of edge weights. Here we show that on non-bipartite graphs, the problem becomes NP-hard, but 2-approximable if the number of forced edges is sufficiently large or zero. As in case BP, we also discuss the complexity of degree-constrained restrictions and establish that the NP-hardness results remain intact even for graphs with degree at most 3, while the case with degree at most 2 is polynomially solvable.
A structured overview of our results for general sm and sr instances is contained in Table 1.

Preliminaries and techniques
In this section, we introduce the notation used in the remainder of the paper and also define the key problems that we investigate later. An instance I = (G, O) of the Stable Marriage problem (sm) consists of a bipartite graph G = (U ∪ W, E) with n vertices and m edges, and a set O: the set of strictly ordered, but not necessarily complete preference lists. These lists are provided on the set of adjacent vertices at each vertex. The Stable Roommates problem (sr) differs from sm in one sense: the underlying graph G need not be bipartite. In both sm and sr, a matching M in G is sought, assigning each agent to at most one partner. If a vertex v ∈ V (G) is matched in M , we denote by M (v) the partner of v in M . An edge uw ∈ E \ M blocks M , or forms a blocking pair of M if either u is unmatched or prefers w to M (u), and either w is unmatched or prefers u to M (w). A matching that is not blocked by any edge is called stable.
As already mentioned in the Introduction, an sr instance need not admit a stable solution. The number of blocking edges is a characteristic property of every matching. The set of edges blocking M is denoted by bp(M ). A natural goal is to find a matching minimising |bp(M )|; following the consensus in the literature, such a matching is called almost stable. This approach has a broad literature: almost stable matchings have been investigated in sm [17][18][19] and sr [20,21] instances.
All problems investigated in this paper deal with at least one set of restricted edges. The set of forbidden edges is denoted by P , while Q stands for the set of forced edges. We assume throughout the paper that P ∩ Q = ∅. A matching M satisfies all constraints on restricted edges if M ∩ P = ∅ and Q ⊆ M .
In Fig. 1, a sample sm instance on four men and four women can be seen. The preference ordering is shown on the edges. For instance, vertex u 2 ranks w 1 best, then w 4 , and w 2 last. The set of forbidden edges P = {u 2 w 2 , u 3 w 3 } is marked by dotted grey edges. The unique stable matching M = {u 1 w 1 , u 2 w 2 , u 3 w 3 , u 4 w 4 } contains both forbidden edges. Later on, we will return to this sample instance to demonstrate approximation concepts on it.
The first approximation concept (case BP described in Section 1) is to seek a matching M that satisfies all constraints on restricted edges, but among these matchings, it admits the minimum number of blocking edges. This leads to the following problem definition.
Special attention is given to two special cases of min bp sr restricted: in min bp sr forbidden, Q = ∅, while in min bp sr forced, P = ∅. Note that an instance of min bp sr forced or min bp sr restricted can always be transformed into an instance of min bp sr forbidden by forbidding all edges that are adjacent to a forced edge. This transformation does not affect the number of blocking edges.
According to the other intuitive approximation concept (case CV described in Section 1), stability constraints need to be fulfilled, while some of the constraints on restricted edges are relaxed. The goal is to find a stable matching that violates as few constraints on restricted edges as possible. Output: A stable matching M such that |M ∩ P | + |Q \ M | ≤ |M ′ ∩ P | + |Q \ M ′ | for every stable matching M ′ in G.
Just as in the previous approximation concept (referred to as case BP in Section 1), we separate the two subcases with only forbidden and only forced edges. If Q = ∅, sr min restricted violations is referred as sr min forbidden, while if P = ∅, the problem becomes sr max forced. If P = ∅ or Q = ∅, then that set is omitted from an instance of min bp sr restricted or sr min restricted violations as appropriate.
When considering the decision versions of the problems defined in this section, we append dec to the problem name and add a positive integer K to the problem instance. The problem is then to decide whether a feasible solution exists with measure at most K. For example, in the case of the optimisation problem In all discussed problems, n is the number of vertices and m is the number of edges in the graph underlying the particular problem instance. When considering the restriction of any of the above problems to the case of a bipartite graph sr is replaced by sm in the problem name.
In case BP, the subcase with only forced edges can be transformed into the other subcase, simply by forbidding edges adjacent to forced edges. This straightforward transformation is not valid for case CV. Suppose a forced edge was replaced by an unrestricted edge, but all of its adjacent edges were forbidden. A solution that does not contain the original forced edge might contain two of the forbidden edges, violating more constraints than the original solution. Yet most of our proofs are presented for the problem with only forbidden edges, and they require only slight modifications for the case with forced edges.
A powerful tool used in several proofs in our paper is to convert some of these problems into a weighted sm or sr problem, where the goal is to find a stable matching with the lowest total edge weight, taken over all stable matchings. Irving et al. [11] were the first to show that weighted sm can be solved in polynomial time, giving an O(n 4 log n) algorithm if the weight function is monotone in the preference ordering, non-negative and integral. Feder [12,14] showed a method to drop the monotonicity requirement. He also presented the best known bound for the running time of an algorithm for finding a minimum weight stable matching in sm: where K is the weight of an optimal solution. Redesigning the weight function to avoid the monotonicity requirement using Feder's method can radically increase K. Fortunately, linear programming techniques allow the conditions to be dropped while retaining polynomial-time solvability. A simple and elegant formulation of the sm polytope is known [13] and using this, a minimum weight stable matching can be computed for all real-valued weight functions in polynomial time via linear programming. For weighted sr, finding an optimal matching is NP-hard, but 2-approximable with combinatorial methods, under the assumption of monotone, non-negative and integral weights [12]. With the help of LP methods, a 2-approximation can be found for every non-negative weight function [22,23].

Almost stable matchings with restricted edges
In this section, constraints on restricted edges must be fulfilled strictly, while the number of blocking edges is minimised. Our results are presented in three subsections, and most of the results are given for min bp sm restricted. Firstly, in Section 3.1, basic complexity results are discussed. In particular, we prove that the studied problem min bp sm restricted is in general NP-hard and very difficult to approximate. Thus, restricted cases are analysed in Section 3.2. First we assume that the number of forbidden, forced or blocking edges can be considered as a constant. Due to this assumption, two of the three problems that naturally follow from imposing these restrictions become tractable, but surprisingly, not all of them. Then, degreeconstrained cases are discussed. We show that the NP-hardness result for min bp sm restricted holds even for instances where each preference list is of length at most 3, while on graphs with maximum degree 2, the problem becomes tractable. Finally, in Section 3.3 we consider the problem min bp sr restricted and briefly elaborate on whether the results established for the bipartite case carry over to the sr case.

General complexity and approximability results
When minimising the number of blocking edges, one might think that removing the forbidden edges temporarily and then searching for a stable solution in the remaining instance leads to an optimal solution. Such a matching can only be blocked by forbidden edges, but as the upcoming example demonstrates, optimal solutions are sometimes blocked by unrestricted edges exclusively. In some instances, all almost stable solutions admit only non-forbidden blocking edges. Moreover, a man-or woman-optimal almost stable matching with forbidden edges does not always exist.
Let us recall the sm instance in Fig. 1. In the graph with edge set E(G) \ P , a unique stable matching exists: In Theorems 3.1 and 3.5 we present two results demonstrating the NP-hardness and inapproximability of special cases of min bp sm restricted. Proof. Clearly both problems belong to NP. We show the NP-hardness of both problems by giving a reduction from the following problem: min bp psmi denotes the minimisation version of min bp psmi dec, in which we seek a perfect matching with the minimum number of blocking pairs, taken over all perfect matchings in G. min bp psmi-dec is NP-complete, and unless P = NP, min bp psmi is not approximable within a factor of n 1−ε , for any ε > 0 [19].
We firstly show NP-hardness of min bp sm forbidden dec and then indicate how to adapt the proof to show a similar result for min bp sm forced dec. We reduce from min bp psmi dec as In O ′ the preference lists of vertices already in V (G) are structured in three blocks. Each man u i in the original instance I keeps his preference list in O at the top of his new list in O ′ . After these vertices, the entire set of newly-introduced women in Y follows, in arbitrary order. Finally, the rest of the women in W , not already in u i 's list follow, in arbitrary order. A similar ordering is used when defining the preference list of each w j . The original list in O is followed by the vertices in X, and then the rest of the men in U follow.
The added newly-added vertices in X ∪ Y have different preference orderings. Man x i 's list consists of the women in W in arbitrary order, followed by y i , and then the women in Y \ {y i } in arbitrary order. Similarly y j ranks all men in U first in arbitrary order, followed by x j , and then the men in X \ {x j } in arbitrary order. The preference lists of the vertices in I ′ are shown in Fig. 2.
Having described G ′ and O ′ completely, all that remains is to specify the set of forbidden edges P . Each man u i has K +1 forbidden edges adjacent to him, namely, all edges to the newly-introduced y 1 , y 2 , . . . , y K+1 vertices. Similarly, edges between every w j and all x 1 , x 2 , . . . , x K+1 vertices are also forbidden. In total, I ′ has n(K + 1) forbidden edges. M ′ is a perfect matching in G ′ , not containing any of the forbidden edges. Next, we show that no edge in E(G ′ ) \ M ′ blocks M ′ that did not block M already. First of all, the forbidden edges do not block M ′ , because the preference lists of the vertices already in V (G) were constructed in such a way that the vertices on preference lists in O are better than the vertices in X ∪ Y , and all u i , w j vertices were matched in the perfect matching M . The first n/2 choices of any newly-added vertex in X ∪ Y are thus not blocking edges. At the same time, all these new vertices are matched to their first-choice partners among the newly-added vertices. Therefore no edge incident to them can block M ′ . All that remains is to observe that u i w j edges blocking M ′ in I ′ already blocked M in I, because M is the restriction of M ′ to G. Therefore, the edges blocking M and M ′ are identical. First, we discuss some essential structural properties of M ′ . The forbidden edges are not in M ′ , and at most K of them can block it. Suppose that there is a man u i not married to any woman w j in matching M . Since w j ranks exactly K + 1 forbidden edges after its listed partners in G, and forbidden edges are the first n/2 choices of their other end vertex, all K + 1 of them block M ′ , regardless of the remaining edges in M ′ . Having derived a contradiction to our assumption that at most K edges block M ′ in total, we can state that each man u i is matched in M ′ to a vertex w j in O. Thus, the restriction of M ′ to G is a perfect matching with at most K blocking edges.
NP-hardness can be obtained for min bp sm forced dec by simply forcing all edges of the form x i y i in the above reduction.
We now strengthen Theorem 3.1 by giving strong lower bounds for the approximability of min bp sm forbidden and min bp sm forced. The reduction given in the proof of the next theorem builds on the reduction given in the proof of Theorem 3.1.
Theorem 3.5. Each of min bp sm forbidden and min bp sm forced is not approximable within a factor of n 1−ε , for any ε > 0, unless P = NP. The result holds even if all preference lists are complete.
Proof. We will give a reduction from the following NP-complete problem: Problem 3.6 (exact maximal matching). Input: I = (G, K) comprising a bipartite graph G and a positive integer K.
Question: Is there a maximal matching M in G such that |M | = K? exact maximal matching is NP-complete even for graphs where all vertices representing men have degree two, while all vertices of the other colour class have degree three [24]. We show that if there were a polynomial approximation algorithm within a factor of n 1−ε to min bp sm forbidden, then it would also find an exact maximal matching in I.
In our proof, every instance I = (G, K) of exact maximal matching is transformed into an instance I ′′ = (G ′ , O ′ , P ) of min bp sm forbidden. We later show how to adapt the proof for min bp sm forced. Let n 1 and n 2 denote the size of each colour class in I, such that m = 2n 1 = 3n 2 .
We show that if there were a polynomial approximation algorithm with a performance guarantee of n 1−ε for min bp sm forbidden (where n is the number of vertices in G ′ ), then it would solve exact maximal matching in polynomial time. To do so, another transformation is used, involving I ′ , an instance of min bp psmi. In [19], an instance I ′ = (G, O) of min bp psmi is created from I with special properties. One of them is that if G has a maximal matching of cardinality K, then I ′ has a perfect matching admitting exactly n 1 + n 2 blocking edges. Otherwise, if G has no maximal matching of cardinality K, then any perfect matching in I ′ is blocked by at least n 1 + n 2 + C edges, where C is a huge number. To be more precise, let B =  3 ε  and C = (n 1 + n 2 ) B+1 + 1 (in [19], the value of B was the same to that used here, but the value of C was slightly different). The number of vertices in each colour class of I ′ is 3n 1 + 2mC + 4n 2 − K. Now we describe how I ′ is transformed into I ′′ . Note that this method is very similar to the one we used in the proof of Theorem 3.1. Denote by U and W the set of men and women in I ′ , and let u i and w j denote an arbitrary man and woman in I ′ respectively. Add these vertices to I ′′ and then introduce C new men, namely X = {x 1 , x 2 , . . . , x C }, and C new women, namely Y = {y 1 , y 2 , . . . , y C }. Then each colour class in I ′′ consists of 3n 1 + 2mC + 4n 2 − K + C vertices. The preference lists of the vertices in I ′′ are shown in Fig. 3.
The set of forbidden edges comprises all edges of the form u i x j or w j y i . For min bp sm forced, the set of forced edges consists of all edges of the form x i y i . Due to this construction, and as in the proof of Theorem 3.1, if M is a matching in I ′′ in which there is a man u i not matched to a woman in O, then M is blocked by at least C edges.
It follows that if G has a maximal matching of size at most K, then I ′′ has a matching with at most n 1 +n 2 blocking pairs. On the other hand if G has no maximal matching of size at most K, then any matching in I ′′ has at least C > (n 1 + n 2 ) B+1 blocking pairs. Hence an (n 1 + n 2 ) B -approximation algorithm for min bp sm restricted or min bp sm forced could be used to solve exact maximal matching in polynomial time.
To complete the proof it remains to show that if n is the number of vertices in I ′′ , then n 1−ε ≤ (n 1 +n 2 ) B . Using Inequalities (1)-(7) we give an upper bound for n, whilst with Inequalities (8)-(10) we establish a lower bound. Then, combining these two in Inequalities (11)-(14), we derive that n 1−ε ≤ (n 1 + n 2 ) B . Explanations for the steps are given as necessary after each of the three sets of inequalities.
In (8) we keep only C from the right-hand side of the equality above and use the fact that C > (n 1 + n 2 ) B+1 , whilst in (10) we assume without loss of generality that n 2 ≥ 6 so n 1 ≥ 9 (recall that 2n 1 = 3n 2 ).

Bounded parameters
Our results presented so far show that min bp sm restricted is computationally hard even if P = ∅ or Q = ∅. Yet if certain parameters of the instance or the solution can be considered as a constant, the problem can be solved in polynomial time. Theorem 3.7 firstly shows that this is true for min bp sm forbidden.
Proof. We firstly show how to solve min bp sm forbidden dec in polynomial time. We assume that, for the purposes of this proof, the problem definition is modified so that, given an instance I = (G, O, P, K), we are required to find a matching M in G such that M ∩ P = ∅ and |bp(M )| ≤ K, or report that no such matching exists.
Our first observation is that this problem is trivially solvable if the target value K satisfies K ≥ L. In this case, deleting the L forbidden edges from E(G) and finding a stable matching in the remaining graph delivers a matching that is blocked in the original instance by only a subset of the removed edges (if any). Thus, a matching M with M ∩ P = ∅ and |bp(M )| ≤ L ≤ K always exists. Now assume that K < L. Suppose firstly that there is a matching M with M ∩ P = ∅ and |bp(M )| = k ≤ K < L. If those k blocking edges are deleted from E(G), then M is a stable matching in the remainder of G, and M contains none of the forbidden edges. Note that we did not specify which edges block M : they can be both forbidden and unrestricted.
Hence to solve min bp sm forbidden dec we generate all subsets S of potential blocking edges, where |S| ≤ K. After deleting the edges in S from G, we try to find, in the remaining graph, a matching M such that M ∩ P = ∅ and M is stable, or we report that no such matching exists. By Theorem 1.2, this step can be accomplished in O(m) time. If such a matching M exists, then it admits at most K blocking edges in I.
subsets are generated to determine whether the desired matching exists. We now show how to use the above approach in order to solve min bp sm forbidden. If we find a solution during the course of this process, then G admits a matching M such that M ∩ P = ∅ and |bp(M )| ≤ L. In order to minimise |bp(M )| it suffices to use the technique in the previous paragraph in combination with a binary search procedure on values of K ≤ L. This requires O(log L) invocations of the algorithm for the decision problem, which is a constant, and hence the overall time complexity remains O(m L+1 ).
In sharp contrast to the previous result on polynomial solvability when the number of forbidden edges is small, we state the following theorem for min bp sm forced dec.  Proof. The NP-complete problem we reduce to min bp sm forced dec is exact maximal matching. As previously mentioned, this problem is NP-complete even for graphs where all vertices representing men have degree two, while all vertices of the other side have degree three [24]. Hence suppose we are given an instance I = (G, K) of this restriction, where in G, U 0 and W 0 are the two colour classes and E is the edge set.
In this proof, we construct a min bp sm forced dec instance I ′ = (G ′ , O ′ , Q, K ′ ) with a single forced edge in such a way that there is a maximal matching of cardinality K in I if and only if there is a matching containing the forced edge and admitting exactly K ′ = |U 0 | + |W 0 | blocking edges in I ′ . Our construction is based on ideas presented in [19].
All vertices in G rank their edges in an arbitrary but fixed order. We will refer to these labels when constructing I ′ . We now describe I ′ . The vertex set of graph G ′ in I ′ can be partitioned into seven sets: U , V , W , Z, S 1 , S 2 , X and Y , where U ∪ V ∪ X ∪ S 1 are the men and W ∪ Z ∪ Y ∪ S 2 are the women. Specific subgraphs of G ′ are referred to as u-gadgets, w-gadgets, together with a special gadget containing the forced edge; see Fig. 4. Aside from these, G ′ also contains some extra vertices, the so-called garbage collectors, partitioned into two sets: X and Y . Later we will see that these garbage collectors are paired to the vertices not covered by the matching in G. To that end, |X| = |W 0 | − K and |Y | = |U 0 | − K. The whole construction is illustrated in Fig. 5.
Each u-gadget replaces a vertex u ∈ U 0 in G. It is defined on five vertices: u 1 , u 2 , u 3 ∈ U and z 1 , z 2 ∈ Z. Its edges and the preferences on them are shown in Fig. 4. Two interconnecting edges connect the special gadget to u 3 , and an interconnecting edge connects the special gadget to each of u 1 and u 2 . These edges are ranked last in the case of u 1 and u 2 , and ranked as the last two edges by u 3 . It is described later which vertices of the special gadget are incident to these interconnecting edges. The u-gadget also has edges to all w-gadgets representing vertices in W 0 to which u was adjacent. After describing the w-gadget, we elaborate on the position of these edges, referred to as relevant edges. Aside from these, every u 1 has edges to all garbage collectors in Y . These edges are all worse than the relevant edges of u 1 and they are ranked arbitrarily at the bottom of u 1 's list. The vertices in Y also rank all u 1 vertices arbitrarily.
The w-gadgets are structured similarly. Each gadget consists of seven vertices: w 1 , w 2 , w 3 , w 4 ∈ W and v 1 , v 2 , v 3 ∈ V . Aside from the edges within the gadget, it has two interconnecting edges between w 4 and vertices in the special gadget (described in detail later), and three relevant edges between w 1 , w 2 , w 3 and vertices of u-gadgets. These are the edges drawn in accordance with the edge labels. Suppose in I, edge uw was ranked ith by u and jth by w, where i ∈ {1, 2} and j ∈ {1, 2, 3}. Then in I ′ , u i in the u-gadget is connected to w j in the w-gadget. Therefore, each edge in I is transformed into a single edge in I ′ and each u i , i ∈ {1, 2} and w j , j ∈ {1, 2, 3}, has exactly one relevant edge. All of these edges are second choices of both of their end vertices. In addition to these, if a u-and a w-gadget, for which uw ∈ E(G) are not already connected by u 1 w 1 , we add u 1 w 1 , which is referred as an adjacency edge. This edge is ranked by both u 1 and w 1 after their relevant edges, but ahead of their edges to garbage collectors. Similar to u-gadgets, w-gadgets are also connected to garbage collectors. Each w 1 vertex has |W 0 | − K edges to the vertices in X, ranked arbitrarily at the bottom of w 1 's preference list. Also the vertices in X rank the w 1 vertices arbitrarily.
The special gadget is defined on only six vertices in the set The unique forced edge in the entire instance is u 0 w 0 . Apart from u ′ 0 and w ′′ 0 , they are connected to u-and w-gadgets. In each u-gadget, u 3 is adjacent to w 0 and w ′ 0 , and each of u 1 and u 2 is adjacent to w 0 . In each w-gadget, w 4 is adjacent to u 0 and u ′′ 0 , and each of w 1 , w 2 and w 3 is adjacent to u 0 . Moreover, u 0 and w 0 are connected to all garbage collectors of the opposite side via additional interconnecting edges. These edges are ranked last by the vertices in X and Y . The four vertices u 0 , u ′′ 0 , w 0 , w ′ 0 prefer their interconnecting edges to their edges inside of the special gadget. In u-gadgets, where either of u 1 and u 2 has a relevant edge in M ′ , the other vertex in U is matched to its copy in Z. The remaining two vertices of the gadget are then paired to each other. In the other case, if u was unmatched in M , then {u 2 z 2 , u 3 z 1 } ⊆ M ′ , and M ′ (u 1 ) ∈ Y . Given the set of u 1 vertices to pair with the garbage collectors in Y , we find any stable matching in this subgraph and add it to M ′ . Note that this step matches the |U 0 | − K u 1 vertices to the |U 0 | − K garbage collectors in Y .
The strategy is similar for the w-gadgets. Suppose that some w j is already matched to a vertex in U , because that relevant edge corresponds to a matching edge in M . In M ′ we then match w 4 with v j and pair the remaining two vertices in W with their partners in V . Otherwise, if w was unmatched in M , then in M ′ , w 1 is matched to a garbage collector, and {w 2 v 2 , w 3 v 3 , w 4 v 1 } ⊆ M ′ . In the subgraph induced by the garbage collectors in X and the w 1 vertices corresponding to unmatched w vertices we construct a stable matching and add it to M ′ . This step matches the |W 0 | − K w 1 vertices to the |W 0 | − K garbage collectors in X.
In the special gadget, u 0 w 0 , u ′ 0 w ′ 0 and u ′′ 0 w ′′ 0 are chosen. It is easy to see that in the special gadget, none of the four non-matching edges blocks M ′ . Then M is a matching in G and moreover |M | = K, since all |U 0 | − K vertices in Y are matched in M ′ to u 1 vertices of various u-gadgets, and similarly, all |W 0 | − K vertices in X are matched in M ′ to w 1 vertices. That leaves K of the u-gadgets that contribute a single relevant edge (or adjacency edge) to M ′ . All that remains to show is that this matching is maximal. Let us suppose otherwise, i.e., there are two gadgets corresponding to vertices u and w in G such that all their vertices in U and W in G ′ are matched to either garbage collectors or to their z-or v-copies. This is only possible if u 1 and w 1 are both matched to garbage collectors, but then the adjacency edge u 1 w 1 blocks M ′ .
A counterpart to Theorem 3.7 holds in the case of min bp sm restricted if the number of blocking pairs in an optimal solution is a constant.

Theorem 3.11. min bp sm restricted is solvable in O(m L+1 ) time, where L is the minimum number of edges blocking an optimal solution, which is polynomial if L is a constant.
Proof. Analogously to the proof of Theorem 3.7, we show how to solve min bp sm restricted dec in polynomial time. Again, we assume for the purposes of this proof that the problem definition is modified so that, given an instance I = (G, O, P, Q, K), we are required to find a matching M in G such that M ∩P = ∅, Q ⊆ M and |bp(M )| ≤ K, or report that no such matching exists.
Suppose there exists a matching M in G such that M ∩P = ∅, Q ⊆ M and |bp(M )| ≤ K. If we form G ′ by deleting the edges in bp(M ), then M is stable in G ′ . Hence to find M it suffices to generate all subsets S of edges of size at most K and form a graph G S by deleting S from G. We can determine in linear time whether G S admits a stable matching M ′ that satisfies all constraints on restricted edges [10]. If so, |bp(M ′ )| ≤ K in G. There are O(Km K ) sets of edges to remove and checking the existence of a stable matching satisfying constraints on restricted edges can be done in O(m) time.
We now show how to use the above approach to solve min bp sm restricted. For each value of K, where K starts from 0 and increases by 1 after each iteration, we execute the algorithm in the previous paragraph, noting that it is sufficient to generate all subsets of size exactly K at each iteration. We terminate as soon as we find a matching M satisfying the constraints on restricted edges such that |bp(M )| ≤ K. This process is bound to halt, since by definition, I admits a matching M such that M ∩ P = ∅, Q ⊆ M and |bp(M )| = L, so K ≤ L. Thus the overall time complexity of this approach is O((L + 1)m L+1 ) = O(m L+1 ), which is polynomial if L is a constant.
Next we study the case of degree-constrained graphs; for most hard sm and sr problems, it is the most common special case to investigate [25,18,21]. Here, we show in Theorem 3.12 that min bp sm restricted remains computationally hard even for instances with preference lists of length at most 3. On the other hand, according to Theorem 3.17, the problem can be solved in polynomial time when the length of preference lists is bounded by 2. Proof. We give a reduction from (2,2)-e3-sat, a restriction of satisfiability, which may be defined as follows: Problem 3.13 ((2,2)-e3-sat). Input: a Boolean formula B in CNF, in which each clause comprises exactly 3 literals and each variable appears exactly twice unnegated and exactly twice negated.
Question: Is there a satisfying truth assignment for B?
(2,2)-e3-sat is NP-complete [26]. Given an instance B of this problem, let us denote the number of variables by n B and the number of clauses by m B .
Using the simple transformation described in Section 2, any min bp sm forced instance can be converted into a min bp sm forbidden instance without increasing the preference list lengths. Hence it is sufficient to investigate min bp sm forbidden. Our construction combines ideas from two papers. Corresponding to B, we introduce a variable gadget and a clause gadget. The first one is a slightly more sophisticated variant of the variable gadget used in Theorem 7 of [19], to show NP-hardness of finding a maximum cardinality almost stable matching. Our clause gadget is a simplified version of another clause gadget from Theorem 1 in [21]. There, the Almost Stable Roommates problem is shown to be NP-hard. Both proofs investigate the case with bounded preference lists.
When constructing instance I from the given Boolean formula B, we keep track of the order of the three literals in each clause and the order of the two unnegated and two negated appearances of each variable.
The variable gadget. For each variable in B, a variable gadget, which is a graph on 44 vertices, is defined. The right hand-side of Fig. 6 illustrates the essential part of such a gadget, which is a cycle of length 24. This cycle contains no forbidden edges, and each vertex along it has degree 3 due to being incident to an additional forbidden edge. For sake of simplicity, only four of these forbidden edges are depicted in the figure, namely the ones incident to vertices x 1 , x 2 , x 3 and x 4 , as they are responsible for the communication between clause and variable gadgets. Each of these four vertices has its third, forbidden edge connected to a clause gadget. These edges are called interconnecting edges and are ranked second on the preference list of both of their end vertices.
Consider a variable v in B. Due to the properties of (2,2)-e3-sat, v occurs twice in unnegated form, say, in clauses C 1 and C 2 . Suppose that v's first unnegated appearance is as the ith literal of C 1 . This is represented by the interconnecting edge between x 1 (in the vertex gadget corresponding to v) and vertex a i in the clause gadget (described below) corresponding to C 1 . Similarly, x 2 is connected to an a-vertex in the clause gadget of C 2 . The same variable, v, also appears twice in negated form. The relevant variables in the gadgets representing those clauses are connected to x 3 and x 4 . The other end vertices of these two interconnecting edges mark where these two literals appear in their clauses.
As mentioned before, all vertices along the cycle have exactly one forbidden edge attached to them. In the case of x 1 , x 2 , x 3 and x 4 , these edges take the form of interconnecting edges. Regarding the remaining 20 vertices of the cycle, there is a dummy vertex with a forbidden edge attached to each of them, which we call variable pendant edges (these edges are not depicted in Fig. 6). This edge is their last choice. These The clause gadget. To each clause in B, a graph on 14 vertices is defined, which we refer to as the clause gadget. Three of them, a 1 , a 2 and a 3 , are connected to variable gadgets via interconnecting edges, all ranked second. There are three special matchings on a clause gadget, blocked by only a single edge. They can be seen on the left hand-side of Fig. 6. The grey edges selected in each of the clause gadget copies from top to bottom denote M 1 , M 2 and M 3 respectively. In addition to the interconnecting edges, a clause gadget has two forbidden edges, namely p 3 r 1 and q 3 r 2 . Proof. First, suppose that M ̸ = M i for all i ∈ {1, 2, 3} and that M is blocked by at most one edge. Since all three edges connecting a and b-vertices are first choices of both of their end vertices, they block any matching not including them. Another restriction arises from the fact that the forbidden edges r 1 p 3 and r 2 q 3 ensure that if p 3 or q 3 is unmatched, they also contribute a blocking edge. Similarly, if p 1 or q 1 is unmatched, they contribute a blocking edge.
Suppose b i a i ∈ M for all i ∈ {1, 2, 3}. Then, p 2 is matched either to p 1 or to p 3 , leaving the other one unmatched. The same argument applies for the q-vertices on the other side of the gadget. Therefore, at least two edges from the clause gadget block M .
In the remaining case, exactly one of the b i a i edges is outside of M . Since we are searching for a matching blocked by at most one edge, no further blocking edge can occur. Therefore, p 1 , q 1 , p 3     Proof. In this constructive proof we describe an algorithm that produces an optimal matching. First, the input is simplified. Then, the graph is segmented so that each subgraph falls into a category with a specified rule for selecting the edges of an optimal matching. As in previous cases, it is sufficient to tackle min bp sm forbidden, because instances of min bp sm forced can be transformed to this problem.
Due to the degree constraints, every component of the underlying graph is a path or a cycle. If any of these components is free of forbidden edges, then we simply fix a stable matching on it. This step is executed whenever such a component appears during the course of the algorithm. For those components with forbidden edges, we split all vertices having a first-choice forbidden edge and a second-choice edgeunrestricted or forbidden -into two vertices. This change does not affect |bp(M )|, because in this case, each edge blocks the matching if and only if its other end vertex is matched to a worse partner or is unmatched. After this splitting is executed, all components contain forbidden edges that start paths or that are inside a path, being the last choices of both of their end vertices.
Each component consists of segments of unrestricted edges, separated by forbidden edges. When talking about a segment, we always mean a series of adjacent unrestricted edges. Since unrestricted cycles have already been eliminated by fixing a stable matching on them, every segment is a path. Due to Theorem 1.1, each path admits a unique stable matching. Fixing a matching on a segment induces blocking edges only among the unrestricted edges of the segment and the forbidden edges adjacent to the segment. We claim that in an optimal solution, each segment and the (at most two) forbidden edges surrounding it contribute at most two blocking edges. This is simply due to the fact that any stable solution on the unrestricted edges is blocked only by forbidden edges. Therefore, deviating from this solution might only pay off if the matching restricted to this segment is blocked by a single edge and covers both of its end vertices.
The unique stable matching M on a segment ⟨v 1 , v 2 , . . . , v k ⟩ falls into exactly one of the following categories: 1. M covers both v 1 and v k ; 2. M covers either v 1 or v k ; 3. M covers neither v 1 nor v k .
In each step of our algorithm, a segment is chosen and a matching is fixed on it. The segment and some of the forbidden edges adjacent to it are then removed from the graph. This is done in the following way in these three cases.
In case 1, an optimal solution arises from choosing M . If a forbidden edge e is incident to either v 1 or v k , it cannot block M . Nor can it block any superset of M in the original instance, so e can be deleted. In case 2, again the optimal solution arises from choosing M . Without loss of generality suppose that v 1 is covered. As in case 1, if a forbidden edge is incident to v 1 , it cannot block a superset of M in the original instance. Now suppose that a forbidden edge e is incident to v k . Edge e may block M , and may also block a superset of M in the original instance, so it is retained.
The third case is divided into two subcases, depending on whether there is a matching M ′ that is blocked by only one edge and covers both v 1 and v k . Finding such a matching or proving that none exists can be done iteratively, assuming that a chosen edge is the single blocking edge and then constructing M ′ so that no more edge blocks it. If such an M ′ does not exist, then M is chosen, and the segment (but not the forbidden edges) is removed. In the end the matching restricted to this segment will be blocked by no edge other than the two forbidden edges. Suppose M is not an optimal choice in this segment. Then the optimal matching M ′′ has at most one blocking edge from this segment and its adjacent edges. M ′′ must cover at least one endpoint vertex of the segment (otherwise we have at least two blocking edges)-without loss of generality let that vertex be v 1 . M ′′ cannot cover v k given the non-existence of the aforementioned matching M ′ that was sought. Hence the forbidden edge incident to v k contributes a blocking edge. This implies that M ′′ restricted to the segment itself is a stable matching, contradicting the fact that the unique stable matching for this segment covers neither v 1 nor v k .
The only remaining case is that, in the segment ⟨v 1 , v 2 , . . . , v k ⟩, the unique stable matching M covers neither v 1 nor v k , but there is a matching M ′ blocked by one (unrestricted) edge that covers both v 1 and v k , and this is true for all remaining segments. Let C be any remaining component, which is a path comprising segments S 1 , S 2 , . . . , S r , where S i and S i+1 are separated by a forbidden edge (1 ≤ i ≤ r − 1), together with a possible additional forbidden edge at each end of the path that may be remaining. Let M i denote a stable matching in S i (which covers neither endpoint vertex, as previously noted), and let M ′ i denote a matching in segment S i that covers both endpoint vertices and is blocked by at most one unrestricted edge. Now let M ′′ be an optimal matching in C. We will show how to transform M ′′ to M ′′′ such that |bp(M ′′′ )| ≤ |bp(M ′′ )|, It follows that M ′′′ has the desired properties once this process terminates. Thus to reach an optimal solution in C it suffices to let M 1 be the union of M 1 , M ′ 2 , M 3 , . . . , and let M 2 be the union of M ′ 1 , M 2 , M ′ 3 , . . . , and pick whichever of the two admits the fewer blocking pairs in C.
Even with the previous two theorems, we have not quite drawn the line between tractable and hard cases in terms of vertex degrees. The complexity of min bp sm restricted remains open for the case when preference lists are of length at most 2 on one side of the bipartite graph and are of unbounded length on the other side. However we believe that this problem is solvable in polynomial time.

Stable Roommates problem
Having discussed several cases of sm, we turn our attention to non-bipartite instances. Since sm is a restriction of sr, all established results on the NP-hardness and inapproximability of min bp sm restricted carry over to the non-bipartite sr case. As a matter of fact, more is true, since min bp sr restricted is NP-hard and difficult to approximate even if P = ∅ and Q = ∅ [20]. We summarise these observations as follows.
Remark 3.19. By Theorems 3.1 and 3.5, each of min bp sr forbidden and min bp sr forced is NP-hard and not approximable within n 1−ε , for any ε > 0, unless P = NP. Moreover Theorems 3.12 and 3.8 imply that each of min bp sr forbidden and min bp sr forced is NP-hard even if all preference lists are of length at most 3 or, in the latter case, |Q| = 1. Finally min bp sr restricted is NP-hard and not approximable within n 1 2 −ε , for any ε > 0, unless P = NP, even if P = ∅ and Q = ∅ [20].
Remark 3.19 already shows that Theorem 3.7 does not carry over to the sr case, since min bp sr forbidden is computationally hard even if P = ∅. As for the other polynomially solvable cases, the proof of Theorem 3.11 carries over without applying any modifications. Theorem 3.17 also carries over to the sr case, but it needs a slight modification. If deg(v) ≤ 2 for every v ∈ V (G), then G consists of paths and cycles. Each odd preference cycle without a forbidden edge contributes at least one blocking edge to any matching [27] and any maximal matching on such a cycle is blocked by exactly one edge. On the remainder of the graph, the algorithm described in the proof of Theorem 3.17 delivers an optimal matching for min bp sr restricted. The following remark summarises the discussed positive results.
Remark 3.20. min bp sr restricted is solvable in polynomial time if the minimal number of edges blocking an optimal solution is a constant or if each preference list consists of at most 2 elements.

Stable matchings with the minimum number of violated constraints on restricted edges
In this section, we study the second intuitive approximation concept. The desired matching is stable and violates as few constraints on restricted edges as possible. We return to our example that already appeared in Fig. 1. As already mentioned earlier, the instance admits a single stable matching, namely M = {u 1 w 1 , u 2 w 2 , u 3 w 3 , u 4 w 4 }. Since M contains both forbidden edges, the minimum number of violated constraints on restricted edges is 2.
This section is structured as follows: in Section 4.1, complexity and approximability results are presented for sm min restricted violations, sr min forbidden, sr max forced and sr min restricted violations. In Section 4.2 we consider the complexity of sr min restricted violations when the degree of the underlying graph is bounded.

General complexity and approximability results
As mentioned in Section 1, a weighted stable matching instance models sm min restricted violations. Proof. We convert sm min restricted violations into a weighted sm problem using the following weight function: if e is forbidden.
Then a stable matching M has weight |M ∩ P | − |M ∩ Q| = |M ∩ P | + |Q \ M | − |Q|. Since |Q| is invariant, a stable matching of minimum weight will violate the minimum number of constraints on restricted edges. The polynomial-time solvability of sm min restricted violations then follows by the fact that we can find a minimum weight stable matching in sm in polynomial time as discussed in the last paragraph of Section 2.
In the sr context, finding a minimum weight stable matching is NP-hard [12], so the above technique for sm does not carry over to sr. Indeed special cases of sr min restricted violations are NP-hard, as the following result shows. Proof. Clearly both problems belong to the class NP. We begin by proving the NP-hardness of sr min forbidden dec. To do so, we will use a reduction from the decision version of the following problem: Specifically, define min vx cover dec to be the problem of deciding, given a graph G and an integer K, whether G admits a vertex cover of size at most K. min vx cover dec is NP-complete [28].
Given an instance (G, K) of min vx cover dec, the following instance (G ′ , O, P, K) of sr min forbidden dec is constructed. The entire graph G is copied, and then, a gadget is attached to each vertex v i ∈ V (G). It is a complete bipartite graph on four vertices: one of them is p i = v i , whilst the remaining three are denoted byp i , q i andq i . Vertex p i ranksp i at the top, followed by all p j vertices such that v i v j ∈ E(G), in arbitrary order, followed byq i at the bottom of this list. The new vertices' orderings can be seen in Fig. 7. In order to derive an instance with complete lists, all remaining vertices can be placed in arbitrary order to the bottom of the lists. Later we will see that these edges never appear in stable matchings, neither do they block them. The set of forbidden edges comprises all p ipi edges corresponding to the dotted grey edges in our illustrations in Fig. 7.
Proof. This claim follows from the structure of the introduced gadget. First, we observe that in M , eachp i is either matched to p i or to q i , for otherwise These three requirements imply that the claim must hold.
Proof. The matching M is constructed based on the following case distinction: Clearly |M ∩ P | ≤ K. Moreover, no edge in the gadgets can block M , because the preferences inside the gadget are cyclic. Due to the vertex cover property, edges between two p-vertices have at least one end vertex in C, thus, at least one of their end vertices is matched to its first-choice partnerp in G ′ . For each vertex in G ′ , the edges in the sets "rest" are worse than the edge in M .
Proof. Claim 4.4 allows us to investigate only two cases per gadget. We use a similar function to that in Claim 4.5, but in the opposite direction, in order to derive C from M , as follows: Trivially, |C| ≤ K. Suppose C is not a vertex cover. Then, there is an edge v i v j = p i p j for which {p iqi , p jqj } ⊂ {p iqi ,p i q i , p jqj ,p j q j } ⊆ M . Then p i p j blocks M .
To prove NP-completeness for sr max forced dec, let (G ′ , O, Q, K) be the constructed instance, where G ′ , O and K are defined as in the sr min forbidden dec case, and Q = {p iqi : 1 ≤ i ≤ n}. The correctness of the reduction then follows by a similar argument. We remark that min vx cover is NP-hard and cannot be approximated within a factor of 2 − ε for any ε > 0, assuming that the Unique Games Conjecture (UGC) is true [29]. When viewing the construction in Theorem 4.2 as a reduction from min vx cover to sr min forbidden, the measures of an optimal solution in each problem instance are identical. The same is true in the case of sr max forced. It follows that each of sr min forbidden and sr max forced is not approximable within a factor of 2 − ε for any ε > 0, assuming the UGC holds.
On the positive side, for the general sr min restricted violations problem we can close the gap with the best possible approximation ratio if Q = ∅ or |Q| is sufficiently large. To derive this result, we use the 2-approximability of weighted sr for non-negative weight functions [12,23]. Due to the non-negativity constraint, the case of 0 < |Q| < |M | remains open. Proof. The NP-hard minimum weight sr problem is 2-approximable in polynomial time [12,23] for all nonnegative weight functions. The assumption Q = ∅ or |Q| ≥ |M | is needed to guarantee non-negativity. A simple computation shows that the weight of a stable matching M is |Q \ M | + |P ∩ M |, if the following weight function is defined on the edges: When studying sr max forced, we measured optimality by keeping track of the number of violated constraints. One might find it more intuitive instead to maximise |Q ∩ M |, the number of forced edges in the stable matching. Our NP-hardness proof for sr max forced given in Theorem 4.2 can be used without modification to show NP-hardness under this different measure, however the approximability results need to be revisited. In fact, this modification of the measure changes the approximability of the problem as well: Theorem 4.8. For sr max forced, the maximum of |Q ∩ M | cannot be approximated within n 1 2 −ε for any ε > 0, unless P = NP.
Proof. We adapt the proof of Theorem 4.2 so that the reduction is from max ind set, the problem of finding a maximum independent set in a given graph G = (V, E). max ind set is not approximable within N 1−ε for any ε > 0, unless P = NP [30], where N = |V |. In the modified reduction an independent set of vertices S in G corresponds to the matching in the constructed instance I of sr max forced. Suppose that A is an n 1 2 −ε -approximation algorithm that approximates |Q ∩ M opt | in I, for some ε > 0, where M opt is an optimal solution and n is the number of agents in I. Note that |S opt | = |M opt |, where S opt is a maximum independent set in G. Moreover n 1 2 −ε = (4N ) 1 2 −ε ≤ N 1−ε since n = 4N and without loss of generality we can assume that N ≥ 4. We thus reach a contradiction to the inapproximability of max ind set.

Bounded parameters
We now turn to the complexity of sr min restricted violations and its variants when the degree of the underlying graph is bounded or some parameter of the instance can be considered as a constant. With Theorems 4.9 and 4.13 we draw the line between NP-hard and polynomially solvable cases in terms of degree constraints.
Theorem 4.9. sr min forbidden dec and sr max forced dec are NP-complete even if every preference list is of length at most 3.
Proof. As in Theorem 4.2, both problems belong to NP. We firstly show the NP-hardness of sr min forbidden dec for this length restriction on preference lists. To do so, we reduce from min vx cover dec in cubic graphs, which is NP-complete [31,32]. Hence let I = (G, K) be an instance of min vx cover, where G = (V, E) is a cubic graph, V = {v 1 , . . . , v n } and E = {e 1 , . . . , e m }. For each i (1 ≤ i ≤ n), suppose that v i is incident to edges e j1 , e j2 and e j3 in G, where without loss of generality j 1 < j 2 < j 3 . Define We construct an instance I ′ of sr min forbidden dec as follows. The set V ′ ∪ W ∪ E ′ ∪ F constitutes the set of vertices in I ′ , where these sets are defined as follows: . The preference lists of these vertices (also indicating the edges of the graph) are as shown in Fig. 8 Claim 4.10. I ′ admits a stable matching in which every vertex is matched.
Starting with the argument that each v r i ∈ V ′ , each e 1 j ∈ E ′ and each f 1 j ∈ F receive its first-choice partner in M , it is straightforward to verify that M is stable: the remaining vertices prefer, to their partners, only vertices that already have their first-choice partners. Theorem 1.1 implies then that every stable matching in I ′ matches every vertex in I ′ .
In Claims 4.11 and 4.12 we show that G has a vertex cover C where |C| ≤ K if and only if I ′ has a stable matching M where |M ∩ P | ≤ K.
Claim 4.11. If G has a vertex cover C such that |C| ≤ K in I, then there is a stable matching M in I ′ with |M ∩ P | ≤ K.
Proof. We construct a matching M in I as follows.  Proof. We construct a set of vertices C in G as follows. Claim 4.10 states that M matches every vertex in I. Hence for each i (1 ≤ i ≤ n), either V c i ⊆ M or V u i ⊆ M . In the former case add v i to C. As |M ∩ P | ≤ K, it follows that |C| ≤ K. Also, for each j (1 ≤ j ≤ m), as M matches every vertex in I, either E 1 j ⊆ M or E 2 j ⊆ M . Assume that C is not a vertex cover in G, i.e., there is an edge e j = v j,1 v j,2 such that v j,1 ̸ ∈ C and v j,2 ̸ ∈ C. Suppose that v i1 = v j, 1 and v i2 = v j,2 . Then V u i1 ⊆ M and V u i2 ⊆ M . Now let r ∈ {1, 2, 3} be such that e j = e i1,r and let r ′ ∈ {1, 2, 3} be such that e j = e i2,r ′ . Then e(v r i1 ) = e 1 j and v r i1 prefers e 1 j to its partner in M . Similarly e(v r ′ i2 ) = e 2 j and v r ′ i2 prefers e 2 j to its partner in M . If E 1 j ⊆ M , then v r ′ i2 e 2 j blocks M . Otherwise E 2 j ⊆ M and v r i1 e 1 j blocks M . This contradiction to the stability of M implies that C is a vertex cover in G.  Proof. Since the set of matched vertices is the same in all stable matchings by Theorem 1.1, finding a stable matching in O(n) time in these very strongly restricted instances marks all vertices that need to be matched.
In each component C, since C is a path or a cycle, there are at most two possible stable matchings satisfying these constraints. We choose the stable matching in C that violates fewer constraints.
Short preference lists are not the only case when sr min restricted violations becomes tractable, as our last theorem shows. Proof. Suppose firstly that L = |P | + |Q| is a constant. We will show how to solve sr min restricted violations dec in polynomial time. We assume that, for the purposes of this proof, the problem definition is modified so that, given an instance I = (G, O, P, Q, K), we are required to find a stable matching M in G such that |M ∩ P | + |Q \ M | ≤ K, or report that no such matching exists.
Our first observation is that this problem is trivially solvable if the target value K satisfies K ≥ L. In this case, any stable matching will suffice. Now assume that K < L. Suppose firstly that there is a stable matching M in G violating k ≤ K restrictions. Then |M ∩ P | = k 1 and |Q \ M | = k 2 , where k 1 + k 2 = k. If we let P ′ = M ∩ P and Q ′ = Q \ M , then M is a stable matching in I containing no edge in (P \ P ′ ) ∪ Q ′ and containing all edges in P ′ ∪ (Q \ Q ′ ).
Hence to solve sr min restricted violations dec we generate all subsets S of P ∪ Q of size k, for each k ≤ K. Then we run the algorithm of [15]  We now show how to use the above approach in order to solve sr min restricted violations. If we find a solution during course of this process, then G admits a stable matching M such that |M ∩P |+|Q\M | ≤ K. In order to minimise |M ∩ P | + |Q \ M | it suffices to use the above technique in combination with a binary search procedure on values of K ≤ L. This requires O(log L) invocations of the algorithm for the decision problem, which is a constant, and hence the overall time complexity remains O(m L+1 ). Now suppose that L is the minimal number of violated constraints, and that L is constant. For each value of K, where K starts from 0 and increases by 1 after each iteration, we execute the algorithm described above to solve sr min restricted violations dec, noting that it is sufficient to generate all subsets of size exactly K at each iteration. We terminate as soon as we find a stable matching M such that |M ∩ P | + |Q \ M | ≤ K. This process is bound to halt, since by definition, I admits a stable matching M such that |M ∩ P | + |Q \ M | = L, so K ≤ L. Thus the overall time complexity of this approach is O((L + 1)m L+1 ) = O(m L+1 ), which is polynomial if L is a constant.

Conclusion and open questions
In this paper, we investigated the stable marriage and the stable roommates problems on graphs with forced and forbidden edges. Since a solution satisfying all constraints need not exist, two relaxed problems were defined. In min bp sm restricted, constraints on restricted edges are strict, while a matching with the minimum number of blocking edges is searched for. On the other hand, in sr min restricted violations, we seek stable solutions that violate as few constraints on restricted edges as possible. For both problems, we determined the complexity and studied several special cases.
One of the most striking open questions is the approximability of sr min restricted violations if 0 < |Q| < |M |. Our other open question is formulated as Conjecture 3.18: the complexity of min bp sm restricted is not known if each woman's preference list consists of at most 2 elements. A more general direction of further research involves the sm min restricted violations problem. We have shown that it can be solved in polynomial time, using algorithms for minimum weight stable marriage. The following question arises naturally: is there a faster method for sm min restricted violations that avoids reliance on Feder's algorithm or linear programming methods?
Another natural generalisation is to consider preference lists involving ties. Our hardness results carry over to this case, but the positive results need to be revisited.
Besides the two main problems discussed in this paper, other approximation concepts can also be investigated in the framework of restricted edges. For example one alternative would be to combine the two objectives that we considered. Can we efficiently find matchings that minimise the total number of violated constraints, that is, |bp(M )| + |M \ Q| + |M ∩ P |?
Counting the number of blocking pairs is the most prevalent, but not the only relaxation of stability that has been studied in the literature. Other relaxations can also be combined with the presence of restricted edges in the instance, such as the following concepts.
• Maximum internally stable matchings [33], where the goal is to maximise the set of pairs that are stable within themselves. • Maximum irreversible stable matchings [34], where the goal is to maximise the number of irreversible pairs. A pair is irreversible if, once it is contained in a matching, no agent from the pair will ever be in a blocking edge, irrespective of how the outside agents are matched. • Socially stable matchings [35], where only a fixed subset of pairs (described by a given social network graph) can be blocking.