Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
operations_research::MPCallbackContext Class Referenceabstract

#include <linear_solver_callback.h>

Inheritance diagram for operations_research::MPCallbackContext:
operations_research::ScipMPCallbackContext operations_research::XpressMPCallbackContext

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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ ~MPCallbackContext()

virtual operations_research::MPCallbackContext::~MPCallbackContext ( )
inlinevirtual

Definition at line 65 of file linear_solver_callback.h.

Member Function Documentation

◆ AddCut()

virtual void operations_research::MPCallbackContext::AddCut ( const LinearRange & cutting_plane)
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.

◆ AddLazyConstraint()

virtual void operations_research::MPCallbackContext::AddLazyConstraint ( const LinearRange & lazy_constraint)
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.

◆ CanQueryVariableValues()

virtual bool operations_research::MPCallbackContext::CanQueryVariableValues ( )
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.

◆ Event()

virtual MPCallbackEvent operations_research::MPCallbackContext::Event ( )
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.

◆ NumExploredNodes()

virtual int64_t operations_research::MPCallbackContext::NumExploredNodes ( )
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.

◆ SuggestSolution()

virtual double operations_research::MPCallbackContext::SuggestSolution ( const absl::flat_hash_map< const MPVariable *, double > & solution)
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.

◆ VariableValue()

virtual double operations_research::MPCallbackContext::VariableValue ( const MPVariable * variable)
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.


The documentation for this class was generated from the following file: