Overview | Group | Tree | Graph | Index | Concepts |
In order to state constraints on arbitrary objects, Solver defines
classes of constrained enumerated expressions and variables. In particular,
the class IlcAnyExp
is the root for constrained enumerated
expressions. A constrained enumerated variable is itself a constrained
enumerated expression: the class IlcAnyVar
is a subclass of
IlcAnyExp
.
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
Each constrained enumerated expression has a domain representing the
possible values that can be assigned to the expression. These values are of
type IlcAny
. That is, they are pointers. Those pointers can be
pointers to any C++ entity, including objects and instances of user-defined
classes.
When the domain contains only one possible value, we say that the expression is bound.
The domain of a constrained enumerated expression can be reduced to the point of being empty. In such a case, failure is triggered since no solution is then possible.
Implementation Class
The implementation class for IlcAnyExp
is the class
IlcIntExpI
. In other words, both classes IlcIntExp
and IlcAnyExp
have the same
implementation class. The member functions for IlcAnyExp
cast
their IlcAny
arguments into instances of IlcInt
,
then call member functions of IlcIntExpI
, and cast back the
result, if needed.
For example, the member function setValue
could be defined
like this:
void IlcAnyExp::setValue(IlcAny value) const { assert(getImpl()); getImpl()->setValue((IlcInt) value); }
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.
For more information, see the concept Propagation.
A modifier is a member function that reduces the domain of a constrained enumerated expression, if it can. A modifier is not stored, in contrast to a constraint. If the constrained enumerated expression is a constrained enumerated variable, the modifications due to the modifier are stored in its domain. Otherwise, the effect of the modifier is propagated to the subexpressions of the constrained enumerated expression. If the domain becomes empty, a failure occurs. If the domain does not become empty, propagation events are generated for that expression. Modifiers are usually used to define new classes of constraints.
See Also:
IlcAnyExpIterator, IlcAnySet, IlcAnyVar, IlcAnyVarArray, operator<<
Constructor Summary | |
---|---|
public | IlcAnyExp() |
public | IlcAnyExp(IlcIntExpI * impl) |
Method Summary | |
---|---|
public IlcAnyExp | getCopy(IloSolver solver) const |
public IlcIntExpI * | getImpl() const |
public const char * | getName() const |
public IlcAny | getObject() const |
public IlcInt | getSize() const |
public IloSolver | getSolver() const |
public IloSolverI * | getSolverI() const |
public IlcAny | getValue() const |
public IlcBool | isBound() const |
public IlcBool | isInDomain(IlcAny value) const |
public void | operator=(const IlcAnyExp & h) |
public void | removeDomain(IlcAnyArray array) |
public void | removeDomain(IlcAnySet set) |
public void | removeValue(IlcAny value) const |
public void | setDomain(IlcAnyArray array) |
public void | setDomain(IlcAnySet set) |
public void | setDomain(IlcAnyExp var) |
public void | setName(const char * name) const |
public void | setObject(IlcAny object) const |
public void | setValue(IlcAny value) const |
public void | whenDomain(IlcDemon demon) const |
public void | whenValue(IlcDemon demon) const |
Constructor Detail |
---|
Method Detail |
---|
This member function returns a copy of the invoking expression and associates that copy with solver
.
This member function returns the number of elements in the domain of the invoking expression. In particular, it returns 1 if the invoking constrained enumerated expression is bound.
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 enumerated 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 enumerated expression is bound, that is, if its domain contains only one element. Otherwise, the member function returns IlcFalse
.
This member function returns IlcTrue
if value
is in the domain of the invoking constrained enumerated expression. Otherwise, the member function returns IlcFalse
.
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 failure occurs. 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 set indicated by set
from the domain of the invoking constrained expression. If the domain thus becomes empty, then failure occurs. Otherwise, if the domain is modified, the corresponding propagation events are 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 failure occurs. Otherwise, if the domain is modified, the domain propagation event is generated. Moreover, if the invoking constrained enumerated expression becomes bound, then the value propagation event is also generated. The effects of this member function are reversible.
When it removes a value from a domain, Solver may need to allocate more memory for the representation of the remaining domain. The amount of memory allocated depends on the size of the domain of the variable.
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 failure occurs. 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 failure occurs. 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 failure occurs. 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 different from value
from the domain of the invoking constrained enumerated expression. This has two possible outcomes:
value
was not in the domain of the invoking constrained enumerated expression, the domain becomes empty, and failure occurs.
value
was in the domain, then
value
becomes the value of the expression, and the value and domain propagation events are generated.The effects of this member function are reversible.
This member function associates demon
with the domain propagation 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 value propagation 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.