Problem Formulation
PIQP expects QP of the form
\[\begin{aligned} \min_{x} \quad & \frac{1}{2} x^\top P x + c^\top x \\ \text {s.t.}\quad & Ax=b, \\ & Gx \leq h, \\ & x_{lb} \leq x \leq x_{ub} \end{aligned}\]with primal decision variables \(x \in \mathbb{R}^n\), matrices \(P\in \mathbb{S}_+^n\), \(A \in \mathbb{R}^{p \times n}\), \(G \in \mathbb{R}^{m \times n}\), and vectors \(c \in \mathbb{R}^n\), \(b \in \mathbb{R}^p\), \(h \in \mathbb{R}^m\), \(x_{lb} \in \mathbb{R}^n\), and \(x_{ub} \in \mathbb{R}^n\).
PIQP can handle infinite box constraints well, i.e. when elements of \(x_{lb}\) or \(x_{ub}\) are \(-\infty\) or \(\infty\), respectively. On the contrary, infinite values in the general inequalities \(Gx \leq h = \pm \infty\) can cause problems. PIQP internally disables them by setting the corresponding rows in \(G\) to zero (sparsity structure is preserved). For best performance, consider removing the corresponding constraints from the problem formulation directly.
Example QP
In the following the C++ interface of PIQP will be introduced using the following example QP problem:
\[\begin{aligned} \min_{x} \quad & \frac{1}{2} x^\top \begin{bmatrix} 6 & 0 \\ 0 & 4 \end{bmatrix} x + \begin{bmatrix} -1 \\ -4 \end{bmatrix}^\top x \\ \text {s.t.}\quad & \begin{bmatrix} 1 & -2 \end{bmatrix} x = 1, \\ & \begin{bmatrix} 1 & -1 \\ 2 & 0 \end{bmatrix} x \leq \begin{bmatrix} 0.2 \\ -1 \end{bmatrix}, \\ & -1 \leq x_1 \leq 1. \end{aligned}\]Problem Data
PIQP supports dense and sparse problem formulations. For small and dense problems the dense interface is preferred since vectorized instructions and cache locality can be exploited more efficiently, but for sparse problems the sparse interface and result in significant speedups.
To use the Matlab interface of PIQP make sure it is properly added to the path. We can then define the problem data as
P = [6 0; 0 4];
c = [-1; -4];
A = [1 -2];
b = 1;
G = [1 -1; 2, 0];
h = [0.2; -1];
x_lb = [-1; -Inf];
x_ub = [1; Inf];
For the sparse interface \(P\), \(A\), and \(G\) should be sparse matrices.
P = sparse([6 0; 0 4]);
A = sparse([1 -2]);
G = sparse([1 -1; 2, 0]);
Solver Instantiation
You can instantiate a solver object using
% for dense problems
solver = piqp('dense');
% or for sparse problems
solver = piqp('sparse');
Settings
Settings can be updated using the update_settings
method:
solver.update_settings('verbose', true, 'compute_timings', true);
In this example we enable the verbose output and internal timings. The full set of configuration options can be found here.
Solving the Problem
We can now set up the problem using
solver.setup(P, c, A, b, G, h, x_lb, x_ub);
The data is internally copied, and the solver initializes all internal data structures.
Now, the problem can be solver using
result = solver.solve()
The result of the optimization are directly returned. More specifically, the most important information includes
result.x
: primal solutionresult.y
: dual solution of equality constraintsresult.z
: dual solution of inequality constraintsresult.z_lb
: dual solution of lower bound box constraintsresult.z_ub
: dual solution of upper bound box constraintsresult.info.staus
: solver statusresult.info.primal_obj
: primal objective valueresult.info.run_time
: total runtime
Timing information like result.info.run_time
is only measured if compute_timings
is set to true
.
Efficient Problem Updates
Instead of creating a new solver object everytime it’s possible to update the problem directly using
solver.update('P', P_new, 'A', A_new, 'b', b_new, ...);
with a subsequent call to
result = solver.solve()
This allows the solver to internally reuse memory and factorizations speeding up subsequent solves.
Note the dimension and sparsity pattern of the problem are not allowed to change when calling the update
function.