Hello,
I have the following JuMP model:
using JuMP
using MathProgBase
using Ipopt
model=Model(solver=IpoptSolver())
@variable(model, -100 <= x[1:5] <=100)
@constraint(model, sum(x[i] for i in 1:5) <= 50)
@NLconstraint(model, sum(x[i]^2 for i in 1:3) <= 50)
@NLobjective(model, Min, sum(x[i]^2 for i in 1:5))
I get the objective expression from the above model as below:
d = JuMP.NLPEvaluator(model)
MathProgBase.initialize(d, [:ExprGraph])
obj_expr=MathProgBase.obj_expr(d)
Now, I have a new model like this:
m=Model(solver=IpoptSolver())
@variable(m, -100 <= x[i=1:6] <= 100)
@constraint(m, sum(x[i] for i in 1:5) <=100)
@NLconstraint(m, sum(x[i]^2 for i in 1:5)<= 100)
@objectve(m, Min, sum(x[i] for i in 1:6))
And in the model “m” I need to add the following constraint:
JuMP.addNLconstraint(m, x[6]>= obj_expr)
or
JuMP.addNLconstraint(m, x[6]>=sum(x[i]^2 for i in 1:5) )
I have tried the following way:
expr=:(x[6]>=$(obj_expr))
JuMP.addNLconstraint(m, expr)
But it did not work. Can anyone help me with finding a way to add the constraint in model “m”. Thank you.
NOTE: I am using JuMPv0.18 and MathProgBase