Overview | Group | Tree | Graph | Index | Concepts |
The macros ILOPREDICATEi
and ILOCTXPREDICATEi
define one function named
name
that creates and returns an instance of a
predicate on objects of class tx
with i data members
of type td1...td
i. ILOCTXPREDICATEi
allows
an additional context to be passed to be used inside the
user-defined test function.
This function's signature returns a predicate allocated on an environment or on a solver heap:
IloPredicate<tx> name(IloEnv, td1, ..., tdi) IloPredicate<tx> name(IloSolver, td1, ..., tdi)
Note the important difference between data members and contexts.
For a given instance of predicate, data members represent a unique
instance of object linked with the predicate and given at
construction time, whereas contexts are given in the test
function IloPredicate<tx>::operator()(tx nx, IloAny nu)
and thus may change depending on the instance of object that is
tested.
The two examples below show how to define a predicate that
tests whether an instance of IloNumVar
is bound in a
solution.
Example 1
In the first case, it is assumed that you may have to test variables in
different instances of solution
so that the solution must be given
as a context to the test function:
ILOCTXPREDICATE0(IsBoundInContextualSolution, IloNumVar, v, IloSolution, solution) { return solution.isBound(v); }
The above macro invocation defines the following function:
IloPredicate<IloNumVar> IsBoundInContextualSolution(IloEnv);
The test function must be given the address of the solution handle as context:
IloEnv env; IloNumVar v = ...; IloSolution solution = ...; IloPredicate<IloNumVar> pred1 = IsBoundInContextualSolution(env); IloBool bound = pred1(v, &solution);
Example 2
In the second case, it is assumed that you only have one instance of
solution
in the problem and all the tests will use this
solution so that the solution can be represented as a data member
of the predicate.
ILOPREDICATE1(IsBoundInTheSolution, IloNumVar, v, IloSolution, solution) { return solution.isBound(v); }
The macro above defines the following function:
IloPredicate<IloNumVar> IsBoundInTheSolution(IloEnv, IloSolution);
The test function does not use any context:
IloEnv env; IloNumVar v = ...; IloSolution solution = ...; IloPredicate<IloNumVar> pred2 = IsBoundInTheSolution(env, solution); IloBool bound = pred2(v);
For more information, see Selectors.