Skip to main content

Save runtime in a list

Answered

Comments

1 comment

  • 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

Please sign in to leave a comment.