Hi,
I am trying to use GAMS to solve a constrained optimization problem. My own problem is quite complicated, and I must use user-defined functions for both the objective and constraints. Below is a reproducible, simple version.
utility(x…) is the objective function, while budget(x…) is the constraint
const p1 = 10.0
const p2 =10.0
const income = 100.0
function utility(x…)
x0 = collect(x)
out = log(x0[1])+log(x0[2])
return out
end
function budget(x…)
x0 = collect(x)
surplus = income - p1x0[1] - p2x0[2]
return surplus
end
Now I use JuMP and GAMS to solve the problem:
set_optimizer_attribute(model_gams, GAMS.SysDir(), “/Library/Frameworks/GAMS.framework/Versions/43/Resources/”)
model_gams = Model(GAMS.Optimizer)
@variable(model_gams, x[1:2] >= 0)
JuMP.register(model_gams, :utility, 2, utility, autodiff=true)
JuMP.register(model_gams, :budget, 2, budget, autodiff=true)
@constraint(model_gams, budget(x…) >= 0)
@NLobjective(model_gams, Max, utility(x…))
JuMP.optimize!(model_gams)
Then an error message appears:
Error: Unrecognized operation (utility)
I am really confused why this utility(x…) function can’t be recognized. Because Is it a user-defined function? I started using JuMP very recently, and I am not a mature programmer. So any suggestions or comments will be highly valuable to me!