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. IlcIntVar
is one of a group of classes for
expressing constraints on constrained integer variables. In fact,
IlcIntVar
(the class of constrained integer variables) is a
subclass of IlcIntExp, the class of constrained integer
expressions. A constrained integer variable is a constrained integer
expression whose domain is explicitly stored.
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.
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 or by the assignment operator.
Domain-Delta and Propagation
When a propagation event is triggered for a constrained variable, the variable is pushed into the propagation queue if it was not already in the queue. Moreover, the modifications of the domain of the constrained variable are stored in a special set called the domain-delta. This domain-delta can be accessed during the propagation of the constraints posted on that variable. When all the constraints posted on that variable have been processed, then the domain-delta is cleared. If the variable is modified again, then the whole process begins again. The state of the domain-delta is reversible.
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.
See Also:
IlcIntExp, IlcIntExpIterator, IlcIntVarArray, IlcIntVarDeltaIterator, IlcTableConstraint
Constructor Summary | |
---|---|
public | IlcIntVar() |
public | IlcIntVar(IloSolver s, IlcInt min, IlcInt max, const char * name=0) |
public | IlcIntVar(IloSolver s, const IlcIntArray values, const char * name=0) |
public | IlcIntVar(IlcIntVarI * impl) |
public | IlcIntVar(const IlcIntExp exp) |
Method Summary | |
---|---|
public IlcInt | getMax() const |
public IlcInt | getMaxDelta() const |
public IlcInt | getMin() const |
public IlcInt | getMinDelta() const |
public IlcInt | getOldMax() const |
public IlcInt | getOldMin() const |
public IlcBool | isInDelta(IlcInt value) const |
public IlcBool | isInProcess() const |
public void | operator=(const IlcIntVar & exp) |
public void | operator=(const IlcIntExp & exp) |
Inherited Methods from IlcIntExp |
---|
getCopy, getImpl, getMax, getMin, getName, getNextHigher, getNextLower, getObject, getSize, getSolver, getSolverI, getValue, isBound, isInDomain, operator=, removeDomain, removeDomain, removeRange, removeValue, setDomain, setDomain, setDomain, setMax, setMin, setName, setObject, setRange, setValue, whenDomain, whenRange, whenValue |
Constructor Detail |
---|
This constructor creates a constrained integer variable which is empty, that is, whose handle pointer is null. This object must then be assigned before it can be used, exactly as when you, as a developer, declare a pointer.
This constructor creates a constrained integer variable with a domain containing all the integer values between min
and max
, inclusive. If min
is greater than max
, the function IlcFail
is called. The optional argument name
, if provided, becomes the name of the constrained integer variable.
For example, if we want to create a constrained integer variable with the domain [0 ... 10]
, then we use the constructor like this:
IlcIntVar var (s, 0, 10);
In case you want to create a constrained integer variable where the domain is not an interval of integers, this constructor creates a constrained integer variable with a domain containing exactly those integers that belong to values
, an array of integers. The optional argument name
, if provided, becomes the name of the constrained integer variable.
Here's how to use that constructor to create a constrained integer variable with a domain of non-consecutive integers.
IlcIntArray values (s, 10, 28, 45, 65, 78, 90, 102, 113, 123, 123, 138); IlcIntVar aVar (values);
This constructor creates a handle object (an instance of the class
IlcIntVar
from a pointer to an object (an instance of the class
IlcIntVarI
.
To transform a constrained integer expression (which computes its domain from its subexpressions) into a constrained integer variable (which stores its domain), you can use this constructor. It associates a domain with the constrained integer expression exp
. This expression thus becomes a constrained integer variable. Moreover, the newly created constrained integer variable points to the same implementation object as exp
. (You can also use the assignment operator for the same purpose.)
Method Detail |
---|
This member function returns the maximum of the domain of the invoking object.
This member function returns the difference between the maximum of the domain of the invoking constrained variable and the maximum of its domain-delta. This member function can be applied only to the variable currently in process.
For example, to know whether the maximum of a constrained integer
variable x
has been modified since the last time the
constraints posted on x
were processed, it is sufficient
to test the value of x.getMaxDelta()
. If that test returns
0, then the maximum of x
has not been modified.
This member function returns the minimum of the domain of the invoking object.
This member function returns the difference between the minimum of the domain of the invoking constrained variable and the minimum of its domain-delta. This member function can be applied only to the variable currently in process.
For example, to know whether the minimum of a constrained integer
variable x
has been modified since the last time the
constraints posted on x
were processed, it is sufficient
to test the value of x.getMinDelta()
. If that test returns
0, then the minimum of x
has not been modified.
This member function returns the maximum of the domain-delta of the invoking constrained variable. This member function can be applied only to the variable currently in process.
This member function returns the minimum of the domain-delta of the invoking constrained variable. This member function can be applied only to the variable currently in process.
This member function returns IlcTrue
if the argument
value
belongs to the domain-delta of the invoking constrained
variable. This member function can be applied only to the variable
currently in process.
This member function returns IlcTrue
if the invoking
constrained variable is currently being processed by the constraint
propagation algorithm. Only one variable can be in process at a time.
This operator assigns an address to the handle pointer of the invoking object. That address is the location of the implementation object of the argument exp
. After the execution of this operator, the invoking object and the exp
object both point to the same implementation object. This assignment operator has no effect on its argument.