Gurobi callback functions in PuLP

613 views
Skip to first unread message

Emily Frost

unread,
Jan 14, 2013, 8:42:59 AM1/14/13
to pulp-or...@googlegroups.com
Hi all,

I am using PuLP to model a MIP problem with Gurobi as the solver.  I've used a custom callback function in Gurobi before (copied below) to log interim solutions and the time at which they were found. (the version below also terminates the optimization once the rate of improvement slows.) Is there a way to tell Gurobi to optimize according to this callback function in PuLP?

Thanks,
Emily

def mycallback(mod, where):
    global oldsol
    if where == GRB.callback.MIPSOL:
        print mod.cbGet(GRB.callback.MIPSOL_SOLCNT), ",", mod.cbGet(GRB.callback.RUNTIME), ",", mod.cbGet(GRB.callback.MIPSOL_OBJ)
        if mod.cbGet(GRB.callback.MIPSOL_SOLCNT) == 1:
            oldsol = mod.cbGet(GRB.callback.MIPSOL_OBJ)
        elif (mod.cbGet(GRB.callback.MIPSOL_OBJ) - oldsol) > 15:
            oldsol = mod.cbGet(GRB.callback.MIPSOL_OBJ)
        else:
            mod.terminate()

Stuart Mitchell

unread,
Jan 17, 2013, 4:53:27 PM1/17/13
to pulp-or...@googlegroups.com
extra keywords to the LpProblem.solve() and LpProblem.resolve() get passed through to gurobi underneath so

>>> prob.solve(callback=mycallback) 

should work.

Also the gurobi solver model is attached to the LpProblem object as prob.solverModel if you want to attach information to it.

Stu



--
You received this message because you are subscribed to the Google Groups "pulp-or-discuss" group.
To view this discussion on the web visit https://groups.google.com/d/msg/pulp-or-discuss/-/jjYPuqgbS0MJ.
To post to this group, send email to pulp-or...@googlegroups.com.
To unsubscribe from this group, send email to pulp-or-discu...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pulp-or-discuss?hl=en.



--
Stuart Mitchell
PhD Engineering Science
Extraordinary Freelance Programmer and Optimisation Guru
Reply all
Reply to author
Forward
0 new messages