Mixed-integer quadratic program

A mixed-integer quadratic program (MIQP) is an optimization problem of the form $$ \begin{array}{ll} \mbox{minimize} & x^T Q x + q^T x + r \\ \mbox{subject to} & x \in \mathcal{C}\\ & x \in \mathbf{Z}^n, \end{array} $$ where $x \in \mathbf{Z}^n$ is the optimization variable ($\mathbf Z^n$ is the set of $n$-dimensional vectors with integer-valued components), $Q \in \mathbf{S}_+^n$ (the set of $n \times n$ symmetric positive semidefinite matrices), $q \in \mathbf{R}^n$, and $r \in \mathbf{R}$ are problem data, and $\mathcal C$ is some convex set.

An example of an MIQP is mixed-integer least squares, which has the form $$ \begin{array}{ll} \mbox{minimize} & \|Ax-b\|_2^2 \\ \mbox{subject to} & x \in \mathbf{Z}^n, \end{array} $$ where $x \in \mathbf{Z}^n$ is the optimization variable, and $A \in \mathbf{R}^{m \times n}$ and $b \in \mathbf{R}^{m}$ are the problem data. A solution $x^{\star}$ of this problem will be a vector in $\mathbf Z^n$ that minimizes $\|Ax-b\|_2^2$.

Example

In the following code, we solve a mixed-integer least-squares problem with CVXPY.


In [1]:
import cvxpy as cp
import numpy as np

In [2]:
# Generate a random problem
np.random.seed(0)
m, n= 40, 25

A = np.random.rand(m, n)
b = np.random.randn(m)

In [3]:
# Construct a CVXPY problem
x = cp.Variable(n, integer=True)
objective = cp.Minimize(cp.sum_squares(A@x - b))
prob = cp.Problem(objective)
prob.solve()


Out[3]:
13.66000322824753

In [7]:
print("Status: ", prob.status)
print("The optimal value is", prob.value)
print("A solution x is")
print(x.value)


Status:  optimal
The optimal value is 13.66000322824753
A solution x is
[-1.  1.  1. -1.  0.  0. -1. -2.  0.  0.  0.  1.  1.  0.  1.  0. -1. -1.
 -1.  0.  2. -1.  2.  0. -1.]