Register array of symbolic functions

Dear all,

I have the following issue with JuMP: I define an array of symbolic expression I want to use as constraint in a mathematical program. In particular, I have defined my function in the array gn and I want to write something like:

for k in 1:num_cnsts
 g = Symbol("g$(k)")
 register(model, g, num_vars, gn[k]; autodiff = true)
 @NLconstraint(model, :($g) <= 0)
end

I found an answer in https://discourse.julialang.org/t/registering-an-array-of-functions-and-using-them-in-constraints-and-objectives/53294/2, but it seems no longer working.

Thanks in advance for all your help.
Best regards,
Luca

JuMP v1.15 released a rewrite of the nonlinear interface that intended to fix the many issues related to the @NL interface: ANN: JuMP v1.15 is released

See the new docs:

If your functions support tracing, you may be able to do:

@constraint(model, [k in 1:num_cnsts], gn[k](x...) <= 0)

otherwise, do:

for k in 1:num_cnsts
    op_g = add_nonlinear_operator(model, num_vars, gn[k]; name = Symbol("g$k"))
    @constraint(model, op_g(x...) <= 0)
end