Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
|
#include <linear_solver_callback.h>
Public Member Functions | |
virtual | ~MPCallbackContext () |
virtual MPCallbackEvent | Event ()=0 |
virtual bool | CanQueryVariableValues ()=0 |
virtual double | VariableValue (const MPVariable *variable)=0 |
virtual void | AddCut (const LinearRange &cutting_plane)=0 |
virtual void | AddLazyConstraint (const LinearRange &lazy_constraint)=0 |
virtual double | SuggestSolution (const absl::flat_hash_map< const MPVariable *, double > &solution)=0 |
virtual int64_t | NumExploredNodes ()=0 |
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().
Definition at line 63 of file linear_solver_callback.h.
|
inlinevirtual |
Definition at line 65 of file linear_solver_callback.h.
|
pure virtual |
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::AddLazyConstraint() if you are cutting off integer solutions.
Implemented in operations_research::ScipMPCallbackContext, and operations_research::XpressMPCallbackContext.
|
pure virtual |
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).
Implemented in operations_research::ScipMPCallbackContext, and operations_research::XpressMPCallbackContext.
|
pure virtual |
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
Implemented in operations_research::ScipMPCallbackContext, and operations_research::XpressMPCallbackContext.
|
pure virtual |
What the solver is currently doing. How you can interact with the solver from the callback depends on this value.
Implemented in operations_research::ScipMPCallbackContext, and operations_research::XpressMPCallbackContext.
|
pure virtual |
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.
Implemented in operations_research::ScipMPCallbackContext, and operations_research::XpressMPCallbackContext.
|
pure virtual |
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.
Implemented in operations_research::ScipMPCallbackContext, and operations_research::XpressMPCallbackContext.
|
pure virtual |
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).
Implemented in operations_research::ScipMPCallbackContext, and operations_research::XpressMPCallbackContext.