Engine representation of variables
Decision variables in the engine can be accessed via a method of the optimizer object.
A model variable (an instance of IloIntVar) contains just the domain information
for that variable. An engine variable (an instance of IlcIntVar) contains the
same information plus some additional data structures to handle constraint propagation.
Let us take an example of code to illustrate the differences between model variables and engine variables:
IloIntVar x(env, 0, 10, "x");
IloIntVar y(env, 0, 10, "y");
IloModel model(env);
model.add(x*x <= y);
IloCP cp(model);
cp.propagate();
cp.out() << "The engine variable of " << x << " is " << cp.domain(x) << std::endl;
cp.out() << "The engine variable of " << y << " is " << cp.domain(y) << std::endl;
produces the output:
The engine variable of x[0..10] is x[0..3]
The engine variable of y[0..10] is y[0..10]
It is important to note that the domain
reductions are not performed on the modeling objects themselves, but on
the corresponding internal engine objects, instances of IlcIntVar.
There are basically two ways of accessing engines variables from model variables. The first way
is available at the top level, through an API on IloCP, as in the previous example.
For example, you can display the current domain of an engine variable with
IloCP::domain(IloIntVar x), get the lower bound of the domain with
IloCP::getMin(IloIntVar x), or after a successful solve, get the value of the
variable with IloCP::getValue(IloIntVar x).
Note that, at the top level, you cannot directly get the engine variable (the
IlcIntVar) from a model variable (the IloIntVar), since the engine
variable depends also on the worker.
The second way of accessing engine variables is available only during the search process. This
happens inside a worker and through a constraint, a goal, a demon, or a macro defining the
extraction. In this case, you can directly get the engine variable corresponding to a model variable
by using the IloCPEngine associated with the worker. For example, a constraint or a
goal using the function getCPEngine(), to get an instance of
IloCPEngine:
IloIntVar var;
...
IloCPEngine cp = getCPEngine();
IlcIntVar engineVar = cp.getInt(var);