![]() |
SuperSCS
1.3.2
|
Let us solve the following second-order cone program:
\begin{eqnarray*} &&\mathrm{Minimize}\ \langle c, x \rangle\\ &&Ax + s = b\\ &&s\in\mathcal{K}, \end{eqnarray*}
where \(x\in\mathbb{R}^3\), \(A\in\mathbb{R}^{4\times 3}\) is the following sparse matrix
\begin{eqnarray*} A &=& \begin{bmatrix} 0.3\\ & 0.7\\ && 0.2\\ -0.5 & 0.9 \end{bmatrix} \end{eqnarray*}
and \(c\in\mathbb{R}^3\) and \(b\in\mathbb{R}^4\) are the vectors
\begin{eqnarray*} c &=& \begin{bmatrix} 1 & -2 & -3 \end{bmatrix}^{\top} \end{eqnarray*}
and
\begin{eqnarray*} b &=& \begin{bmatrix} 0.2 & 0.1 & -0.1 & 0.1 \end{bmatrix}^{\top}. \end{eqnarray*}
Last, \(\mathcal{K}\) is the second-order cone in \(\mathbb{R}^4\).
Let us first start with some declarations:
We then need to allocate a ScsData object and define \(b\) and \(c\)
Next, we construct the sparse matrix \(A\) and we pass it to the ScsData object
For more information about sparse matrices, read this documentation page.
Next, we may modify some of the default settings
The following utility functions can be used to facilitate the configuration of SuperSCS:
Function scs_set_default_settings sets the default settings
Last thing to define is the second-order cone \(\mathcal{K}\)
Note that the last couple of lines are important!
We now invoke scs to solve the problem
It is highly recommended that you use these initializers to create these structures.
Now
is the exit-flag of the solver and it is equal to SCS_SOLVED.
The primal-dual solution \((x^\star,s^\star,y^\star)\) is now stored in sol
.
If data->stgs->verbose
is set to 1
, the following will be printed
The last thing to do is to free the used memory
If we need to collect progress data for the algorithm, we need to activate logging using
This option is otherwise disabled by default.
We may then print various statistics
If do_record_progress
is, instead, set to 0
, no progress data are stored and the above pointers are equal to SCS_NULL.