Overview | Group | Tree | Graph | Index | Concepts |
In a typical application exploiting Solver, 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 bound 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 of saying that idea 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
. For more information, see Chapter 3,
“Constrained Integer Variables,” in the IBM ILOG Solver
User's Manual.
Overflow and Underflow
Previous versions of Solver did not check for integer overflow nor underflow, and we formerly recommended that users with concerns about overflow and underflow should use floating-point variables. However, as of version 5, Solver manages integer overflow and underflow in these ways:
+
,
*
,
-
,
/
do not cause overflow in Solver.IlcIntExp::getSize
returns IlcIntMax
whenever
max - min
is greater than IlcIntMax
.IlcIntMin
), then Solver replaces that bound by
IlcIntMin
.IlcIntMax
) then Solver replaces that bound by
IlcIntMax
.IlcIntMin - 1
(sometimes known as the Joker) is
treated correctly as long as you do not use it in expressions in
+
,
*
,
-
,
/
.
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 Solver backtracks.
Modifiers
For modifiers of IlcIntExp
, see the concept Propagation Events.
For more information, see the concept Propagation.
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
IloSolver::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-, operator<<
Constructor Summary | |
---|---|
public | IlcIntExp() |
public | IlcIntExp(IlcIntExpI * impl) |
public | IlcIntExp(IlcConstraint bexp) |
public | IlcIntExp(IlcBoolVar bexp) |
Method Summary | |
---|---|
public IlcIntExp | getCopy(IloSolver solver) const |
public IlcIntExpI * | getImpl() const |
public IlcInt | getMax() const |
public IlcInt | getMin() const |
public const char * | getName() const |
public IlcInt | getNextHigher(IlcInt threshold) const |
public IlcInt | getNextLower(IlcInt threshold) const |
public IlcAny | getObject() const |
public IlcInt | getSize() const |
public IloSolver | getSolver() const |
public IloSolverI * | getSolverI() const |
public IlcInt | getValue() const |
public IlcBool | isBound() const |
public IlcBool | isInDomain(IlcInt value) const |
public void | operator=(const IlcIntExp & h) |
public void | removeDomain(IlcIntSet set) |
public void | removeDomain(IlcIntArray array) |
public void | removeRange(IlcInt min, IlcInt max) const |
public void | removeValue(IlcInt value) const |
public void | setDomain(IlcIntArray array) |
public void | setDomain(IlcIntSet set) |
public void | setDomain(IlcIntExp var) |
public void | setMax(IlcInt max) const |
public void | setMin(IlcInt min) const |
public void | setName(const char * name) const |
public void | setObject(IlcAny object) const |
public void | setRange(IlcInt min, IlcInt max) const |
public void | setValue(IlcInt value) const |
public void | whenDomain(const IlcDemon demon) const |
public void | whenRange(const IlcDemon demon) const |
public void | whenValue(const IlcDemon demon) const |
Constructor Detail |
---|
A constrained Boolean expression in Solver 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);
A constrained Boolean variable in Solver 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 Boolean variable to a
8 constrained integer expression.
Method Detail |
---|
This member function returns a copy of the invoking constrained
integer expression and associates that copy with solver
.
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.
If threshold
is greater than or equal to the maximum
of the domain of the invoking constrained integer expression, then
this member function returns threshold
. Otherwise, it
returns the first element that is strictly greater than
threshold
in the domain of the invoking constrained
integer expression.
If threshold
is less than or equal to the minimum of
the domain of the invoking constrained integer expression, then this
member function returns threshold
. Otherwise, it returns
the first element that is strictly less than threshold
in the domain of the invoking constrained integer expression.
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 bound, and it returns
IlcIntMax
whenever max - min
is greater than IlcIntMax
.
This member function returns an instance of IloSolver
associated with the invoking object.
This member function returns a pointer to the implementation object of the solver where the invoking object was extracted.
This member function returns the value of the invoking constrained
integer expression if that object is bound; otherwise, Solver will
throw an exception (an instance of
IloSolver::SolverErrorException
). To avoid errors with
getValue
, you can test expressions by means of
isBound
.
This member function returns IlcTrue
if the invoking
constrained integer expression is bound, that is, if its minimum equals
its maximum. Otherwise, the member function returns
IlcFalse
.
This member function returns IlcTrue
if value
is in the domain of the invoking constrained integer expression.
Otherwise, the member function returns IlcFalse
.
This member function removes all the elements of the set indicated
by set
from the domain of the invoking constrained expression.
If the domain thus becomes empty, then the member function
IloSolver::fail
is called. Otherwise, if the domain is
modified, the corresponding propagation events are generated. The effects
of this member function are reversible.
This member function removes all the elements of the array
indicated by array
from the domain of the invoking
constrained expression. If the domain thus becomes empty, then
the member function IloSolver::fail
is called.
Otherwise, if the domain is modified, the corresponding propagation
events are generated. The effects of this member function are
reversible.
This member function removes all the elements that are both greater
than or equal to min
and less than or equal to
max
from the domain of the invoking constrained expression.
If the domain thus becomes empty, then the member function
IloSolver::fail
is called. Otherwise, if the domain is
modified, the domain propagation event is generated. If min
or max
was one of the bounds of the domain, then the range
propagation event is generated, too. Moreover, if the invoking
constrained integer expression becomes bound, then the value propagation
event is also generated. The effects of this member function are
reversible.
This member function removes value
from the domain of
the invoking constrained expression. If the domain thus becomes empty,
then the member function IloSolver::fail
is called.
Otherwise, if the domain is modified, the domain propagation event is
generated. If value
was one of the bounds of the domain,
then the range propagation event is generated, too. Moreover, if the
invoking constrained integer expression becomes bound, 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 not in
the array indicated by array
from the domain of the
invoking constrained expression. If the domain thus becomes empty,
then the member function IloSolver::fail
is called.
Otherwise, if the domain is modified, the corresponding propagation
events are generated. The effects of this member function are
reversible.
This member function removes all the elements that are not in
the set indicated by set
from the domain of the
invoking constrained expression. If the domain thus becomes empty,
then the member function IloSolver::fail
is called.
Otherwise, if the domain is modified, the corresponding propagation
events are generated. The effects of this member function are
reversible.
This member function removes all the elements that are not in
domain of var
from the domain of the invoking
constrained expression. If the domain thus becomes empty, then the
member function IloSolver::fail
is called. Otherwise,
if the domain is modified, the corresponding propagation events are
generated. The effects of this member function are reversible.
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 member function
IloSolver::fail
is called. Otherwise, if the domain is
modified, the range and domain propagation events are generated.
Moreover, if the invoking constrained integer expression becomes
bound, 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 member function
IloSolver::fail
is called. Otherwise, if the domain is
modified, the range and domain propagation events are generated.
Moreover, if the invoking constrained integer expression becomes
bound, 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 the member function IloSolver::fail
is called. Otherwise,
if the domain is modified, the propagation events range
and
domain
are generated. Moreover, if the invoking constrained
integer expression becomes bound, 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 different
from value
from the domain of the invoking constrained
integer expression. This has two possible outcomes:
value
was not in the domain of the invoking constrained
integer expression, the domain becomes empty, and the member
function
IloSolver::fail
is called.
value
was in the domain, then
value
becomes the value of the expression, and the value,
range, and domain propagation events are generated.The effects of this member function are reversible.
This member function associates demon
with the domain
event of the invoking constrained expression. Whenever the domain of
the invoking constrained expression changes, the demon will be executed
immediately.
Since a constraint is also a demon, a constraint can also be passed as an argument to this member function. Whenever the domain of the invoking constrained expression changes, the constraint will be propagated.
This member function associates demon
with the range
event of the invoking constrained expression. Whenever one of the
bounds of the domain of the invoking constrained expression changes,
the demon will be executed immediately.
Since a constraint is also a demon, a constraint can also be passed as an argument to this member function. Whenever one of the bounds of the domain of the invoking constrained expression changes, the constraint will be propagated.
This member function associates demon
with the value
event of the invoking constrained expression. Whenever the invoking
constrained expression becomes bound, the demon will be executed
immediately.
Since a constraint is also a demon, a constraint can also be passed as an argument to this member function. Whenever the invoking constrained expression becomes bound, the constraint will be propagated.