variable in Gurobi
AnsweredIf I want to run my model over few weeks, and for all days of the week as:
days of week = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
for week in range(2):
for day in days of week:
If I define my variables within the loop, do I need to define an index representing the day of the week for each of them as well?!
-
Hi Shahrzad,
Each call to Model.addVar() creates a variable and a corresponding handle to access it. Since you need access to the variables to build the constraints, you must organize and store your handles somehow. You can do this however you like in Python, but one approach might be to use a dictionary with the day strings as keys.
Alternatively, Gurobi provides a so-called tupledict that organizes your variable handles. For example,
vars = Model.addVars(days_of_week)
would generate a dictionary with the day strings as keys and the variable handles as values.
Best regards,
Mario0
Please sign in to leave a comment.
Comments
1 comment