ModelPredictiveControl.jl
is still using the legacy syntax for NLP, but I’m starting the migration right now. The nonlinear inequality constraints are currently added programmatically with (simplified for the purpose of the explanation):
using JuMP, Ipopt
model = Model(Ipopt.Optimizer)
nx = 2
@variable(model, x[1:nx])
gfunc_i(i, x) = 10x[i]^2 - 10
gfunc = [(x...) -> gfunc_i(i, x) for i in 1:nx]
ymin, ymax = [-1, -1], [1, 1]
for i in eachindex(ymin)
sym = Symbol("g_ymin_$i")
register(model, sym, nx, gfunc[i], autodiff=true)
add_nonlinear_constraint(model, :(-$(sym)($(x...)) <= -$(ymin[i])))
end
for i in eachindex(ymax)
sym = Symbol("g_ymax_$i")
register(model, sym, nx, gfunc[i], autodiff=true)
add_nonlinear_constraint(model, :(+$(sym)($(x...)) <= +$(ymax[i])))
end
is there an equivalent for the add_nonlinear_constraint
method in the new NLP syntax? I’ve tried add_constraint
but I’m not sure how to use it since the docstring is not very detailed:
help?> add_constraint
search: add_constraint add_nonlinear_constraint
add_constraint(model::GenericModel, con::AbstractConstraint, name::String="")
Add a constraint con to Model model and sets its name.
Thanks for the help