Simple variable selection
To chose decision variables, you evaluate the variables with an evaluator.
In the C++ API, a decision variable evaluator is an instance
of IloIntVarEval. This class implements
the function:
IloNum IloIntVarEvalI::eval(IloCPEngine cp, IloIntVar x);
that returns the evaluation of the variable x.
Several predefined evaluators exist in CP Optimizer. For
instance, the evaluator returned by the C++ API function call IloDomainSize(env) returns the current size of the
domain of the variable that is being evaluated. Another example is
the evaluator returned by IloVarIndex(env, vars) that
returns the index in the array vars of the
evaluated variable.
In order to select a decision variable with an evaluator, an instance of a variable selector needs to be created with the evaluator as an argument. Here are two functions in the C++ API that can create such selectors:
IloVarSelector IloSelectSmallest(IloIntVarEval e);
IloVarSelector IloSelectLargest(IloIntVarEval e);
The selector created by IloSelectSmallest(IloDomainSize(env)) will
select the variable in the search phase that has the smallest domain.
The selector returned by IloSelectRandomVar(env) chooses
a variable randomly. This selector is useful for breaking ties.
In the C++ API of CP Optimizer, you use
the classes IloIntVarEval and IloVarSelector and the functions IloDomainSize, IloVarIndex, IloSelectSmallest and IloSelectRandomVar.
In the Java™ API of
CP Optimizer, you use the interfaces IloIntVarEval and
IloVarSelector and the methods IloCP.domainSize, IloCP.varIndex, IloCP.selectSmallest and IloCP.selectRandomVar.
In the C# API of CP Optimizer, you use
the interfaces IIntVarEval and IVarSelector and the methods CP.DomainSize, CP.VarIndex, CP.SelectSmallest and CP.SelectRandomVar.