Dynamic generation of constraints


#1

Is there an easy way to expand the base set of a constraint?

For instance, suppose that I have created @constraint(model, mycons[i in 1:2], x[i] >= 1) and that I would like to extend it to @constraint(model, mycons[i in 1:4], x[i] >= 1) ?

The only why I found to do that is the following:

@constraintref mycons[1:2]
for i in 1:2 mycons[i] = @constraint(model, x[i] >= 1) end
...
mycons2 = mycons
@constraintref mycons[1:4]
for i in 1:2 mycons[i] = mycons2[i] end

#2

Nope. JuMP doesn’t have a concept of base sets like in AMPL. The syntax @constraint(model, mycons[i in 1:2], x[i] >= 1) is just a convenient way of writing the for loop:

@constraintref mycons[1:2]
for i in 1:2 mycons[i] = @constraint(model, x[i] >= 1)

Empty constraint
#3

Thank’s.