Generate nonlinear expressions in an explicit loop

I want to generate nonlinear expressions in an explicit loop. I know You can iterate over constraints and store references like in the next example:

@variable(m, x[1:5] >= 0)
@constraintref myCons[1:5]
for i = 1:5
  myCons[i] = @constraint(m, x[i] >= i)
end

so, I wonder if there is one way to do the same with nonlinear expressions?

1 Like

In JuMP 0.18.5, you can do:

mod = Model()
@variable(mod, x[1:5])
@constraintref nlconstr[1:5]
for i = 1:5
  nlconstr[i] = @NLconstraint(mod, x[i]^4 >= i)
end
JuMP.registercon(mod, :nlconstr, nlconstr)

Found out about this from issue 1090

1 Like