C++ Reference: class BaseIntExpr

This documentation is automatically generated.


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.
Method
BaseIntExpr

Return type: explicit

Arguments: Solver* const s

~BaseIntExpr

CastToVar

Return type: virtual IntVar*

Var

Return type: IntVar*