  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.
