For syntax in @constraints

Hi!

I am looking for the most elegant way of adding multiple constraints (e.g. with a for loop) in a JuMP model.

For example I would like to be able to write :

using JuMP

m = Model()
@variable(m,x[1:5])
@constraints(m, begin
    x[i+1] <= x[i] , for i in 1:4  
   x[i]+x[2i] == 1, for i in 1:2
    end)

Currently I’m makin a for loop and using @constraint(m,…) inside the loop. Is there another way ?

See http://www.juliaopt.org/JuMP.jl/v0.20.0/constraints/#Constraint-containers-1

You need

@constraints(model, begin
    [i=1:4], x <= i
end)