I would like to write a callback function that does something similar to this:
(gurobipy)
but it seems much more complicated to do this in JuMP .
see
and here
[ANN] Upcoming breaking changes to CPLEX.jl and Gurobi.jl
Any suggestions?
I would like to write a callback function that does something similar to this:
(gurobipy)
but it seems much more complicated to do this in JuMP .
see
and here
[ANN] Upcoming breaking changes to CPLEX.jl and Gurobi.jl
Any suggestions?
Ideally I would like something like:
The literal translation of the example in the Gurobi documentation is:
softlimit = 5
hardlimit = 100
function my_callback_function(cb_data, cb_where::Cint)
if cb_where == GRB_CB_MIP
runtimeP = Ref{Cdouble}()
objbstP = Ref{Cdouble}()
objbndP = Ref{Cdouble}()
GRBcbget(cb_data, cb_where, GRB_CB_RUNTIME, runtimeP)
GRBcbget(cb_data, cb_where, GRB_CB_MIP_OBJBST, objbstP)
GRBcbget(cb_data, cb_where, GRB_CB_MIP_OBJBND, objbndP)
gap = abs((objbstP[] - objbndP[]) / objbstP[])
if runtimeP[] > softlimit && gap < 0.5
GRBterminate(backend(model))
end
end
return
end
MOI.set(model, Gurobi.CallbackFunction(), my_callback_function)
You should be able to modify it as needed.
Here’s the list of other things you can query: Callback Codes