oxfordcontrol/COSMO.jl

Usage of `SecondOrderCone`: Supply value of t

DanielDoehring opened this issue · 1 comments

I have a constraint of the form
$$ \Vert A \boldsymbol x + \boldsymbol b \Vert_2 \leq 1 $$ which seems to be a perfect fit for the COSMO.Constraint together with SecondOrderCone with $t=1$. However, there seems to be no way to supply the value of $t$, but only the dimensionality dimof the argument of the norm (in my case $A \boldsymbol x + \boldsymbol b$).

Unfortunately, there are no examples how to use theSecondOrderCone cone without using JuMP. I would like to avoid JuMP since it seems unnecessary overhead for my problem and also complicates (if not completely prevents) the use of higher precision types then Float64.

Hi Daniel,

COSMO's native constraints are of the form $A x + b \in \mathcal{K}$
where $\mathcal{K}$ is one of the supported proper convex cones.

The second-order cone is defined as $(t,z) \in \mathcal{K}_{socp}$ such that
$| z|_2 \leq t $.

Therefore, to get your norm constraint into the right form, we define the vector $s = (t,z) = (1,z)$ and model the constraint
$| \hat{A} x + \hat{b} |_2 = z \leq 1$ as

(0, hat_A ) x + (1, hat_b) = $s \in \mathcal{K}_{socp}$.

Example

To solve the problem

$$ \begin{array}{ll} \text{maximize} & x_1 + x_2\\ \text{s.t.} & | \hat{A} x + \hat{b} |_2 \leq 1 \end{array} $$

where A = [sqrt(2)/4, 0; 0, \sqrt(2)/4] and b = [sqrt(2)/4; sqrt(2)/4], I would write the constraints natively like this:

using COSMO, SparseArrays, LinearAlgebra, Test

q = [-1; -1.];
P = spzeros(2, 2);
A = [sqrt(2)/4 0; 0 sqrt(2)/4];
b = [2/4; 2/4]
# We model the norm constraint using `COSMO.SecondOrderCone` as the convex set:
Aa = [0. 0; A]
ba = [1; b]
constraint1 = COSMO.Constraint(Aa, ba, COSMO.SecondOrderCone(3));

# Next, we define the settings object, the model and then assemble everything:
settings = COSMO.Settings(verbose=true);
model = COSMO.Model();
assemble!(model, P, q, constraint1, settings = settings);
res = COSMO.optimize!(model);

The solution should be $x_1=x_2 = 1$ if I am not mistaken.