changing the type of variables when they are defined with Model.addVars() in Gurobi Python

Viewed 21

I have defined the variables as following: y = m.addVars(2,6, vtype= GRB.BINARY, name = 'y')

Now I wish changing their type to GRB.CONTINUOUS.

How can I do it in a compact way? I want to avoid repeting this line for all 12 variables: y[0,0].VType = GRB.CONTINUOUS

Thank you. Best, Paola

1 Answers

Simply iterate over the values in the tupledict y:

for v in y.values():
  v.VType = GRB.CONTINUOUS
Related