# COSMO.jl: SecondOrderCone

I would like to use the COSMO optimizing package for a second order cone program.

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 the SecondOrderCone 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.

Is someone here who managed to use SecondOrderCone without using JuMP?
I also opened an issue on github since in any case, the documentation on this could be improved.

I played with the problem a bit. Looking at the documentation for using SecondOrderCone in JuMP and in MOI it looks like we need to increase the dimensionality of our problem by adding one more variable t. Let’s say that we are looking for x. Then we pass [t x] ϵ SecondOrderCone to a constraint. And since we want t=1, we also need to add a constraint for that. After this lengthy introduction, this code works (based on the QP example from COSMO):

using COSMO, SparseArrays, LinearAlgebra, Test

q = [0;1; 1.];
P = sparse([0 0 0; 0 0. 0;0 0 0]);
A = [1. 0 0; 0 0 0;0 0 0];
l = [1.; 0; 0];  # We don't care about lower and upper bound for x, only for t
u = [1.; 0; 0];

constraint1 = COSMO.Constraint(A, zeros(3), COSMO.Box(l,u),1); # Here we say that we only want box constraints for t
constraint2 = COSMO.Constraint([1 0 0;0 1.0 0; 0 0 1.0], [0.0;0;0], COSMO.SecondOrderCone)

constraints = [constraint1; constraint2]

settings = COSMO.Settings(verbose=true);
model = COSMO.Model();
assemble!(model, P, q,constraints, settings = settings);
res = COSMO.optimize!(model);


Just to check, the same problem in JuMP:

using COSMO, SparseArrays, LinearAlgebra, Test, JuMP

q = [1; 1.];
P = sparse([0. 0;0 0]);

m = JuMP.Model(COSMO.Optimizer);

@variable(m,t)
@variable(m,x[1:2])
@objective(m, Min, x'*P*x+q'*x)
@constraint(m, [t; x] in MOI.SecondOrderCone(3))
@constraint(m,t==1.0)

optimize!(m)

2 Likes

Thanks for your effort! Based on my understanding,
constraint2 = COSMO.Constraint([1 0 0;0 1.0 0; 0 0 1.0], [0.0;0;0], COSMO.SecondOrderCone)
should translate into
\Vert t + x_1 + x_2 \Vert_2 \leq ? which is not the same as \Vert x_1 + x_2 \Vert_2 \leq t, right?

Not really. If you look at how JuMP does it (and since COSMO has an interface to JuMP, I am assuming they do in the same way), we have: which then gets translated into: The first element in constraint2 = COSMO.Constraint([1 0 0;0 1.0 0; 0 0 1.0], [0.0;0;0], is put on the right-hand side of the inequality, whereas the rest is under the norm.

1 Like