# Package in julia for solving optimization problems with cubic objective function

**URL:** <https://discourse.julialang.org/t/package-in-julia-for-solving-optimization-problems-with-cubic-objective-function/113055>\
**Category:** Optimization (Mathematical)\
**Created:** [April 17, 2024, 9:47am UTC](https://discourse.julialang.org/t/package-in-julia-for-solving-optimization-problems-with-cubic-objective-function/113055 "2024-04-17T09:47:46Z")\
**Posts on this page:** 5\
**Page:** 2

<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 23, 2024, 12:20am UTC](https://discourse.julialang.org/t/package-in-julia-for-solving-optimization-problems-with-cubic-objective-function/113055/21 "2024-04-23T00:20:31Z")

</div>

In addition to @mbesancon 's answer, if you’re using Gurobi, you can write the SOC constraint as a quadratic constraint directly; Gurobi will recognize it automatically.

Namely, instead of writing

```julia
model = Model()
@variable(model, x[1:n])
@variable(model, z)
@constraint(model, soc, [t; x] in SecondOrderCone())

```

you can write

```julia
model = Model(Gurobi.Optimizer)
@variable(model, x[1:n])
@variable(model, z >= 0) # ⚠️ z must be non-negative
@constraint(model, qcp, sum(x[i]^2 for i in 1:n) <= z^2)

```

and Gurobi will detect that the problem is convex.

Please note:

- the `z` variable must be non-negative for the problem to be convex
- as far as I know, only Gurobi supports this; other solvers will likely treat the problem as non-convex
- if you pass the constraint `z >= sqrt(sum(x[i]^2 for i in 1:n))`, Gurobi will 1) not support it out of the box and 2) likely won’t recognize this as a convex problem.

---

<div class="post-metadata">

**Author:** ![heiwie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heiwie/32/208105_2.png) [@heiwie](https://discourse.julialang.org/u/heiwie)\
**Post date:** [April 25, 2024, 1:33pm UTC](https://discourse.julialang.org/t/package-in-julia-for-solving-optimization-problems-with-cubic-objective-function/113055/22 "2024-04-25T13:33:44Z")

</div>

Thank you! 🙂

I am not sure if I have understood you correctly but I do not think that substituting the euclidean norm (||sqrt(A) \* sqrt(p) \* eta||\_2) with t will solve the problem. The reason for this is that the same etas are also present in other constraints as just a one-dimensional variable.

An example is:  
For a given node m in t = t I have the following constraint where S\_m is the set of successors of the node m and v is the parent of node m:

B\_{t} \cdot (w\_{v} \cdot w\_m) + \eta\_{m} + x\_{m} \geq A \cdot \sqrt{\sum\_{n \in \mathcal{S}\_{m}} p\_n \cdot \eta\_n^2}

In t = t+1, every node will have the same type of constraint. Looking at a node n which is a successor of m, the constraint will be:

B\_{t+1} \cdot (w\_{m} \cdot w\_n) + \eta\_{n} + x\_{n} \geq A \cdot \sqrt{\sum\_{r \in \mathcal{S}\_{n}} p\_r \cdot \eta\_r^2}

Here we see that the eta in the euclidean norm of the first constraint will appear in another constraint on the left hand side of the \geq. The same holds for all of the other etas.

Is there another way I could reformulate the problem instead of substituting the whole euclidean norm, so I can use Gurobi?

---

<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:** [April 26, 2024, 7:56am UTC](https://discourse.julialang.org/t/package-in-julia-for-solving-optimization-problems-with-cubic-objective-function/113055/23 "2024-04-26T07:56:25Z")

</div>

You can introduce a new variable z\_{m} with the SOC constraint

z\_m \ge \sqrt{...}

and then use z\_m in the constraint:

\ldots + x\_m \ge A \cdot z\_m

---

<div class="post-metadata">

**Author:** ![heiwie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heiwie/32/208105_2.png) [@heiwie](https://discourse.julialang.org/u/heiwie)\
**Post date:** [May 4, 2024, 10:31am UTC](https://discourse.julialang.org/t/package-in-julia-for-solving-optimization-problems-with-cubic-objective-function/113055/24 "2024-05-04T10:31:20Z")

</div>

I understood that a square root in a constraint was problematic when running the model using Gurobi. Wouldn’t I get the same problem with this formulation?

---

<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:** [May 4, 2024, 9:46pm UTC](https://discourse.julialang.org/t/package-in-julia-for-solving-optimization-problems-with-cubic-objective-function/113055/25 "2024-05-04T21:46:27Z")

</div>

Oh, yes, I didn’t mean to actually use the `sqrt`.

You should implement it as z\_m^2 \ge ... with z\_m \>= 0.

[Previous page](https://discourse.julialang.org/t/package-in-julia-for-solving-optimization-problems-with-cubic-objective-function/113055.md?page=1)
