How to get @NLparameter in a model?

For variables and constraints, we can use the function getindex(m, :x) to get the variable or constraints.
But for @NLparameter defined in a model, getindex doesn’t work for me. Does anyone know how to get the NLparameter in a model. Many thanks!

Best regards,

You could register the parameter to your model,

p = :x
JuMP.registerobject(m, p, eval(p), "Warning: $(p) has already been registered.")

Although, I am not sure if that is the recommended way of doing things.

Also, make sure that you surround code with backticks, particularly when you are referring to a macro. Otherwise somebody called NLparameter might get pinged (not very likely in this case, but it could happen in general).

1 Like

@NLparameter objects aren’t automatically stored in the model dictionary. But you can just put them there if you want:

@NLparameter(m, p == 1)
m[:p] = p

Thanks a lot!