Solver callbacks¶
This section describes the standardized methods for solver callbacks. This callback interface is targeted primarily at interacting with branchandbound solvers which are based on solving continous relaxations to find bounds, combined with heuristics to find solutions which satisfy integrality constraints. Currently there is support for adding:
 Lazy constraints (only added to model if violated by integerfeasible solution)
 Cut callbacks (only cuts off noninteger feasible solutions)
 Heuristic callbacks (proposes heuristically constructed integerfeasible solutions)
A more detailed description of the three types of supported callbacks can be found in the JuMP documentation here.
The SolverInterface
module exports an abstract type MathProgCallbackData
which represents the solverspecific data needed to implement the callback.
If a callback function returns :Exit
, the solver is expected to terminate with UserLimit
status.

setlazycallback!
(m::AbstractMathProgModel, f)¶ Adds lazy constraint callback
f
to the model. Functionf
takes as argument only aMathProgCallbackData
object.

setcutcallback!
(m::AbstractMathProgModel, f)¶ Adds cut callback
f
to the model. Functionf
takes as argument only aMathProgCallbackData
object.

setheuristiccallback!
(m::AbstractMathProgModel, f)¶ Adds heuristic callback
f
to the model. Functionf
takes as argument only aMathProgCallbackData
object.

setinfocallback!
(m::AbstractMathProgModel, f)¶ Adds informational callback
f
to the model. Functionf
takes as argument only aMathProgCallbackData
object.

cbgetmipsolution
(d::MathProgCallbackData[, output])¶ Grabs current best integerfeasible solution to the model. The optional second argument specifies an output vector.

cbgetlpsolution
(d::MathProgCallbackData[, output])¶ Grabs current relaxation solution to the model. The optional second argument specifies an output vector.

cbgetobj
(d::MathProgCallbackData)¶ Grabs objective value for current best integerfeasible solution.

cbgetbestbound
(d::MathProgCallbackData)¶ Grabs best bound for objective function found so far (lower bound when minimizing, upper bound when maximizing).

cbgetexplorednodes
(d::MathProgCallbackData)¶ Returns number of nodes that have been explored so far in the solve process.

cbgetstate
(d::MathProgCallbackData)¶ Returns current location in solve process:
:MIPNode
if at node in branchandcut tree,:MIPSol
at an integerfeasible solution, and:Intermediate
otherwise.MIPNode
: when we are at a node in the branchandcut tree. This is generally used for access to the solution of a relaxation (viacbgetlpsolution()
), or for adding cuts (viacbaddcut!()
orcbaddcutlocal!()
).MIPSol
: when we have found a new MIP incumbent (an integerfeasible solution). This is generally used for keeping track of the intermediate solutions generated (viacbgetmipsolution()
) inside the branchandcut tree.Intermediate
: when we are still in the process of MIP or during iterations of a continuous solver. For MIPs, this is generally be used for keeping track of pessimistic and optimistic bounds (viacbgetobj()
andcbgetbestbound()
respectively), or the number of explored nodes (viacbgetexplorednodes()
) in the branchandcut tree.

cbaddcut!
(d::MathProgCallbackData, varidx, varcoef, sense, rhs)¶ Adds cut to model. The coefficient values are represented sparsely, with (oneindexed) indices in
varidx
and values invarcoef
. The constraint sensesense
is a character taking value<
,>
, or=
, and the righthand side value isrhs
.

cbaddcutlocal!
(d::MathProgCallbackData, varidx, varcoef, sense, rhs)¶ Adds local cut to model. It works as
cbaddcut!
but the cut is local in the sense that it only applies to the current node and the subtree rooted at this node.

cbaddlazy!
(d::MathProgCallbackData, varidx, varcoef, sense, rhs)¶ Adds lazy constraint to model. The coefficient values are represented sparsely, with (oneindexed) indices in
varidx
and values invarcoef
. The constraint sensesense
is a character taking value<
,>
, or=
, and the righthand side value isrhs
.

cbaddlazylocal!
(d::MathProgCallbackData, varidx, varcoef, sense, rhs)¶ Adds local lazy constraint to model. It works as
cbaddlazy!
but the lazy constraint is local in the sense that it only applies to the current node and the subtree rooted at this node.

cbaddsolution!
(d::MathProgCallbackData)¶ Submit a (possibly partially defined) heuristic solution for the model. Should reset the solution stored in
d
to the original state at the start of callback.

cbsetsolutionvalue!
(d::MathProgCallbackData, varidx, value)¶ Sets the value of a variable with (onebased) index
varidx
tovalue
in the current partial solution being constructed by a user heuristic.