# Integer optimisation with user's multivariate functions: Possible in Julia?

**URL:** <https://discourse.julialang.org/t/integer-optimisation-with-users-multivariate-functions-possible-in-julia/17924>\
**Category:** Optimization (Mathematical)\
**Tags:** jump, optimization\
**Created:** [November 23, 2018, 7:23pm UTC](https://discourse.julialang.org/t/integer-optimisation-with-users-multivariate-functions-possible-in-julia/17924 "2018-11-23T19:23:33Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Olegg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/olegg/32/51316_2.png) [@Olegg](https://discourse.julialang.org/u/Olegg)\
**Post date:** [November 23, 2018, 7:23pm UTC](https://discourse.julialang.org/t/integer-optimisation-with-users-multivariate-functions-possible-in-julia/17924/1 "2018-11-23T19:23:33Z")

</div>

My optimisation problem has convex multivariate constraints with matrix operations: inverse and determinant. The matrices are symmetric PSD from dim 2x2 up to 10x10. I’ve solved the continuous case in JuMP and Ipopt, with user-defined multivariate constraints and analytical derivatives. This worked extremely well.

There’s been less luck with the integer case. What I’ve tried:

- Define @NLconstraints in JuMP =\> The _det_ and _inv_ weren’t recognised

- Use Pavito.jl and Ipopt with CbcSolver or CplexSolver =\> Requires Hessians, which isn’t possible in JuMP for multivariate user-defined functions, even though Ipopt doesn’t require exact Hessians

- Juniper, POD, AmplNLWriter =\> No user-defined multivariate functions (to the best of my knowledge)

- Convex.jl and SCS + Pajarito =\> some luck with the _det_, but slow convergence and inexact solutions, like -0.2039 for an Int x \>= 0. Also, _inv_ isn’t really allowed.

I’d very much appreciate any suggestions and recommendations of library tools, ideally open source. Many thanks!

---

<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:** [November 24, 2018, 5:01pm UTC](https://discourse.julialang.org/t/integer-optimisation-with-users-multivariate-functions-possible-in-julia/17924/2 "2018-11-24T17:01:12Z")

</div>

If you have a JuMP model that is working for an NLP problem, I don’t foresee why Juniper would not work for an MINLP variant of that JuMP model. Can you indicate what type of error you are getting in that case?

---

<div class="post-metadata">

**Author:** ![Olegg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/olegg/32/51316_2.png) [@Olegg](https://discourse.julialang.org/u/Olegg)\
**Post date:** [November 24, 2018, 5:40pm UTC](https://discourse.julialang.org/t/integer-optimisation-with-users-multivariate-functions-possible-in-julia/17924/3 "2018-11-24T17:40:43Z")

</div>

I get “LoadError: KeyError: key :g not found”. Here, :g is the user-defined constraint registered with JuMP and added through JuMP.addNLconstraint. This constraint is indexed and added in a loop, as in [JuMP; Rewriting an @eval @NLexpression with a user defined function in local scope w/ Expr](https://discourse.julialang.org/t/jump-rewriting-an-eval-nlexpression-with-a-user-defined-function-in-local-scope-w-expr/8757)

---

<div class="post-metadata">

**Author:** ![Wikunia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wikunia/32/2180_2.png) [@Wikunia](https://discourse.julialang.org/u/Wikunia)\
**Post date:** [November 25, 2018, 8:17am UTC](https://discourse.julialang.org/t/integer-optimisation-with-users-multivariate-functions-possible-in-julia/17924/4 "2018-11-25T08:17:48Z")

</div>

Can you provide me a small test script that I can work with?

---

<div class="post-metadata">

**Author:** ![Olegg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/olegg/32/51316_2.png) [@Olegg](https://discourse.julialang.org/u/Olegg)\
**Post date:** [November 25, 2018, 12:46pm UTC](https://discourse.julialang.org/t/integer-optimisation-with-users-multivariate-functions-possible-in-julia/17924/5 "2018-11-25T12:46:24Z")

</div>

I found a workaround by disabling Hessians in Pavito if they aren’t provided by the JuMP model. There’s a PR in [Disable Hessians when not provided by JuMP by spockoyno · Pull Request #12 · jump-dev/Pavito.jl · GitHub](https://github.com/JuliaOpt/Pavito.jl/pull/12).

---

<div class="post-metadata">

**Author:** ![Olegg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/olegg/32/51316_2.png) [@Olegg](https://discourse.julialang.org/u/Olegg)\
**Post date:** [November 25, 2018, 12:49pm UTC](https://discourse.julialang.org/t/integer-optimisation-with-users-multivariate-functions-possible-in-julia/17924/6 "2018-11-25T12:49:21Z")

</div>

I’ve found a workaround, but maybe there’s a better solution. There’s an example script in my other question, [How to avoid re-computing the same matrix in optimisation/JuMP?](https://discourse.julialang.org/t/how-to-avoid-re-computing-the-same-matrix-in-optimisation-jump/17883) Many thanks!

---

<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:** [November 25, 2018, 7:03pm UTC](https://discourse.julialang.org/t/integer-optimisation-with-users-multivariate-functions-possible-in-julia/17924/7 "2018-11-25T19:03:22Z")

</div>

@Olegg, glad to hear that you found a work around for Pavito.

Still, it would be a great help to us if you could provide a small JuMP model that exhibits this issue, then we can add it to the unit tests for various solvers to make sure they work for user defined functions.

---

<div class="post-metadata">

**Author:** ![Olegg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/olegg/32/51316_2.png) [@Olegg](https://discourse.julialang.org/u/Olegg)\
**Post date:** [November 25, 2018, 8:30pm UTC](https://discourse.julialang.org/t/integer-optimisation-with-users-multivariate-functions-possible-in-julia/17924/8 "2018-11-25T20:30:05Z")

</div>

Sure! I’ve edited and double-checked the code linked in my reply to @Wikunia. Should be working now with the workaround. Hope it helps.

---

<div class="post-metadata">

**Author:** ![jacob-roth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jacob-roth/32/1862_2.png) [@jacob-roth](https://discourse.julialang.org/u/jacob-roth)\
**Post date:** [May 5, 2019, 11:24pm UTC](https://discourse.julialang.org/t/integer-optimisation-with-users-multivariate-functions-possible-in-julia/17924/9 "2019-05-05T23:24:47Z")

</div>

@Olegg: I may have a similar problem [here](https://discourse.julialang.org/t/encode-matrix-function-which-depends-on-optimization-variables-at-each-step/23831/6) where I want to define constraints in JuMP involving matrix `inv`s. Would you mind sharing how you registered a multivariate function / derivative? Or did you find an alternative approach?
