Skip to main content

Storing solutions at given time intervals

Answered

Comments

1 comment

  • Maliheh Aramon
    • Gurobi Staff

    Hi David, 

    • The easiest approach would be to use MIPSOL callback which is triggered upon finding a new MIP solution. You can then query the elapsed time and the objective value for the new incumbent via Model.cbGet(GRB.Callback.RUNTIME) and Model.cbGet(GRB.Callback.MIPSOL_OBJ) methods, respectively. See the basic script below:
    def callback(model, where):
    if where==GRB.Callback.MIPSOL:
    obj=model.cbGet(GRB.Callback.MIPSOL_OBJ)
    time=model.cbGet(GRB.Callback.RUNTIME)

    model._data.append((time, obj))

    model._data = []
    model.optimize(callback)
    • Another approach is to use the MESSAGE callback which is triggered upon printing a log message. By default, the Gurobi MIP solver prints a log line every 5 seconds (the interval between log messages can be controlled via the DisplayInterval parameter). You can then access the message using the Model.cbGet(GRB.Callback.MSG_STRING) method and use Python regular expression (re) package to process the log message. You can check the nodelog.py script in the Gurobi's open source grblogtools package for the regular expression patterns appearing during the search tree. 
    • If you do not need the progress report live, you can also use the grblogtools to extract the search progress form the gurobi log after the solve is terminated. See the grblogtools documentation for more details. 

    Best regards,

    Maliheh

    0

Please sign in to leave a comment.