FRAMES NO FRAMES

Macro ILOPREDICATE0

Definition file: ilsolver/iloselector.h
ILOPREDICATE0(name, tx, nx)
ILOPREDICATE1(name, tx, nx, td, nd)
ILOPREDICATE2(name, tx, nx, td1, nd1, td2, nd2)
ILOPREDICATE3(name, tx, nx, td1, nd1, td2, nd2, td3, nd3)
ILOPREDICATE4(name, tx, nx, td1, nd1, td2, nd2, td3, nd3, td4, nd4)
ILOPREDICATE5(name, tx, nx, td1, nd1, td2, nd2, td3, nd3, td4, nd4, td5, nd5)
ILOPREDICATE6(name, tx, nx, td1, nd1, td2, nd2, td3, nd3, td4, nd4, td5, nd5, td6, nd6)
ILOPREDICATE7(name, tx, nx, td1, nd1, td2, nd2, td3, nd3, td4, nd4, td5, nd5, td6, nd6, td7, nd7)
ILOCTXPREDICATE0(name, tx, nx, tu, nu)
ILOCTXPREDICATE1(name, tx, nx, tu, nu, td, nd)
ILOCTXPREDICATE2(name, tx, nx, tu, nu, td1, nd1, td2, nd2)
ILOCTXPREDICATE3(name, tx, nx, tu, nu, td1, nd1, td2, nd2, td3, nd3)
ILOCTXPREDICATE4(name, tx, nx, tu, nu, td1, nd1, td2, nd2, td3, nd3, td4, nd4)
ILOCTXPREDICATE5(name, tx, nx, tu, nu, td1, nd1, td2, nd2, td3, nd3, td4, nd4, td5, nd5)
ILOCTXPREDICATE6(name, tx, nx, tu, nu, td1, nd1, td2, nd2, td3, nd3, td4, nd4, td5, nd5, td6, nd6)
ILOCTXPREDICATE7(name, tx, nx, tu, nu, td1, nd1, td2, nd2, td3, nd3, td4, nd4, td5, nd5, td6, nd6, td7, nd7)

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...tdi. 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.