Thank you for your last advice. I tried to come up with the following callback function and I am wondering if this will work. I ran this but I didn't find the solutions saved
opt = pe.SolverFactory('gurobi_persistent')
opt.set_instance(m)
opt.set_gurobi_param('PreCrush', 1)
def mycallback(cb_m, cb_opt, cb_where):
if cb_where == GRB.Callback.MIPSOL:
obj = cb_opt.cbGet(GRB.Callback.MIPSOL_OBJ)
nodecnt = int(cb_opt.cbGet(GRB.Callback.MIPSOL_NODCNT))
for v in model.component_objects(Var, active=True):
varobject = get_var_attr(model, str(v))
for index in varobject:
x = cb_opt.cbGetSolution(vars = [varobject[index]] )
print('**** New solution at node %d, obj %g, sol %d, '
'x[0] = %g ****' % (nodecnt, obj, x[0]))
opt.set_callback(mycallback)
opt.solve()
Please can you correct where I may be getting it wrong?
I also noticed Gurobi v9.1.2 has a parameter 'SolFiles' which should save incumbent solution. I tried it in my Pyomo model but I didn't see any files saved. Please does this work in Pyomo?
Thank you for your help.