variable in Gurobi
回答済みIf 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?!
-
正式なコメント
This post is more than two years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum, or try Gurobot, our chatbot interface offering instant, expert-level support. -
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
投稿コメントは受け付けていません。
コメント
2件のコメント