FRAMES NO FRAMES

Class IlcAnyExp

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

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:

Constructor Summary
public IlcAnyExp()
public IlcAnyExp(IlcIntExpI * impl)
Method Summary
public IlcAnyExpgetCopy(IloSolver solver) const
public IlcIntExpI *getImpl() const
public const char *getName() const
public IlcAnygetObject() const
public IlcIntgetSize() const
public IloSolvergetSolver() const
public IloSolverI *getSolverI() const
public IlcAnygetValue() const
public IlcBoolisBound() const
public IlcBoolisInDomain(IlcAny value) const
public voidoperator=(const IlcAnyExp & h)
public voidremoveDomain(IlcAnyArray array)
public voidremoveDomain(IlcAnySet set)
public voidremoveValue(IlcAny value) const
public voidsetDomain(IlcAnyArray array)
public voidsetDomain(IlcAnySet set)
public voidsetDomain(IlcAnyExp var)
public voidsetName(const char * name) const
public voidsetObject(IlcAny object) const
public voidsetValue(IlcAny value) const
public voidwhenDomain(IlcDemon demon) const
public voidwhenValue(IlcDemon demon) const
Constructor Detail

IlcAnyExp

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

IlcAnyExp

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

Method Detail

getCopy

public IlcAnyExp getCopy(IloSolver solver) const

This member function returns a copy of the invoking 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.

getName

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

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 enumerated expression is bound.


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 IlcAny getValue() const

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.


isBound

public IlcBool isBound() const

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.


isInDomain

public IlcBool isInDomain(IlcAny value) const

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


operator=

public void operator=(const IlcAnyExp & 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(IlcAnyArray 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 failure occurs. Otherwise, if the domain is modified, the corresponding propagation events are generated. The effects of this member function are reversible.


removeDomain

public void removeDomain(IlcAnySet 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 failure occurs. Otherwise, if the domain is modified, the corresponding propagation events are generated. The effects of this member function are reversible.


removeValue

public void removeValue(IlcAny value) const

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.


setDomain

public void setDomain(IlcAnyArray 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 failure occurs. Otherwise, if the domain is modified, the corresponding propagation events are generated. The effects of this member function are reversible.


setDomain

public void setDomain(IlcAnySet 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 failure occurs. Otherwise, if the domain is modified, the corresponding propagation events are generated. The effects of this member function are reversible.


setDomain

public void setDomain(IlcAnyExp 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 failure occurs. Otherwise, if the domain is modified, the corresponding propagation events are 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.

setValue

public void setValue(IlcAny value) const

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:

The effects of this member function are reversible.


whenDomain

public void whenDomain(IlcDemon demon) const

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.


whenValue

public void whenValue(IlcDemon demon) const

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.