There are a few comments leading you astray in this thread, so let me summarize.
- Your problem is nonlinear. You need to use the nonlinear interface for JuMP. In particular, you need to use a user-defined function: https://jump.dev/JuMP.jl/stable/nlp/#User-defined-Functions-1.
- The nonlinear interface requires functions with scalar inputs, so
s
can’t be a vector input. Read this suggested work-around. -
@Henrique_Becker is correct that
@objective(model, Max, C_opt(s)
evaluates this function with the arguments as JuMP variables before passing it to the solver. This is a little confusing, but is very helpful in some cases. - I don’t understand the need for
OffSetArray
, but it looks like your nonlinearity is just the singlemax(0, C)
? Due to nondifferentiability and the large flat area, Ipopt tends to struggle with this. You might get a local optima. - There is nothing wrong with how you have defined
@variable
. - Your issue with
Model(GLPK.Optimizer)
is because you are using an old version of JuMP, although I think you’ve fixed this in another issue.