C++ Reference
C++ Reference: Routing
Detailed Description
This is the base class for all expressions that are not variables.
It provides a basic 'CastToVar()' implementation.
The class of expressions represent two types of objects: variables and subclasses of BaseIntExpr. Variables are stateful objects that provide a rich API (remove values, WhenBound...). On the other hand, subclasses of BaseIntExpr represent range-only stateless objects. That is, min(A + B) is recomputed each time as min(A) + min(B).
Furthermore, sometimes, the propagation on an expression is not complete, and Min(), Max() are not monotonic with respect to SetMin() and SetMax(). For instance, if A is a var with domain [0 .. 5], and B another variable with domain [0 .. 5], then Plus(A, B) has domain [0, 10].
If we apply SetMax(Plus(A, B), 4)), we will deduce that both A and B have domain [0 .. 4]. In that case, Max(Plus(A, B)) is 8 and not 4. To get back monotonicity, we 'cast' the expression into a variable using the Var() method (that will call CastToVar() internally). The resulting variable will be stateful and monotonic.
Finally, one should never store a pointer to a IntExpr, or BaseIntExpr in the code. The safe code should always call Var() on an expression built by the solver, and store the object as an IntVar*. This is a consequence of the stateless nature of the expressions that makes the code error-prone.
Definition at line 109 of file constraint_solveri.h.
Public Member Functions | |
BaseIntExpr (Solver *const s) | |
~BaseIntExpr () override | |
IntVar * | Var () override |
virtual IntVar * | CastToVar () |
Constructor & Destructor Documentation
◆ BaseIntExpr()
|
inlineexplicit |
Definition at line 111 of file constraint_solveri.h.
◆ ~BaseIntExpr()
|
inlineoverride |
Definition at line 112 of file constraint_solveri.h.
Member Function Documentation
◆ CastToVar()
|
virtual |
◆ Var()
|
override |
The documentation for this class was generated from the following file: