Storing solutions at given time intervals
回答済みI am trying to retrieve and keep track of solutions at given time intervals over a MIP problem instance. For example, I wish to find and keep track of the current objective value every 5 seconds until an optimal solution has been found (or a given time limit). How would I go about doing this?
Thanks!
0
-
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
サインインしてコメントを残してください。
コメント
1件のコメント