MIP best objective and bound output with runtime
AnsweredHi, I am using Gurobi to solve a max MIP via Python. Is there any way that I could collect information on current best objective (lower bound) and bound (upper bound) with respect to runtime (while Gurobi is still optimizing)? Thank you very much!
Best,
Wu
0
-
Hi Wu,
Yes, you can do this with a callback. A similar question was answered here.
I'll re-post the code below. It generates a list of times, incumbent objective values, and best bounds using a callback. Then, these values are saved to a CSV file.
import gurobipy as gp
import csv
import time
def data_cb(model, where):
if where == gp.GRB.Callback.MIP:
cur_obj = model.cbGet(gp.GRB.Callback.MIP_OBJBST)
cur_bd = model.cbGet(gp.GRB.Callback.MIP_OBJBND)
# Did objective value or best bound change?
if model._obj != cur_obj or model._bd != cur_bd:
model._obj = cur_obj
model._bd = cur_bd
model._data.append([time.time() - m._start, cur_obj, cur_bd])
# Build model m here
m._obj = None
m._bd = None
m._data = []
m._start = time.time()
m.optimize(callback=data_cb)
with open('data.csv', 'w') as f:
writer = csv.writer(f)
writer.writerows(m._data)Thanks,
Eli
0 -
Thank you very much!
0
Please sign in to leave a comment.
Comments
2 comments