\section{Missing proofs}\label{sec:appendix}
The following problem will be useful for the proofs that we provide in this Appendix. 
\begin{problem}[{\textsc{Max-Card HRTI}}]
\label{problem_maxcar}
\boxxx{
{\sc instance}:  An \emph{HRTI} instance $\Gamma = \langle {\mathcal R},{\mathcal H},\succ, \mathbf{c} \rangle$ with $c_j\in\{0,1\}$, for all $j \in {\mathcal H}$, $| {\mathcal H}|=|{\mathcal R}|$ and a non-negative integer target value $K \in {\mathbb Z}_+$.\\
{\sc question}: Is there a weakly stable matching $M$ such that $\vert M \vert \geq K$?
}
\end{problem}
Recall that HRTI corresponds to the problem with ties and incomplete preference lists. In~\cite{manlove2002hard}, the authors proved that {\textsc{Max-Card HRTI}} is NP-complete. As the next remark states, this result holds even if ties are at the head of the preference list, only on one side of it, at most one tie per list, and each tie is of length 2.

\begin{remark}\label{remark-wlog}
After the proof of Lemma 1 in \cite{manlove2002hard}, the authors showed that the problem {\textsc{Max-Card HRTI}}
can be simplified to the case in which ties are only on one side of the bipartition and are at the end of the preference list. Since the ties of the new instance created in Lemma 1 from \cite{manlove2002hard} are at most two, we can use the same reasoning to assume instead, without loss of generality, that in an instance of {\textsc{Max-Card HRTI}} and the corresponding {\textsc{Min-w SMT}} instance of Corollary~\ref{corollary-Manlove} ties occur only at the \emph{head} of a preference list. 
\end{remark}

\subsection{Proof of Corollary \ref{corollary-Manlove}}


In this section, we prove that {\textsc{Min-w SMT}} is NP-complete and its optimization version cannot be approximated within a certain factor.  The proof is inspired by the proof of Theorem 7 in~\cite{manlove2002hard}. The result in~\cite{manlove2002hard} is stated in the traditional notation of the stable marriage problem where both sides are defined as women and men, instead of residents and hospitals. To keep coherence with the previous work, for this proof we also denote both sides as women and men.

\begin{proof}[Proof of Corollary \ref{corollary-Manlove}]
Clearly, {\textsc{Min-w SMT}} is in NP.  Given $\varepsilon>0$, let $a= \lceil (3 / \varepsilon)\rceil .$ From Theorem 2 in \cite{manlove2002hard}, we know that, when ties occur on the women's side only, and each tie has length two, {\textsc{Max-Card HRTI}} is NP-complete. Consider an instance of Problem~\ref{problem_maxcar} with ${\mathcal H}=\left\{m_{1}, m_{2}, \ldots, m_{n}\right\}$  and ${\mathcal R}=\left\{w_{1}, w_{2}, \ldots, w_{n}\right\}$. We assume that the target value $K$ is equal to $n$, since it was shown that even for this target value the problem is NP-complete. Let $O_{h}$ (resp. $R_{h}$) denote the preference list of man $m_{h}$ (resp. woman $w_{h}$) for $h\in[n]$. Next, we build an instance of {\textsc{Min-w SMT}}. Let $C:=n^{ a-1 }$, then 
 \begin{itemize}
     \item the set of men is ${\mathcal H}'={\mathcal H}^{0} \cup\left(\bigcup_{h=1}^{C} {\mathcal H}^{h}\right)$ with $ {\mathcal H}^{0}=\left\{m_{1}^{0}, m_{2}^{0}, \ldots, m_{n^a}^{0}\right\}$ and ${\mathcal H}^{h}=\left\{m_{1}^{h}, m_{2}^{h}, \ldots, m_{n}^{h}\right\}$ for $h\in[C]$;
     \item the set of women is ${\mathcal R}'={\mathcal R}^{0} \cup\left(\bigcup_{h\in[C]} {\mathcal R}^{h}\right)$ with
    ${\mathcal R}^{0}=\left\{w_{1}^{0}, w_{2}^{0}, \ldots, w_{n^a}^{0}\right\}$ and ${\mathcal R}^{h}=\left\{w_{1}^{h}, w_{2}^{h}, \ldots, w_{n}^{h}\right\}$ for $h\in[C]$;
    \item for each $h\in[n]$ and $s\in[C]$, let $O_{h}^{s}$ be the preference list obtained from $O_{h}$ by replacing woman $w_{k}$ in $O_{h}$ by the corresponding woman $w_{k}^{s}$, for every  $k\in[n]$. We refer to the women in $O_{h}^{s}$ as the proper women for $m_{h}^{s} .$ Similarly, we define $R_{h}^{s}$ and the proper men for $w_{h}^{s}$. The preference lists for ${\mathcal H}'$ and ${\mathcal R}'$ are 
\begin{align*}
    m_{h}^{0}&: w_{h}^{0} \ldots  \hspace{4.7em} h\in[n^{a}] \\
    m_{h}^{s}&: O_{h}^{s}, {\mathcal R}^{0} \ldots \hspace{3em} h\in[n], \, s\in[C]\\
   
    w_{h}^{0}&: m_{h}^{0} \ldots  \hspace{4.6em} h\in[n^{a}] \\
    w_{h}^{s}&: R_{h}^{s},{\mathcal H}^0 \ldots \hspace{3em}  h\in[n], \ s\in[C]
\end{align*}
    where the dots \lq\lq\ldots \rq\rq\, in the preference lists mean that the remaining agents on the other side of the bipartition are ranked strictly and arbitrarily, and the sets mean that the agents within are ranked according to their indices;
    \item the target value is $K'=(n^{a+2})/2$.
 \end{itemize}
 

Our {\textsc{Min-w SMT}} instance comprises $2 n^{a}$ men and $2 n^{a}$ women, so that $\bar{n}:=2 n^{a} $. Note also that the only ties in {\textsc{Min-w SMT}} occur in the preference lists of women $w_{h}^{s}$ for $h\in[n], \ s\in[C]$. Moreover, there is at most one tie per list, and each tie has length 2. 

Suppose that we have a YES instance for {\textsc{Max-Card HRTI}}, \emph{i.e.}, there is a stable matching $M$ with $|M|=n$. 
We create a matching $M^{\prime}$ in {\textsc{Min-w SMT}} as follows: For every $h\in[n^a]$, we add the pair $\left(m_{h}^{0}, w_{h}^{0}\right)$ to $M^{\prime}$, and for each $s\in[n]$, we add the pair $\left(m_{s}^{\ell}, w_{k}^{\ell}\right)$ to $M^{\prime}$ for all $ \ell\in[C]$, where $\left(m_{s}, w_{k}\right) \in M $. Note that $M^{\prime}$ is
stable for our {\textsc{Min-w SMT}} instance. We also have that
\[
\text{AvgRank}\left(M^{\prime}\right) \leq n^a + n^{a-1} n^{2} \leq \frac{n^{a+2}}{2}=K',
\]
since, without loss of generality, we may choose $n \geq 3$. Therefore, the objective value in  {\textsc{Min-w SMT}} satisfies the target of $K'$.

On the other side, let us suppose that we have a NO instance for {\textsc{Max-Card HRTI}}, \emph{i.e.}, it does not have a stable matching of cardinality $n$. Then, in any stable matching $M^{\prime}$ of {\textsc{Min-w SMT}}, it holds that, for every $s\in[C]$, there is some $h\in[n]$ for which $w_{h}^{s}$ is not matched to one of her proper men. 
Nonetheless, in $M^{\prime}, m_{h}^{0}$ and $w_{h}^{0}$ must be partners, for every $h\in[n^{a}]$. Therefore, there is some $h\in[n]$ such that  $\text{rank}_{w_{h}^{s}}\left( M'(w_{h}^{s}) \right)>n^{a} $.
Hence, $\text{AvgRank}\left(M^{\prime}\right)> n^{2 a-1}>K'$ for any stable matching of our {\textsc{Min-w SMT}} instance.

Therefore, the existence of a polynomial-time approximation algorithm for {\textsc{Min-w SMT opt}}  whose approximation ratio is as good as $\left(2 n^{2 a-1}\right) / n^{a+2}=2 n^{a-3}$ would give a polynomial-time algorithm for determining whether {\textsc{Max-Card HRTI}} has a stable matching in which everybody is matched (\emph{i.e.}, $K=n$). To conclude, we note that $2 n^{a-3}=\left(2 / 2^{1-3 / a}\right) \bar{n}^{1-3 / a}>\bar{n}^{1-3 / a} > \bar{n}^{1-\varepsilon}$, which ends the proof.
\end{proof}


\subsection{Proof of Theorem \ref{theorem_max_expansion}}
In this section, we prove that {\textsc{Max-Card$_{\text{exp}}^{\text{sub}}$ HRI}} is NP-complete.

\begin{proof}[Proof of Theorem \ref{theorem_max_expansion}]
We build  a polynomial reduction from an instance of {\textsc{Max-Card HRTI}} where ties are only on the hospital side, they are at the head of the preference list and are of length two. Let ${\mathcal H}$ and ${\mathcal R}$ be the set of hospitals and residents in $\Gamma$, respectively; ${\mathcal H}={\mathcal H}'\cup {\mathcal H}''$, where ${\mathcal H}'$ is the set of hospitals with a tie at the head of the preference list and ${\mathcal H}''$ is the set of hospitals with a strict preference list. 

We build an instance $\hat\Gamma=\langle \hat{\mathcal R},\hat{\mathcal H},\hat\succ, \hat{\mathbf{c}} \rangle$ of {\textsc{Max-Card$_{\text{exp}}^{\text{sub}}$ HRI}} as follows: 
\begin{itemize}
    \item The set of residents is a copy of $\hat{\mathcal R}={\mathcal R}$;
    \item The set of hospitals $\hat{\mathcal H}$ consists of a copy of ${\mathcal H}''$ and the set $\tilde {\mathcal H} = \{ j': \ j \in {\mathcal H}'\} \cup \{j'': \ j\in {\mathcal H}' \}$, \emph{i.e.}, we make two copies per hospital in ${\mathcal H}'$. Each hospital in $\tilde {\mathcal H}$ has capacity 0 and each hospital in ${\mathcal H}''$ has capacity 1;
    \item For each resident in $\hat{\mathcal R}$, we keep the preference list that she has in the original instance $\Gamma$, with the exception that each $j \in {\mathcal H}'$ in her preference lists is replaced by $j'$ if she does not appear in the tie. If she is the first resident listed in the tie of $j\in {\mathcal H}'$, then we replace the hospital $j$ in the preference list by $j'$; otherwise, if the resident is listed second in the tie of $j\in {\mathcal H}'$, then we replace the hospital $j$ in the preference list by $j''$;
    \item For the hospitals in ${\mathcal H}''$, we maintain their preference lists of $\Gamma$ over the residents in ${\mathcal R}$. For a hospital $j\in {\mathcal H}'$ with a preference list $(i_{\sigma_1}, i_{\sigma_2}),i_{\sigma_3},\ldots,i_{\sigma_s}$,  the preference list of $j'$ becomes $i_{\sigma_1},i_{\sigma_3},\ldots,i_{\sigma_s}$ and that of $j''$ becomes $i_{\sigma_2},i_{\sigma_3},\ldots,i_{\sigma_s}$;
    \item For each hospital $j\in {\mathcal H}''$, we create a set ${\mathcal H}_j=\{j\}$ with $B_j =0$. For every hospital $j\in {\mathcal H}'$, we create a set ${\mathcal H}_j=\{ j', j''\}$ with $B_j =1$. Clearly, the sets ${\mathcal H}_j$ induce a partition of the set of hospitals $\hat{\mathcal H}$.
    \item The target value is $K$, \emph{i.e.}, the same as in the {\textsc{Max-Card HRTI}} instance.
\end{itemize}








Let $M$ be a weakly stable matching of the {\textsc{Max-Card HRTI}} instance. We will show that there is a feasible allocation of the capacities $\mathbf{t}$ and a stable matching $M_{\mathbf{t}}$ in $\hat{\Gamma}_{\mathbf{t}}$ with the same cardinality, and thus, establishing the problems equivalence.  For every pair $(i,j)$ in $M$, we have to distinguish whether $j\in {\mathcal H}'$ or $j\in {\mathcal H}''$. If $j\in {\mathcal H}''$, then we add the corresponding pair $(i,j)$ to $M_{\mathbf{t}}$; recall that for a hospital $j\in{\mathcal H}''$, $B_j = 0$.
Otherwise, $j\in {\mathcal H}'$. If $i\neq i_{\sigma_2}$, then we allocate the extra capacity of part ${\mathcal H}_j$ to $j'$ and we match the pair $(i,j')$. If, instead, $i= i_{\sigma_2}$, then we match the pair $(i,j'')$ by assigning the extra capacity of part ${\mathcal H}_j$ to $j''$. If there is a hospital $j\in {\mathcal H}'$ that has not been assigned to any resident, then we may allocate the extra capacity of part ${\mathcal H}_j$ to $j'$.\footnote{Alternatively, we may leave un-assigned the extra capacity $B_j$ for every unassigned hospital $j\in {\mathcal H}'$ in $M$.} 


Note that $M_{\mathbf{t}}$ is stable indeed. If not, there must be a blocking pair $(i,j)$ where both the resident and the hospital have a capacity of 1 (otherwise, a hospital with capacity 0 could not create a blocking pair). Note that $j$ must be in some ${\mathcal H}_k$ given that those subsets form a partition of $\hat{\mathcal H}$.  Indeed, in each set ${\mathcal H}_k$  exactly one hospital has capacity 1, and for $k=j$, $j$ is exactly such hospital. If $|{\mathcal H}_j|=1$, then $j\in{\mathcal H}''$ and, thus, it has exactly the same preference list that it has in the instance $\Gamma$; therefore the corresponding pair $(i,j)$ in $M$ is a blocking pair, which yields a contradiction. If $|{\mathcal H}_j|=2$, then we have to distinguish whether $j=j'$ or $j=j''$. If $j=j'$, then we find that $(i,j)$ is a blocking pair in $M$. Otherwise, if $j=j''$, then $(i,j)$ is a blocking pair if and only if $i= i_{\sigma_2}$ since it is the only resident ranking $j''$ in $\hat\Gamma$.  The pair $(i,j'')$ could be a blocking pair only if $j''$ has capacity 1; the extra capacity $B_j=1$ was assigned to $j''$ in accordance with the reduction. Therefore $(i,j'')$ is already matched in $M_{\mathbf{t}}$ and $(i,j'')$ cannot be a blocking pair.

Note that we have created a bijection between the set of stable matchings in the {\textsc{Max-Card HRTI}} instance  and the allocation of extra spots as well as the set of stable matchings in the {\textsc{Max-Card$_{\text{exp}}^{\text{sub}}$ HRI}} instance modulo the  stable matchings in  the {\textsc{Max-Card$_{\text{exp}}^{\text{sub}}$ HRI}} instance that have some unassigned hospitals of the form $j'$ or $j''$. Moreover, this correspondence preserves the cardinality of the stable matching. 

To conclude, note that the created instance introduces a polynomial number of hospitals, residents, preferences and pairs $\{({\mathcal H}_j, B_j)\}_{j\in {\mathcal H}}$ in the input. Moreover, it can be verified in polynomial time that: (1) the vector of allocation $\mathbf{t}$ satisfies the corresponding constraints and (2) the constructed stable matching has a cardinality greater or equal than the target value. 
\end{proof}














\section{The Capacity Expansion Problem}\label{sec:expansion}


Our main result in this section establishes the computational complexity and inapproximability of Problem \ref{problem_def}. Denote by {\textsc{Min-Avg$_{\text{exp}}$ HR opt}} the optimization version of Problem \ref{problem_def}, \emph{i.e.}, the problem of finding the allocation of extra spots and the stable matching in the expanded instance that minimizes $\text{AvgRank}$. Formally, our main result is the following.
\begin{theorem}\label{HR_ext_NP_complete}
{{\sc CA}$_{\text{ext}}$} is NP-complete. Moreover, for any $\varepsilon>0$, {\textsc{Min-Avg$_{\text{exp}}$ HR opt}} cannot be approximated within a factor of $(\bar{n}/2)^{(1-\varepsilon)/2}$, where $\bar{n}$ is the number of residents, unless \emph{P=NP}. 
\end{theorem}


To give some insights on the difficulty of Problem \ref{problem_def},
we first present an intuitive approach when $B=1$ and we show that it does not always provide an optimal solution.
In real life instances, certain hospitals may be ``more popular'' than others, namely, they are preferred by well-known voting methods such as Majority or Borda count \cite{zwicker2016introduction}. 
Thus, when $B=1$, a natural approach is to assign the additional spot to the hospital that is preferred by the majority or Borda count. 
However, as the following example shows, this is not necessarily optimal. 


\paragraph{Counterexample for the Majority and Borda count}  Let ${\mathcal R}=\{i_1,i_2,i_3,i_4,i_5, i_6\}$ and ${\mathcal H}=\{j_1,j_2,j_3,j_4 \}$.  We assume that all hospitals have the same preference list: $i_1\succ i_2\succ\cdots\succ i_6$. Hospitals $j_1, j_2$ and $j_3$ have each capacity 1, and hospital $j_4$ has capacity 3. Resident $i_1$ ranks hospitals as $j_2\succ j_1\succ j_3\succ j_4$. Resident $i_2$ ranks hospitals as $j_2\succ j_3\succ j_1\succ j_4$. Resident $i_3$ ranks hospitals as $j_3\succ j_2\succ j_4\succ j_1$. Residents $i_4$, $i_5$ and $i_6$ rank hospitals as $j_1\succ j_4\succ j_3\succ j_2$. The resident-optimal stable matching is $ M = \{ (i_1,j_2), (i_2,j_3), (i_3,j_4), (i_4,j_1), (i_5,j_4),(i_6,j_4)\}$ with $\text{AvgRank}(M)=11$. Now, consider Problem \ref{problem_def} with $B=1$ and $K=9$. For this instance, an intuitive solution is allocating the extra spot to $j_1$, which is the most preferred hospital according to both Majority vote and Borda vote; the allocation of one extra capacity to $j_1$ is sub-optimal. Indeed, if we expand the capacity $c_{j_1}=1$ to $c_{j_1}=2$, then resident $i_5$ would be assigned to hospital $j_1$, which leaves an extra spot in hospital $j_4$. This solution reduces the average hospital rank by 1 unit and the resulting matching does not meet the target $K=9$. Instead, if we expand the capacity of $j_2$ to 2, then resident $i_2$ is admitted by hospital $j_2$, leaving an empty spot in hospital $j_3$ that is filled by resident $i_3$; the resulting matching has an average hospital rank of 9.\\


 



As the previous example shows, the allocation of one extra spot is not trivial when we try to solve it by just looking at the residents' preferences. 
However, we can still solve this problem in polynomial time by doing an exhaustive search in combination with the DA algorithm. To achieve this, we compute the resident-optimal stable matching using the DA mechanism in the instance $\Gamma_{\mathbf{t}}$ with $\mathbf{t}={\mathbf{1}}_{j}$ for each $j\in {\mathcal H}$, where ${\mathbf{1}}_j\in\{0,1\}^{{\mathcal H}}$ is the indicator vector whose $j$-th component is 1 and the rest is 0. Once we obtain the cost for each $j\in{\mathcal H}$, we output the resident-optimal stable matching of minimum average hospital rank. Finally, we compare with our target $K$ to decide if such an allocation exists or not. Since the DA algorithm's runtime complexity is $O(|{\mathcal R}|\cdot |{\mathcal H}|)$ \cite{gale1962college}, then this exhaustive search runs in $O(|{\mathcal R}|\cdot |{\mathcal H}|^2)$. Whether this can be improved remains an open question.

To prove Theorem \ref{HR_ext_NP_complete}, we first study a variant of the \emph{egalitarian stable marriage} problem \cite{manlove2013algorithmics}. 
Formally, the stable marriage (SM) problem corresponds to the HR problem where $c_j= 1$ for all $j\in{\mathcal H}$. 
We use SMT to indicate the version of SM when ties are present in the preference lists. A tie appears when an agent allocates in the same position of the list two different participants of the opposite side. For example, if the preference list for resident $i$ is $j_4, (j_1, j_3), j_2$,\footnote{Throughout this paper, round brackets denote a tie.} then the rankings are $\text{rank}_i(j_4) = 1$, $\text{rank}_i(j) = 2$ for $j \in \{j_1,j_3\}$ and $\text{rank}_i(j_2) = 4$. For the SMT problem, stable matchings can be defined in several ways, but in this paper we consider \emph{weak stability} \cite{manlove2013algorithmics}. Formally, a matching $M$ is weakly stable if there is no pair such that both agents \emph{strictly} prefer each other over their allocation in $M$.
An egalitarian stable matching is a stable matching that minimizes the total sum of the rankings, \emph{i.e.}, $\sum_{(i,j)\in M} [\text{rank}_i(j)+\text{rank}_j(i)]$. Manlove et al.~\cite{manlove2002hard} proved that the problem of finding the egalitarian stable matching for SMT is not approximable within $\bar{n}^{1-\epsilon}$, for any $\epsilon>0$, unless $\text{P}=\text{NP}$, where $\bar{n}$ is the size of one side of the bipartition. For more details, we refer to Theorem 7 in \cite{manlove2002hard}.

Let us define the following variant of the egalitarian SMT problem.
\begin{problem}[\textsc{Min-w SMT}]
\label{problem_minW}
\boxxx{
{\sc Instance}: An \emph{SMT} instance $\Gamma = \langle {\mathcal R},{\mathcal H},\succ, \mathbf{c} \rangle$ with $ c_j = 1$ for all $j \in {\mathcal H}$ and a target value $K \in \mathbb{{\mathbb Z}_+}$.  \\
{\sc Question}: Is there a weakly stable matching $M$ such that $\text{\emph{AvgRank}}(M) \leq K$?}
\end{problem}

We use {\textsc{Min-w SMT opt}} to denote the optimization version of {\textsc{Min-w SMT}}, \emph{i.e.}, the problem of finding a weakly stable matching that minimizes $\text{AvgRank}$. Using the ideas in \cite{manlove2002hard}, we can obtain the following result for \textsc{Min-w SMT}. 
\begin{corollary}\label{corollary-Manlove}
{\textsc{Min-w SMT}} is NP-complete. Moreover, for any $\varepsilon>0$, {\textsc{Min-w SMT opt}} is not approximable within a factor of $\bar{n}^{1-\varepsilon}$, unless $\mathrm{P}=\mathrm{NP}$, where $\bar{n}=|{\mathcal H}|$. This result holds even if ties are only in one side, there is at most one tie per list, and each tie is of length two. 
\end{corollary}
For completeness, we provide the proof of this corollary in the Appendix.
Let us now provide a sketch of the steps to prove Theorem \ref{HR_ext_NP_complete}.
Given an instance $\Gamma$ of {\textsc{Min-w SMT}}, we construct the following instance $\hat\Gamma$ of  {{\sc CA}$_{\text{ext}}$}: For every hospital in $\Gamma$ that has ties in its preference list, we create a \textit{village} of residents and hospitals with different capacities and strict preferences. 
In Lemma \ref{lemma_first_complexity}, we prove that the construction can be done in polynomial time and it selects a special stable matching in the new instance. Let $M$ be the stable matching of minimum average hospital rank in {\textsc{Min-w SMT}};  in Lemma \ref{lemma_second_complexity}, we prove that the stable matching $\hat{M}_{\mathbf{t}}$ in $\hat\Gamma$ is in fact the stable matching of minimum average hospital rank in {{\sc CA}$_{\text{ext}}$}. 



\subsection{Design of the Instance}\label{sec:exp_reduction}

First, we observe that {\textsc{Min-w SMT}} is NP-complete even if ties occur only among the preference lists of residents and in each preference list there is at most one tie of length 2, and it is positioned at the head of the list. For more details, we refer to Remark~\ref{remark-wlog} in the Appendix. Throughout this section, we assume that an instance of SMT satisfies these properties. Now, we introduce a polynomial transformation from such an instance of {\textsc{Min-w SMT}} to an instance of {{\sc CA}$_{\text{ext}}$}.

Let $\Gamma = \langle {\mathcal R},{\mathcal H},\succ, \mathbf{c} \rangle$ be an instance of {\textsc{Min-w SMT}} such that $c_j = 1$ for all $j\in {\mathcal H}$ and $|{\mathcal R}|=|{\mathcal H}|=n$. Let $L\leq n$ be the number of residents with ties in their preference list.
The set of residents is partitioned in two sets ${\mathcal R}={\mathcal R}'\cup {\mathcal R}''$ where ${\mathcal R}'$ is the set of residents with a tie of length two at the head of the preference list and ${\mathcal R}''$ is the set of residents with a strict preference list. Henceforth, we fix an ordering of the residents in ${\mathcal R}$ and denote ${\mathcal R}'=\{i_1,\ldots,i_L\}$ and ${\mathcal R}''=\{i_{L+1},\ldots, i_n\}$. Since preference lists are complete, observe that in any weakly stable matching every resident is matched.\footnote{This follows from the hypothesis that preference lists are complete and that the total capacity of the hospitals can accommodate all the residents.
}

In the following, we create an instance $\hat\Gamma = \langle \hat{\mathcal R},\hat{\mathcal H},\hat\succ, \hat{\mathbf{c}} \rangle$ of {{\sc CA}$_{\text{ext}}$} with a specific target value and budget.  

\paragraph{Hospitals and residents.} First, we add a copy of the hospitals in ${\mathcal H}=\{j_1,\ldots,j_n\}$ and residents in ${\mathcal R}''=\{i_{L+1},\ldots,i_{n}\}$ 
We also introduce a set of hospitals ${\mathcal H}^0=\{j^0_1,\ldots,j^0_{n^2}\}= {\mathcal H}^{0,1}\cup\ldots\cup{\mathcal H}^{0,n}$ of size $n^2$ (where each ${\mathcal H}^{0,h}$ has size $n$), a set ${\mathcal Z}=\{z_1,\ldots,z_{n^3}\}$ of hospitals of size $n^3$, and a set ${\mathcal X}=\{x_1,\ldots,x_{n\cdot L}\}$ of hospitals of size $n\cdot L$. Recall that we index the residents in ${\mathcal R}'$ as $i_1,\ldots,i_L$. For every resident $i_\ell\in {\mathcal R}'$, where $\ell\in[L]$, we introduce additional hospitals and residents, to form a structure that we call \textit{village}, namely
\begin{itemize}
    \item a set of residents ${\mathcal W}_\ell=\{ w_{\ell,h} \}_{h\in[n]}$;
    \item a resident $y_\ell$;
   
    \item two sets of hospitals ${\mathcal V}_{\ell,0}=\{v^{0}_{\ell,h} \}_{h\in [n]}$ and ${\mathcal V}_{\ell,1}=\{v^{1}_{\ell,h} \}_{h\in [n]}$. Let ${\mathcal V}_\ell={\mathcal V}_{\ell,0} \cup {\mathcal V}_{\ell,1}$.
\end{itemize}
We denote as ${\mathcal B}_{i_\ell}$ the village associated with resident $i_\ell\in{\mathcal R}'$ and ${\mathcal V}:= \bigcup_{\ell=1}^L {\mathcal V}_\ell$. 
In summary, we have $\hat{\mathcal R} = {\mathcal R}''\cup\{{\mathcal W}_\ell,y_\ell\}_{\ell\in[L]}$ and $\hat{\mathcal H} = {\mathcal H} \cup {\mathcal H}^0\cup {\mathcal X}\cup {\mathcal V}\cup {\mathcal Z}$.

\paragraph{Capacity vector.} Now, let us construct the capacity vector: For each hospital $v\in{\mathcal V}\cup{\mathcal H}^0\cup{\mathcal Z}$, we consider $\hat{c}_v = 0$; for every other hospital $j\in {\mathcal H}\cup{\mathcal X}$, we take $\hat{c}_j=1$.

\paragraph{Preference lists.} We now proceed to construct the preference lists in $\hat\Gamma$.


Given a resident $i_\ell\in {\mathcal R}'$ with $\ell\in[L]$, let $(j_{\sigma_1}, j_{\sigma_2}), j_{\sigma_3}\ldots $ be her ranking of the hospitals in the original instance $\Gamma$ (the parenthesis symbolizes the tie at the head of the list). We provide the preference lists of the residents and hospitals in village ${\mathcal B}_{i_\ell}$ with $\ell\in [L]$, namely 
\begin{subequations}
\begin{alignat*}{2} 
 w_{\ell,1} &: v^1_{\ell,1},{\mathcal V}_{\ell,0}\setminus \{v_{\ell,1}^0\}, {\mathcal H}_{n-1}^0, j_{\sigma_1}   ,  {\mathcal Z}, \ldots , {\mathcal X}    \\
 w_{\ell,2} &: v^1_{\ell,2},{\mathcal V}_{\ell,0}\setminus \{v_{\ell,2}^0\}, {\mathcal H}_{n}^0, j_{\sigma_2},   {\mathcal Z},\ldots , {\mathcal X}    \\
 w_{\ell,h} &:  v^1_{\ell,h},{\mathcal V}_{\ell,0}\setminus \{v_{\ell,h}^{0}\},  {\mathcal H}_{(n-1)\cdot h}^0, j_{\sigma_h},   {\mathcal Z},\ldots , {\mathcal X}  \hspace{2em}  h\in\{3,\ldots, n\}\\ 
 y_\ell &:  v_{\ell, 2}^{0}, v_{\ell, 1}^{ 0}, v_{\ell, 3}^{ 0}, \ldots,  v_{\ell, n}^{ 0} ,{\mathcal Z},  \ldots , {\mathcal X}   \\
 v^1_{\ell,h} &: w_{\ell,h},  \ldots \hspace{17.5em}   \ h\in[n] \\
 v^0_{\ell,h} &: {\mathcal W}_\ell\setminus \{ w_{\ell,h} \}  , y_\ell,  \ldots \hspace{13.2em}  h\in[n] 
\end{alignat*}
\end{subequations}
where ${\mathcal H}_h^0=\{j_{1}^0,\ldots,  j_{h}^0  \}$. The purpose of positioning of set ${\mathcal H}_h^0$ in the preference lists of the residents $w_{\ell,h}$ for $h\in[n]$, is to ensure that we can mimic  $\text{rank}_{i_\ell}(j)$, for every $j\in{\mathcal H}$, of the original instance.  The symbol \lq\lq \ldots\rq\rq\ means that the remaining agents on the other side of the bipartition are ranked strictly and arbitrarily.


Now, we present the preference list of the copy of every hospital $j\in {\mathcal H}$ and every resident $i\in {\mathcal R}''$ in the new instance. 
 We modify the original preference list of $j \in {\mathcal H}$ by substituting every resident $i_\ell\in {\mathcal R}'$ (for $\ell\in[L] $) with resident $w_{\ell, r}$, where $r=\text{rank}_{i_\ell}(j)$ is the rank of $j$ in the list of $i_\ell$. If $j$ is ranked first by $i_\ell$, then we substitute $i_\ell$ with resident $w_{\ell, 1}$ when $j$ is the first hospital listed in the tie, otherwise with $w_{\ell, 2}$. Then, hospital $j$ ranks arbitrarily a strict ordering of the remaining residents.

Let $i\in {\mathcal R}''$ and let $j_{\sigma_1},\ldots, j_{\sigma_n} $ be her strict and complete preference list in $\Gamma$.  The preference list of $i$ in our new instance  $\hat\Gamma$ is 
\[
{\mathcal H}^{0,1}_{n-1},j_{\sigma_1},{\mathcal H}^{0,2}_{n-1},j_{\sigma_2},\ldots,{\mathcal H}^{0,n}_{n-1}, j_{\sigma_n}, {\mathcal Z}\ldots \]  

The preference lists of hospitals in ${\mathcal X}$, ${\mathcal H}^0$ and ${\mathcal Z}$ are arbitrary. The sole purpose of the hospitals in ${\mathcal X}$ is to ensure that there are sufficient capacities for all the residents. The scope of the set ${\mathcal H}^0$ is to help mimic the original ranking of the copies of the hospitals. The set of hospitals ${\mathcal Z}$ is introduced to make costly certain re-allocation of extra spots. The set ${\mathcal V}$ is used to leverage the stability and ensure that different allocations of extra spots yield sub-optimal results.

\paragraph{Target value and budget.} Given target $K$ and $L$  residents  with a tie in their list in an instance of {\textsc{Min-w SMT}}, we define target $\bar{K}=n\cdot K + 2n\cdot L$ and budget $B=L\cdot n$ for {{\sc CA}$_{\text{ext}}$}, where $L$ is the number of residents with a tie in their list.\\

Finally, note that $\hat{\mathcal R} = {\mathcal R}''\cup\{{\mathcal W}_\ell,y_\ell\}_{\ell\in[L]}$ and $\hat{\mathcal H} = {\mathcal H} \cup {\mathcal H}^0\cup {\mathcal X}\cup {\mathcal V}\cup {\mathcal Z}$. Therefore, the instance $\hat\Gamma$ consists of $((n-L)+  L \cdot (n+1) ) + (n+ n^2 + n\cdot L + L\cdot 2n + n^3)= n^3 + n^2 + 4n\cdot L + 2n$ residents and hospitals, which is $O(n^3)$; therefore the construction can be done in polynomial time.








\begin{remark}
Note that if no extra spots are assigned in our new instance, the set of hospitals ${\mathcal X}$ ensures that the residents are always matched.\footnote{This could be done also by adding a copy of themselves at the end of their list, which is usually referred to as individual rationality. Matching with oneself means being unassigned.}
Matching the residents to the hospitals in ${\mathcal X}$ leads to a higher average hospital rank. 
In the following section, we will prove that it is optimal to assign $L\cdot n$ extra capacities to the hospitals in ${\mathcal V}$, whose initial capacity is zero. 
\end{remark}

\subsection{Useful Lemmata}
For this section, recall that we are considering budget $B=L\cdot n$, where $L=|{\mathcal R}'|$ is the number of residents with a tie in their preference list.


\begin{lemma}\label{lemma_first_complexity}
For every weakly stable matching $M$ in $\Gamma$ with $\text{\emph{AvgRank}}(M)=K^M$, there is an allocation $\mathbf{t}$ respecting the budget $B=L \cdot n$ and a stable matching $\hat{M}_\mathbf{t}$ in $\hat{\Gamma}_\mathbf{t} = \langle \hat{\mathcal R},\hat{\mathcal H}, \hat\succ,\hat{\mathbf{c}}+\mathbf{t} \rangle$ with $\text{\emph{AvgRank}}(\hat{M}_\mathbf{t})=n\cdot K^M + 2n\cdot L$.
\end{lemma}
\begin{proof}



Let $M$ be a (complete) weakly stable matching in $\Gamma$. Recall that ${\mathcal R}'=\{i_1,\ldots,i_L\}$ is the set of residents in $\Gamma$ with a single tie at the head of the list. Define the following set of indices in $M$: 
\[
\texttt{Idx}(M) = \{(\ell,r): \ r=\text{rank}_{i_\ell}(j), \ (i_\ell,j)\in M\cap({\mathcal R}'\times{\mathcal H})\}.
\]
The set $\texttt{Idx}(M)$ contains the information of the pairs ${\mathcal R}'\times{\mathcal H}$ that are matched in $M$.  Given $M$ and \texttt{Idx}, we now define the following sets that will be helpful in this proof. First, define the set of residents
\[
{\mathcal W}^M = \{w_{\ell, r}\in {\mathcal W}: \ (\ell,r)\in \texttt{Idx}(M)\},
\]
and define the sets of hospitals
\begin{align*}
{\mathcal V}^{M,0} &= \{v^0_{\ell,r}\in {\mathcal V}: \ (\ell,r)\in \texttt{Idx}(M) \},\\
{\mathcal V}^{M,1} &= \{v^1_{\ell,h}: \ (\ell,r)\in \texttt{Idx}(M), \ h\in[n]\setminus\{r\}\}.
\end{align*}
We now provide an allocation of extra spots $\mathbf{t}$ with a total budget $B=L\cdot n$ and a stable matching $\hat{M}_{\mathbf{t}}$ in $\hat\Gamma_{\mathbf{t}}$. 

\begin{itemize}
\item \emph{Allocation of extra spots.}
We assign one extra position to each hospital in ${\mathcal V}^{M,0}\cup{\mathcal V}^{M,1}$. For the rest of the hospitals, we assign 0 extra capacity. We denote this allocation $\mathbf{t}$. Formally, we have
\[
t_u = \left\{\begin{matrix}1 & u\in {\mathcal V}^{M,0}\cup {\mathcal V}^{M,1}\\ 0 & \text{otherwise}\end{matrix}\right.
\]
Since $L= |{\mathcal R}'|$, all of the extra positions $B=L\cdot n$ were used. 

\item \emph{Matching.} For each $(\ell,r)\in\texttt{Idx}(M)$ with $j$ such that $r = \text{rank}_{i_\ell}(j)$ in $\Gamma$, we match the following pairs in $\hat{M}_{\mathbf{t}}$: $(w_{\ell,r},j)$, $(y_\ell, v^0_{\ell,r} )$, and $(w_{\ell,h}, v^1_{\ell,h} )$ for $h\in [n]\setminus \{ r \} $. Note that if $j$ is ranked first by $i_\ell$, the hospital is listed first or second in the tie. If $j$ is listed first, then $r=1$ and we match the pair $(w_{\ell,1},j)$, otherwise, $r=2$ and we match the pair $(w_{\ell,2},j)$.
For each $(i,j)\in M$ with $i\in {\mathcal R}''$, we match the pair $(i,j)$ in $\hat{M}_{\mathbf{t}}$, where $j$ is the corresponding copy in ${\mathcal H}$; recall that ${\mathcal R}''$ is the set of residents with a strict preference list. Formally, matching $\hat{M}_{\mathbf{t}}$ is as follows:
\begin{align*}
\hat{M}_{\mathbf{t}} =& \{(i,j): \ (i,j)\in M\cap({\mathcal R}''\times{\mathcal H})\}\\
& \cup \{(w_{\ell,r},j): \ r=\text{rank}_{i_\ell}(j), \ (i_\ell,j)\in M\cap({\mathcal R}'\times{\mathcal H})\}\\
& \cup \{(y_\ell, v^0_{\ell,r}): \ (\ell,r)\in \texttt{Idx}(M)\}\\
&\cup \{(w_{\ell,h},v^1_{\ell,h}): \ (\ell,r)\in \texttt{Idx}(M), \ h\in[n]\setminus\{r\}\}.
\end{align*}
\end{itemize}

Let us verify that $\hat{M}_{\mathbf{t}}$ is a stable matching $\hat{\Gamma}_{\mathbf{t}} $. First, note that residents $i \in{\mathcal R}''$ and hospitals $j\in {\mathcal H}$ cannot create blocking pairs because of their stability in $M$. Now, let us check the stability of the pairs in each village ${\mathcal B}_{i_\ell}$, where $i_\ell\in{\mathcal R}'$ with $\ell\in[L]$. Consider $j\in\hat{{\mathcal H}}$ and assume for now that $j$ is ranked first by $i_\ell$, \emph{i.e.}, $j$ is listed first or second in the tie: $j = j_{r}$ with $r = 1,2$. The pairs matched in village ${\mathcal B}_{i_\ell}$ are $(w_{\ell, r},j)$, $(y_\ell, v^0_{\ell,r})$ and $(w_{\ell,h}, v^1_{\ell,h})$ for $h\in[n]\setminus\{r\}$.
\begin{itemize}
\item The pair $(w_{\ell, r},j)$ is clearly stable; in fact, $w_{\ell, r}$ cannot be matched to any of the hospitals in $v^1_{\ell,r}$ and ${\mathcal V}_{\ell,0}\setminus \{v_{\ell,r}^0\}$ because they have capacity 0. If $r=2$, $w_{\ell, r} $ cannot be matched to any hospital in ${\mathcal H}^0_{n}$ because they all have capacity 0. Also, $j$
cannot create a blocking pair. Indeed, all the residents $w_{\ell', r'}$ ranked in its preference list before $w_{\ell, r}$ are matched to hospitals of the form $v^1_{\ell', r'}$ that they rank first. The case in which $r=1$ is analogous.
\item For $h\in[n]\setminus\{r\}$, $w_{\ell,h}$ ranks $v^1_{\ell,h}$ first and vice-versa, hence the $n-1$ pairs $(w_{\ell,h}, v^1_{\ell,h})$ are stable.
\item If $r=2$, then $y_\ell$ ranks $v^0_{\ell,r}$ first, and $v^0_{\ell,r}$ cannot be matched to any of the residents in ${\mathcal W}_\ell\setminus \{ w_{\ell,r} \}$ because of the previous point; therefore, pairs $(y_\ell, v^0_{\ell,r})$ are stable when $r =2$. If $r=1$, then  $y_\ell$ ranks $v^0_{\ell,r}$ second, and $y_\ell$ cannot be matched to $v^0_{\ell,2}$ because it has capacity 0. As before, $v^0_{\ell,r}$ cannot create a blocking pair with any of the residents in ${\mathcal W}_\ell\setminus \{ w_{\ell,1} \}$ because they are matched to their most preferred hospital. Therefore, the pair $(y_\ell, v^0_{\ell,r})$ is also stable when $r = 1$. 
\end{itemize}
The case in which $j$ is ranked third or more by $i_\ell$ is analogous to the case in which $j$ is of the form $j_{r}$ with $r =2$ in $i_\ell$'s preference list. Therefore, $\hat{M}_{\mathbf{t}}$ is a stable matching in $\hat{\Gamma}_{\mathbf{t}}$.




Next, we compute the average hospital rank in $M$ and $\hat{M}_{\mathbf{t}}$. In $M$, we can distinguish whether a resident is matched to a hospital ranked first or not, and we can distinguish if a resident is in ${\mathcal R}'$ or ${\mathcal R}''$. Let $K''$ be the average hospital rank of residents in ${\mathcal R}''$, $K^t$ be the average hospital rank of the residents in ${\mathcal R}'$ that are matched to a hospital in their ties, and $K^s$ be the average hospital rank of the residents in ${\mathcal R}'$ that are matched to a hospital they rank third or more. Note that $K^t$ is also the number of residents matched to a hospital they rank first. The average hospital rank of $M$ is $K^M=K'' +K^t + K^s$. We now show that $\text{AvgRank}(\hat{M}_{\mathbf{t}})$ is $n \cdot K'' + n \cdot K^t + n \cdot K^s + (n+1) \cdot (K^t + L - K^t  ) +  L\cdot(n-1)$: 
\begin{itemize}
\item The first term, $n \cdot K''$, is given by the contribution from the residents in ${\mathcal R}''$.
\item The second term is given by the pairs $(w_{\ell,r},j)$, $(y_\ell, v^0_{\ell,r} )$ (for $r=1$ or $r=2$) in the villages ${\mathcal B}_{i_\ell}$ of the residents $i_\ell$ in $M$ that are matched to a hospital they rank first. 
\item The third contribution is given by the pairs  $(w_{\ell,r},j)$, $(y_\ell, v^0_{\ell,r} )$ (for $r\geq 3$) in the villages ${\mathcal B}_{i_\ell}$ of the residents $i_\ell$ in $M$ that are matched to a hospital they rank third or more.
\item The forth term, $L\cdot(n-1)$, is given by the pairs of the form $(w_{\ell,h}, v^1_{\ell,h})$ for $h\neq r$, of which there are $n-1$ in each of the $L$ villages.
\end{itemize}
If we rearrange the terms, we obtain $\text{AvgRank}(\hat{M}_{\mathbf{t}})= n \cdot K'' + n \cdot K^t + n \cdot K^s + (n+1) \cdot (K^t + L - K^t  ) +  L\cdot(n-1) =  n \cdot K^M + 2 n \cdot L   $.
\end{proof}

In the next result, we show that the allocation vector and the stable matching constructed in Lemma~\ref{lemma_first_complexity} correspond to the solution with the minimum average hospital rank, as long as the original matching is of minimum average hospital rank.

\begin{lemma}\label{lemma_second_complexity}
Consider a weakly stable matching $M$ in $\Gamma$ of minimum average hospital rank. Then, the allocation $\mathbf{t}$ and the stable matching $\hat{M}_{\mathbf{t}}$ constructed in Lemma~\ref{lemma_first_complexity} are the solutions of minimum average hospital rank for $\hat{\Gamma}$ when $B= L \cdot n$.
\end{lemma}
\begin{proof}
Let $M$ be a stable matching in $\Gamma$ of minimum average hospital rank. Recall the instance $\hat{\Gamma}$ constructed in Section~\ref{sec:exp_reduction}, the allocation 
\[
t_u = \left\{\begin{matrix}1 & u\in {\mathcal V}^{M,0}\cup {\mathcal V}^{M,1}\\ 0 & \text{otherwise,}\end{matrix}\right.
\]
and the matching 
\begin{align*}
\hat{M}_{\mathbf{t}} &= \{(i,j): \ (i,j)\in M\cap({\mathcal R}''\times{\mathcal H})\}\\
& \cup \{(w_{\ell,r},j): \ r=\text{rank}_{i_\ell}(j), \ (i_\ell,j)\in M\cap({\mathcal R}'\times{\mathcal H})\}\\
& \cup \{(y_\ell, v^0_{\ell,r}): \ (\ell,r)\in \texttt{Idx}(M)\}\\
&\cup \{(w_{\ell,h},v^1_{\ell,h}): \ (\ell,r)\in \texttt{Idx}(M), \ h\in[n]\setminus\{r\}\},
\end{align*}
constructed in Lemma~\ref{lemma_first_complexity}.
Denote by $\bar{K}= nK^M + 2nL $, which is the average rank of $\hat{M}_{\mathbf{t}}$ in $\hat{\Gamma}$. Now, we will prove that any other feasible allocation $\tilde{\mathbf{t}}$ with total budget $B=L\cdot n$ and any stable matching $\hat{M}_{\tilde{\mathbf{t}}}$ in the expanded instance $\hat{\Gamma}_{\tilde{\mathbf{t}}}$ have $\text{AvgRank}(\hat{M}_{\tilde{\mathbf{t}}})\geq\bar{K}$. 
\footnote{Note that the optimal solution may not use the entire budget, for instance, when every resident is matched with her top choice. However, we can always arbitrarily assign the remaining extra spots without affecting the final average hospital rank.}



Given allocation $\mathbf{t}$, note that it is not optimal to move one extra capacity from a hospital $v^s_{\ell,h}$ to a hospital $j\in {\mathcal H}\cup {\mathcal H}^0 \cup {\mathcal X} \cup {\mathcal Z}$ for $s=0,1$. Indeed,  ${\mathcal X}$ already has $B$ positions available, but since it is at the end of the preference list of every resident, it would be sub-optimal to match a resident to a hospital in it. Similarly, it would be sub-optimal to allocate an extra-capacity to ${\mathcal Z}$, since all the residents are already matched to a hospital they prefer to any hospital in ${\mathcal Z}$. 

Regarding the hospitals in ${\mathcal H}^0$, let us assume we move a capacity from $v^s_{\ell,h}$ to a hospital $h^0\in {\mathcal H}^0$ with $s=0,1$ and $h\in[n]$.  If $v^s_{\ell,h}$ was matched to $y_\ell$, then $y_\ell$ will be matched to some hospital ranked after ${\mathcal Z}$ with a rank of at least $n^3$, making the transfer sub-optimal. Otherwise, $v^s_{\ell,h}$ was matched to resident $w_{\ell,h}$; therefore, resident $w_{\ell,h}$ will be matched to a certain $v^0_{\ell,h'}$, which was previously matched to $y_\ell$; hence, the same reasoning just seen for $y_\ell$ applies, making the transfer of the extra spots sub-optimal. 

The additional cost in the average rank obtained by moving a position from $v^s_{\ell,h}$ to a hospital in ${\mathcal H}$ follows the same reasoning just outlined for ${\mathcal H}^0$. Therefore, this is also a sub-optimal re-allocation, and it is optimal to assign all the extra capacities to hospitals in ${\mathcal V}$. Consequently, $B$ residents are matched to hospitals in ${\mathcal V}$ and the remaining residents are matched to hospitals in ${\mathcal H}\cup {\mathcal H}^0$.





Given the fact above, we only have to focus on feasible allocations in hospitals that belong to ${\mathcal V}$. In the following, we analyze why a different allocation of extra capacities in ${\mathcal V}$ does not lead to a stable matching with a lower average hospital rank.
Since $M$ is a stable matching of minimum average hospital rank in $\Gamma$ and each resident in the new instance $\hat{\Gamma}$ ranks in the first $n^3$ positions only one hospital in ${\mathcal H}$, a re-allocation of extra capacities within the same village would result in a matching with a worse objective within the village. Therefore, the re-allocation of extra capacities that could improve the objective is the one obtained by transferring extra positions from one village to another village. 
Consider $i_\ell, i_{\ell'}\in{\mathcal R}'$. We now analyze the effects of moving one extra capacity from village ${\mathcal B}_{i_{\ell'}}$ to village ${\mathcal B}_{i_{\ell}}$. The reason why we are analyzing these transfers of extra capacities is because the corresponding residents are not necessarily matched with their top choice so their ranking and the overall average ranking may improve. 


\begin{itemize}
\item From $v^{0}_{\ell',r'}$ to $v^{0}_{\ell,2}$. Note that, by assumption, both residents $y_{\ell'}$ and $y_\ell$ are matched in $\hat{M}_{\mathbf{t}}$ to $v^{0}_{\ell',r'}$ and $v^{0}_{\ell,r}$ (for a certain $r\leq n$), respectively. If we move one extra position from $v^{0}_{\ell',r'}$ to $v^{0}_{\ell,2}$, then $w_{\ell,r}$ un-matches from $j$ ($r=\text{rank}_{i_\ell}(j)$) and matches to $v^{0}_{\ell,2}$, thus providing a reduction in the objective value between $n$ and $n^2$. The preference list of $v^{0}_{\ell,2}$ prevents $y_\ell$ to be matched to $v^{0}_{\ell,2}$ because $w_{\ell,r}$  is more preferred and $w_{\ell,r}$ prefers $v^{0}_{\ell,2}$ over $j$. As a consequence, $j$ is un-matched and is re-assigned to $y_{\ell'}$ (who was un-matched as a consequence of removing the extra spot of $v^{0}_{\ell',r'}$). By matching $y_{\ell'}$ to $j$, the objective value increases by at least $n^3$. Therefore, it is sub-optimal to move an extra capacity in this way. 

\item All the remaining cases follow a similar reasoning.
\end{itemize}

\begin{comment}
\begin{itemize}

\item from $v^{r'}_{\ell',0}$ to $v^2_{\ell,0}$. Note that, by assumption, both residents $y_{\ell'}$ and $y_\ell$ are matched, in $\hat{M}_{\mathbf{t}}$, to $v^{r'}_{\ell',0}$ and $v^{r}_{\ell,0}$ (for a certain $r\leq n$) respectively. If we move one extra position from $v^{r'}_{\ell',0}$ to $v^2_{\ell,0}$, then $w_{\ell,r}$ un-matches from $j$ ($r=\text{rank}_{i_\ell}(j)$) and matches to $v^2_{\ell,0}$, thus providing a reduction in the objective value between $n-2$ and $2n$. The preference list of $v^2_{\ell,0}$ prevents $y_\ell$ to be matched to it if $w_{\ell,r}$ is not matched to a preferred hospital (which is not the case since $v^2_{\ell,0} \succ_{w_{\ell,r}} j $). As a consequence, $j$ is un-matched and is re-assigned to $y_{\ell'}$ (who was un-matched as a consequence of removing the extra capacity from $v^{r'}_{\ell',0}$). By matching $y_{\ell'}$ to $j$, the objective value increases by at least $n^2$. Therefore, it is sub-optimal to move an extra capacity in this way. 

\item from $v^1_{\ell',h}$ to $v^2_{\ell,0}$ (for $h\geq 1$).  A reasoning analogous to the one provided above proves that by doing this transfer, we obtain a reduction in the objective value of at most $2n$ and an increase of at least $n^2$. 

\item from $v^1_{\ell',h'}$ to $v^1_{\ell,r}$ (for $h'\geq 1$). In $\hat{M}_{\mathbf{t}}$, $w_{\ell',h'}$ is matched to $v^1_{\ell',h'}$ and $w_{\ell,r}$ is matched to $j$, where $r=\text{rank}_{i_\ell}(j)$. If we transfer an extra spot from $v^1_{\ell',h'}$ to $v^1_{\ell,r}$, we un-match $w_{\ell',h'}$ from $v^1_{\ell',h'}$, and $w_{\ell,r}$ from $j$. Then, we match $w_{\ell,r}$ to $v^1_{\ell,r}$ and we obtain a reduction in the cost less than $3n$. We can also move the extra capacity assigned to $v^r_{\ell,0}$ to the hospital $v^2_{\ell,0}$, thus obtaining another reduction in the objective value of $y_\ell$ of at most $n$. Finally, we have to match $w_{\ell',h'}$. Note that the pair $(w_{\ell',h'},j) $ would not be stable because $w_{\ell',h'}$ prefers $v^s_{\ell',0}$ (for some $s\neq i$ with capacity 1) to $j$, and $v^s_{\ell',0}$ prefers $w_{\ell',h}$ over its current match $y_{\ell'}$. Therefore, we match $w_{\ell',h'}$ to $v^s_{\ell',0}$ and $y_{\ell'}$ to $j$ with an increase in the objective value of at least $n^2$. As a conclusion, this transfer of extra positions is sub-optimal. 

\item from $v^1_{\ell',h'}$ to $v^2_{\ell,0}$ (for $h'\geq 1$). In $\hat{M}_{\mathbf{t}}$, $w_{\ell',h'}$ is matched to $v^1_{h',\ell'}$ and $y_\ell$ is matched to  $v^r_{\ell,0}$ for a certain $r\leq n$. If we move the extra position as suggested, we may also move the extra position attributed to $v^r_{\ell,0}$ to $v^1_{\ell,r}$. Thus, we obtain the following two stable pairs $(y_\ell, v^2_{\ell,0} )$ and $(w_{\ell,r}, v^1_{\ell,r} )$. The final objective decreases at most $4n$. Therefore, $j$ with $r=\text{rank}_{i_\ell}(j)$ and $w_{\ell',h'}$ remain un-matched. Now, we match $w_{\ell',h'}$ to $v^{s}_{\ell',0}$ for a given $s$ and we match $y_{\ell'} $ to $j$. The objective value increases is at least $n^2$. Thus, this way of transferring extra positions is sub-optimal.


\end{itemize}
\end{comment}

Therefore, there is no allocation $\tilde{\mathbf{t}}\neq \mathbf{t}$ and a stable matching $\hat{M}_{\tilde{\mathbf{t}}}$ with an objective value strictly lower than $\bar{K}$. 


\end{proof}

 

\subsection{{{\sc CA}$_{\text{ext}}$} is NP-complete}\label{sec:main_theorem_reduction}
In the following, we prove the main result of this section, Theorem \ref{HR_ext_NP_complete}.
\begin{proof}[Proof of Theorem \ref{HR_ext_NP_complete}]
{{\sc CA}$_{\text{ext}}$} is clearly in NP since given $\mathbf{t}$ and a matching $\hat{M}_{\mathbf{t}}$ in instance $\hat{\Gamma}_{\mathbf{t}}$, we can verify in polynomial time whether $\hat{M}_{\mathbf{t}}$ is stable, whether the budget $B=L\cdot n$ is satisfied and whether its objective value is less than the target value. We now show that {{\sc CA}$_{\text{ext}}$} is NP-complete.

From Corollary \ref{corollary-Manlove}, we know that {\textsc{Min-w SMT}} is NP-complete.
Consider the reduction given in Section \ref{sec:exp_reduction}. In the constructed instance $\hat\Gamma$ of {{\sc CA}$_{\text{ext}}$}, we set the budget to $B=L\cdot n$ and the target value to $\bar{K}=n\cdot K+2n\cdot L$, where $K$ is the target value of the instance of {\textsc{Min-w SMT}}.


First, suppose that the answer to the instance of {\textsc{Min-w SMT}} is NO, \emph{i.e.}, there is no weakly stable matching $M$ with an average hospital rank less or equal than $K$. Let $M$ be a weakly stable matching with minimum average hospital rank $K^M$; note that $K^M>K$. Next, we prove that there is no allocation of extra positions and a stable matching in the respective instance $\hat\Gamma$ of {{\sc CA}$_{\text{ext}}$} with an objective value less or equal than $nK + 2nL$. Indeed, in Lemma \ref{lemma_first_complexity}, we show that there is an allocation $\mathbf{t}$ and a stable matching $\hat{M}_{\mathbf{t}}$ with $\text{AvgRank}(\hat{M}_{\mathbf{t}})=nK^M + 2nL$. In Lemma \ref{lemma_second_complexity}, we prove that these are the best solutions since $M$ is the optimal matching. Therefore, $nK^M+ 2nL> nK + 2nL = \bar{K}$, which means that the answer for the instance of {{\sc CA}$_{\text{ext}}$} is also NO.


On the other hand, consider a YES instance of {\textsc{Min-w SMT}}. Then, there is a weakly stable matching  $M$  with an average hospital rank of $K^M\leq K$. Therefore, the allocation $\mathbf{t}$ and the stable matching $\hat{M}_{\mathbf{t}}$ in $\hat\Gamma$ constructed in Lemma \ref{lemma_first_complexity} have an objective value of  $nK^M+2nL\leq nK+2nL=\bar{K}$. Hence, the instance of {{\sc CA}$_{\text{ext}}$} has a YES answer. 

Let us prove now that, for any $\varepsilon$, {\textsc{Min-Avg$_{\text{exp}}$ HR opt}} is not approximable within a factor of $(\bar{n}/2)^{\frac{1-\epsilon}{2}}$, where $\bar{n}$ is the number of residents, unless P$=$NP.
Consider an instance $\Gamma$ of {\textsc{Min-w SMT}} with $n$ residents and $L\geq1$ of them with a tie in their preference list. Let $M^{yes}$ and $M^{no}$ be the stable matchings of minimum average hospital rank for the cases in which the answer of the decision problem {\textsc{Min-w SMT}} is YES and NO, respectively. Corollary \ref{corollary-Manlove} implies that, for any $\varepsilon>0$, $\text{AvgRank}(M^{no})\geq n^{1-\epsilon}\cdot\text{AvgRank}(M^{yes})$. Now, consider the reduction presented in Section \ref{sec:exp_reduction} from instance $\Gamma$ to an instance $\hat{\Gamma}$ of {{\sc CA}$_{\text{ext}}$}. Lemma \ref{lemma_second_complexity} implies that there are allocations $\mathbf{t}$ and $\mathbf{t}'$, and matchings $\hat{M}^{yes}_{\mathbf{t}}$ and $\hat{M}^{no}_{\mathbf{t}'}$ for the respective YES and NO answers of {{\sc CA}$_{\text{ext}}$} such that
\begin{align*}
\text{AvgRank}(\hat{M}^{yes}_{\mathbf{t}}) &= n\cdot\text{AvgRank}(M^{yes}) + 2nL\\
\text{AvgRank}(\hat{M}^{no}_{\mathbf{t}'}) &= n\cdot\text{AvgRank}(M^{no}) + 2nL.
\end{align*}
Recall that the reduction in Section \ref{sec:exp_reduction} constructs $\hat{\Gamma}$ with $\bar{n}:=|\hat{{\mathcal R}}|\leq 2n^2$ residents. Then, for any $\varepsilon>0$, we have
\begin{align*}
\frac{\text{AvgRank}(\hat{M}^{no}_{\mathbf{t}'})}{\text{AvgRank}(\hat{M}^{yes}_{\mathbf{t}})}&=\frac{n\cdot\text{AvgRank}(M^{no}) + 2nL}{n\cdot\text{AvgRank}(M^{yes}) + 2nL}\geq \frac{\text{AvgRank}(M^{no})}{\text{AvgRank}(M^{yes})}\\
&\geq n^{1-\epsilon}\geq \left(\frac{\bar{n}}{2}\right)^{\frac{1-\varepsilon}{2}},
\end{align*}
where the first inequality is because $f(x)=(a+x)/(b+x)$ is increasing when $b>a$. This completes the proof.
\end{proof}

Note that the proof can be slightly modified to obtain a similar result for HR with incomplete preference lists, as long as the condition $\sum_{j\in{\mathcal H}}c_j\geq |{\mathcal R}|$ is met (\emph{e.g.}, we can remove one hospital in ${\mathcal X}$ from the preference list of a resident).




























    




\section{The Capacity Reduction Problem}\label{sec:reduction}









In this section, we focus on Problem \ref{problem_reduction} that looks for the reduction of capacities such that the residents' allocations are impacted the least.
Our main result establishes the computational complexity of this problem. Formally, our result is the following.
\begin{theorem}\label{theorem_reduction_standard}
{\textsc{Min-Avg$_{\text{red}}$ HR}} is NP-complete.
Moreover, for any $\varepsilon>0$, {\textsc{Min-Avg$_{\text{red}}$ HR opt}} cannot be approximated within a factor of $(\bar{n}/2)^{(1-\varepsilon)/2}$, where $\bar{n}$ is the number of residents, unless \emph{P=NP}.
\end{theorem}
\begin{proof}
We restrict our analysis to the case in which hospitals' capacities are all 1.  
Recall that Problem \ref{problem_reduction} assumes that reducing the capacities of hospitals does not leave any resident un-assigned. 


First, clearly {\textsc{Min-Avg$_{\text{red}}$ HR}} is in NP, since for a given vector $\mathbf{t}$ and a matching $M_{\mathbf{t}}$, we can verify in polynomial time whether $\mathbf{t}$ satisfies the lower bound on the number of spots to be removed, whether $M_{\mathbf{t}}$ is stable in $\Gamma_{-\mathbf{t}}$ and if the target value is attained. Now, we concentrate on showing that the problem is NP-complete.

The rest of the proof follows the same idea than the proof of Theorem~\ref{HR_ext_NP_complete}.
 We build a reduction from an instance $\Gamma$  of {{\textsc{Min-w SMT}}} into an instance $\hat{\Gamma}$ of {\textsc{Min-Avg$_{\text{red}}$ HR}}.  We assume that $\Gamma$ satisfies $|{\mathcal R}|=|{\mathcal H}|=n$, ties occur only in residents' lists, and each of their preference list has at most one tie of length 2 positioned at the head of it. Recall also that we denoted by ${\mathcal R}'$ the set of residents with a tie in their preference list and by ${\mathcal R}''$ the set of residents with strict preference lists. The corresponding  $\hat\Gamma$ is defined as in the reduction presented in the proof of Theorem~\ref{HR_ext_NP_complete}, with the following difference:
\begin{itemize}
    \item  For every \emph{village} ${\mathcal B}_\ell$ defined for $i_\ell\in{\mathcal R}'$: Each hospital $v^1_{\ell,h}$ for $h\in[n]$ has capacity 1 and each hospital in ${\mathcal V}_{\ell,0}$ has capacity 1. All the remaining preferences and capacities remain as in Section \ref{sec:exp_reduction}.
\end{itemize}



Given a weakly stable matching $M$ in the instance $\Gamma$ with an average hospital rank $K^{M}$, we provide a reduction of the capacities $\mathbf{t}$ that respects the budget $B=n\cdot L$ and we build a stable matching $\hat{M}_{\mathbf{t}}$ in $\hat{\Gamma}_{\mathbf{t}}$ with an average hospital rank $\bar{K}=n K^M+  2nL$. 

\begin{itemize}
\item \emph{Reduction of capacities.} We remove $n$ spots from each village $B_\ell$ in the following way: Assume in $M$ we have the pair $(i_\ell, j)$, where $j$ is such that $r=\text{rank}_{i_\ell}(j)$. Then, we reduce by 1 the capacities of $v^1_{\ell,r}$  and of each hospital in ${\mathcal V}_{\ell,0}\setminus\{ v^0_{\ell,r}\}$.
\item \emph{Matching.} We build the matching $\hat{M}_{\mathbf{t}}$ as follows: We match $(w_{\ell,r}, j)$, $(y_{\ell}, v^0_{\ell,r})$, $\{(w_{\ell,h}, v^1_{\ell,h})\}_{h\neq r}$. The remaining pairs are the same as in the proof of Lemma~\ref{lemma_first_complexity}.
\end{itemize}

The rest of the proof is analogous to the proofs of Lemma~\ref{lemma_first_complexity}, Lemma~\ref{lemma_second_complexity}, and Theorem~\ref{HR_ext_NP_complete}. 

 \end{proof}

Note that the proof can be slightly modified to obtain a similar result for HR with incomplete preference lists, as long as the condition $-B+\sum_{j\in{\mathcal H}}c_j\geq |{\mathcal R}|$ is met. 




\section{Conclusions}
\label{sec:conclusions}

In this work, we have investigated the following question: How should a centralized institution optimally manage a variation in the capacities of the hospitals? 
We addressed this question from two points of view: Capacity expansion and capacity reduction. Our analysis is focused on the computational complexity of these problems and some of its variations. 

Our first result established the approximation hardness of the problem of finding the resident-optimal stable matching in the presence of ties. Our theorem defined a boundary on the complexity of the resident-optimal stable matching, which is well known to be polynomial-time solvable when there are no ties. We used this result as the first building block in the construction of the main proof of the paper: The approximation hardness of the problem of allocating optimally extra capacities to the hospitals to reduce the average hospital rank. Our proof introduced a crucial structure, the \emph{village}, that enabled us to manage the subtleties of the allocation of extra capacities. The problem of allocating extra resources is not easier when we restrict the distribution of capacities to a partition of the hospitals. If the objective of the problem is the cardinality of the stable matching, we proved that it is NP-complete when the problem has incomplete lists. If the objective is the average hospital rank, the corresponding optimization problem cannot be approximated within a certain factor.  The problem of reducing the capacities is equally interesting. Indeed, we showed that the capacity reduction problem is NP-complete. We generalized this result to the case in which the set of hospitals is partitioned and there is a budget for each part. For this problem, we proved that its optimization version is also inapproximable within a certain factor. Finally, we studied the variant of the problem that seeks to maximize the cardinality of the matching when the preference lists are incomplete. 

We believe these results are significant because they emphasize the existence of an underlying structure in the stable matching problem which governs both the capacity expansion and reduction. Unveiling the properties of this structure is certainly an open question worth being explored. Another interesting future direction of research is understanding what is the role of meta-rotations \cite{gusfield1989stable,bansal2007polynomial,cheng2008unified} in the capacity variation problem. 




\section{Extensions}\label{sec:extensions}


In this section, we investigate the variants of Problems \ref{problem_def} and \ref{problem_reduction} where the decision-maker has budgets for different subsets of hospitals. In the remainder of this section, we say that ${\mathcal P} = \{{\mathcal H}_1,\ldots{\mathcal H}_q\}$ is a partition of the set of hospitals ${\mathcal H}$ if $\cup_{k\in[q]}{\mathcal H}_k= {\mathcal H}$ and ${\mathcal H}_k\cap{\mathcal H}_{k'}=\emptyset$ for all $k,k'\in[q]$ with $k\neq k'$.
























\subsection{Allocating Extra Spots to a Partition of Hospitals}\label{sec: subsets of extra capacities}
We generalize Problem \ref{problem_def} to the setting where the set of hospitals is partitioned and we seek to find an allocation of extra spots such that each part has a specific budget. Formally, we study the following problem. 
\begin{problem}[\textsc{Min-Avg$_{\text{exp}}^{\text{sub}}$ HR}]
\label{problem_expansion_subsets}
\boxxx{
{\sc instance}:  A \emph{{CA}} instance $\Gamma=\langle {\mathcal R},{\mathcal H},\succ, \mathbf{c} \rangle$, a partition ${\mathcal P}=\{{\mathcal H}_1,\ldots{\mathcal H}_q\}$ of ${\mathcal H}$, budget for each part $\{ B_k \in{\mathbb Z}_+  \colon \,  k \in [q]\}$, and a non-negative integer target value $K \in \mathbb{Z}_+$.\\
{\sc question}: Is there a non-negative vector $\mathbf{t}\in{\mathbb Z}_+^{{\mathcal H}}$ and a matching $M_\mathbf{t}$ such that 
\[
\text{\emph{AvgRank}}(M_{\mathbf{t}}) \leq K,
\]
where $\mathbf{t}$ is such that $\sum_{j\in{\mathcal H}_k}t_j\leq B_k$ for each $k\in[q]$ 
and $M_\mathbf{t}$ is a stable matching in instance $\Gamma_{\mathbf{t}} $?
}
\end{problem}

The next result can be directly obtained by considering a single set of hospitals in the partition, \emph{i.e.}, $q= 1$ and ${\mathcal P} = {\mathcal H}$, and by using Theorem \ref{HR_ext_NP_complete}.
\begin{corollary}\label{HR_extsub_NP_complete}
{\textsc{Min-Avg$_{\text{exp}}^{\text{sub}}$ HR}} is NP-complete.
\end{corollary}
Denote by {\textsc{Min-Avg$_{\text{exp}}^{\text{sub}}$ HR opt}} the optimization version of {\textsc{Min-Avg$_{\text{exp}}^{\text{sub}}$ HR}}, \emph{i.e.}, the problem of finding an allocation of extra capacities and a stable matching in the expanded instance of minimum average hospital rank. 
In the following result, we show the approximation complexity of {\textsc{Min-Avg$_{\text{exp}}^{\text{sub}}$ HR opt}}.

\begin{theorem}\label{theorem_stud_set_expansion}
For any $\varepsilon>0$, {\textsc{Min-Avg$_{\text{exp}}^{\text{sub}}$ HR opt}} is not approximable within a factor of $n^{1-\varepsilon}$, unless P=NP, where $n$ is the number of residents. This result holds even if the partition ${\mathcal P}=\{{\mathcal H}_1,\ldots,{\mathcal H}_q\}$ is such that each ${\mathcal H}_k$ contains at most two hospitals and $B_k\in \{0,1\}$ for every $k\in [q]$.
\end{theorem}

Before proving Theorem \ref{theorem_stud_set_expansion}, we need to introduce a variant of Problem \ref{problem_expansion_subsets}, where the goal is to find a stable matching whose size is at least a certain target. The problem of finding the maximum cardinality stable matching is one of  the main focus of the literature \cite{manlove2013algorithmics}. We investigate it in relation with capacity expansion when there are incomplete preference lists.
Recall that a {CA} instance with incomplete preference lists means that there is at least one resident or one hospital that does not rank completely the opposite side. 
Formally, we consider the following problem.
\begin{problem}[{\textsc{Max-Card$_{\text{exp}}^{\text{sub}}$ HRI}}]
\label{maxcard_expansion_subsets}
\boxxx{
{\sc instance}:  A \emph{HR} instance $\Gamma=\langle {\mathcal R},{\mathcal H},\succ, \mathbf{c} \rangle$ with incomplete preference lists, a partition ${\mathcal P}=\{{\mathcal H}_1,\ldots,{\mathcal H}_q\}$ of ${\mathcal H}$, budget for each part $\{ B_k \in{\mathbb Z}_+  \colon \,  k \in [q]\}$ and a non-negative integer target value $K \in {\mathbb Z}_+$.\\
{\sc question}: Is there a non-negative vector $\mathbf{t}\in{\mathbb Z}_+^{{\mathcal H}}$ and a matching $M_{\mathbf{t}}$ such that 
\[
\left|M_{\mathbf{t}}\right| \geq K,
\]
where $\mathbf{t}$ is such that $\sum_{j\in{\mathcal H}_k}t_j\leq B_k$ for each $k\in[q]$ 
and $M_\mathbf{t}$ is a stable matching in instance $\Gamma_{\mathbf{t}} $?
}
\end{problem}

Recall that if we consider complete preference lists, the problem above becomes trivial since all stable matchings have the same size. We prove the following result.
\begin{theorem}\label{theorem_max_expansion}
{\textsc{Max-Card$_{\text{exp}}^{\text{sub}}$ HRI}} is NP-complete, even if the partition ${\mathcal P}=\{{\mathcal H}_1,\ldots,{\mathcal H}_q\}$ is such that each ${\mathcal H}_k$ is of size at most two and $B_k\in \{0,1\}$ for every $k\in[q]$.  
\end{theorem}
The proof of this result can be found in the Appendix. Let us now focus on the proof of Theorem \ref{theorem_stud_set_expansion}.

\begin{proof}[Proof of Theorem \ref{theorem_stud_set_expansion}]

Let $\epsilon>0$ and define $a=\lceil (3 / \varepsilon)\rceil $. We consider an instance $\Gamma$ of {\textsc{Max-Card$_{\text{exp}}^{\text{sub}}$ HRI}} in which the set of hospitals is ${\mathcal H}$, the set of residents is ${\mathcal R}$ (we assume $|{\mathcal R}|=n$), every ${\mathcal H}_k$ is of size at most two and $B_k\in \{0,1\}$ for every $k\in [q]$. We denote by $O_j$ (resp. $O_i$) the preference list of hospital $j$ (resp. resident $i$). We assume that the target value $K$ is equal to $n$.

We now build an instance $\hat\Gamma$ of {\textsc{Min-Avg$_{\text{exp}}^{\text{sub}}$ HR opt}}. Let us define $A=n^{a-1}$. In this instance, the set of hospitals is $\left(\bigcup_{h=1}^A {\mathcal H}^h \right) \cup {\mathcal H}^0$ with ${\mathcal H}^h=\{j_1^h,\ldots, j_n^h \}$ and ${\mathcal H}^0=\{j_1^0,\ldots, j_{n^a}^0 \}$. The set of residents is $\left(\bigcup_{h=1}^A {\mathcal R}^h\right) \cup {\mathcal R}^0$ with ${\mathcal R}^h=\{i_1^h,\ldots, i_n^h \}$ and ${\mathcal R}^0=\{i_1^0,\ldots, i_{n^a}^0 \}$.
For every pair $\{{\mathcal H}_k,B_k\}$ for $k\in[q]$ in $\Gamma$, we introduce copies in $\hat\Gamma$ of the form $\{{\mathcal H}_k^h,B_k^h\}$ in ${\mathcal H}^h$  for $k\in [q]$ and $h\in[A]$. The hospitals in ${\mathcal H}^0$ have all capacity 1; the other hospitals have the same capacities of the original hospitals in $\Gamma$. For $j\in{\mathcal H}$ and $h\in[A]$, we denote by $O_j^h$ the preference list  obtained by substituting in the preference list $O_j$ the residents in ${\mathcal R}$ with the residents in ${\mathcal R}^h$. We define similarly $O_i^h$. The preference lists of the hospitals and residents in $\hat\Gamma$ are as follows: 
\begin{align*}
j_{h}^{0}&: i_{h}^{0},\ldots \hspace{5.2em} h\in[n^{a}] \\
j_{s}^{h}&: O_{j_s}^{h}, {\mathcal R}^{0},\ldots \hspace{3em} s\in[n], \, h\in[A]\\
i_{h}^{0}&: j_{h}^{0},\ldots \hspace{5.2em} h\in[n^{a}] \\
i_{s}^{h}&: O_{i_s}^{h}, {\mathcal H}^{0}, \ldots \hspace{3em}  s\in[n], \, h\in[A],
\end{align*}
where the dots \lq\lq\ldots \rq\rq\, in the preference lists mean that the remaining agents on the other side of the bipartition are ranked strictly and arbitrarily.

Our {\textsc{Min-Avg$_{\text{exp}}^{\text{sub}}$ SM}} instance comprises $2 n^{a}$  residents, so that $\bar{n}:=2 n^{a} $; the target value  is $K'=n^{a+2}/2$.
The remainder of the proof follows the same reasoning as of Corollary~\ref{corollary-Manlove}; the proof can be found in the Appendix.
\end{proof}













\subsection{Removing Spots from a Partition of Hospitals}\label{sec: reduction_subsets}
Similar to the problems presented in the previous section, we now study the generalization of Problem \ref{problem_reduction} where the set of hospitals is partitioned in $q$ parts and each part has a budget for the removal of spots. Specifically, we consider the following problem.

\begin{problem}[{\textsc{Min-Avg$_{\text{red}}^{\text{sub}}$ HR}}]
\label{problem_reduction_subsets}
\boxxx{
{\sc instance}:  A \emph{{CA}} instance $\Gamma=\langle {\mathcal R},{\mathcal H},\succ, \mathbf{c} \rangle$, a partition ${\mathcal P}=\{{\mathcal H}_1,\ldots{\mathcal H}_q\}$ of ${\mathcal H}$, budget for each part $\{ B_k \in{\mathbb Z}_+  \colon \,  k \in [q]\}$, and a non-negative integer target value $K \in \mathbb{Z}_+$.\\
{\sc question}: Is there a non-negative vector $\mathbf{t}\in{\mathbb Z}_+^{{\mathcal H}}$ and a matching $M_\mathbf{t}$ such that 
\[
\text{\emph{AvgRank}}(M_{\mathbf{t}}) \leq K,
\]
where $\mathbf{t}$ is such that $\sum_{j\in{\mathcal H}_k} t_j\geq B_k$ and $c_j-t_j\geq 0$ for $k\in[q]$,
and $M_{\mathbf{t}}$ is a stable matching in instance $\Gamma_{\mathbf{t}} $?
}
\end{problem}
For Problem \ref{problem_reduction_subsets}, we prove the following inapproximability result.
\begin{theorem}\label{capacity_red_sub_complexity}
For any $\varepsilon>0$, {\textsc{Min-Avg$_{\text{red}}^{\text{sub}}$ HR opt}} is not approximable within a factor of $n^{1-\varepsilon}$, unless P=NP, where $n$ is the number of residents. This result holds even with a partition in which each part ${\mathcal H}_k$ contains at most two hospitals and $B_k\in \{0,1\}$ for every $k\in[q]$.
\end{theorem}

To prove Theorem \ref{capacity_red_sub_complexity}, we need to study the analogous version of Problem \ref{maxcard_expansion_subsets} for the capacity reduction setting. Formally, we define the following problem.

\begin{problem}[{\textsc{Max-Card$_{\text{red}}^{\text{sub}}$ SMI}}]
\label{maxcard_reduction_subsets}
\boxxx{
{\sc instance}:  A \emph{{CA}} instance $\Gamma=\langle {\mathcal R},{\mathcal H},\succ, \mathbf{c} \rangle$ with incomplete preference lists, a partition ${\mathcal P}=\{{\mathcal H}_1,\ldots{\mathcal H}_q\}$ of ${\mathcal H}$, budget for each part $\{ B_k \in{\mathbb Z}_+  \colon \,  k \in [q]\}$, and a non-negative integer target value $K \in \mathbb{Z}_+$.\\
{\sc question}: Is there a non-negative vector $\mathbf{t}\in{\mathbb Z}_+^{{\mathcal H}}$ and a matching $M_\mathbf{t}$ such that 
\[
\left|M_{\mathbf{t}}\right| \geq K,
\]
where $\mathbf{t}$ is such that $\sum_{j\in{\mathcal H}_k} t_j\geq B_k$ and $c_j-t_j\geq 0$ for $k\in[q]$,
and $M_{\mathbf{t}}$ is a stable matching in instance $\Gamma_{\mathbf{t}} $?
}
\end{problem}
In particular, we show the following result.
\begin{theorem}\label{card_cap_sub_red_complexity}
{\textsc{Max-Card$_{\text{red}}^{\text{sub}}$ SMI}} is NP-complete. This result holds even with a partition in which each part ${\mathcal H}_k$ is of size at most two and $B_k\in \{0,1\}$ for every $k\in[q]$.
\end{theorem}
\begin{proof}
The proof is analogous to the proof of Theorem~\ref{theorem_max_expansion} with the difference that every hospital in each part ${\mathcal H}_k$ has capacity 1.
\end{proof}

\begin{proof}[Proof of Theorem~\ref{capacity_red_sub_complexity}]
The proof follows a similar reasoning as the proof of Theorem~\ref{theorem_stud_set_expansion} with the difference that every hospital in each part ${\mathcal H}_k$ has capacity 1.
\end{proof}







\section{Introduction}\label{sec:introduction}






The stable matching problem has found multiple applications such as daycare admission in Denmark \cite{kennes2011daycare}, school and hospital-resident allocation in the USA \cite{abdulkadirouglu2005boston, abdulkadiroglu2006changing, abdulkadirouglu2005new,roth1984evolution,roth1999redesign}, school and university admission in Hungary \cite{biro2008student, biro2015college}, school admission in Singapore \cite{teo1999gale}, university admission in China \cite{zhang2010analysis}, Germany \cite{braun2010telling} and Spain \cite{romero1998implementation}, faculty recruitment in France \cite{baiou2003admissions}. The many-to-one stable matching problem (HR) consists of two sides---henceforth referred to as hospitals and residents---where hospitals have fixed and known capacities. Both sides have preferences over each other, and the goal of the decision-maker is to find an assignment such that, in each pair, both agents \emph{simultaneously} prefer each other over any other agent. The HR problem, and its multiple variants, have been widely studied in the literature by different disciplines: From a polyhedral  \cite{baiou2000stable, baiou2004student} and algorithmic  \cite{gale1962college} perspective, to geometry \cite{sethuraman2006many}, mathematical programming \cite{vate1989linear}, combinatorics \cite{knuth1976marriages}, fixed-point methods \cite{subramanian1994new} and graph theory \cite{balinski1997stable}. 

As mentioned, in the standard version of HR, the capacity of the hospitals are fixed and known in advance. The decision-maker in charge of the final assignment does not have control over these quota. However, there are multiple real-life situations in which the variation of the size of the market, expansion or reduction, could play a significant role. For example, when allocating couples in hospitals~\cite{roth1984evolution}, siblings in school~\cite{correa2021school}, scholarships or expenses reduction.





The idea of introducing new participants in the matching market has been previously studied through the lens of game theory and econonomics. 
This problem is known as \textit{entry comparative static}, and is usually assumed that the introduced agent is an independent entity with a certain preference list; the participants of the opposite side also rank this new agent. It has been shown that when a new agent is introduced, then the resulting matching is \textit{weakly better} (\emph{i.e.}, equal or better) for the agents of the opposite side  \cite{KelsoCrawford1982,GaleSotomayor1985,RothSotomayor1990}. On the mathematical programming domain, for the HR, the problem of deciding simultaneously capacity expansions  on the hospitals' side and a stable matching was first proposed in \cite{bobbio2021capacity}. Using integer programming, the authors demonstrated empirically that significantly better matchings for the residents can be obtained through the allocation of a few extra spots.

In this work, we study the computational complexity of the problem proposed in~\cite{bobbio2021capacity} as well as its counterpart, \emph{i.e.}, when reduction of the hospitals' capacity is required. Roughly speaking, for the expansion of the market we study the following question: 
\begin{quote}
    \it Given a non-negative integer number $B\in{\mathbb Z}_+$ of extra spots, which hospitals should the decision-maker expand the capacity of to obtain the best stable matching for the residents?
\end{quote}
In the second part of this work, we focus on the reduction of the market. Simply, we study the following question:
\begin{quote}
\it Given a non-negative integer number $B\in{\mathbb Z}_+$ of spots to be removed, which hospitals should the decision-maker reduce the capacity of in order to obtain the best stable matching for the residents?
\end{quote}

We primarily focus on a rank-based metric to choose the best matching for residents. We also study the variants of the problems above under a cardinality-based metric, which has been widely studied in the literature \cite{roth1984evolution,GaleSotomayor1985,roth1986allocation,manlove2013algorithmics}.
















\subsection{Related Work}\label{sec:related_work}








In their seminal paper, Gale and Shapley \cite{gale1962college} introduced the stable matching problem and provided a polynomial time algorithm known as the deferred acceptance (DA) algorithm. The DA algorithm computes an assignment such that there is no pair of agents that would simultaneously prefer to be paired to each other rather than being in their current assignment; this is known as a \emph{stable matching}. In practice, the DA mechanism has been extensively used to improve admission processes, \emph{e.g.}, see~\cite{abdulkadirouglu2005new,biro2008student}. For further details on stable matching mechanisms, see~\cite{RothSotomayor1990,manlove2013algorithmics}.
In general, the main focus of the literature has been on finding the maximum cardinality stable matching, which can be efficiently obtained when there are incomplete preference lists\footnote{Not all the agents are ranked. In the case of incomplete preference lists, the Rural Hospital Theorem holds~\cite{roth1984evolution,GaleSotomayor1985,roth1986allocation,manlove2013algorithmics}, which states that all the stable matchings have the same cardinality.} without ties or complete preference lists that include ties.\footnote{Some agents in the preference list are ranked equally. In the case of preference lists with ties, all the weakly stable matchings are complete (under the assumption that the cardinalities on the two sides of the bipartition are equal). Weakly stability means there is no pair of agents that strictly prefer to be matched to each other rather than being in their current assignment.} Once we assume both, incomplete lists and ties, the problem of finding the maximum cardinality stable matching becomes NP-hard even under very restrictive conditions \cite{manlove2002hard}. In terms of approximation ratios, the best known factor is $\frac{3}{2}$ \cite{kiraly2013linear} and the best lower bound is $\frac{33}{29}$ \cite{yanagisawa2007approximation}.


The design of a stable matching mechanism, when the number of participants of one side is increased, has already been investigated in the past. If hospitals have capacity one, this is known as the \emph{entry comparative static} in the stable marriage problem. In this setting, the two sides are traditionally called women and men. In~\cite{KelsoCrawford1982,GaleSotomayor1985,RothSotomayor1990}, the authors proved that when a new woman is added to the instance,  all men are matched \textit{weakly better}.
Recently, Kominers \cite{Kominers2019} extended this result to the many-to-one stable matching problem. On a similar path, Balinski and Sonmez \cite{BalinskiSonmez1999} proved that the DA method is invariant with respect to residents who improve their score in the ranking lists, \emph{i.e.}, instead of introducing a new agent, the ranking of an existing agent is improved.
A substantial part of the literature has focused on strategy-proof matching mechanisms, \emph{i.e.}, on matching mechanisms that incentivize participants to reveal their true preferences. Sonmez \cite{Sonmez1997} proved that hospitals can manipulate the stable matching in their favor by falsely reporting a reduced capacity. Moreover, Romm \cite{Romm2014} proved that the stable matching mechanism can still be manipulated even if the reported capacities are enforced during the admission process. Digressing from the entry comparative static approach and strategy-proof mechanisms, Bobbio et al.~\cite{bobbio2021capacity} considered the allocation of extra capacities to hospitals as a decision variable rather than a parameter. Alternatively to the integer programming approach proposed by the authors, a solution methodology for optimizing the outcome for the residents is devised in~\cite{abe2022anytime}. Our work focuses on providing the computational complexity landscape of the problem tackled in~\cite{bobbio2021capacity,abe2022anytime}, its counterpart where existent hospital spots are removed, and other variants.






In \cite{chade2006simultaneous,ali2021college}, the problem of capacity expansion was addressed in the framework of residents' interviews for the hospital admission and was solved through an optimal portfolio choice. In \cite{manjunath2021interview}, the authors studied how the expansion of interviews (only on the residents' side) impacts the final matching. 

Kamada and Kojima~\cite{kamada2015efficient} studied matching mechanisms that impose regional quotas for the Japan Residency Matching Program. Our work differs from this, since we look to optimize the quotas rather than imposing them. A problem related to ours was addressed in \cite{yahiro2020game}. As part of their problem's input, they considered a profile of ``resources'' that can be allocated to ``projects'' (which would be the hospitals). The authors concentrated on designing strategy-proof and efficient mechanisms. In the capacity variation problems considered in our work, the resources are decision variables rather than part of the input. Even if we translate the capacity expansion problem into the setting in~\cite{yahiro2020game}, the input size would be exponential.
In \cite{nguyen2018near}, the authors studied the presence of couples in matching markets. The authors proved that by adding at most 9 extra capacities in a market with couples, the existence of a stable matching is guaranteed.

The problems studied in our work also relate to the literature on resource augmentation \cite{phillips1997optimal,kalyanasundaram2000speed,roughgarden2020resource}, where the goal is to design algorithms whose performance is compared to the benchmark that takes decisions with complete information but with a deficit in resources. For more details, we refer the interested reader to \cite{roughgarden2020resource} and the references therein.
Finally, in the context of ride sharing, it has been shown that the expansion of the capacities of the drivers by $\epsilon$ leads to a substantial reduction in the cost of the matching \cite{akbarpour2021value}, which, however, is not required to be stable.

\subsection{Contributions and Organization} 


This paper is organized as follows. 
In Section~\ref{sec:preliminaries}, we introduce the formal notation, the problem of expanding capacities (Problem~\ref{problem_def}), and the problem of reducing capacities (Problem~\ref{problem_reduction}). 

In Section~\ref{sec:expansion}, our main focus is to establish the complexity of Problem~\ref{problem_def}. To achieve this result, we first prove, in Corollary~\ref{corollary-Manlove}, that determining the resident-optimal stable matching in the presence of ties is NP-hard and is not approximable within $\bar{n}^{1-\varepsilon}$, for any $\varepsilon>0$, where $\bar{n}$ is the number of residents. This result puts a boundary on the computability of the resident-optimal stable matching, which is well known to be polynomially solvable when there are no ties.
The remainder of Section~\ref{sec:expansion} is devoted to study the complexity of the capacity expansion problem. All our results are proven in the special case in which the capacity of every hospital is at most 1.
 Indeed, even under very restrictive assumptions, finding the allocation of extra capacities to the hospitals that minimizes the average hospital rank of the residents is NP-hard, and for any $\varepsilon>0$, it cannot be approximated within a factor of $(\bar{n}/2)^{(1-\varepsilon)/2}$
 unless P=NP (Theorem~\ref{HR_ext_NP_complete}). This result may be counter-intuitive because, in the vanilla version of HR, we can compute in polynomial-time the resident-optimal stable matching, which is equivalent to the one that minimizes the average hospital rank. Our complexity proof is based on a new structure that we call \emph{village}. Each village is assigned some extra capacities, and the preferences of the hospitals and residents in a village ensure that the extra capacities can be optimally allocated only in a specific way. 


In Section~\ref{sec:reduction}, we study the capacity reduction problem. We prove that this problem is NP-hard, and for any $\varepsilon>0$, it cannot be approximated within a factor of $(\bar{n}/2)^{(1-\varepsilon)/2}$
unless P=NP (Theorem~\ref{theorem_reduction_standard}). The proof follows a similar reasoning as in Theorem~\ref{HR_ext_NP_complete}. We exploit again the structure of the village, in which now every relevant hospital has capacity 1.



In Section~\ref{sec:extensions}, we study several variants of Problems \ref{problem_def} and \ref{problem_reduction}. Specifically, we partition the set of hospitals and allocate (remove) a certain amount of capacities to (from) each set of the partition. Theorem~\ref{theorem_stud_set_expansion} shows that, even when we partition the set of hospitals and we allocate to or remove from each set at most one spot, finding the optimal allocation is an NP-hard problem. Moreover, we prove that the optimization version of the problem is not approximable within a factor of $\bar{n}^{1-\varepsilon}$, for any $\varepsilon>0$
(Theorem~\ref{theorem_stud_set_expansion}). The equivalent results for the reduction problem are shown in Theorem \ref{capacity_red_sub_complexity}. Finally, we provide similar results to the variant of the problems that consider as an objective function the cardinality of the matching, Theorems \ref{theorem_max_expansion} and \ref{card_cap_sub_red_complexity}, respectively.

Finally, some conclusions are drawn in Section \ref{sec:conclusions}.
A summary of our results and relevant results from the literature can be found in Table~\ref{tab:our_results}.








\begin{table}[ht]
\begin{center}
\resizebox{\columnwidth}{!}{
\begin{tabular}{|l|cc|}\hline
& \multicolumn{2}{c|}{\textsc{Decision version of the problem}}\\
\textsc{Framework} &   Maximum cardinality & Average hospital rank    \\ \hline
HR/HRI & Polynomial \cite{roth1984evolution,GaleSotomayor1985,roth1986allocation,manlove2013algorithmics} & Polynomial \cite{gale1962college,mcvitie1971stable,dubins1981machiavelli,roth1982economics} \\
HRT & Polynomial \cite{manlove2013algorithmics} & Inapprox. (Section~\ref{sec:expansion}) \\
HRTI & NP-complete  \cite{manlove2002hard} & Inapprox. (Section~\ref{sec:expansion}) \\ \hline
HR capacity variation & Trivial  & Inapprox. (Sections~\ref{sec:expansion} and \ref{sec:reduction}) \\
\hline
HR cap. variation subsets & Trivial & Inapprox. (Section~\ref{sec:extensions})\\
HRI cap. variation subsets & NP-complete (Section~\ref{sec:extensions}) & Inapprox. (Section~\ref{sec:extensions})\\\hline
\end{tabular}
}
\vskip 0.10in
\caption{\normalsize{Compilation of our contributions and relevant computational complexity results from the literature. HR corresponds to the many-to-one stable matching problem, the suffixes I and T stand for incomplete preference lists and for preference lists with ties, respectively.
}
}
\label{tab:our_results}
\end{center}
\end{table}

\section{Preliminaries and Problem Definition}\label{sec:preliminaries}
The many-to-one stable matching problem consists of a set of residents ${\mathcal R}=\{i_1,\ldots,i_{|{\mathcal R}|}\}$, a set of hospitals ${\mathcal H}=\{j_1,\ldots,j_{|{\mathcal H}|}\}$ and a set of edges ${\mathcal E}$ between ${\mathcal R}$ and ${\mathcal H}$. A resident and a hospital are linked by an edge in ${\mathcal E}$ if they deem each other acceptable. In this work, we assume (if not otherwise stated) that every resident-hospital pair is acceptable, \emph{i.e.}, ${\mathcal E}={\mathcal R}\times{\mathcal H}$. Each hospital $j\in{\mathcal H}$ has an non-negative integer capacity $c_j\in{\mathbb Z}_+$ 
that represents the maximum number of residents that hospital $j$ can admit.
In this setting, a \emph{matching} $M$ is a subset of ${\mathcal E}$ in which each hospital $j$ appears in at most $c_j$ pairs and each resident appears in at most 1 pair. We denote by $M(i)$ and $M(j)$ the hospital assigned to resident $i$ and the subset of residents assigned to hospital $j$, respectively.

An instance $\Gamma$ of the HR problem corresponds to a tuple $\Gamma=\langle {\mathcal R},{\mathcal H},\succ, \mathbf{c} \rangle$, where $\mathbf{c}\in{\mathbb Z}_+^{ {\mathcal H}}$ is the vector of capacities and $\succ$ corresponds to the profile of preferences that residents have over hospitals and vice-versa.
Specifically, we assume that the preference list of each resident is a linear order. We use the notation  $j\succ_i j'$ to describe when resident $i$ prefers hospital $j$ over hospital $j'$. 
We assume that every agent is {\it individually rational}, i.e., every agent prefers the proposed assignment than to be unmatched.
Concerning the preference list of every hospital, we assume it is a \textit{responsive} linear order over the power-set of the residents \cite{roth1985college}.\footnote{For any two subsets of residents ${\mathcal R}',{\mathcal R}''$, we denote that hospital $h$ prefers ${\mathcal R}'$ over ${\mathcal R}''$ as ${\mathcal R}'\succ_{h} {\mathcal R}''$. A preference relation of a hospital is responsive if for every ${\mathcal R}'\subseteq {\mathcal R}$ with $|{\mathcal R}'|\leq c_h$, $s'\in {\mathcal R}'$ and $s'' \notin {\mathcal R}'$, we have that  (i) ${\mathcal R}' \succ_h {\mathcal R}'\cup \{s''\} \setminus \{s'\}$ if and only if  $\{ s'\} \succ_h \{s''\}$, and (ii) ${\mathcal R}' \succ_h {\mathcal R}'\setminus \{s'\}$ if and only if $\{ s'\} \succ_h \emptyset$. Therefore, a responsive preference list can be obtained from the linear order over singletons. Since responsive preferences are substitutable and satisfy the law of aggregated demand, our results hold also under these more relaxed assumptions.}
A responsive linear order facilitates the description of the preference list, since we only have to focus on the linear order over single residents.
We write $i\succ_{j} i'$ to denote when hospital $j$ prefers resident $i$ over $i'$. Whenever the context is clear, we drop the subscript in $\succ$. We emphasize that in the HR problem, unless otherwise stated, the preference lists are complete and strict (there are no \emph{ties}). Under these assumptions, the length of the preference list of each agent, hospital or resident, is exactly the size of the other side of the bipartition. Therefore, preference lists can be interpreted in terms of rankings. Formally, for each resident $i\in{\mathcal R}$ and hospital $j\in {\mathcal H}$, we denote by $\text{rank}_i(j)\in\{1,\ldots,|{\mathcal H}|\}$ the rank of hospital $j$ in the list of resident $i$.
This means, for example, that the most preferred hospital has the lowest ranking. 
Analogously, we define $\text{rank}_j(i)\in\{1,\ldots,|{\mathcal R}|\}$ for all $j\in{\mathcal H}, \ i\in{\mathcal R}$.

Given a matching $M$, we say that a pair $(i,j)\in {\mathcal E}$ is a \emph{blocking pair} if the following two conditions are satisfied: (1) resident $i$ is unassigned or prefers hospital $j$ over $M(i)$, and (2) $|M(j)|<c_j$ or hospital $j$ prefers resident $i$ over at least one resident in $M(j)$. The matching $M$ is said to be \emph{stable} if it does not admit a blocking pair.  
Gale and Shapley \cite{gale1962college} showed that every instance of the HR problem admits a stable matching that can be found in polynomial time by the deferred acceptance method, also known simply as the Gale-Shapley algorithm. In particular, this algorithm can be designed to prioritize the residents in the following sense: Let $M$ and $M'$ be two different stable matchings, we say that a resident $i$ \emph{weakly prefers} $M$ over $M'$ if $M(i)\succ_i M'(i)$ or $M(i)=M'(i)$.
Then, the DA algorithm can be adapted to compute the unique stable matching that is weakly preferred by all residents over all the other possible stable matchings. Such unique stable matching is called \emph{resident-optimal}.

\paragraph{Notation} To ease the exposition, we avoid using the symbol $\succ$ when presenting a preference list, instead we simply separate agents by \lq\lq,\rq\rq\, and use the convention that the leftmost agents are the most preferred. For instance, we will represent the preference list $w\succ w' \succ w''$ as $w,w',w''$. Throughout this work, for a given integer $k\geq 1$, we use the shorthand $[k]:=\{1,\ldots,k\}$. Finally, otherwise stated, we use indices $i$ for residents and $j$ for hospitals.



\subsection{Problem Definition}

In this work, we focus on the stable matchings that minimize the \emph{average hospital rank}. Recall that we denote by $\text{rank}_i(j)$ the position of hospital $j$ in the list of resident $i$.
The average hospital rank of a matching $M$ is defined as
\begin{equation}\label{eq:matching_cost}
\text{AvgRank}(M):=\sum_{(i,j)\in M} \text{rank}_i(j),
\end{equation}
where, to ease the exposition, we do not divide by the total number of hospitals. 
We consider Expression \eqref{eq:matching_cost} as the objective function, since a basic result states that a stable matching $M$ is resident-optimal if, and only if, it is a stable matching of minimum average hospital rank \cite{bobbio2021capacity}.

In our first problem, proposed in~\cite{bobbio2021capacity}, we aim to improve the allocation of residents by increasing the capacity of the hospitals. For a non-negative vector $\mathbf{t}\in{\mathbb Z}_+^{{\mathcal H}}$, we denote by $\Gamma_{\mathbf{t}} = \langle {\mathcal R},{\mathcal H}, \succ,\mathbf{c}+\mathbf{t} \rangle$ an instance of the {CA} problem in which the capacity of each hospital $j\in{\mathcal H}$ is $c_j+t_j$. Observe that $\Gamma_\mathbf{0}$ corresponds to the original instance $\Gamma$ with no capacity expansion.
Formally, we define the capacity expansion problem as follows. 
\begin{problem}[{\sc CA}$_{\text{ext}}$]
\label{problem_def}
\boxxx{
{\sc instance}: A \emph{CA} instance $\Gamma=\langle {\mathcal R},{\mathcal H},\succ, \mathbf{c} \rangle$, a non-negative integer expansion budget $B\in{\mathbb Z}_+$,  and a target value $K \in \mathbb{Z}_+$.\\
{\sc question}: Is there a non-negative vector $\mathbf{t}\in{\mathbb Z}_+^{{\mathcal H}}$ and a matching $M_{\mathbf{t}}$ such that 
\[
\text{\emph{AvgRank}}(M_{\mathbf{t}}) \leq K,
\]
where $\mathbf{t}$ satisfies $\sum_{j\in {\mathcal H}}t_j\leq B$  and $M_{\mathbf{t}}$ is a stable matching in instance $\Gamma_{\mathbf{t}}$?
}
\end{problem}



Given parameters $B$ and $K$, Problem \ref{problem_def} aims to determine the existence of an allocation of $B$ extra spots through vector $\mathbf{t}$ such that there is a stable matching with an average hospital rank of at most $K$.

Throughout the paper, we assume that the total capacity of the hospitals is at least the total number of residents, \emph{i.e.}, $\sum_{j\in {\mathcal H}}c_j\geq |{\mathcal R}|$. If this assumption does not hold, we must define the cost of an un-assigned resident. A natural option is to add an artificial hospital with large capacity such that is ranked last by every resident. Therefore, un-assigned residents will be allocated in the artificial hospital whose rank is $|{\mathcal H}|+1$. Note that as a consequence of our assumption, $\sum_{j\in {\mathcal H}}c_j\geq |{\mathcal R}|$, there may be hospitals that do not fill their quota. 


In our second problem, we aim to find the reduction of the hospitals' capacities such that the final average hospital rank is the lowest possible, i.e., that has the least impact on the allocation of residents. As before, for a non-negative vector $\mathbf{t}\in{\mathbb Z}_+^{{\mathcal H}}$, we denote by $\Gamma_{-\mathbf{t}} = \langle {\mathcal R},{\mathcal H}, \succ,\mathbf{c}-\mathbf{t} \rangle$ an instance of the {CA} problem in which the capacity of each hospital $j\in{\mathcal H}$ is $c_j-t_j$.
Formally, we define our second problem as follows.
\begin{problem}[\textsc{Min-Avg$_{\text{red}}$ HR}]
\label{problem_reduction}
\boxxx{
{\sc instance}:  A \emph{{CA}} instance $\Gamma=\langle {\mathcal R},{\mathcal H},\succ, \mathbf{c} \rangle$, a non-negative integer reduction budget $B\in{\mathbb Z}_+$ such that $- B+\sum_{j\in {\mathcal H}}c_j \geq |{\mathcal R}|$ and a target value $K \in \mathbb{Z}_+$.\\
{\sc question}: Is there a non-negative vector $\mathbf{t}\in{\mathbb Z}_+^{{\mathcal H}}$ and a matching $M_\mathbf{t}$ such that 
\[
\text{\emph{AvgRank}}(M_{\mathbf{t}}) \leq K,
\]
where $\mathbf{t}$ satisfies $\sum_{j\in {\mathcal H}}t_j\geq B$ and $(c_j - t_j) \geq 0$ for every $ j \in {\mathcal H}$,  and $M_\mathbf{t}$ is a stable matching in instance $\Gamma_{-\mathbf{t}} $?
}
\end{problem}

Note that in Problem~\ref{problem_reduction}, we have the additional constraint that the capacity of every hospital should remain non-negative after removing spots, \emph{i.e.}, $c_j-t_j\geq 0$ for all $j\in{\mathcal H}$. We further assume that the sum of the reduced hospitals' capacities is greater or equal than the number of residents, \emph{i.e.}, $-B + \sum_{j\in {\mathcal H}}c_j\geq |{\mathcal R}|$. 
As in Problem \ref{problem_def}, if this assumption does not hold, we can transform the instance by adding an artificial hospital with a large capacity (which is ranked last in every resident's list) and by allowing the reduction of capacities to the original hospitals only.








 





















\section*{Acknowledgments}
This work was funded by the Institut de valorisation des donn\'ees and Fonds de Recherche du Qu\'ebec through the FRQ–IVADO Research Chair in Data Science for Combinatorial Game Theory, and the Natural Sciences and Engineering Research Council of Canada through the discovery grant 2019-04557. Part of the work was conducted when the third author was Canada Excellence Research Chair at Polytechnique Montr\'eal, the generous support of the CERC grant being warmly acknowledged.




\bibliographystyle{plain}
{\small 