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 |
| Creates a variable from the expression. More... | |
| virtual IntVar * | CastToVar () |
| virtual int64 | Min () const =0 |
| virtual void | SetMin (int64 m)=0 |
| virtual int64 | Max () const =0 |
| virtual void | SetMax (int64 m)=0 |
| virtual void | Range (int64 *l, int64 *u) |
| By default calls Min() and Max(), but can be redefined when Min and Max code can be factorized. More... | |
| virtual void | SetRange (int64 l, int64 u) |
| This method sets both the min and the max of the expression. More... | |
| virtual void | SetValue (int64 v) |
| This method sets the value of the expression. More... | |
| virtual bool | Bound () const |
| Returns true if the min and the max of the expression are equal. More... | |
| virtual bool | IsVar () const |
| Returns true if the expression is indeed a variable. More... | |
| IntVar * | VarWithName (const std::string &name) |
| Creates a variable from the expression and set the name of the resulting var. More... | |
| virtual void | WhenRange (Demon *d)=0 |
| Attach a demon that will watch the min or the max of the expression. More... | |
| void | WhenRange (Solver::Closure closure) |
| Attach a demon that will watch the min or the max of the expression. More... | |
| void | WhenRange (Solver::Action action) |
| Attach a demon that will watch the min or the max of the expression. More... | |
| virtual void | Accept (ModelVisitor *const visitor) const |
| Accepts the given visitor. More... | |
| std::string | DebugString () const override |
| Solver * | solver () const |
| void | FreezeQueue () |
| This method freezes the propagation queue. More... | |
| void | UnfreezeQueue () |
| This method unfreezes the propagation queue. More... | |
| void | EnqueueDelayedDemon (Demon *const d) |
| This method pushes the demon onto the propagation queue. More... | |
| void | EnqueueVar (Demon *const d) |
| void | ExecuteAll (const SimpleRevFIFO< Demon * > &demons) |
| void | EnqueueAll (const SimpleRevFIFO< Demon * > &demons) |
| void | set_action_on_fail (Solver::Action a) |
| void | reset_action_on_fail () |
| This method clears the failure callback. More... | |
| void | set_variable_to_clean_on_fail (IntVar *v) |
| Shortcut for variable cleaner. More... | |
| virtual std::string | name () const |
| Object naming. More... | |
| void | set_name (const std::string &name) |
| bool | HasName () const |
| Returns whether the object has been named or not. More... | |
| virtual std::string | BaseName () const |
| Returns a base name for automatic naming. More... | |
|
inlineexplicit |
Definition at line 111 of file constraint_solveri.h.
|
inlineoverride |
Definition at line 112 of file constraint_solveri.h.
|
virtualinherited |
Accepts the given visitor.
Reimplemented in operations_research::IntVar.
|
virtualinherited |
Returns a base name for automatic naming.
Reimplemented in operations_research::BooleanVar.
|
inlinevirtualinherited |
Returns true if the min and the max of the expression are equal.
Reimplemented in operations_research::BooleanVar.
Definition at line 3799 of file constraint_solver.h.
|
virtual |
|
inlineoverridevirtualinherited |
Reimplemented from operations_research::BaseObject.
Reimplemented in operations_research::Pack, operations_research::Assignment, operations_research::SequenceVar, operations_research::Constraint, and operations_research::BooleanVar.
Definition at line 3109 of file constraint_solver.h.
|
inherited |
|
inlineinherited |
This method pushes the demon onto the propagation queue.
It will be processed directly if the queue is empty. It will be enqueued according to its priority otherwise.
Definition at line 3129 of file constraint_solver.h.
|
inlineinherited |
Definition at line 3130 of file constraint_solver.h.
|
inherited |
|
inlineinherited |
This method freezes the propagation queue.
It is useful when you need to apply multiple modifications at once.
Definition at line 3120 of file constraint_solver.h.
|
inherited |
Returns whether the object has been named or not.
|
inlinevirtualinherited |
Returns true if the expression is indeed a variable.
Reimplemented in operations_research::IntVar.
Definition at line 3802 of file constraint_solver.h.
|
pure virtualinherited |
Implemented in operations_research::BooleanVar.
|
pure virtualinherited |
Implemented in operations_research::BooleanVar.
|
virtualinherited |
Object naming.
|
inlinevirtualinherited |
By default calls Min() and Max(), but can be redefined when Min and Max code can be factorized.
Definition at line 3785 of file constraint_solver.h.
|
inlineinherited |
This method clears the failure callback.
Definition at line 3143 of file constraint_solver.h.
|
inlineinherited |
Definition at line 3137 of file constraint_solver.h.
|
inherited |
|
inlineinherited |
Shortcut for variable cleaner.
Definition at line 3146 of file constraint_solver.h.
|
pure virtualinherited |
Implemented in operations_research::BooleanVar.
|
pure virtualinherited |
Implemented in operations_research::BooleanVar.
|
inlinevirtualinherited |
This method sets both the min and the max of the expression.
Reimplemented in operations_research::BooleanVar.
Definition at line 3790 of file constraint_solver.h.
|
inlinevirtualinherited |
This method sets the value of the expression.
Definition at line 3796 of file constraint_solver.h.
|
inlineinherited |
Definition at line 3116 of file constraint_solver.h.
|
inlineinherited |
This method unfreezes the propagation queue.
All modifications that happened when the queue was frozen will be processed.
Definition at line 3124 of file constraint_solver.h.
|
overridevirtual |
Creates a variable from the expression.
Implements operations_research::IntExpr.
|
inherited |
Creates a variable from the expression and set the name of the resulting var.
If the expression is already a variable, then it will set the name of the expression, possibly overwriting it. This is just a shortcut to Var() followed by set_name().
|
pure virtualinherited |
Attach a demon that will watch the min or the max of the expression.
Implemented in operations_research::BooleanVar.
|
inlineinherited |
Attach a demon that will watch the min or the max of the expression.
Definition at line 3816 of file constraint_solver.h.
|
inlineinherited |
Attach a demon that will watch the min or the max of the expression.
Definition at line 3822 of file constraint_solver.h.