Overview | Group | Tree | Graph | Index | Concepts |
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 IlcAny | getObject() const |
public IlcDemon | getParentDemon() const |
public IloSolver | getSolver() const |
public IlcBool | isFalse() const |
public IlcBool | isTrue() const |
public void | setName(const char * name) const |
public void | setObject(IlcAny object) const |
Inherited Methods from IlcDemon |
---|
getConstraint, getImpl, getSolver, operator= |
Constructor Detail |
---|
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.
This copy constructor creates a reference to a constraint. That constraint and c
both
point to the same implementation object.
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 |
---|
This member function returns the implementation object of the invoking object. You can use this member function to check whether a constraint is empty.
This member function returns the name of the invoking handle, if the handle has a name. Otherwise, it returns the empty string.
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.
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.
This member function returns the solver (a handle) of the invoking constraint.
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).
When this member function returns IlcTrue
, the invoking constraint is necessarily
satisfied, no matter what.
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
.
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
).