| Overview | Group | Tree | Graph | Deprecated | Index | Concepts |

In a typical application exploiting CP Optimizer, the unknowns of the problem
will be expressed as constrained variables. The most commonly used class of
constrained variables is the class of constrained integer
variables. IlcIntExp, the class of constrained integer
expressions, is the root class of a group of classes for expressing
constraints on integer variables.
Most member functions in this class contain assert
statements. For an explanation of the macro NDEBUG (a way to
turn on or turn off these assert statements), see the concept
Assert and NDEBUG.
Domain
The domain of a constrained integer expression is computed from
the domains of its subexpressions. For example, the domain of the expression
x+y contains the range [x.getMin()+y.getMin(),
x.getMax()+y.getMax()].
A constrained integer variable is a constrained expression that
stores its domain instead of computing it from its subexpressions.
The domain of a constrained integer variable contains values of type
IlcInt. This domain is represented by an interval when the
values are consecutive or by an enumeration of integers otherwise.
Constrained integer variables can be combined with arithmetic operators to yield constrained integer expressions. Each constrained integer expression has a minimum and a maximum. We say that the expression is fixed if its minimum equals its maximum.
The domain of a constrained integer expression can be reduced to the point of being empty. In such a case, failure occurs since no solution is then possible.
Expression versus Variable
IlcIntVar is a subclass deriving from
IlcIntExp. Another way to describe this is that a
constrained variable is a constrained expression that happens to store its
domain. You can convert a constrained integer expression (which computes its
domain) into a constrained integer variable (which stores its domain) by
either of two means: by the casting constructor of
IlcIntVar or by the assignment operator of
IlcIntVar.
Overflow and Underflow
CP Optimizer manages integer overflow and underflow in these ways:
+, *, -, / do not cause
overflow in CP Optimizer.IlcIntExp::getSize returns IlcIntMax whenever
max - min is greater than IlcIntMax.IlcIntMin), then CP Optimizer replaces that bound by
IlcIntMin.IlcIntMax) then CP Optimizer replaces that bound by
IlcIntMax.
0/0 as the interval
[IlcIntMin..IlcIntMax].Backtracking and Reversibility
All the member functions and operators defined for this class and capable of modifying constrained variables are reversible. In particular, the changes made by constraint-posting functions are made with reversible assignments. Thus, the value, the domain, and the constraints posted on any constrained variable are restored when CP Optimizer backtracks.
Modifiers
For modifiers of IlcIntExp, see the concept
Propagation events in CP Optimizer.
For more information, see the concept Propagation in CP Optimizer.
A modifier is a member function that reduces the domain of a constrained
integer expression, if it can. The modifier is not stored, in contrast to a
constraint. If the constrained integer expression is a constrained integer
variable, the modifications due to the modifier call are stored in its
domain. Otherwise, the effect of the modifier is propagated to the
subexpressions of the constrained integer expression. If the domain becomes
empty, a failure is triggered by a call to the member function
IloCP::fail. Modifiers are usually used to define new
classes of constraints.
See Also:
IlcAbs, IlcIntExpIterator, IlcIntSet, IlcIntVar, IlcIntVarArray, IlcMax, IlcMin, IlcScalProd, IlcSquare, IlcSum, operator+, operator/, operator*, operator-, operator<<
| Method Summary | |
|---|---|
public IlcInt | getMax() const |
public IlcInt | getMin() const |
public IlcInt | getSize() const |
public IlcInt | getValue() const |
public | IlcIntExp(IlcConstraint bexp) |
public IlcBool | isFixed() const |
public void | setMax(IlcInt max) const |
public void | setMin(IlcInt min) const |
public void | setRange(IlcInt min, IlcInt max) const |
| Method Detail |
|---|
A constrained Boolean expression in CP Optimizer can be seen as a 0-1 (that
is, binary) constrained integer expression where IlcFalse
corresponds to 0, and IlcTrue corresponds to 1. This
constructor creates a constrained integer expression which is equal
to the truth value of the argument bexp. In other words,
you can use this constructor to cast a constraint to a constrained
integer expression.
Such a constrained integer expression can then be used like any other constrained integer expression. It is thus possible to express sums of constraints. For example, the following code expresses the idea that three variables cannot all be equal.
m.add((x != y) + (y != z) + (z != x) >= 2);
This member function returns the maximum of the domain of the invoking object.
This member function returns the minimum of the domain of the invoking object.
This member function returns the number of elements in the domain of
the invoking expression. In particular, it returns 1 if the invoking
constrained integer expression is fixed, and it returns
IlcIntMax whenever max - min
is greater than IlcIntMax.
This member function returns the value of the invoking constrained
integer expression if that object is fixed; otherwise, CP Optimizer will
throw an exception (an instance of
IloCP::Exception). To avoid errors with
getValue, you can test expressions by means of
isFixed.
This member function returns IlcTrue if the invoking
constrained integer expression is fixed, that is, if its minimum equals
its maximum. Otherwise, the member function returns
IlcFalse.
This member function removes all the elements that are greater than
max from the domain of the invoking constrained expression.
If the domain thus becomes empty, then the current goals fails and
the engine backtracks. Otherwise, if the domain is
modified, the range and domain propagation events are generated.
Moreover, if the invoking constrained integer expression becomes
fixed, then the value propagation event is also generated. The
effects of this member function are reversible.
This member function removes all the elements that are less than
min from the domain of the invoking constrained expression.
If the domain thus becomes empty, then the current goal fails and
the engine backtracks. Otherwise, if the domain is
modified, the range and domain propagation events are generated.
Moreover, if the invoking constrained integer expression becomes
fixed, then the value propagation event is also generated. The
effects of this member function are reversible.
This member function removes all the elements that are either less
than min or greater than max from the domain
of the invoking constrained expression. If the domain thus becomes empty,
then current goal fails, the engine backtracks. Otherwise,
if the domain is modified, the propagation events range and
domain are generated. Moreover, if the invoking constrained
integer expression becomes fixed, then the value propagation event is
also generated. The effects of this member function are reversible.