# Solving a binary quadratic problem in CPLEX

**URL:** https://discourse.julialang.org/t/solving-a-binary-quadratic-problem-in-cplex/22771
**Category:** Optimization (Mathematical)
**Created:** [April 4, 2019, 9:37pm UTC](https://discourse.julialang.org/t/solving-a-binary-quadratic-problem-in-cplex/22771 "2019-04-04T21:37:34Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![angeloaliano1](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@angeloaliano1](https://discourse.julialang.org/u/angeloaliano1)
#### Post date: [April 4, 2019, 9:37pm UTC](https://discourse.julialang.org/t/solving-a-binary-quadratic-problem-in-cplex/22771/1 "2019-04-04T21:37:34Z")

</div>

Hello colleagues,  
I have the code:

```nohighlight
m = Model(with_optimizer(CPLEX.Optimizer,
CPX_PARAM_TILIM=1800,CPX_PARAM_SCRIND=0,CPX_PARAM_EPGAP=0.01))
@variables m begin
    x[i in 1:5] >=3, Int
end
@objective(m,Min,sum(x[i]^2 for i=1:5))

@constraints m begin
   co, 2*x[1] + 3x[2]+4x[3]-x[4]+x[5] >= 1
 end
 status=optimize!(m)``
But give a error message. 
How can I solve a binary quadratic problem by using CPLEX? Anyone has an example to share with me?
```

---

<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: [April 4, 2019, 10:22pm UTC](https://discourse.julialang.org/t/solving-a-binary-quadratic-problem-in-cplex/22771/2 "2019-04-04T22:22:51Z")

</div>

> <https://github.com/jump-dev/CPLEX.jl/issues/217>
>
> As reported in Discourse: https://discourse.julialang.org/t/quadratic-programmin…g-problem-cpl/21068/3
> 
> The CPLEX wrapper hasn't implemented the quadratic components yet. Pull requests accepted :)
> 
> It shouldn't be too hard because you can copy the Gurobi implementation (it's more or less just matching up the different C names).
> 
> You would need to edit the \[\`CPLEX/src/MOI\_wrapper.jl\`\](https://github.com/JuliaOpt/CPLEX.jl/blob/master/src/MOI\_wrapper.jl) and add the functions beginning with \`LQOI.\` and containing \`quadratic\` in the Gurobi wrapper:
> https://github.com/JuliaOpt/Gurobi.jl/blob/f1418b5c470fb91b417e3424241a3440078c9212/src/MOI\_wrapper.jl#L311-L367
> 
> You also have to add these lines to the list of supported objectives
> https://github.com/JuliaOpt/Gurobi.jl/blob/f1418b5c470fb91b417e3424241a3440078c9212/src/MOI\_wrapper.jl#L9
> and constrints
> https://github.com/JuliaOpt/Gurobi.jl/blob/f1418b5c470fb91b417e3424241a3440078c9212/src/MOI\_wrapper.jl#L17-L19

---

<div class="post-metadata">

### Author: ![angeloaliano1](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@angeloaliano1](https://discourse.julialang.org/u/angeloaliano1)
#### Post date: [April 4, 2019, 11:25pm UTC](https://discourse.julialang.org/t/solving-a-binary-quadratic-problem-in-cplex/22771/3 "2019-04-04T23:25:54Z")

</div>

Do you suggest other solver???  
An example implemented in JuMP?

---

<div class="post-metadata">

### Author: ![ccoffrin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ccoffrin/32/400_2.png) [@ccoffrin](https://discourse.julialang.org/u/ccoffrin)
#### Post date: [April 5, 2019, 3:31am UTC](https://discourse.julialang.org/t/solving-a-binary-quadratic-problem-in-cplex/22771/4 "2019-04-05T03:31:34Z")

</div>

I would try with Gurobi.
