Overview | Group | Tree | Graph | Index | Concepts |
This macro defines an integer predicate class named nameI
with n data members. When n is greater than 0 (zero), the
types and names of the data members must be supplied as arguments to the
macro. Each data member is defined by its type T
i and
a name data
i. The call to the macro must be followed
immediately by the body of the isTrue
member function of the
integer predicate class being defined. Besides the definition of the class
nameI
, this macro also defines a function named
name
that creates an instance of the class nameI
and that returns an instance of the class IlcIntPredicate
that points to it.
Solver does not check the arity of the predicate that you defined. It
assumes that the size of the array (an instance of IlcIntArray
) passed as an argument to the member function
IlcIntPredicate::isTrue
will always be the
same. It also assumes that the name of the array passed as an argument is
val
. That is, you must use that name to define a
predicate.
You are not obliged to use this macro to define integer predicates. When the macro seems too restrictive for your purposes, we recommend that you define an integer predicate class directly.
Since the argument name
is used to name the integer
predicate class, it is not possible to use the same name for several integer
predicate definitions.
Example
Here's how to define an integer predicate with one data member:
ILCINTPREDICATE1(AllLessThanX, IlcInt, x){ return (val[0] < x && val[1] < x && val[2] < x); }
That predicate is a ternary predicate, so it assumes that the array
passed an argument to the member function IlcIntPredicate::isTrue
is of size three. The predicate is
true if all the values are less than the integer x.
That macro generates code similar to the following lines:
class AllLessThanXI : public IlcIntPredicateI { IlcInt x; public: AllLessThanXI(IlcInt xx):x(xx){} ~AllLessThanXI(){} IlcBool isTrue(IlcIntArray val); }; IlcIntPredicate AllLessThanX(IloSolver s, IlcInt xx){ return new (s.getHeap()) AllLessThanXI(xx); } IlcBool AllLessThanXI::isTrue(IlcIntArray val){ return (val[0] < x && val[1] < x && val[2] < x); }
The following statement creates an instance of the class
AllLessThanXI
and returns a handle that points to it.
AllLessThanX(s, 4);
See Also:
IlcIntArray, IlcIntPredicate, IlcIntPredicateI, IlcTableConstraint