
























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

























Enric Rodr´
ıguez-Carbonell
April 28, 2021
■
Among other things, CPLEX allows one to deal with: ◆
Real linear progs(all vars are in
min
Tc x A
x 1
b
1
x 2
b
2
x 3
b
3
x
n
◆
Mixed integer linear progs(some vars are in
min
Tc x A
x 1
b
1
x 2
b
2
x 3
b
3
i^
x
i^
i^
x
i^
■
Two kinds of objects: ◆
Modeling objects
for defining the optimization problem
(constraints, objective function, etc.)They are grouped into an
IloModel
object representing the complete
optimization problem (recall: here,
model = problem
◆
Solving objects
for solving problems represented by modeling objects.
An
IloCplex
object reads a model, extracts its data, solves the
problem and answers queries on solution.
■
The class
IloEnv
constructs a CPLEX environment.
■
The environment is the first object created in an application.
■
To create an environment named
env
, you do this:
IloEnv
env
■
The environment object needs to be available to the constructor of allother Concert Technology classes
■
IloEnv
is a handle class: variable
env
is a pointer to an implementation
object, which is created at the same time
■
Before terminating destroy the implementation object with^ env
end
for just
of its
IloEnv
handles
■
After an
IloModel
object has been constructed, it can be populated with
objects of classes: ◆
IloNumVar
, representing modeling variables;
◆
IloRange
, which define constraints of the form
l
u
where
is a linear expression;
◆
IloObjective
, representing an objective function.
■
Any object
obj
can be added to the model by calling:
model
add
obj
■
No need to explicitly add the variable objects to a model, as they areimplicitly added when they are used in range constraints (instances of IloRange
) or in the objective.
■
At most one objective function can added to a model.
■
Modeling variables are constructed as objects of class
IloNumVar
, e.g.:
IloNumVar
x^
env
This definition creates the modeling variable
x
with lower bound
upper bound
and type
■
Variable types: ◆
: continuous variable
◆
: integer variable
◆
: Boolean variable
■
Note that even for variables of type
the lower bound (0) and the upper bound (1) have to be specified.
■
One may have arrays of variables:
IloNumVarArray
■
Actually in^ model
add
x
y
z^
an object of class
IloExpr
(a linear expression) is also implicitly created
before the object of class
IloRange
is created
■
Sometimes it is convenient to create objects of class
IloExpr
explicitly.
E.g., when expressions cannot be spelled out in source code but have to bebuilt up dynamically. Operators like
provide an efficient way to do this.
■
Example:
IloEnv
env
IloModel
model
env
IloNumVarArray
env
n^
IloExpr
expr
env
for
int
i^
i^
n
i
expr
i^
model
add
expr
expr
end
IloEnv
env
IloModel
model
env
IloNumVarArray
env
n
IloExpr
expr
env
for
int
i^
i
n
i
expr
i^
model
add
expr
expr
end
Notice
this!
■
IloExpr
objects are handles.
So
if an
IloExpr
object has been created explicitly
then method
end()
must be called when it is no longer needed.
■
Example of explicitly defining an
IloRange
object
IloRange
c
env
IloInfinity
x
x
x
■
One may have arrays of constraints:
IloRangeArray
■
More precise information about the outcome of the last call to themethod
solve
can be obtained by calling:
cplex
getStatus
■
Returned value tells what CPLEX found out: whether ◆
it found the optimal solution or only a feasible one; or
◆
it proved the model to be unbounded or infeasible; or
◆
nothing at all has been proved at this point.
■
More info is available with method
getCplexStatus
■
Query methods access information about the solution.
■
Numbers in solution, etc. are of type
IloNum
double
■
To query the solution value for a variable:^ IloNum
v
cplex
getValue
x
■
Warning!
Sometimes for integer variables the value is not integer
but just “almost” integer (e.g. 1e-9 instead of 0).Explicit rounding necessary(use functions
round
of
<math.h>
or
IloRound
■
To query the solution value for an array of variables:^ IloNumVarArray
x
env
... IloNumArray
v
env
cplex
getValues
v^
x
■
To get the values of the reduced costs of an array of variables:^ IloNumVarArray
x
env
... IloNumArray
v
env
cplex
getReducedCosts
v
x^
■
To avoid logging messages by CPLEX on screen:^ cplex
setOut
env
getNullStream
cplex
setError
env
getNullStream
■
Output operator
is defined for type
IloAlgorithm::Status
returned
by
getStatus
, as well as for
IloNum
IloNumVar
is also defined for any array of elements if the output operator is defined for the elements.
■
Default names are of the form
IloNumVar
n
u
for variables, and
similarly for constraints, e.g.,^ IloNumVar
(1)[0..9]
+^
IloNumVar
(3)[0..
inf
]
<=
20
■
One can set names to variables and constraints:
x^
.^
setName
(
" x "
);
c^
.^
setName
(
" c "
);
■
Very
old
format (
age of punched cards!) by IBM
◆
Has become
industry standard
over the years
◆
Column-oriented
◆
Not
really human-
readable
nor
comfortable
for writing
◆
All
LP solvers
support
this language
■
specific file format
◆
Row-oriented
◆
Very
readable
, close to mathematical formulation
◆
Supported by CPLEX
(which can translate from one format to the other!)
■
A company can produce
6 different products
6
■
Production requires
labour
energy
and
machines
, which are all limited
■
The company wants to
maximize revenue
■
The next table describes the requirements of producing one unit of eachproduct, the corresponding revenue and the availability of resources:
1
2
3
4
5
6
Limit
Revenue
Machine
Labour
Energy