Skip to main content
FRAMES NO FRAMES

Class IlcIntVar

Definition file: ilcp/cpext.h
Include file: <ilcp/cp.h>
Map of IlcIntVarIlcIntVarIlcIntVarIlcIntExp
The class for representing constrained integer variables.

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. 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 CP Optimizer backtracks.

See Also:

Method Summary
public ILCDEPRECATED IlcIntgetMaxDelta() const
public ILCDEPRECATED IlcIntgetMinDelta() const
public IlcIntgetNextHigher(IlcInt threshold) const
public IlcIntgetNextLower(IlcInt threshold) const
public IlcIntgetOldMax() const
public IlcIntgetOldMin() const
public IlcIntVar()
public IlcIntVar(IlcCPEngine solver, IlcInt min, IlcInt max, const char * name=0)
public IlcIntVar(IlcCPEngine solver, const IlcIntArray values, const char * name=0)
public IlcIntVar(IlcIntVarI * impl)
public IlcIntVar(const IlcIntExp exp)
public IlcBoolisInDelta(IlcInt value) const
public IlcBoolisInDomain(IlcInt value) const
public IlcBoolisInProcess() const
public voidremoveDomain(IlcIntSet set) const
public voidremoveDomain(IlcIntArray array) const
public voidremoveRange(IlcInt min, IlcInt max) const
public voidremoveValue(IlcInt value) const
public voidsetDomain(IlcIntArray array) const
public voidsetDomain(IlcIntSet set) const
public voidsetDomain(IlcIntVar var) const
public voidwhenDomain(const IlcDemon demon) const
public voidwhenRange(const IlcDemon demon) const
public voidwhenValue(const IlcDemon demon) const
Inherited Methods from IlcIntExp
getMax, getMin, getSize, getValue, IlcIntExp, isFixed, setMax, setMin, setRange
Method Detail

IlcIntVar

public IlcIntVar()

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.


IlcIntVar

public IlcIntVar(IlcCPEngine solver, IlcInt min, IlcInt max, const char * name=0)

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.

To avoid potential problems on 64-bit architectures, we recommend min and max be in the range [IlcIntMin ...IlcIntMax].

For example, to create a constrained integer variable with the domain [0 ... 10], use the constructor:

 IlcIntVar var (cp, 0, 10);
 

IlcIntVar

public IlcIntVar(IlcCPEngine solver, const IlcIntArray values, const char * name=0)

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.

To avoid potential problems on 64-bit architectures, we recommend the integers be in the range [IlcIntMin ...IlcIntMax].

To use this constructor to create a constrained integer variable with a domain of non-consecutive integers:

 IlcIntArray values (cp, 10, 28, 45, 65, 78, 90, 102, 113,
                     123, 123, 138);
 IlcIntVar aVar (cp, values);

IlcIntVar

public IlcIntVar(IlcIntVarI * impl)

This constructor creates a handle object (an instance of the classIlcIntVar) from a pointer to an object (an instance of the class IlcIntVarI.


IlcIntVar

public IlcIntVar(const IlcIntExp exp)

This constructor creates a constrained integer variable from a constrained integer expression. The newly created variable has an associated domain which will be maintained consistent with the computed bounds of exp.


getMaxDelta

public ILCDEPRECATED IlcInt getMaxDelta() const

This member function is deprecated in CP Optimizer 2.2.

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.


getMinDelta

public ILCDEPRECATED IlcInt getMinDelta() const

This member function is deprecated in CP Optimizer 2.2.

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.


getNextHigher

public IlcInt getNextHigher(IlcInt threshold) const

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.


getNextLower

public IlcInt getNextLower(IlcInt threshold) const

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.


getOldMax

public IlcInt getOldMax() const

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.


getOldMin

public IlcInt getOldMin() const

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.


isInDelta

public IlcBool isInDelta(IlcInt value) const

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.


isInDomain

public IlcBool isInDomain(IlcInt value) const

This member function returns IlcTrue if value is in the domain of the invoking constrained integer expression. Otherwise, the member function returns IlcFalse.


isInProcess

public IlcBool isInProcess() const

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.


removeDomain

public void removeDomain(IlcIntSet set) const

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 current goal fails and the engine backtracks. Otherwise, if the domain is modified, the corresponding propagation events are generated. The effects of this member function are reversible.


removeDomain

public void removeDomain(IlcIntArray array) const

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 current goal fails and the engine backtracks. Otherwise, if the domain is modified, the corresponding propagation events are generated. The effects of this member function are reversible.


removeRange

public void removeRange(IlcInt min, IlcInt max) const

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 current goal fails and the engine backtracks. 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 fixed, then the value propagation event is also generated. The effects of this member function are reversible.


removeValue

public void removeValue(IlcInt value) const

This member function removes value from the domain of the invoking constrained expression. If the domain thus becomes empty, then the member function IlcCPEngine::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 fixed, then the value propagation event is also generated. The effects of this member function are reversible.


setDomain

public void setDomain(IlcIntArray array) const

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 current goal fails and the engine backtracks. Otherwise, if the domain is modified, the corresponding propagation events are generated. The effects of this member function are reversible.


setDomain

public void setDomain(IlcIntSet set) const

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 current goal fails and the engine backtracks. Otherwise, if the domain is modified, the corresponding propagation events are generated. The effects of this member function are reversible.


setDomain

public void setDomain(IlcIntVar var) const

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 current goal fails and the engine backtracks. Otherwise, if the domain is modified, the corresponding propagation events are generated. The effects of this member function are reversible.


whenDomain

public void whenDomain(const IlcDemon demon) const

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.


whenRange

public void whenRange(const IlcDemon demon) const

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.


whenValue

public void whenValue(const IlcDemon demon) const

This member function associates demon with the value event of the invoking constrained expression. Whenever the invoking constrained expression becomes fixed, 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 fixed, the constraint will be propagated.