# Second order conic constraints with CPLEX

**URL:** https://discourse.julialang.org/t/second-order-conic-constraints-with-cplex/26413
**Category:** Optimization (Mathematical)
**Tags:** jump
**Created:** [July 16, 2019, 11:59am UTC](https://discourse.julialang.org/t/second-order-conic-constraints-with-cplex/26413 "2019-07-16T11:59:03Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![giadasp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giadasp/32/10143_2.png) [@giadasp](https://discourse.julialang.org/u/giadasp)
#### Post date: [July 16, 2019, 11:59am UTC](https://discourse.julialang.org/t/second-order-conic-constraints-with-cplex/26413/1 "2019-07-16T11:59:03Z")

</div>

I have to solve a MISOCP problem with JuMP and CPLEX but I really didn’t understand how to write the constraints with the new syntax `in SecondOrderCone()`.  
I need to minimize the squared norm of a vector in which I have my binary optimization variables, e.g.  
Min(sum((y[n]-sum(x[n,j]\*b[j] for j=1:J))^2 for n=1:N))  
where x[n,j] are my binary opt variables and y and b are observed.  
I can write the objective function in terms of constraints of the type:

```julia
@variable(m,x[n=1:N,j=1:J],Bin)
@variable(m, w[n=1:N]>=0)
@objective(m, Min , sum(w[n] for n=1:N))
for n=1:N
     @constraint(m, [w[n]; y[n]-sum(x[n,j]*b[j] for j=1:J)] in SecondOrderCone())
end

```

but it doesn’t work.  
It says “ERROR: Constraints of type MathOptInterface.VectorAffineFunction{Float64}-in-MathOptInterface.SecondOrderCone are not supported by the solver and there are no bridges that can reformulate it into supported constraints.”

What can I do to solve my problem?

Thank you for your attention.

Giada

---

<div class="post-metadata">

### Author: ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)
#### Post date: [July 16, 2019, 1:57pm UTC](https://discourse.julialang.org/t/second-order-conic-constraints-with-cplex/26413/2 "2019-07-16T13:57:37Z")

</div>

There is no need to use `SecondOrderCone`. Just write out the problem using the quadratic form:

```nohighlight
model = Model()
@variable(model, x[1:N, 1:J], Bin)
@objective(model, Min, 
    sum(
        (y[n] - sum(b[j] * x[n, j] for j in 1:J))^2 
        for n in 1:N
    ) 
)
```

---

<div class="post-metadata">

### Author: ![giadasp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giadasp/32/10143_2.png) [@giadasp](https://discourse.julialang.org/u/giadasp)
#### Post date: [July 16, 2019, 2:02pm UTC](https://discourse.julialang.org/t/second-order-conic-constraints-with-cplex/26413/3 "2019-07-16T14:02:06Z")

</div>

Thank you odow, are you sure it works with binary opt variables?

---

<div class="post-metadata">

### Author: ![giadasp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giadasp/32/10143_2.png) [@giadasp](https://discourse.julialang.org/u/giadasp)
#### Post date: [July 16, 2019, 2:07pm UTC](https://discourse.julialang.org/t/second-order-conic-constraints-with-cplex/26413/4 "2019-07-16T14:07:48Z")

</div>

I tried and it does not work.  
It says “The solver does not support an objective function of type MathOptInterface.ScalarQuadraticFunction{Float64}.”

---

<div class="post-metadata">

### Author: ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)
#### Post date: [July 16, 2019, 2:10pm UTC](https://discourse.julialang.org/t/second-order-conic-constraints-with-cplex/26413/5 "2019-07-16T14:10:08Z")

</div>

This is fixed on master. Run

```nohighlight
] add CPLEX#master

```

---

<div class="post-metadata">

### Author: ![giadasp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giadasp/32/10143_2.png) [@giadasp](https://discourse.julialang.org/u/giadasp)
#### Post date: [July 16, 2019, 2:16pm UTC](https://discourse.julialang.org/t/second-order-conic-constraints-with-cplex/26413/6 "2019-07-16T14:16:52Z")

</div>

Fantastic!  
Thank you very much 🙂
