Hi,
I’m currently writing a model predictive control package. The JuMP package is really helpful, thanks for everything.
For nonlinear programming, my decision variable is a vector so I need to rely on the splatting syntax. I also need vector nonlinear parameters with @NLparameter(model, x[i=1:n] == x_val[i])
. Knowing that :
The expression splatted can be only a symbol. More complex expressions are not recognized.
is there a way to create an objective function both with nonscalar decision variable and nonscalar parameters as argument ?
For example, I can do:
using JuMP, Ipopt
function myfunc()
model = Model(Ipopt.Optimizer)
nvar = 3
@variable(model, x[1:nvar])
@NLparameter(model, a == 1)
f(a, x...) = sum((x .- a).^2)
register(model, :f, 1+nvar, f; autodiff = true)
@NLobjective(model, Min, f(a, x...))
optimize!(model)
value.(x)
end
myfunc()
but this:
using JuMP, Ipopt
function myfunc()
model = Model(Ipopt.Optimizer)
nvar = 3
@variable(model, x[1:nvar])
@NLparameter(model, a[i=1:nvar] == 1)
f(a, x...) = sum((x .- a).^2)
register(model, :f, 1+nvar, f; autodiff = true)
@NLobjective(model, Min, f(a, x...))
optimize!(model)
value.(x)
end
myfunc()
results in:
ERROR: Unexpected array NonlinearParameter[parameter[1] == 1.0, parameter[2] == 1.0, parameter[3] == 1.0] in nonlinear expression. Nonlinear expressions may contain only scalar expressions.
Thanks for your help,
Francis Gagnon