COSMO.jl: SecondOrderCone

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