I would like to convert a SymPy expression in order to use as an objetive function in JuMP. Suppose my variable involves two variables p [1,1] and p [1,2].
using SymPy
using JuMP, Ipopt
# expr is my SymPy expression
fn = lambdify( expr )
Now, my model
model = Model(Ipopt.Optimizer)
l = zeros(1,2)
@variable(model, p[ j = 1:S] >= 0 )
#obj function
@objective(model,Min,fn)
print(model)
The objective function `#99` is not supported by JuMP.
I will often need to optimize a function with many variables. I wouldn’t want to have to write variable by variable. Is there any way to avoid this for automation issues?
model = Model(Ipopt.Optimizer)
@variable(model, p[1:S] >= 0)
register(model, :fn, 2, fn; autodiff = true)
@NLobjective(model, Min, fn( p[1:S] ) )
Incorrect number of arguments for "fn" in nonlinear expression.