The Active Model

Modeling objects, constraints and objective functions, created as described above are now added to the active model. The active model is the model implemented by the IloCplex object itself. In fact, IloModeler is an extension of the IloModel interface defining the model API. Thus, IloCplex implements IloModel, or in other words, an IloCplex object is a model. We will refer to the model implemented by the IloCplex object itself as the active model of the IloCplex object, or if there is no possibility of confusion between several optimizers, simply as the active model.

A model is just a set of modeling objects of type IloAddable such as IloObjective and IloRange. Objects of classes implementing this interface can be added to an instance of IloModel. Other IloAddable objects usable with IloCplex are IloLPMatrix, IloConversion, IloSOS1, and IloSOS2. These will be covered in the IloMPModeler section.

Variables cannot be added to a model because IloNumVar is not an extension of IloAddable. All variables used by other modeling objects (IloAddable objects) that have been added to a model are implicitly part of this optimization model. The explicit addition of a variable to a model can thus be avoided.

During modeling, a typical sequence of operations is to create a modeling object and immediately add it to the active model. To facilitate this for most constructor methods methodName() there is also a constructor method addMethodName() which immediately adds the newly constructed modeling object to the active model. For example, the call

    IloObjective obj = cplex.addMaximize(expr);

is equivalent to

    IloObjective obj = cplex.add(cplex.maximize(expr));

Not only do the addMethodName() methods simplify the program, they are also more efficient than the two equivalent calls because an intermediate copy can be avoided.


Previous Page: Modeling with IloModeler   Return to Top Next Page: Building the Model