Is there a difference in the time taken to build the JuMP model if I use
for loops for defining variables/constraints. For example:
using JuMP model = Model() @variable(model, x[i in 1:7, j in 1:10] >= 0) @constraint(model, [i in 2:6, j in 3:7], x[i,j] + x[j,i] >= 10)
Now, instead, if I do the following:
using JuMP model = Model() for i in 1:7 for j in 1:10 @variable(model, x[i,j] >= 0) end end for i in 2:6 for j in 3:7 @constraint(model, x[i,j] + x[j,i] >= 10) end end
Although the first method is more succinct, is it always better than defining variables/constraint using
for loops (or the other way round)? For small models, I understand there is practically no difference, but how do the two methods differ for large models. I obviously have a large model and want to make sure that the model building time is reduced.
Also, is one method better than the other if I have conditions in the variable/constraint definition? For example, something like
x[i=1:4; mod(i, 2)==0]. Is it better (or worse) to use a for loop in this case?