Overview | Group | Tree | Graph | Index | Concepts |
The macros ILOEVALUATORi
and
ILOCTXEVALUATORi
define one function named
name
that creates and returns an instance of an
evaluator of objects of class tx
with i data members
of type td1...td
i. ILOCTXEVALUATORi
allows
an additional dynamic evaluation context to be passed to be used inside the
user-defined evaluation function.
This function's signature returns an evaluator allocated on an environment or on a solver heap:
IloEvaluator<tx> name(IloEnv, td1, ..., tdi); IloEvaluator<tx> name(IloSolver, td1, ..., tdi);
Note the important difference between data members and contexts. For a given instance of evaluator, data members represent a unique instance of object linked with the evaluator and given at construction time, whereas the context is given in the evaluation function at evaluation time and thus may change depending on the instance of object that is evaluated:
IloEvaluator<tx>::operator()(tx nx, IloAny nu)
The two following examples show how to define an evaluator that
evaluates the value of an instance of IloNumVar
in a
solution.
Example 1
In the first case, it is assumed that you may have to evaluate variables in
different instances of solution
so that the solution must be given
as a context to the evaluation function:
ILOCTXEVALUATOR0(ValueInContextualSolution, IloNumVar, v, IloSolution, solution) { assert(solution.isBound(v)); return solution.getValue(v); }
The macro above defines the following function:
IloEvaluator<IloNumVar> ValueInContextualSolution(IloEnv);
The evaluation function must be given the address of a solution handle as context:
IloEnv env; IloNumVar v = ...; IloSolution solution = ...; IloEvaluator<IloNumVar> eval1 = ValueInContextualSolution(env); IloNum val = eval1(v, &solution);
Example 2
In the second case, it is assumed that you only have one instance of
solution
in the problem and that all the evaluations will use this
solution so that the solution can be represented as a data member
of the evaluator.
ILOEVALUATOR1(ValueInTheSolution, IloFloatVar, v, IloSolution, solution) { assert(solution.isBound(v)); return solution.getValue(v); }
The macro above defines the following function:
IloEvaluator<IloNumVar> ValueInTheSolution(IloEnv, IloSolution);
The evaluation function does not use any context:
IloEnv env; IloNumVar v = ...; IloSolution solution = ...; IloEvaluator<IloNumVar> eval2 = ValueInTheSolution(env, solution); IloNum val = eval2(v);
For more information, see Selectors.