Extracting a model
Describes the method that extracts a model for an algorithm in the C++ API.
This manual defines only one optimization model and uses
only one instance of IloCplex
at a time to solve the model. Consequently, this manual talks
about these as the model and the cplex object.
However, in Concert Technology, an arbitrary
number of models and algorithm-objects can be created. The cplex object
can be created by the constructor:
IloCplex cplex(env);
To use CPLEX to solve the model, the model must first be
extracted to cplex by a call like this:
cplex.extract(model);
This method copies the data from the model into the appropriate
efficient data structures, which CPLEX uses for solving the problem.
It does so by extracting each of the modeling objects added to the
model and each of the objects referenced by them. For every extracted
modeling object, corresponding data structures are created internally
in the cplex object. For readers familiar
with the sparse matrix representation used internally by CPLEX, a
variable becomes a column and a constraint becomes a row. As discussed
later, these data structures are synchronized with the modeling objects
even if the modeling objects are modified.
If you consider a variable to be part of your model, even though it is not (initially) used in any constraint, you should add this variable explicitly to the model. This practice makes sure that the variable will be extracted. This practice may also be important if you query solution information for the variable, since solution information is available only for modeling objects that are known to CPLEX because they have been extracted from a model.
If you feel uncertain about whether or not an object will be extracted, you can add it to the model to be sure. Even if an object is added multiple times, it will be extracted only once and thus will not slow the solution process down.
Since the sequence of creating the cplex object
and extracting the model to it is such a common one,
IloCplex provides the shortcut:
IloCplex cplex(model);
This shortcut is completely equivalent to separate calls
and makes sure that the environment used for the cplex object
will be the same as that used for the model when it is extracted,
as required by Concert Technology. The shortcut uses the environment
from the model to construct the cplex object
before extraction.