Simple value selection
To chose the value at which you fix a decision variable, you evaluate the values with an evaluator.
As with decision variables, values are evaluated with an evaluator.
In the C++ API, a value evaluator is an instance of IloIntValueEval. This class implements the function:
IloNum IloIntValueEvalI::eval(IloCPEngine cp, IloIntVar x, IloInt v)
that returns the evaluation of assigning the value v to the variable x.
Several predefined value evaluators exist in CP Optimizer.
For instance, the evaluator returned by the C++ API function call IloValue(env) returns the value itself. Another
example is the evaluator returned by IloExplicitValueEval(env,
valueArray, evalArray) that returns the evaluation evalArray[i] when evaluating valueArray[i].
In order to select a value with an evaluator, an instance of a value selector needs to be created with the evaluator as argument. Here are two functions in the C++ API that can create such selectors:
IloValueSelector IloSelectSmallest(IloIntValueEval e);
IloValueSelector IloSelectLargest(IloIntValueEval e);
The selector created by IloSelectLargest(IloValue(env)) will
select the largest value in the domain of the selected variable. The
selector returned by IloSelectRandomValue(env) chooses
a value randomly. This selector is useful for breaking ties.
In the C++ API of CP Optimizer, you use
the classes IloIntValueEval and IloValueSelector and the functions IloValue, IloExplicitValueEval, IloSelectLargest and IloSelectRandomValue.
In the Java™ API of
CP Optimizer, you use the interfaces IloIntValueEval and
IloValueSelector and the methods IloCP.value, IloCP.explicitValueEval, IloCP.selectLargest and IloCP.selectRandomValue.
In the C# API of CP Optimizer, you use
the interfaces IIntValueEval and IValueSelector and the methods CP.Value, CP.ExplicitValueEval, CP.SelectLargest and CP.SelectRandomValue.