メインコンテンツへスキップ

Save runtime in a list

回答済み

コメント

2件のコメント

  • 正式なコメント
    Simranjit Kaur
    • Gurobi Staff
    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.
  • Maliheh Aramon
    • Gurobi Staff

    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

投稿コメントは受け付けていません。