FRAMES NO FRAMES

Class IlcConstraint

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

A constraint is an object in Solver. Like other Solver entities, a constraint is implemented by means of two classes: a handle class and an implementation class. In other words, an instance of the class IlcConstraint (a handle) contains a data member (the handle pointer) that points to an instance of the class IlcConstraintI (its implementation object).

Parent of a Constraint

When you use the member function IloSolver::add to add the constraint C to the constraint P, then we say that the constraint P is the parent of constraint C.

If there is no other constraint associated with a given constraint as its parent, then we say that the constraint is its own parent, and we also say that it is an external constraint. In that case, the member function IlConstraint::getParentDemon returns 0 (zero, an empty handle).

Parents of constraints are useful in the trace mechanism of Solver.

Constraints as Boolean Expressions

You might also think of a constraint as a Boolean expression with a value of either IlcFalse or IlcTrue. The value of the expression depends on the satisfiability of the constraint: if the constraint cannot be violated, then the expression is bound to IlcTrue; if the constraint cannot be satisfied, then the expression is bound to IlcFalse. We sometimes call a constraint, a constrained Boolean expression. These expressions can be constrained themselves, and they can be combined with logical operators: or, and, and not.

Posting Constraints

When you create a constraint, Solver does not automatically take it into account. You must explicitly add the constraint to a model and extract the model for an algorithm.

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.

Constructor Summary
public IlcConstraint()
public IlcConstraint(const IlcConstraint & c)
public IlcConstraint(IlcConstraintI * impl)
Method Summary
public IlcConstraintI *getImpl() const
public char *getName() const
public IlcAnygetObject() const
public IlcDemongetParentDemon() const
public IloSolvergetSolver() const
public IlcBoolisFalse() const
public IlcBoolisTrue() const
public voidsetName(const char * name) const
public voidsetObject(IlcAny object) const
Inherited Methods from IlcDemon
getConstraint, getImpl, getSolver, operator=
Constructor Detail

IlcConstraint

public IlcConstraint()

This constructor creates a constraint which is empty, that is, one whose handle pointer is null. This object must then be assigned before it can be used, exactly as when you declare a pointer.


IlcConstraint

public IlcConstraint(const IlcConstraint & c)

This copy constructor creates a reference to a constraint. That constraint and c both point to the same implementation object.


IlcConstraint

public IlcConstraint(IlcConstraintI * impl)

This constructor creates a handle object (an instance of the class IlcConstraint) from a pointer to an object (an instance of the implementation class IlcConstraintI).


Method Detail

getImpl

public IlcConstraintI * getImpl() const

This member function returns the implementation object of the invoking object. You can use this member function to check whether a constraint is empty.


getName

public char * getName() const

This member function returns the name of the invoking handle, if the handle has a name. Otherwise, it returns the empty string.


getObject

public IlcAny getObject() const

It is possible to associate some object (other than the implementation object) with a handle. This member function accesses such an associated object. It returns a pointer to the associated object, if one exists. Otherwise, the member function returns the null pointer.


getParentDemon

public IlcDemon getParentDemon() const

When you use the macro ILCCTDEMON0 to construct a class of demons, then each demon of that class may be associated with a constraint as the parent of that constraint. This member function returns the handle of the demon associated with the invoking constraint. If there is no demon explicitly associated as the parent of the invoking constraint, then this member function returns the invoking constraint itself.


getSolver

public IloSolver getSolver() const

This member function returns the solver (a handle) of the invoking constraint.


isFalse

public IlcBool isFalse() const

When this member function returns IlcTrue, the invoking constraint cannot be satisfied, no matter what.

For example, consider the constraint x <= y. If the domain of x is [0, 10] and the domain of y is [10, 20], then the constraint is necessarily satisfied. In contrast, if the domain of x is [11, 20] and the domain of y is [0, 10], then the constraint is necessarily violated (that is, it cannot be satisfied).


isTrue

public IlcBool isTrue() const

When this member function returns IlcTrue, the invoking constraint is necessarily satisfied, no matter what.


setName

public void setName(const char * name) const

This member function sets the name of the invoking handle to a copy of the given name. This is a reversible action: the new name is allocated on the Solver heap, and the previous name is automatically restored upon backtracking. This member function keeps no pointer to the string name.


setObject

public void setObject(IlcAny object) const

It is possible to associate some object (other than the implementation object) with a handle by means of this member function. If the invoking handle has no associated object, then object becomes the associated object. If the invoking handle already has an associated object, Solver will throw an exception (an instance of IloSolver::SolverErrorException). The argument object must not be the null pointer; otherwise, Solver will throw an exception (an instance of IloSolver::SolverErrorException).