I am currently trying to speed up an MIP. An approach I was considering was to implement a cut callback heuristic with PuLP (one which rounds relaxed integer variables greater than .9 to 1). Unfortunately, I do not believe PuLP has such a function to call, and I have looked into the mip module as well as dippy, but I don't feel like jumping to those. So, as a side note, if anyone knows how this can be done natively with PuLP let me know...
This leads me to my main question. Since PuLP is a wrapper and can be used with other solvers, I did see that Gurobi has such a function, and was able to call the code to Gurobi from PuLP with the code below:
Lp_prob = plp.LpProblem('Problem', plp.LpMinimize) sd = plp.solvers.GUROBI(mip=True) sd.actualSolve(Lp_prob, callback=mycallback)
Here is the function I am trying to call:
def mycallback(model, where): model._vars = model.getVars() if where == GRB.Callback.MIPNODE: for x in model._vars: if model.cbGetNodeRel(x) > 0.9 and model.cbGetNodeRel(x) < 1.0: model.cbSetSolution(x, 1.0) else: return
However, after running a couple of times, the heuristic doesn't quite speed things up, in fact it kind of slows it down. I was wondering if this was implemented correctly, or if I were missing something. Any help or suggestions would be greatly appreciated.