C++ Reference: class MPCallbackContext
Note: This documentation is automatically generated.
When querying solution values or modifying the model during a callback, use this API, rather than manipulating MPSolver directly. You should only interact with this object from within MPCallback::RunCallback().Method | |
---|---|
AddCut | Return type: Arguments: Adds a constraint to the model that strengths the LP relaxation. Call only when the event is kMipNode. Requires that MPCallback::might_add_cuts() is true. This constraint must not cut off integer solutions, it should only strengthen the LP (behavior is undefined otherwise). Use MPCallbackContext::AddLazyConstriant() if you are cutting off integer solutions. |
AddLazyConstraint | Return type: Arguments: Adds a constraint to the model that cuts off an undesired integer solution. Call only when the event is kMipSolution or kMipNode. Requires that MPCallback::might_add_lazy_constraints() is true. Use this to avoid adding a large number of constraints to the model where most are expected to not be needed. Given an integral solution, AddLazyConstraint() MUST be able to detect if there is a violated constraint, and it is guaranteed that every integer solution will be checked by AddLazyConstraint(). Warning(rander): in some solvers, e.g. Gurobi, an integer solution may not respect a previously added lazy constraint, so you may need to add a constraint more than once (e.g. due to threading issues). |
CanQueryVariableValues | Return type: Always false if event is not kMipSolution or kMipNode, otherwise behavior may be solver dependent. For Gurobi, under kMipNode, may be false if the node was not solved to optimality, see MIPNODE_REL here for details: http://www.gurobi.com/documentation/8.0/refman/callback_codes.html |
Event | Return type: What the solver is currently doing. How you can interact with the solver from the callback depends on this value. |
~MPCallbackContext | Return type: |
NumExploredNodes | Return type: Returns the number of nodes explored so far in the branch and bound tree, which 0 at the root node and > 0 otherwise. Call only when the event is kMipSolution or kMipNode. |
SuggestSolution | Return type: Arguments: Suggests a (potentially partial) variable assignment to the solver, to be used as a feasible solution (or part of one). If the assignment is partial, certain solvers (e.g. Gurobi) will try to compute a feasible solution from the partial assignment. Returns the objective value of the solution if the solver supports it. Call only when the event is kMipNode. |
VariableValue | Return type: Arguments: Returns the value of variable from the solver's current state. Call only when CanQueryVariableValues() is true. At kMipSolution, the solution is integer feasible, while at kMipNode, the solution solves the current node's LP relaxation (so integer variables may be fractional). |