# Suggestions on model and solvers

**URL:** https://discourse.julialang.org/t/suggestions-on-model-and-solvers/79345
**Category:** Optimization (Mathematical)
**Created:** [April 11, 2022, 2:33pm UTC](https://discourse.julialang.org/t/suggestions-on-model-and-solvers/79345 "2022-04-11T14:33:14Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Patrik\_Waldmann](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/patrik_waldmann/32/11154_2.png) [@Patrik\_Waldmann](https://discourse.julialang.org/u/Patrik_Waldmann)
#### Post date: [April 11, 2022, 2:33pm UTC](https://discourse.julialang.org/t/suggestions-on-model-and-solvers/79345/1 "2022-04-11T14:33:14Z")

</div>

I would be happy for suggestions on how and where to implement the model for the data below (the plan is to extend to a much larger data set later so speed is of interest):

```julia
#Toy data
A = [1.0000 0 0.5000 0.5000 0.4714 0.2357;
    0 1.0000 0.5000 0 0.2357 0.5893;
    0.5000 0 0.2500 1.0000 0.5893 0.2946;
    0.5000 0 0.2500 1.0000 0.5893 0.2946;
    0.4714 0.2357 0.5893 0.5893 1.0000 0.6111;
    0.2357 0.5893 0.5303 0.2946 0.6111 1.0000]

g = [0.5 -0.2 0.3 0.2 0.0 -0.1]
s = [1 0 1 1 0 0]
d = [0 1 0 0 1 1]
F = 0.3

#Model
max c'*g

constr c'*A*c/2 ≤ F
       c'*s = 0.5
       c'*d = 0.5
       c ≥ 0

```

---

<div class="post-metadata">

### Author: ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)
#### Post date: [April 11, 2022, 2:45pm UTC](https://discourse.julialang.org/t/suggestions-on-model-and-solvers/79345/2 "2022-04-11T14:45:13Z")

</div>

If your decision variable is indeed `c`, then this looks like a [Quadratic Program (QP)](https://en.wikipedia.org/wiki/Quadratic_programming).  
I would try my luck with [JuMP.jl](https://jump.dev/JuMP.jl/stable/) (see nonlinear modeling examples such as [this one](https://jump.dev/JuMP.jl/stable/tutorials/nonlinear/portfolio/)). You will need to select an appropriate solver from [this list](https://jump.dev/JuMP.jl/stable/installation/#Supported-solvers), i.e. one that supports QP.

---

<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: [April 11, 2022, 11:30pm UTC](https://discourse.julialang.org/t/suggestions-on-model-and-solvers/79345/3 "2022-04-11T23:30:59Z")

</div>

The objective `c'*g` is linear, and the constraint `c'*A*c/2 ≤ F` is quadratic, so this is a quadratically-constrained problem, not linearly-constrained QP. The corresponding example in the JuMP doc would be [this one](https://jump.dev/JuMP.jl/stable/tutorials/nonlinear/qcp/).

If `A` is symmetric positive semi-definite, then the problem is convex and solvable fairly efficiently by several solvers such as Ipopt, CPLEX, Gurobi, Xpress, etc.

If `A` is _not_ symmetric positive semi-definite, then the problem is non convex (and much more difficult to solve exactly). In that situation, Ipopt should give decent solution, though no guarantee of feasibility / optimality. Gurobi can solve non-convex QCPs to global optimality, potentially taking some time if the problem is large.

---

<div class="post-metadata">

### Author: ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)
#### Post date: [April 12, 2022, 4:47am UTC](https://discourse.julialang.org/t/suggestions-on-model-and-solvers/79345/4 "2022-04-12T04:47:36Z")

</div>

My bad I had switched the objective and constraints ^^ Edited my answer
