A Concert Technology model consists of a set of C++ objects. Each variable, each constraint, each SOS set, and the objective function in a model are represented by an object of the appropriate Concert Technology class. We refer to these objects as modeling objects.
Before creating modeling objects, an object of class IloEnv
must be constructed. We refer to this object as the environment object. It is constructed with the statement:
which is usually the first Concert Technology statement in an application. At the end, the environment must be closed by calling:
This is usually the last Concert Technology statement in an application. The end()
method must be called because, like most Concert Technology classes, theIloEnv
class is a handle class. This means that IloEnv
objects are really only pointers to implementation objects. Implementation objects are destroyed by calling the end()
method. Failing to call the end()
method can result in memory leaks. Please see the ILOG Concert Technology User's Manual and the ILOG Concert Technology Reference Manual for more details about handle classes in Concert Technology.
Users familiar with the callable C library are cautioned not to confuse the Concert Technology environment object with the CPLEX environment object of type CPXENVptr
, used for setting CPLEX parameters. Such an object is not needed with Concert Technology, as parameters are handled directly by each instance of the IloCplex
class. Thus, when talking about the environment in Concert Technology, we always refer to the object of class IloEnv
required for all other Concert Technology objects.
Probably the first modeling class you will need is IloNumVar
. Objects of this class represent modeling variables. They are described by the lower and upper bound for the variable, and a type which can be one of ILOFLOAT
, ILOINT
, or ILOBOOL
for continuous, integer, or boolean variables, respectively. The following constructor creates an integer variable with bounds -1 and 10:
IloNumVar myIntVar(env, -1, 10, ILOINT);
|
The IloNumVar
class provides methods that allow querying of the data needed to specify a variable. However, only bounds can be modified. Concert Technology provides a modeling object class IloConversion
to change the type of a variable. This allows you to use the same variable with different types in different models.
Variables are usually used to build up expressions, which in turn are used to define the objective or constraints of the optimization problem. An expression can be explicitly written, as in
where x
is assumed to be an array of variables (IloNumVarArray
). Expressions can also be created piece by piece, with a loop:
IloExpr expr(env);
for (int i = 0; i < x.getSize(); ++i)
expr += data[i] * x[i];
|
While Concert Technology supports very general expressions, only linear or piecewise linear expressions can be used in models to be solved with IloCplex
. When you are done using an expression object (that is, you created a constraint with it) you need to delete it by calling its method end()
, for example:
Objects of class IloObjective
represent objective functions of optimization models. IloCplex
may only handle models with at most one objective function, though the modeling API provided by Concert Technology does not impose this restriction. An objective function is specified by creating an instance of IloObjective
. For example:
IloObjective obj(env,
1*x[1] + 2*x[2] + 3*x[3],
IloObjective::Minimize);
|
defines the objective to minimize the expression 1*x[1] + 2*x[2] + 3*x[3].
Similarly, objects of class IloRange
represent constraints for the format lower bound <= expression
<= upper bound
. Any floating point value or +/- IloInfinity
can be used for the bounds. For example:
IloRange r1(env, 3.0, x[1] + x[2], 3.0);
|
defines the constraint x[1] + x[2] == 3.0
.
To formulate a full optimization problem, the objects that are part of it need to be selected. This is done by adding them to an instance of IloModel
, the class used to represent optimization problems. For instance:
IloModel model(env);
model.add(obj);
model.add(r1);
|
defines a model consisting of the objective obj
, constraint r1
, and all the variables they use. Notice that variables need not be added to a model explicitly, as they are implicitly considered if any of the other modeling objects in the model use them. However, variables may be explicitly added to a model if desired.
For convenience, Concert Technology provides the functions IloMinimize
and IloMaximize
to define minimization and maximization objective functions. Also, operators <=, ==
, and <=
are overloaded to create IloRange
constraints. This allows us to rewrite the above examples in a more compact and readable way:
IloModel model(env);
model.add(IloMinimize(env, 1*x[1] + 2*x[2] + 3*x[3]);
model.add(x[1] + x[2] == 3.0);
|
With this notation the C++ variables obj
and r1
need not be created.
The IloModel
class is itself a class of modeling objects. Thus, one model can be added to another. A possible use of this is to capture different scenarios in different models, all of which are extensions to a core model. The core model could be represented as an IloModel
object added to the IloModel
objects that represent the individual scenarios.