Save runtime in a list
回答済みHi, I would like to run my model through different loops, always storing the runtime of each pass in a list. I have managed to do this, but there are two things I would like to adjust to make it more like what I want.
1) If the model is infeasible, then the list should say "infeasible".
2) If the model takes longer than e.g. 5000 seconds to solve, then the next iteration should be started and entered in the 5000 list.
I use m.Runtime to store the duration.
The list is called sec = []
Thanks for t
he help
-
正式なコメント
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 Lorenz,
What does each iteration represent here?
Assuming at each iteration, you are solving a model independent of other iterations, the script below solves model A with different seed values \(n\) times and saves the result as you described in your post:
runtimes = []
for i in range(n):
# Set the Seed
model.params.Seed = i
# Set the time limit
model.params.TimeLimit = 5000
model.optimize()
# If the model solves to optimality, save the runtime
if model.status == GRB.OPTIMAL:
runtimes.append(model.Runtime)
# If the model times out, save the time limit as the runtime
elif model.status == GRB.TIME_LIMIT:
runtimes.append(model.params.TimeLimit)
# If the model terminates with any other status including infeasible status,
# save the model status
else:
runtimes.append(model.status)Best regards,
Maliheh
0
投稿コメントは受け付けていません。
コメント
2件のコメント