# Use of MINLP in Julia

**URL:** https://discourse.julialang.org/t/use-of-minlp-in-julia/22161
**Category:** Optimization (Mathematical)
**Created:** [March 21, 2019, 7:43pm UTC](https://discourse.julialang.org/t/use-of-minlp-in-julia/22161 "2019-03-21T19:43:37Z")
**Posts on this page:** 12
**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: [March 21, 2019, 7:43pm UTC](https://discourse.julialang.org/t/use-of-minlp-in-julia/22161/1 "2019-03-21T19:43:37Z")

</div>

Hello people, all rigth?  
I need to solve a nonlinear integer nonconvex problem. The objective and constraints are nonlinear functions.  
First question:

1. What the ideal package and solve to solve this problem?
2. Is there any code-example for share with me?
3. I found in the net the solver Juniper, able to solve these problems. The article describing this package is in:  
[https://arxiv.org/pdf/1804.07332.pdf](https://arxiv.org/pdf/1804.07332.pdf)  
But, when I run this lines

using JuMP, Ipopt, Cbc, Juniper

ipopt = IpoptSolver(print\_level=0);  
cbc = CbcSolver()  
m = Model(solver=JuniperSolver(ipopt, mip\_solver=cbc))  
v = [10,20,12,23,42];  
w = [12,45,12,22,21]  
@variable(m, 0 \<= x[1:5] \<= 10, Int)  
@objective(m, Max, dot(v,x))  
@constraint(m, sum(x[i] for i=1:5) \<= 6)  
@NLconstraint(m, sum(w[i]\*x[i] for i=1:5) \<= 300)  
status = solve(m);  
getvalue(x)

I have a mistake: “UndefVarError: base not defined”. This solver is very nice for my problem, but I would like to underestand this mistake.

Anyone could help me?

---

<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: [March 21, 2019, 8:10pm UTC](https://discourse.julialang.org/t/use-of-minlp-in-julia/22161/2 "2019-03-21T20:10:24Z")

</div>

> What the ideal package and solve to solve this problem?

JuMP! It seems like you’ve found the right place.

> UndefVarError: base not defined

Do you have the full error message? It’s hard to know where this is coming from otherwise.

p.s. please read [Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757), particularly about formatting code.

---

<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: [March 21, 2019, 8:31pm UTC](https://discourse.julialang.org/t/use-of-minlp-in-julia/22161/3 "2019-03-21T20:31:33Z")

</div>

Thanks for your response.  
Yes, I use JUMP.  
My problem is to use the package Juniper or other that solve MINLP. Do you have other suggestion and help me how to use in JUMP?

The complete message erros is the following, when I complile the code:

using JuMP  
using Juniper  
using Ipopt  
using Cbc

solver = JuniperSolver(IpoptSolver(print\_level=0);  
mip\_solver=CbcSolver())

m = Model(solver=solver)  
v = [10,20,12,23,42]  
w = [12,45,12,22,21]  
@variable(m, x[1:5], Bin)  
@objective(m, Max, dot(v,x))  
@NLconstraint(m, sum(w[i]\*x[i]^2 for i=1:5) \<= 45)  
status = solve(m)

## Complete error message:

UndefVarError: base not defined  
round at Compat.jl:1625 [inlined]  
are\_type\_correct(::Array{Float64,1}, ::Array{Symbol,1}, ::Array{Int64,1}, ::Float64) at bb\_type\_correct.jl:22  
fpump(::Juniper.JuniperModel) at fpump.jl:235  
optimize!(::Juniper.JuniperModel) at model.jl:135  
#solvenlp#165(::Bool, ::Function, ::JuMP.Model, ::JuMP.ProblemTraits) at nlp.jl:1271  
(::JuMP.#kw##solvenlp)(::Array{Any,1}, ::JuMP.#solvenlp, ::JuMP.Model, ::JuMP.ProblemTraits) at :0  
#solve#116(::Bool, ::Bool, ::Bool, ::Array{Any,1}, ::Function, ::JuMP.Model) at solvers.jl:172  
solve(::JuMP.Model) at solvers.jl:150  
include\_string(::String, ::String) at loading.jl:522  
include\_string(::String, ::String, ::Int64) at eval.jl:30  
include\_string(::Module, ::String, ::String, ::Int64, ::Vararg{Int64,N} where N) at eval.jl:34  
(::Atom.##102#107{String,Int64,String})() at eval.jl:82  
withpath(::Atom.##102#107{String,Int64,String}, ::String) at utils.jl:30  
withpath(::Function, ::String) at eval.jl:38  
hideprompt(::Atom.##101#106{String,Int64,String}) at repl.jl:67  
macro expansion at eval.jl:80 [inlined]  
(::Atom.##100#105{Dict{String,Any}})() at task.jl:80

---

<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: [March 21, 2019, 8:44pm UTC](https://discourse.julialang.org/t/use-of-minlp-in-julia/22161/4 "2019-03-21T20:44:18Z")

</div>

This is a weird error. Are you using Julia 0.6? Try running `Pkg.update()` and then try again.

Otherwise, upgrade to Julia 1.0. Note that Juniper hasn’t been updated to the latest version of JuMP (work is in progress [WIP: MOI wrapper by Wikunia · Pull Request #114 · lanl-ansi/Juniper.jl · GitHub](https://github.com/lanl-ansi/Juniper.jl/pull/114)), so you will need to run `] add JuMP#release-0.18`.

---

<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: [March 21, 2019, 9:03pm UTC](https://discourse.julialang.org/t/use-of-minlp-in-julia/22161/5 "2019-03-21T21:03:09Z")

</div>

Thanks. I will try to update my packages.  
I will send you what happened.

---

<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: [March 21, 2019, 9:28pm UTC](https://discourse.julialang.org/t/use-of-minlp-in-julia/22161/6 "2019-03-21T21:28:10Z")

</div>

SCIP.jl was recently completely revamped and brought up to speed with the latest JuMP release. I think the wrapper is in pretty good shape now. SCIP itself can be a bit challenging to install though.

---

<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: [March 22, 2019, 2:18am UTC](https://discourse.julialang.org/t/use-of-minlp-in-julia/22161/7 "2019-03-22T02:18:26Z")

</div>

I already used SCIP in matlab.  
How can I use in JUMP? Do you have some idea?  
Thank you for your atttention!

---

<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: [March 22, 2019, 2:33am UTC](https://discourse.julialang.org/t/use-of-minlp-in-julia/22161/8 "2019-03-22T02:33:26Z")

</div>

Well the wrapper is just over at [GitHub - scipopt/SCIP.jl: Julia interface to SCIP solver](https://github.com/SCIP-Interfaces/SCIP.jl), and it’s registered so you can just add it. If you’re having trouble installing SCIP itself, I can dig up the notes I made while installing it when I’m at my computer.

---

<div class="post-metadata">

### Author: ![leethargo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leethargo/32/6004_2.png) [@leethargo](https://discourse.julialang.org/u/leethargo)
#### Post date: [March 22, 2019, 8:13am UTC](https://discourse.julialang.org/t/use-of-minlp-in-julia/22161/9 "2019-03-22T08:13:28Z")

</div>

> If you’re having trouble installing SCIP itself, I can dig up the notes I made while installing it when I’m at my computer.

Can you elaborate what was difficult about that?

I assumed that most users will just download the `.deb` or `rpm` packages that should work on several popular Linux distributions. I now see that there is also a self-extracting archive with precompiled binarys.  
It is then a matter of setting the environment variable (e.g., in my case `SCIPOPTDIR=/home/rs/opt/scip`) to where the package was installed to.

If you require manual installation, for some reason, then we should make describe the steps in the README, as it was before.

---

<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: [March 22, 2019, 1:44pm UTC](https://discourse.julialang.org/t/use-of-minlp-in-julia/22161/10 "2019-03-22T13:44:25Z")

</div>

If I recall correctly, the `.deb` file didn’t work for me because the latest released version of SCIP required a version of Ipopt that’s newer than what’s available through `apt` on Ubuntu 18.04, so installation failed. I don’t remember if I tried tarbalIs, but at that point I decided to build both SCIP and the latest version of Ipopt from source, also because I wanted to have SCIP use CPLEX.

Building Ipopt then required HSL from [HSL for IPOPT](http://www.hsl.rl.ac.uk/ipopt/) (or at least that’s what my labmate told me is the fastest linear solver package). I needed to add its `lib` directory to `LD_LIBRARY_PATH` and also needed to symlink (or rename) `libcoinhsl.so` to `libhsl.so`, as that’s what Ipopt is looking for (must have been renamed at some point).

Then, for SCIP itself, I needed to edit one of their CMake files, as I was getting linking errors when using their CMake build with CPLEX. In `gcg/cmake/Modules/FindCPLEX.cmake`, I added `dl` and `util` to `CPLEX_LIBRARIES`.

After that, I built using

```bash
mkdir install
mkdir build
cd build
CC=clang-7 CXX=clang++-7 cmake -D CMAKE_BUILD_TYPE=Release -D BUILD_TESTING=OFF -D IPOPT_DIR=/home/twan/code/ipopt/Ipopt-3.12.12 -D CPLEX=ON -D CPLEX_DIR=/opt/ibm/ILOG/CPLEX_Studio128/cplex -D CMAKE_INSTALL_PREFIX=../install ..
make -j 20
make install

```

---

<div class="post-metadata">

### Author: ![leethargo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leethargo/32/6004_2.png) [@leethargo](https://discourse.julialang.org/u/leethargo)
#### Post date: [March 22, 2019, 2:23pm UTC](https://discourse.julialang.org/t/use-of-minlp-in-julia/22161/11 "2019-03-22T14:23:37Z")

</div>

> [@tkoolen](#):
>
> If I recall correctly, the `.deb` file didn’t work for me because the latest released version of SCIP required a version of Ipopt that’s newer than what’s available through `apt` on Ubuntu 18.04, so installation failed.

OK, that should be solved, since recent version of IPOPT (with HSL) is now actually contained in the binary packages, including the `.deb` package.

> [@tkoolen](#):
>
> also because I wanted to have SCIP use CPLEX.

I see. This will require some manual setup and compilation, of course.  
In that case, you might get away with only compiling SCIP (and not SoPlex, GCG, ZIMPL, etc.), so that you also won’t have to fix the GCG CMake files…

---

<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: [May 18, 2019, 7:01pm UTC](https://discourse.julialang.org/t/use-of-minlp-in-julia/22161/12 "2019-05-18T19:01:27Z")

</div>

> [@angeloaliano1](#):
>
> using JuMP  
> using Juniper  
> using Ipopt  
> using Cbc
> 
> solver = JuniperSolver(IpoptSolver(print\_level=0);  
> mip\_solver=CbcSolver())
> 
> m = Model(solver=solver)  
> v = [10,20,12,23,42]  
> w = [12,45,12,22,21]  
> @variable(m, x[1:5], Bin)  
> @objective(m, Max, dot(v,x))  
> @NLconstraint(m, sum(w[i]\*x[i]^2 for i=1:5) \<= 45)  
> status = solve(m)

Hi, I’m the main developer of Juniper. Do you still have an issue with it? It works now with the latest version of JuMP. If you have any issues please use the GitHub issue system. Thanks for using Juniper 😉
