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
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))