# Gurobi SOC Constraint

**URL:** https://discourse.julialang.org/t/gurobi-soc-constraint/3683
**Category:** Optimization (Mathematical)
**Created:** [May 12, 2017, 8:00pm UTC](https://discourse.julialang.org/t/gurobi-soc-constraint/3683 "2017-05-12T20:00:44Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![ahassansan](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@ahassansan](https://discourse.julialang.org/u/ahassansan)
#### Post date: [May 12, 2017, 8:00pm UTC](https://discourse.julialang.org/t/gurobi-soc-constraint/3683/1 "2017-05-12T20:00:44Z")

</div>

I am having issues using Gurobi Solver for my SOC formulation. Following are my constraints:

 ![](https://global.discourse-cdn.com/julialang/original/3X/7/6/76d37f1590855ff0af1f97597067d28ab5f9f705.png)

I am getting an error ERROR: LoadError: MethodError: no method matching NonlinearModel(::Gurobi.GurobiSolver)

The mathematical form of constraints is:  
 ![](https://global.discourse-cdn.com/julialang/original/3X/6/f/6f88d5273da49d89cb266d5f565148362361f4b4.png)

How can I solve this issue? I will appreciate any help.

---

<div class="post-metadata">

### Author: ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)
#### Post date: [May 12, 2017, 8:54pm UTC](https://discourse.julialang.org/t/gurobi-soc-constraint/3683/2 "2017-05-12T20:54:46Z")

</div>

Assuming that ![](https://global.discourse-cdn.com/julialang/original/3X/e/e/ee174dcb4cfa10378ef8b8b81ee37d1d2e072723.gif) is a variable and not a constant, the first of those constraints is a non-convex quadratic constraint. Gurobi can’t handle general nonlinear models. See the table at [Installation Guide — JuMP -- Julia for Mathematical Optimization 0.16 documentation](http://www.juliaopt.org/JuMP.jl/0.16/installation.html#getting-solvers).

---

<div class="post-metadata">

### Author: ![ahassansan](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@ahassansan](https://discourse.julialang.org/u/ahassansan)
#### Post date: [May 12, 2017, 9:03pm UTC](https://discourse.julialang.org/t/gurobi-soc-constraint/3683/3 "2017-05-12T21:03:56Z")

</div>

Thanks for the reply. ![](https://global.discourse-cdn.com/julialang/original/3X/f/1/f12dce39c604e5d1e661217c0b2abb55bf5fb609.png) is a constant. The problem is with the last constraint. It works with Ipopt Solver but by using @NLconstraint command.

---

<div class="post-metadata">

### Author: ![ahassansan](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@ahassansan](https://discourse.julialang.org/u/ahassansan)
#### Post date: [May 12, 2017, 9:54pm UTC](https://discourse.julialang.org/t/gurobi-soc-constraint/3683/4 "2017-05-12T21:54:00Z")

</div>

After trying several times to use this hint ([Models — JuMP -- Julia for Mathematical Optimization 0.16 documentation](http://www.juliaopt.org/JuMP.jl/0.16/refmodel.html#second-order-cone-constraints)), I think that my main problem is that I don’t understand how the last constraint can be represented in terms of norm()… Is there any trick or reformulation that can help me wit this?

Thank y’all again.

---

<div class="post-metadata">

### Author: ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)
#### Post date: [May 12, 2017, 10:17pm UTC](https://discourse.julialang.org/t/gurobi-soc-constraint/3683/5 "2017-05-12T22:17:45Z")

</div>

What are the variables in that constraint / could you provide a minimal code example?

---

<div class="post-metadata">

### Author: ![ahassansan](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@ahassansan](https://discourse.julialang.org/u/ahassansan)
#### Post date: [May 12, 2017, 11:22pm UTC](https://discourse.julialang.org/t/gurobi-soc-constraint/3683/6 "2017-05-12T23:22:24Z")

</div>

My variables are  
 ![](https://global.discourse-cdn.com/julialang/original/3X/e/f/ef70ba4889ceac0e118fa732af8862b2c4ba607d.png)

_R_l , _X_l and _S_l are constants.

---

<div class="post-metadata">

### Author: ![ahassansan](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@ahassansan](https://discourse.julialang.org/u/ahassansan)
#### Post date: [May 12, 2017, 11:25pm UTC](https://discourse.julialang.org/t/gurobi-soc-constraint/3683/7 "2017-05-12T23:25:32Z")

</div>

The constraints are:

 ![](https://global.discourse-cdn.com/julialang/original/3X/2/a/2aef88fb49788be3ba1f408e925a31f5105ec1ff.png)

---

<div class="post-metadata">

### Author: ![ahassansan](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@ahassansan](https://discourse.julialang.org/u/ahassansan)
#### Post date: [May 12, 2017, 11:32pm UTC](https://discourse.julialang.org/t/gurobi-soc-constraint/3683/8 "2017-05-12T23:32:59Z")

</div>

The constraint I am having issues with is:

 ![](https://global.discourse-cdn.com/julialang/original/3X/0/1/01e95b1b96a1021159b9c0386b093a8a4dfad350.png)

---

<div class="post-metadata">

### Author: ![Stephen\_Vavasis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stephen_vavasis/32/3389_2.png) [@Stephen\_Vavasis](https://discourse.julialang.org/u/Stephen_Vavasis)
#### Post date: [May 12, 2017, 11:57pm UTC](https://discourse.julialang.org/t/gurobi-soc-constraint/3683/9 "2017-05-12T23:57:33Z")

</div>

The ‘rotated second-order cone constraint’ is a convex constraint of the form y\*z \>= ||x||^2, y\>=0, z\>=0. It appears that your constraint is of this form. I don’t know if Gurobi supports this, but if it does, then probably it will help Gurobi recognize it if you move the ‘a’ variable to the other side of the inequality.

If Gurobi doesn’t support it, then you can convert it to a standard second-order cone constraint by changing variables: let y=u+v and z=u-v.

---

<div class="post-metadata">

### Author: ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)
#### Post date: [May 13, 2017, 12:02am UTC](https://discourse.julialang.org/t/gurobi-soc-constraint/3683/10 "2017-05-13T00:02:29Z")

</div>

[Please do not use images; instead, copy the code and “quote” it using backticks (`) or the “\</\>” button.]

---

<div class="post-metadata">

### Author: ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)
#### Post date: [May 13, 2017, 12:16am UTC](https://discourse.julialang.org/t/gurobi-soc-constraint/3683/11 "2017-05-13T00:16:08Z")

</div>

The `@constraint` call should not throw the error you originally specified; the division by the `a` variable should fail.

```julia
using JuMP, Gurobi
m = Model(solver = GurobiSolver())
@variables m begin
    fp
    fq
    a
    v
end
@constraint(m, (fp^2 + fq^2) / a^2 <= v)

```

results in

```julia
/(::Int64,::JuMP.GenericQuadExpr{Float64,JuMP.Variable}) is not defined. Are you trying to build a nonlinear problem? Make sure you use @NLconstraint/@NLobjective.

 in /(::Int64, ::JuMP.GenericQuadExpr{Float64,JuMP.Variable}) at /Users/twan/code/julia/RigidBodyDynamics/v0.5/JuMP/src/operators.jl:639

```

while

```julia
using JuMP, Gurobi
m = Model(solver = GurobiSolver())
@variables m begin
    fp
    fq
    a
    v
end
@NLconstraint(m, (fp^2 + fq^2) / a^2 <= v)
solve(m)

```

does result in the error you reported originally. Please do provide a minimal example right off the bat in the future; all of the back and forth above would have been unnecessary.

The constraint is indeed convex since `a` and `v` are also constrained to be positive; this is a rotated Lorentz cone constraint, as @Stephen_Vavasis mentioned.

---

<div class="post-metadata">

### Author: ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)
#### Post date: [May 13, 2017, 12:24am UTC](https://discourse.julialang.org/t/gurobi-soc-constraint/3683/12 "2017-05-13T00:24:57Z")

</div>

See also [https://github.com/JuliaOpt/Convex.jl/blob/31960219657a17d2b4d826282c00935a9f2f8e97/src/atoms/second\_order\_cone/quadoverlin.jl](https://github.com/JuliaOpt/Convex.jl/blob/31960219657a17d2b4d826282c00935a9f2f8e97/src/atoms/second_order_cone/quadoverlin.jl).

---

<div class="post-metadata">

### Author: ![ahassansan](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@ahassansan](https://discourse.julialang.org/u/ahassansan)
#### Post date: [May 13, 2017, 1:43am UTC](https://discourse.julialang.org/t/gurobi-soc-constraint/3683/13 "2017-05-13T01:43:32Z")

</div>

Thank y’all for your help and suggestions. It is working now by implementing the suggestion mentioned by @Stephen_Vavasis. I appreciate your help.

I will be more specific in future and thanks again everyone.
