\documentclass[12pt]{diary} \title{Active set solver for quadratic programming} \author{Alec Jacobson} \date{18 September 2013} \renewcommand{\A}{\mat{A}} \renewcommand{\Q}{\mat{Q}} \newcommand{\RR}{\mat{R}} \newcommand{\Aeq}{\mat{A}_\textrm{eq}} \newcommand{\Aieq}{\mat{A}_\textrm{ieq}} \newcommand{\beq}{\vc{b}_\textrm{eq}} \newcommand{\bieq}{\vc{b}_\textrm{ieq}} \newcommand{\lx}{\Bell} \newcommand{\ux}{\vc{u}} \newcommand{\lameq} {\lambda_\textrm{eq}} \newcommand{\lamieq}{\lambda_\textrm{ieq}} \newcommand{\lamlu} {\lambda_\textrm{lu}} \begin{document} \begin{pullout} \footnotesize \emph{Disclaimer: This document rewrites and paraphrases the ideas in \url{http://www.math.uh.edu/~rohop/fall_06/Chapter3.pdf}, \url{http://www.math.uh.edu/~rohop/fall_06/Chapter2.pdf}, and \url{http://www.cs.cornell.edu/courses/cs322/2007sp/notes/qr.pdf}. Mostly this is to put everything in the same place and use notation compatible with the libigl implementation. The ideas and descriptions, however, are not novel.} \end{pullout} Quadratic programming problems (QPs) can be written in general as: \begin{align} \argmin \limits_\z & \z^\transpose \A \z + \z^\transpose \b + \text{ constant}\\ \text{subject to } & \Aieq \z ≤ \bieq, \end{align} where $\z \in \R^n$ is a vector of unknowns, $\A \in \R^{n \times n}$ is a (in our case sparse) matrix of quadratic coefficients, $\b \in \R^n$ is a vector of linear coefficients, $\Aieq \in \R^{m_\text{ieq} \times n}$ is a matrix (also sparse) linear inequality coefficients and $\bieq \in \R^{m_\text{ieq}}$ is a vector of corresponding right-hand sides. Each row in $\Aieq \z ≤ \bieq$ corresponds to a single linear inequality constraint. Though representable by the linear inequality constraints above---linear \emph{equality} constraints, constant bounds, and constant fixed values appear so often that we can write a more practical form \begin{align} \argmin \limits_\z & \z^\transpose \A \z + \z^\transpose \b + \text{ constant}\\ \text{subject to } & \z_\text{known} = \y,\\ & \Aeq \z = \beq,\\ & \Aieq \z ≤ \bieq,\\ & \z ≥ \lx,\\ & \z ≤ \ux, \end{align} where $\z_\text{known} \in \R^{n_\text{known}}$ is a subvector of our unknowns $\z$ which are known or fixed to obtain corresponding values $\y \in \R^{n_\text{known}}$, $\Aeq \in \R^{m_\text{eq} \times n}$ and $\beq \in \R^{m_\text{eq} \times n}$ are linear \emph{equality} coefficients and right-hand sides respectively, and $\lx, \ux \in \R^n$ are vectors of constant lower and upper bound constraints. \todo{This notation is unfortunate. Too many bold A's and too many capitals.} This description exactly matches the prototype used by the \texttt{igl::active\_set()} function. The active set method works by iteratively treating a subset (some rows) of the inequality constraints as equality constraints. These are called the ``active set'' of constraints. So at any given iterations $i$ we might have a new problem: \begin{align} \argmin \limits_\z & \z^\transpose \A \z + \z^\transpose \b + \text{ constant}\\ \text{subject to } & \z_\text{known}^i = \y^i,\\ & \Aeq^i \z = \beq^i, \end{align} where the active rows from $\lx ≤ \z ≤ \ux$ and $\Aieq \z ≤ \bieq$ have been appended into $\z_\text{known}^i = \y^i$ and $\Aeq^i \z = \beq^i$ respectively. This may be optimized by solving a sparse linear system, resulting in the current solution $\z^i$. For equality constraint we can also find a corresponding Lagrange multiplier value. The active set method works by adding to the active set all linear inequality constraints which are violated by the previous solution $\z^{i-1}$ before this solve and then after the solve removing from the active set any constraints with negative Lagrange multiplier values. Let's declare that $\lameq \in \R^{m_\text{eq}}$, $\lamieq \in \R^{m_\text{ieq}}$, and $\lamlu \in \R^{n}$ are the Lagrange multipliers corresponding to the linear equality, linear inequality and constant bound constraints respectively. Then the abridged active set method proceeds as follows: \begin{lstlisting}[keywordstyle=,mathescape] while not converged add to active set all rows where $\Aieq \z > \bieq$, $\z < \lx$ or $\z > \ux$ $\Aeq^i,\beq^i \leftarrow \Aeq,\beq + \text{active rows of} \Aieq,\bieq$ $\z_\text{known}^i,\y^i \leftarrow \z_\text{known},\y + \text{active indices and values of} \lx,\ux$ solve problem treating active constraints as equality constraints $\rightarrow \z,\lamieq,\lamlu$ remove from active set all rows with $\lamieq < 0$ or $\lamlu < 0$ end \end{lstlisting} The fixed values constraints of $\z_\text{known}^i = \y^i$ may be enforced by substituting $\z_\text{known}^i$ for $\y^i$ in the energy directly during the solve. Corresponding Lagrange multiplier values $\lambda_\text{known}^i$ can be recovered after we've found the rest of $\z$. The linear equality constraints $\Aeq^i \z = \beq^i$ are a little trickier. If the rows of $\Aeq^i \in \R^{(