FRAMES NO FRAMES

Class IlcIntExp

Definition file: ilsolver/intexp.h
Include file: <ilsolver/ilosolver.h>

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:

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:

Constructor Summary
public IlcIntExp()
public IlcIntExp(IlcIntExpI * impl)
public IlcIntExp(IlcConstraint bexp)
public IlcIntExp(IlcBoolVar bexp)
Method Summary
public IlcIntExpgetCopy(IloSolver solver) const
public IlcIntExpI *getImpl() const
public IlcIntgetMax() const
public IlcIntgetMin() const
public const char *getName() const
public IlcIntgetNextHigher(IlcInt threshold) const
public IlcIntgetNextLower(IlcInt threshold) const
public IlcAnygetObject() const
public IlcIntgetSize() const
public IloSolvergetSolver() const
public IloSolverI *getSolverI() const
public IlcIntgetValue() const
public IlcBoolisBound() const
public IlcBoolisInDomain(IlcInt value) const
public voidoperator=(const IlcIntExp & h)
public voidremoveDomain(IlcIntSet set)
public voidremoveDomain(IlcIntArray array)
public voidremoveRange(IlcInt min, IlcInt max) const
public voidremoveValue(IlcInt value) const
public voidsetDomain(IlcIntArray array)
public voidsetDomain(IlcIntSet set)
public voidsetDomain(IlcIntExp var)
public voidsetMax(IlcInt max) const
public voidsetMin(IlcInt min) const
public voidsetName(const char * name) const
public voidsetObject(IlcAny object) const
public voidsetRange(IlcInt min, IlcInt max) const
public voidsetValue(IlcInt value) const
public voidwhenDomain(const IlcDemon demon) const
public voidwhenRange(const IlcDemon demon) const
public voidwhenValue(const IlcDemon demon) const
Constructor Detail

IlcIntExp

public IlcIntExp()
This constructor creates an empty handle. You must initialize it before you use it.

IlcIntExp

public IlcIntExp(IlcIntExpI * impl)
This constructor creates a handle object from a pointer to an implementation object.

IlcIntExp

public IlcIntExp(IlcConstraint bexp)

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);

IlcIntExp

public IlcIntExp(IlcBoolVar bexp)

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

getCopy

public IlcIntExp getCopy(IloSolver solver) const

This member function returns a copy of the invoking constrained integer expression and associates that copy with solver.


getImpl

public IlcIntExpI * getImpl() const
This constructor creates an object by copying another one. This constructor creates an object by copying another one. This member function returns a pointer to the implementation object of the invoking handle.

getMax

public IlcInt getMax() const

This member function returns the maximum of the domain of the invoking object.


getMin

public IlcInt getMin() const

This member function returns the minimum of the domain of the invoking object.


getName

public const char * getName() const
This member function returns the name of the invoking object.

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.


getObject

public IlcAny getObject() const
This member function returns a pointer to the external object associated with the invoking object, if there is such an association. It returns 0 (zero) otherwise.

getSize

public IlcInt getSize() const

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.


getSolver

public IloSolver getSolver() const

This member function returns an instance of IloSolver associated with the invoking object.


getSolverI

public IloSolverI * getSolverI() const

This member function returns a pointer to the implementation object of the solver where the invoking object was extracted.


getValue

public IlcInt getValue() const

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.


isBound

public IlcBool isBound() const

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.


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.


operator=

public void operator=(const IlcIntExp & h)
This operator assigns an address to the handle pointer of the invoking object. That address is the location of the implementation object of the provided argument.

removeDomain

public void removeDomain(IlcIntSet set)

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.


removeDomain

public void removeDomain(IlcIntArray array)

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.


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 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.


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 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.


setDomain

public void setDomain(IlcIntArray array)

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.


setDomain

public void setDomain(IlcIntSet set)

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.


setDomain

public void setDomain(IlcIntExp var)

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.


setMax

public void setMax(IlcInt max) const

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.


setMin

public void setMin(IlcInt min) const

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.


setName

public void setName(const char * name) const
This member function sets the name of the invoking object to a copy of name. This assignment is a reversible action.

setObject

public void setObject(IlcAny object) const
This member function establishes a link between the invoking object and an external object of which the invoking object might be a data member.

setRange

public void setRange(IlcInt min, IlcInt max) const

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.


setValue

public void setValue(IlcInt value) const

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:

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 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.