# Quadratic Programming with CPLEX and JuMP

**URL:** <https://discourse.julialang.org/t/quadratic-programming-with-cplex-and-jump/52950>\
**Category:** Optimization (Mathematical)\
**Tags:** question, jump\
**Created:** [January 6, 2021, 5:05pm UTC](https://discourse.julialang.org/t/quadratic-programming-with-cplex-and-jump/52950 "2021-01-06T17:05:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ahmadreza-marandi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmadreza-marandi/32/13490_2.png) [@ahmadreza-marandi](https://discourse.julialang.org/u/ahmadreza-marandi)\
**Post date:** [January 6, 2021, 5:05pm UTC](https://discourse.julialang.org/t/quadratic-programming-with-cplex-and-jump/52950/1 "2021-01-06T17:05:46Z")

</div>

It has been a while that CPLEX can solve nonconvex quadratic programming problems. But I am wondering if that has been considered in JuMP.  
The reason I am asking is that I coded the following:

```julia
Q=[-50.0 0.0 0.0 0.0 0.0 42.0
   0.0 -50.0 0.0 0.0 0.0 44.0
   0.0 0.0 -50.0 0.0 0.0 45.0
   0.0 0.0 0.0 -50.0 0.0 47.0
   0.0 0.0 0.0 0.0 -50.0 47.5
  42.0 44.0 45.0 47.0 47.5 -0.0];
  A_x=[ 1.0 0.0 0.0 0.0 0.0 0.0
  0.0 1.0 0.0 0.0 0.0 0.0
  0.0 0.0 1.0 0.0 0.0 0.0
  0.0 0.0 0.0 1.0 0.0 0.0
  0.0 0.0 0.0 0.0 1.0 0.0
  0.0 0.0 0.0 0.0 0.0 1.0
  0.0 0.0 0.0 0.0 0.0 -1.0
 20.0 12.0 11.0 7.0 4.0 0.0];
 b_x=[1.0
  1.0
  1.0
  1.0
  1.0
  0.5
 -0.5
 40.0]
n=6;
model = Model(CPLEX.Optimizer)
@variable(model, x[1:n]>=0)
@objective(model, Min, x'*Q*x)
con = @constraint(model, A_x*x .<= b_x)
sol_cplex=optimize!(model)

```

in Julia 1.5.3 using JuMP 0.21.5 and CPLEX 12.10, and got the following error:

```julia
ERROR: LoadError: CPLEX Error 5002: %s is not convex.

Stacktrace:
 [1] error(::String) at .\error.jl:33
 [2] _check_ret(::CPLEX.Env, ::Int32) at C:\Users\20176914\.julia\packages\CPLEX\uUjlQ\src\MOI\MOI_wrapper.jl:126
 [3] _check_ret at C:\Users\20176914\.julia\packages\CPLEX\uUjlQ\src\MOI\MOI_wrapper.jl:243 [inlined]
 [4] _optimize!(::CPLEX.Optimizer) at C:\Users\20176914\.julia\packages\CPLEX\uUjlQ\src\MOI\MOI_wrapper.jl:2431
 [5] optimize!(::CPLEX.Optimizer) at C:\Users\20176914\.julia\packages\CPLEX\uUjlQ\src\MOI\MOI_wrapper.jl:2488
 [6] optimize!(::MathOptInterface.Bridges.LazyBridgeOptimizer{CPLEX.Optimizer}) at C:\Users\20176914\.julia\packages\MathOptInterface\ZJFKw\src\Bridges\bridge_optimizer.jl:264
 [7] optimize!(::MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.AbstractOptimizer,MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}) at C:\Users\20176914\.julia\packages\MathOptInterface\ZJFKw\src\Utilities\cachingoptimizer.jl:215
 [8] optimize!(::Model, ::Nothing; bridge_constraints::Bool, ignore_optimize_hook::Bool, kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at C:\Users\20176914\.julia\packages\JuMP\qhoVb\src\optimizer_interface.jl:130
 [9] optimize! at C:\Users\20176914\.julia\packages\JuMP\qhoVb\src\optimizer_interface.jl:106 [inlined] (repeats 2 times)
 [10] top-level scope at C:\Users\20176914\surfdrive\scientific\University\Codes\MATLAB\Bilinearprog\readLP.jl:46
 [11] include(::String) at .\client.jl:457
 [12] top-level scope at REPL[2]:1
in expression starting at C:\Users\20176914\surfdrive\scientific\University\Codes\MATLAB\Bilinearprog\readLP.jl:46

```

I know from past experience that there are different functions to make the distinction between convex and non-convex. So, I am now wondering if it is only possible to solve convex QPs in JuMP using CPLEX.  
Does anyone have any experience with that?

---

<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:** [January 6, 2021, 8:19pm UTC](https://discourse.julialang.org/t/quadratic-programming-with-cplex-and-jump/52950/2 "2021-01-06T20:19:10Z")

</div>

CPLEX does not support non-convex QPs. I think you are thinking of Gurobi: [https://www.gurobi.com/resource/non-convex-quadratic-optimization/](https://www.gurobi.com/resource/non-convex-quadratic-optimization/)

---

<div class="post-metadata">

**Author:** ![mtanneau](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mtanneau/32/17787_2.png) [@mtanneau](https://discourse.julialang.org/u/mtanneau)\
**Post date:** [January 7, 2021, 12:36am UTC](https://discourse.julialang.org/t/quadratic-programming-with-cplex-and-jump/52950/3 "2021-01-07T00:36:29Z")

</div>

CPLEX does support non-convex QP, just not non-convex QCQP.

@ahmadreza-marandi as mentioned in the [CPLEX documentation](https://www.ibm.com/support/knowledgecenter/SSSA5P_12.10.0/ilog.odms.cplex.help/CPLEX/UsrMan/topics/cont_optim/qp/02_convexity_defn.html), you need to set the [optimality target](https://www.ibm.com/support/knowledgecenter/SSSA5P_12.10.0/ilog.odms.cplex.help/CPLEX/Parameters/topics/OptimalityTarget.html?view=kc) parameter accordingly:

> By default, CPLEX terminates if the quadratic objective term in a QP is found to be non PSD. In such a case, in order to instruct CPLEX not to terminate, you must set the `optimality target` parameter. The value that you set for that parameter depends on the type of results that you expect. If you would like CPLEX to compute a point that satisfies **first-order optimality conditions** (that is, a local optimum), then you set the parameter to the value CPX\_SOLUTIONTARGET\_FIRSTORDER. If you would like CPLEX to find a **global optimum** , then you set the parameter to the value CPX\_SOLUTIONTARGET\_OPTIMALGLOBAL.

Just add the following line:

```julia
set_optimizer_attribute(model, "CPXPARAM_OptimalityTarget", 3)

```

---

<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:** [January 7, 2021, 2:33am UTC](https://discourse.julialang.org/t/quadratic-programming-with-cplex-and-jump/52950/4 "2021-01-07T02:33:16Z")

</div>

My mistake!

---

<div class="post-metadata">

**Author:** ![ahmadreza-marandi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmadreza-marandi/32/13490_2.png) [@ahmadreza-marandi](https://discourse.julialang.org/u/ahmadreza-marandi)\
**Post date:** [January 7, 2021, 7:35am UTC](https://discourse.julialang.org/t/quadratic-programming-with-cplex-and-jump/52950/5 "2021-01-07T07:35:22Z")

</div>

@mtanneau: that was a great help. Thanks. I missed that parameter.
