# MINLP problem

**URL:** <https://discourse.julialang.org/t/minlp-problem/38566>\
**Category:** Optimization (Mathematical)\
**Created:** [May 1, 2020, 4:34pm UTC](https://discourse.julialang.org/t/minlp-problem/38566 "2020-05-01T16:34:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![GiuliaM](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giuliam/32/209287_2.png) [@GiuliaM](https://discourse.julialang.org/u/GiuliaM)\
**Post date:** [May 1, 2020, 4:34pm UTC](https://discourse.julialang.org/t/minlp-problem/38566/1 "2020-05-01T16:34:00Z")

</div>

Hi everyone! I’m fairly new to Julia.  
I’m trying to solve a MINLP problem with Juniper. I have 4 continuous variables (x[1:4]) and a binary variable (xbin).  
I have the following relationship between x[1] and xbin:  
if x[1]\>0  
xbin=1  
else  
xbin=0  
end

If xbin=1 an additional cost is inserted in the objective function.  
If this cost is little (0.2) xbin should be setted equal to 1, otherwise (i.e. addcost=20) xbin should be 0, but with the following code only one option is considered.  
Does anyone knows why this happens? Thanks in advance

```julia
using Juniper, Ipopt, JuMP, Cbc

#input data
l=70
cost=[0.04,0.19,0.02]
addcost=0.2 # 20 
e=[-6.1e-05 7.8e-03 1; 4.4e-04 -4.3e-03 3]
#model
m = Model(with_optimizer(
        Juniper.Optimizer;
            nl_solver = with_optimizer(Ipopt.Optimizer, print_level = 0),
            mip_solver = with_optimizer(Cbc.Optimizer, logLevel=0)
        )
    )
#upper bounds
up=[58,30,30,28]
#variable
@variable(m, 0<= x[i=1:4]<= up[i])
@variable(m, xbin, Bin)
#NLconstraint
@NLconstraint(m, x[2]-x[3]-x[4]==0)
@NLconstraint(m, (e[1,1]*x[1]^3+e[1,2]*x[1]^2+e[1,3]*x[1])*xbin+e[2,1]*x[4]^3+e[2,2]*x[2]^2+e[2,3]*x[4]-l==0)
#objective function
@NLobjective(m, Min, cost[1]*x[1]+cost[2]*x[2]-cost[3]*x[3]+addcost*xbin)
optimize!(m)
#output
println(JuMP.value.(x))
println(JuMP.value.(xbin))
println(JuMP.objective_value(m))
println(JuMP.termination_status(m))

```

---

<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 1, 2020, 7:32pm UTC](https://discourse.julialang.org/t/minlp-problem/38566/2 "2020-05-01T19:32:51Z")

</div>

It looks like you are missing the constraint between `x[1]` and `xbin`.

```nohighlight
@constraint(model, x[1] <= up[1] * xbin)

```
