IloModeler
defines an interface for building optimization models. This interface defines methods for constructing variable, constraint, and objective function objects.
A modeling variable in Concert Technology is represented by an object of type IloNumVar
or one of its extensions. You can choose from a variety of methods defined in IloModeler
and IloMPModeler
to create one or multiple modeling variable objects. An example of the method is:
IloNumVar x = cplex.numVar(lb, ub, IloNumVarType.Float, "xname");
|
This constructor method allows you to set all the attributes of a variable: its lower and upper bounds, its type, and its name. Names are optional in the sense that null
strings are considered to be valid as well.
The other constructor methods for variables are provided mainly for ease of use. For example, because names are not frequently assigned to variables, all variable constructors come in pairs, where one variant requires a name string as the last parameter and the other one does not (defaulting to a null
string).
Integer variables can be created using the intVar()
methods, and do not require the type IloNumVarType.Int
to be passed, as this is implied by the method name. The bound parameters are also specified more consistently as integers. These methods return objects of type IloIntVar
, an extension of interface IloNumVar
that allows you to query and set bounds consistently using integers, rather than doubles as used for IloNumVar
.
Frequently, integer variables with 0/1
bounds are used as decision variables. To help create such variables, the boolVar()
methods are provided. In the Boolean type 0
and 1
are implied, so these methods do not need to accept any bound values.
For all these constructor methods, there are also equivalent methods for creating a complete array of modeling variables at one time. These methods are called numVarArray()
, intVarArray()
, and boolVarArray()
.
Modeling variables are typically used in expressions that define constraints or objective functions. Expressions are represented by objects of type IloNumExpr
. They are built using methods such as sum()
, prod()
, diff()
, negative()
, and square()
. For example, the expression
where x1
and x2
are IloNumVar
objects, is constructed by calling:
IloNumExpr expr = cplex.sum(x1, cplex.prod(2.0, x2));
|
It follows that a single variable is a special case of an expression, since IloNumVar
is an extension of IloNumExpr
.
The special case of linear expressions is represented by objects of type IloLinearNumExpr
. Such expressions are editable, which is especially convenient when building up linear expressions in a loop, such as:
IloLinearNumExpr lin = cplex.linearNumExpr();
for (int i = 0; i < num; ++i)
lin.addTerm(value[i], variable[i]);
|
It should be noted that the special case of the scalar product of an array of values with an array of variables is directly supported through the method scalProd()
. Thus the above loop can be rewritten as:
IloLinearNumExpr lin = cplex.scalProd(value, variable);
|
It is recommended that you build expressions in terms of data that is either integer or double-precision (64 bit) floating point. Single-precision (32 bit) floating point data should be avoided as it can result in unnecessarily ill-conditioned problems. For more information, refer to Numerical Difficulties.
Ranged constraints are constraints of the form: lb
expression
![](../../icons/lt_equal.gif)
ub
and are represented in Concert Technology by objects of type IloRange
. The most general constructor is:
IloRange rng = cplex.range(lb, expr, ub, name);
|
where lb
and ub
are double values, expr
is of type IloNumExpr
, and name
is a string.
By choosing the range bounds appropriately, ranged constraints can be used to model any of the more commonly found constraints of the form:
where rel
is the relation "=", "
", or "
". The following table shows how to choose lb
and ub
for modeling these relations:
The last column contains the method provided with IloModeler
that can be used to directly create the appropriate ranged constraint, specifying parameters rel
and rhs
. For example, the constraint expr
![](../../icons/lt_equal.gif)
1.0
is created by calling
IloRange le = cplex.le(expr, 1.0);
|
Again, all constructors for ranged constraints come in pairs, one constructor with and one without a name parameter.
The objective function in Concert Technology is represented by objects of type IloObjective
. Such objects are defined by an optimization sense, an expression, and an optional name. The objective expression is represented by an IloNumExpr
. The objective sense is represented by an object of class IloObjectiveSense
and can take two values, IloObjectiveSense.Maximize
or IloObjectiveSense.Minimize
. The most general constructor for an objective function object is:
IloObjective obj = cplex.objective(sense, expr, name);
|
where sense
is of type IloObjectiveSense
, expr
is of type IloNumExpr
, and name
is a string.
For convenience, the methods maximize()
and minimize()
are provided to create a maximization or minimization objective respectively, without using an IloObjectiveSense
parameter. Names for objective function objects are optional, so all constructor methods come in pairs, one with and one without the name parameter.