Sunteți pe pagina 1din 19

CPLEX Instructions Page 1 of 19

Introduction
This is a step-by-step guide for using CPLEX, a professional solver for linear programming
problems (LP), mixed integer linear programming problems (MIP), and quadratic programming
problems (QP). Compared with the EXCEL solver and the student version of LINDO, each of
which is limited in the size of problem it will solve, CPLEX is relatively unlimited in problem
size. However, it is more difficult to use.
CPLEX is primarily a library of subroutines (or objects) that can be used in ones own C++
computer codes, but it also has an interactive command system with which a user may access
many elements of the library without writing C++ code. This guide covers the use of the
interactive system only. Also, the guide covers solving only LP and MIP.
The next section gives the general steps for solving an LP and then presents an example to reveal
and illustrate the details of each step. Both the LP and MPS problem formats will also be
covered in this section. The third section gives the general steps for solving an MIP and again
presents an example to show exactly how it is done. The fourth section gives tips on how to
improve the presentation of the solution and how to do sensitivity analysis, again illustrated by
an example. In the last section, the answer report and sensitivity report from EXCEL Solver are
compared with the results of the CPLEX Solver in order to show how to get the same
information from CPLEX as one does from EXCEL.

Solving an LP
The steps for solving an LP that are covered in this section are:
STEP 1: Create a text file describing the problem. This can be done with NotePad (size
limitations), WordPad, Word (must specify file type), or EXCEL (also must
specify file type and possibly clean up the file). The problem description can be
done in two formats, LP, which is good for small problems, and MPS, which is
an industry standard that is best for large problems especially if it is semi-
automatically created in EXCEL.
STEP 2: Start the CPLEX interactive system.
STEP 3: Read the problem file created in STEP 1.
STEP 4: Solve the problem by invoking primopt, which is the CPLEX Solvers primal
simplex code.
STEP 5: Write the solution to a file.
To illustrate these steps and fill in details we will concentrate on a specific example.
Consider the production allocation problem for a process involving S stages of production, and P
products. The stages have finite daily capacity and the problem is to allocate that capacity to the
products so as to maximize daily profits. Deciding how many of each product to produce each
day does this. The general linear programming model of this decision problem follows.



CPLEX Instructions Page 2 of 19
Decision Variables:
p
x
= Number of units of product p produced each day. p = 1, , P
Parameters:
p s
a
,

= Number of minutes required by product p at production stage s. s = 1, , S
s
C = Number of minutes per day available at stage s.
p
v
= Profit per unit of product p
z = Total daily profit

Maximize
z =

=
P
p
p p
x v
1


subject to:

=
s
P
p
s p p s
C x a
1
,

for s = 1, , S

0 >
p
x
for p = 1, , P
A particular case of the model is specified when the values of all the parameters are determined.
For example, consider Table 1 of parameters for the case when S = 3, and P = 3.
TABLE 1
PARAMETER VALUES FOR EXAMPLE
PRODUCTION MODEL
Stage
Production minutes per unit of product Capacity of
production in
minutes per day Product 1 Product 2 Product 3
1
2
3
2
3
1
2
1
4
1
1
0
400
450
390
Profit/Unit $3 $5 $2
Given the data in the table a specific version of the model may be formulated as follows.
Maximize z =
3 2 1
2 5 3 x x x + +

subject to:
3 2 1
2 2 x x x + +
s 400

3 2 1
3 x x x + +
s 450

2 1
4x x +
s 390

0 , 0 , 0
3 2 1
> > > x x x

CPLEX Instructions Page 3 of 19
This problem will be used to illustrate the use of CPLEX with two different problem file formats.
The first is the LP format and the second is the MPS format. Both are industry standard formats.
Using The LP Problem File Format
Step 1 is the creation of a text file containing the model and data for the problem. We will first
illustrate this by using the LP format. Start a text editor and type the above model in plane text
(i. e., without italics, subscripts or special characters). The result is shown in Figure 1.

Maximize
3x1 + 5x2 + 2x3
subject to
2x1 + 2x2 + x3 <= 400
3x1 + x2 + x3 <= 450
x1 + 4x2 <= 390
end
Fig. 1. Text for describing the example problem in LP format.
Notice that the non-negativity constraints are missing. This is because CPLEX assumes non-
negativity constraints on all variables unless stated otherwise. When CPLEX reads this text it
will identify and interpret the key words Maximize and subject to, but other non-blank
character strings are interpreted as variable names starting at the first alphabetic character and
continuing to an operator (+,-), comparator (<=, >=, =), or end of a line. The numeric characters
at the beginning of a string are interpreted as coefficients. Thus, in this example x1, x2, and x3
are the variable names. Actually, more elaborate variable names can be used, the objective and
constraints can be given names, and different key words and different inequality symbols may be
used in creating the text file. These variations are illustrated in Figure 2, which is interpreted by
CPLEX is exactly the same problem as the one in Figure 1.
Max
Profit: 3Product1 + 5Product2 + 2Product3
st
Stage1: 2Product1 + 2Product2 + Product3 < 400
Stage2: 3Product1 + Product2 + Product3 < 450
Stage3: Product1 + 4Product2 < 390
end
Fig. 2. Alternate text for describing the example problem in LP format.
In this second figure it should be noted that < is the same thing as <=, Max is the same as
Maximum, st is the same as subject to and the words left of : are the user selected names for
the objective function and constraints. Once a text version of the problem has been created, it is
saved in a file with a text format (usually signified by .txt file extension). For future
illustration, assume that we have stored the file on a diskette in drive A, and given it the name
productionexamp.txt.
Step 2 is accomplished in the ISE computer labs by first activating the START menu, the
PROGRAMS menu, the APPLICATIONS menu and then locating and clicking on the file
named CPLEX. This will start the CPLEX interactive system in an MS-DOS window (black

CPLEX Instructions Page 4 of 19
screen with white lettering). The cursor will be blinking on the line that starts with CPLEX>,
which is the command line where instructions are entered. The window will typically appear as
in Figure 3, except for the black screen with white lettering (the reverse is shown throughout this
document in order to save printing ink or toner).


Welcome to CPLEX Linear Optimizer 6.6.0
with Mixed Integer & Barrier Solvers
Copyright (c) ILOG 1997-1999
CPLEX is a registered trademark of ILOG

Type 'help' for a list of available commands.
Type 'help' followed by a command name for more
information on commands.

CPLEX>
Fig. 3. Illustration of the initial CPLEX interactive system screen.
Step 3 is accomplished by typing read filename lp at the command line. In our example, we
would type: read a: productionexamp.txt lp and then press the enter (or return) key. The
command can also be entered in stages by first entering read whereupon you will be asked for
the file name. Once that is entered you will be given a relatively long list of file format choices
as a reminder of what is possible. You identify the problem format you want, which is LP, so
you enter lp. Now the window will look as shown in Figure 4.

Welcome to CPLEX Linear Optimizer 6.6.0
with Mixed Integer & Barrier Solvers
Copyright (c) ILOG 1997-1999
CPLEX is a registered trademark of ILOG

Type 'help' for a list of available commands.
Type 'help' followed by a command name for more
information on commands.

CPLEX> read a:productionexamp.txt lp
Problem 'a:productionexamp.txt' read.
Read time = 0.24 sec.
CPLEX>
Fig. 4. Illustration of the command to read a problem text file in LP format.

CPLEX Instructions Page 5 of 19
Step 4 is the solution step, which is accomplished by entering primopt at the command line.
This will cause CPLEX to solve the problem that was read in Step 3 as illustrated in Figure 5.


CPLEX> read a:productionexamp.txt lp
Problem 'a:productionexamp.txt' read.
Read time = 0.24 sec.
CPLEX> primopt
Tried aggregator 1 time.
No LP presolve or aggregator reductions.
Presolve time = 0.21 sec.

Iteration log . . .
Iteration: 1 Objective = 487.500000

Primal - Optimal: Objective = 8.9750000000e+002
Solution time = 0.68 sec. Iterations = 2 (0)

CPLEX>
Fig. 5. Illustration of the solve step for the example problem along with the corresponding
information provided by CPLEX.
Finally, you will want to save the solution in a file. Entering write filename txt (where filename
is your choice) does this. For example, suppose we want to save the solution to our example on
drive A and file name productionsol, then we would type:
write a:productionsol txt
Since the solution file can be viewed with any text editor we can exit the CPLEX interactive
system by entering quit at the command line and then clicking to close the MS-DOS window.
The entire session is now illustrated in Figure 5.

CPLEX Instructions Page 6 of 19


Welcome to CPLEX Linear Optimizer 6.6.0
with Mixed Integer & Barrier Solvers
Copyright (c) ILOG 1997-1999
CPLEX is a registered trademark of ILOG

Type 'help' for a list of available commands.
Type 'help' followed by a command name for more
information on commands.

CPLEX> read a:productionexamp.txt lp
Problem 'a:productionexamp.txt' read.
Read time = 0.24 sec.
CPLEX> primopt
Tried aggregator 1 time.
No LP presolve or aggregator reductions.
Presolve time = 0.21 sec.

Iteration log . . .
Iteration: 1 Objective = 487.500000

Primal - Optimal: Objective = 8.9750000000e+002
Solution time = 0.68 sec. Iterations = 2 (0)

CPLEX> write a:productionsol txt
Solution written to file 'a:productionsol'.
CPLEX> quit
Fig. 6. Summary of the entire problem solving session for the example problem.

Using the MPS Problem File Format
Entering a problem in MPS problem format consists of creating a text file as with the LP
problem format. However, instead of typing out the problem in mathematical form, bits of
information about the problem are entered on each of several lines. At first blush it will seem
that the MPS format is a lot more difficult to create than the LP format. However, for large
problems it is preferable for two basic reasons. First, it is far easier to create the problem in
EXCEL in a semi-automatic way using string concatenation functions along with the other
features in EXCEL. Second, it is far easier to inspect the file for errors in data or problem
structure.
In the MPS format each equation, linear expression, or inequality in a problem is considered a
row and each variable is considered a column. The MPS format requires that you define each

CPLEX Instructions Page 7 of 19
row and each column by giving them names. Each problem parameter (constant) is entered and
identified with the column and row name that describes its location in the problem. For the
example problem given above, the MPS format txt file that would be created is given in Figure 7.

NAME ProductionExample
OBJSENSE
MAXIMIZE
ROWS
N Profit
L Stage1
L Stage2
L Stage3
COLUMNS
X1 Profit 3 Stage1 2
X1 Stage2 3 Stage3 1
X2 Profit 5 Stage1 2
X2 Stage2 1 Stage3 4
X3 Profit 2 Stage1 1
X3 Stage2 1
RHS
Capacity Stage1 400
Capacity Stage2 450
Capacity Stage3 390
ENDATA
Fig. 7. A text description of the example problem using the MPS format.
In the example NAME, ROWS, COLUMNS, RHS, N, L, and ENDATA are key words that
identify sections and the type of information contained within each section. All other
information are user selected names and problem data. The rows section defines one row name
on each line and uses a key word indicator of the type of row. The N indicator for the profit row
indicates that the row is unrestricted (i. e., it is not a constraint). The L indicator for the other
rows indicate that they are s constraints. The next Table 2 summarizes all possible indicators.

TABLE 2
POSSIBLE INDICATORS FOR ROWS

Row Indicator Interpretation
N No restriction used for the objective function
L Less than or equal to constraint
G Greater than or equal to constraint
E Equality constraint


CPLEX Instructions Page 8 of 19
The columns section contains the coefficients of the problem variables, each identified with the
column (variable) and row (constraint or objective function) in which the coefficient appears.
Each line of the column section contains either 1 or 2 coefficients. In each line of the column
section a column (variable) name is listed first followed by a row name (as defined in the rows
section) followed by the coefficient. If a second coefficient is entered in a row the line is
extended to include a second row name and coefficient. All the coefficients in a column must be
entered (using several lines if necessary) before proceeding to the next column that always starts
on a new line.
The RHS section is for entering the right hand side constants of the constraints. In the example,
all the RHSs pertained to capacity constraints, so the name Capacity was chosen. That name
is followed by the name of a row as defined in the rows section and that is followed by the value
of the RHS constant. Each constant requires its own line in the file.
As before, suppose we decided to name the variables Product1, Product2, and Product3 and
suppose we did not wish to enter two coefficients per line in the columns section. The resulting
text file is illustrated in Figure 8.
NAME ProductionExample
OBJSENSE
MAXIMIZE
ROWS
N Profit
L Stage1
L Stage2
L Stage3
COLUMNS
Product1 Profit 3
Product1 Stage1 2
Product1 Stage2 3
Product1 Stage3 1
Product2 Profit 5
Product2 Stage1 2
Product2 Stage2 1
Product2 Stage3 4
Product3 Profit 2
Product3 Stage1 1
Product3 Stage2 1
RHS
Capacity Stage1 400
Capacity Stage2 450
Capacity Stage3 390
ENDATA
Fig. 8. Alternate text description of the example problem in MPS format.
Once the MPS problem format text file is created and saved, the CPLEX interactive system is
started as before, and the problem can be read with a similar command to that used for the LP

CPLEX Instructions Page 9 of 19
problem format. Instead of entering read a: productionexamp.txt lp on the command line the
entry should be read a: productionexamp.txt mps.
We conclude with a list of tips for creating trouble free MPS and LP format problem text files.
1. Do not name anything beginning with numeric characters (01), a period (.), the letter e,
or E.
2. Do not name anything with more than 16 characters.
3. Do not use blanks in the middle of any name.
4. Do not use operators (i. e., +,

-, *, /, ^) or comparators (<, >, =) in any names.
5. Do not use the upper or lower case differences as the only difference in two names.
6. Do not split a term between two lines when continuing a long expression on multiple
lines in the LP format.

Solving MIP Problems
The basic steps for solving mixed integer programming problems are as follows:
STEP 1: Create a text file describing the problem. This can be done in exactly the same
way as we do for the LP problem. It can be done in either LP or MPS format.
The only difference is that these files contain additional information.
STEP 2: Start the CPLEX interactive system.
STEP 3: Read the problem file created in STEP 1.
STEP 4: Solve the problem by invoking mipopt, which is the CPLEX Solvers branch
and bound simplex code for solving problems with integer variables.
STEP 5: Convert the problem to a fixed MIP problem, which is an LP problem in which
the integer variables are set to their optimal integer values and then treated as
constants.
STEP 6: Solve the fixed MIP problem by invoking primopt.
STEP 7: Write the solution to a file.
To illustrate these steps we will embellish the production problem example to include some
integer decision variables. Suppose that management is interested to increase production
capacity. This can be done in the short term by working overtime or by adding a swing shift. At
most two hours of overtime can be added, and because of the lack of available supervisors a
swing shift can be added for only two of the three stages. Both overtime and added shift may not
be done simultaneously in any stage. Thus, we add the following variables and data to the
specific example problem with three stages and three products:

s
o
= Number of hours of overtime to work at stage s, s = 1, 2, 3
s
y
=
1 if a swing shift is added at stage s, s = 1, 2, 3, otherwise it is 0.


CPLEX Instructions Page 10 of 19

TABLE 3
OVERTIME AND SHIFT COSTS AND CAPACITIES
Stage
Fixed And Other
Costs Above Normal
Shift Time Costs
Capacity Increase In
Minutes
Overtime
per hour
Swing
Shift
Overtime
per hour
Swing
Shift
Stage 1 $75 $600 60 400
Stage 2 $80 $700 60 450
Stage 3 $90 $600 60 390

The additional data for the problem is given in Table 3. and the model is modified as follows:
Maximize z =
3 2 1
2 5 3 x x x + +
3 2 1 3 2 1
800 700 600 90 80 75 y y y o o o
subject to:
3 2 1
2 2 x x x + +
1 1
400 60 y o
s 400

3 2 1
3 x x x + +
2 2
450 60 y o
s 450

2 1
4x x +
3 3
390 60 y o
s
390

=
3
1 s
s
y
s 2

1 1
2y o +
s 2

2 2
2y o +
s 2

3 3
2y o +
s 2

0 , 0 , 0
3 2 1
> > > x x x

{ } { } 1 , 0 , 2 , 1 , 0 e e
s s
y o

The first step is to create the problem file in the LP format, as illustrated in Figure 9.
Notice the continuation of the objective function onto a second line. This is permitted for any
long expression as long as the line is not split in the middle of a name or constant or term. The
general section lists those variables that are restricted to integers, while the binary section is
for listing those variables that are restricted to the values of 0 or 1.
As before, the LP format problem definition should be saved in a text file. Step 2 is to start the
CPLEX interactive system, which is done in the same manner as before. The problem file
created in STEP 1 is read with the same command as before.

CPLEX Instructions Page 11 of 19
Maximize
3Product1 + 5Product2 + 2Product3 75o1 80o2 90o3 600y1 700y2
800y3
subject to
2Product1 + 2Product2 + Product3 60o1 400y1 < 400
3Product1 + Product2 + Product3 60o2 450y2 < 450
Product1 + 4Product2 60o3 390y2 < 390
y1 + y2 + y3 < 2
o1 + 2y1 < 2
o2 + 2y2 < 2
o3 + 2y3 < 2
general
o1
o2
o3
binary
y1
y2
y3
end
Fig. 9. The mixed integer production model in LP format.
To solve the MIP problem in Step 4 you invoke the MIP solver with the command mipopt.
Unfortunately, there are no facilities for saving the solution to a text file for later viewing, so we
use a simple work around. First we convert the problem to a linear program in which the integer
variables are fixed to their best values. Then we solve the converted LP. This solution is the
same as the best MIP, but since it is an LP we are able to save the results. This is accomplished
in Step 5 by entering change problem fixed_mip on the command line. Then in Step 6,
primopt is entered on the command line. Finally, Step 7 (saving the solution) can be completed
by entering the command write a:mipsol.txt txt. Of course, in this last step the drive choice
and file name are the users option.
The declaration of integer variables in the MPS format is most easily accomplished by adding a
BOUNDS section to the layout. Naturally, the data for the new variables, constraints, and terms
must also be added to the other sections. The example MPS file layout is illustrated in Figure 10.
The BOUNDS section is a convenient device for setting up simple upper and or lower bounds for
any problem variables whether or not they are integer. CPLEX assumes the simple lower bound
for each problem variable is 0 unless a statement in the BOUNDS section is made to the
contrary. The indicator for the overtime variables is LI, which means lower bound and integer,
and the lower bound is set to 0. Since 0 is automatically assumed this bound is redundant since it
did not change the assumed lower bound, however, it does provided us with the opportunity to
declare the overtime variables to be integer. On the other hand, the shift variables, which are
binary variables, received the indicator UI, which means upper bound and integer, and the
upper bound was set to 1. Since 0 is the automatic lower bound an upper bound of 1 for an
integer variable makes it a binary variable.


CPLEX Instructions Page 12 of 19
NAME ProductionExample
OBJSENSE
MAXIMIZE
ROWS
N Profit
L Stage1
L Stage2
L Stage3
L Totalshifts
L OTvsShift1
L OTvsShift2
L OTvsShift3
COLUMNS
Product1 Profit 3 Stage1 2
Product1 Stage2 3 Stage3 1
Product2 Profit 5 Stage1 2
Product2 Stage2 1 Stage3 4
Product3 Profit 2 Stage1 1
Product3 Stage2 1
O1 Profit -75 Stage1 -60
O1 OTvsShift1 1
O2 Profit -80 Stage2 -60
O2 OTvsShift2 1
O3 Profit -90 Stage3 -60
O3 OTvsShift3 1
Y1 Profit -600 Totalshifts 1
Y1 OTvsShift1 2
Y2 Profit -700 Totalshifts 1
Y2 OTvsShift2 2
Y3 Profit -800 Totalshifts 1
Y3 OTvsShift3 2
RHS
RHS Stage1 400
RHS Stage2 450
RHS Stage3 390
RHS Totalshifts 2
RHS OTvsShift1 2
RHS OTvsShift2 2
RHS OTvsShift3 2
BOUNDS
LI Bound O1 0
LI Bound O2 0
LI Bound O3 0
UI Bound Y1 1
UI Bound Y2 1
UI Bound Y3 1
ENDATA
Fig. 100. MPS file format for the mixed integer problem example


CPLEX Instructions Page 13 of 19
The BOUNDS section can be added to any MPS file even when no integer variables are present,
and it is often convenient to do so. Table 4 provides a list of possible indicators for use in the
BOUNDS section. The word Bound in the BOUNDS section is a user-selected name for the
vector of all bounds regardless of the type of bound.
TABLE 4
TYPE INDICATORS FOR THE BOUNDS SECTION
Indicator Interpretation
LO
UP
FX
FR
LI
UI
For specifying a lower bound
For specifying an upper bound
For setting a variable to a constant.
For removing all bounds from a variable.
For specifying a lower bound and declaring a variable as integer
For specifying an upper bound and declaring a variable as integer

The only change from solving a mixed-integer problem in LP format to solve one in MPS format
is the read statement just as in the non-integer case. All other steps are unchanged.
The only change from solving a mixed-integer problem in LP format to solve one in MPS format
is the read statement just as in the non-integer case. All other steps are unchanged.

Improving the Solution File Format
The text file containing the saved solution should be opened in WORD so that editing for
improved presentation is made easy. Once imported into WORD, change the page layout to
landscape and set all margins to 0.5 in. This should eliminate all unwanted word wrapping.
The report consists of three parts. The first is a header part containing general problem
information and solution statistics. The second part contains solution information in columnar
form about all rows (constraints) of the problem, while the third part provides column (variable)
information, also in columnar form. If the solution document is longer than one page it should
be divided into three sections corresponding to the three parts by doing the following:
1. Insert a next page section bread just before the word ROWS.
2. Locate the line with the word ROWS and the line with the column headings.
3. Move these two lines into a header that is unique to the second section.
4. Insert a next page section break just before the word COLUMNS.
5. Locate the line with the word COLUMNS and the line with the column headings.
6. Move these lines into a header that is unique to the third section.
These steps will provide a heading for the columnar information at the top of each page thereby
making the results much easier to read.

CPLEX Instructions Page 14 of 19

CPLEX Solution Report Verses the EXCEL Solution and Sensitivity Report
The EXCEL solution and sensitivity reports of the example LP in the second section are
provided below. Also provided is the CPLEX solution report of the same problem. These
reports are marked with boxes surrounding important information. The boxes are labeled with
upper case letters. Like information on the reports are labeled with the same letters. A detailed
explanation follows the next two pages.

CPLEX Instructions Page 15 of 19

Microsoft Excel 9.0 Answer Report

Target Cell (Max)



Cell
Name Original Value Final Value
$F$9 profit 10 897.5



Adjustable Cells



Cell
Name Original Value Final Value
$B$2 x1 1 0
$C$2 x2 1 97.5
$D$2 x3
1
205



Constraints



Cell Name
Cell Value
Formula Status Slack
$E$10 stage 1 400 $E$10<=$G$10 Binding 0
$E$11 stage 2 302.5 $E$11<=$G$11 Not Binding 147.5
$E$12 stage 3
390 $E$12<=$G$12
Binding 0



Microsoft Excel 9.0 Sensitivity Report

Adjustable Cells


Final
Reduced
Objective Allowable Allowable
Cell Name Value Cost Coefficient Increase Decrease
$B$2 x1 0 -1.25
3
1.25 1E+30
$C$2 x2 97.5 0 5 1E+30 1
$D$2 x3
205
0
2
0.5 0.833333




Constraints

Final
Shadow
Constraint Allowable Allowable
Cell Name Value Price R.H. Side Increase Decrease
$E$10 stage 1 400 2
400
147.5 205
$E$11 stage 2
302.5
0
450
1E+30 147.5
$E$12 stage 3 390
0.25
390 410 390




A
B
C
a
b
c d
e
D

CPLEX Instructions Page 16 of 19

































P
R
O
B
L
E
M

N
A
M
E





a
:
P
r
o
d
u
c
t
i
o
n
E
x
a
m
p
l
e
.
t
x
t



















D
A
T
A




N
A
M
E



























O
B
J
E
C
T
I
V
E

V
A
L
U
E


8
9
7
.
5











S
T
A
T
U
S











O
P
T
I
M
A
L

S
O
L
N







I
T
E
R
A
T
I
O
N








2






O
B
J
E
C
T
I
V
E








P
r
o
f
i
t















(
M
A
X
)


R
H
S




































R
A
N
G
E
S

































B
O
U
N
D
S

































S
E
C
T
I
O
N

1

-

R
O
W
S



N
U
M
B
E
R


.
.
R
O
W
.
.
.
.
.

A
T


.
.
.
A
C
T
I
V
I
T
Y
.
.
.


S
L
A
C
K

A
C
T
I
V
I
T
Y


.
.
L
O
W
E
R

L
I
M
I
T
.
.
.
U
P
P
E
R

L
I
M
I
T
.
.
D
U
A
L

A
C
T
I
V
I
T
Y






1




P
r
o
f
i
t





B
S








8
9
7
.
5










-
8
9
7
.
5












N
O
N
E












N
O
N
E














1






2




S
t
a
g
e
1





U
L










4
0
0















0












N
O
N
E













4
0
0













-
2






3




S
t
a
g
e
2





B
S








3
0
2
.
5











1
4
7
.
5












N
O
N
E













4
5
0














0






4




S
t
a
g
e
3





U
L










3
9
0















0












N
O
N
E













3
9
0










-
0
.
2
5


S
E
C
T
I
O
N

2

-

C
O
L
U
M
N
S



N
U
M
B
E
R


.
.
C
O
L
U
M
N
.
.
.
.
.

A
T


.
.
.
A
C
T
I
V
I
T
Y
.
.
.


.
.
I
N
P
U
T

C
O
S
T
.
.
.
.
L
O
W
E
R

L
I
M
I
T
.
.
.
U
P
P
E
R

L
I
M
I
T
.

R
E
D
U
C
E
D

C
O
S
T
.






5









X
1







L
L












0















3















0










N
O
N
E









-
1
.
2
5






6









X
2







B
S









9
7
.
5















5















0










N
O
N
E













0






7









X
3







B
S










2
0
5















2















0










N
O
N
E













0


A

B

C

D

c

a

b

d


CPLEX Instructions Page 17 of 19
The EXCEL answer report provides standard information about the solution to the problem, and
this same information is found in the report generated by CPLEX. The elements are explained in
the following:
A. This gives the label the user has given to the objective function and the optimal objective
function value is given.
B. Here the names of the variables and their optimal values are given.
C. The optimal values for slack variable of the constraints are given along with the names
given to the constraints themselves.
D. The slack variables are the difference between the left-hand-side of the constraints and
the RHS, but the report, in addition to the slack variables in C also gives the values of the
left-hand-sides of the constraints.
The EXCEL sensitivity report provides additional information, some of which are found in the
one report produced by CPLEX. The important elements are as follows:
a. Here the reduced costs are given for all variables at the optimal solution.
b. The objective function coefficients are listed for all the variables.
c. This data differs slightly between EXCEL and CPLEX; they do provide the same
information. In the case of EXCEL the shadow price is given while CPLEX gives
instead the value of dual variables under the label Dual Activity. The way these are
defined in these software packages they are the negatives of each other.
d. The values of the RHS constants for all the constraints are listed here.
e. The Allowable Increase and Allowable Decrease information given in the EXCEL
sensitivity report is very useful information but it is not included in the CPLEX report.
However, it can be displayed on the screen while in the CPLEX interactive mode as
described below.
Getting Sensitivity Analysis Information from CPLEX
Although it is a bit inconvenient, one can display sensitivity information on the screen. Once
there it can be copied into a word document for further use. Entering the command display
sensitivity objective, or display sensitivity rhs does this providing the solution to a
problem is still active in memory. This will elicit a query asking the user to name the variable(s)
or constraint(s) for which the sensitivity information is desired. An example of such a dialogue
is given in the Figure 11. As before, annotations are made to facilitate discussion of important
elements of the example. The annotations are explained as follows.
A. The command display sensitivity objective is requesting sensitivity information
about the objective function coefficients of the problem variables. Thus eliciting the
query about which variables. The query was answered 1- which specifies the first
variable and all other variables. Alternatively, 1-3 could have been specified. Also,
any single variable could have been specified by simply entering, for example 2 for the
second variable, or a sub-range of variables could have been specified by entering, again
for example, 2-3, to specify the second and third variable.

CPLEX Instructions Page 18 of 19
B. The command display sensitivity rhs is requesting sensitivity information about the
right-hand-side constants of the problem constraints, whereupon the query asks for the
user to specify which constraints to display the information. The response 1- as before
specifies the first and all other constraints. The same convention applies to specifying
constraints as is used to specify variables.
C. The Dual Prices of values is redundant information in that it is the negative of the dual
activity information given in the answer report. The dual prices in CPLEX are the same
as the shadow prices given by the EXCEL solver.
D. This is essentially the same information concerning the range of allowable changes in
objective coefficient or RHS value given in the EXCEL sensitivity report and annotated
by e above. The difference is the EXCEL report gives the size of the increase and
decrease in the problem data that would not change the solution, while CPLEX
calculates the range of data values implied by the allowable increases and decreases.

CPLEX> read a:example.txt mps
Specified objective sense: MAXIMIZE
Selected objective name: Profit
Selected RHS name: Capacity
Problem 'a:example.txt' read.
Read time = 1.41 sec.
CPLEX> primopt
Tried aggregator 1 time.
No LP presolve or aggregator reductions.
Presolve time = 0.00 sec.

Iteration log . . .
Iteration: 1 Objective = 487.500000

Primal - Optimal: Objective = 8.9750000000e+002
Solution time = 0.02 sec. Iterations = 2 (0)

CPLEX> display sensitivity objective
Display objective sensitivity for which variable(s): 1-
OBJ Sensitivity Ranges
Variable Name Reduced Cost Down Current Up
X1 -1.2500 -infinity 3.0000 4.2500
X2 zero 4.0000 5.0000 +infinity
X3 zero 1.1667 2.0000 2.5000
CPLEX> display sensitivity rhs
Display RHS sensitivity for which constraint(s): 1-
RHS Sensitivity Ranges
Constraint Name Dual Price Down Current Up
Stage1 2.0000 195.0000 400.0000 547.5000
Stage2 zero 302.5000 450.0000 +infinity
Stage3 0.2500 zero 390.0000 800.0000
CPLEX>
Fig. 11. CPLEX session in which sensitivity information is obtained.
A
B
C
D

CPLEX Instructions Page 19 of 19
The biggest inconvenience in the process of displaying, copying, and pasting sensitivity
information comes when a large problem is solved. In this case a request to display the
information for all variables or all constraints may cause the display to scroll several of the first
lines displayed off the top of the screen so that they cannot then be copied. The work around is
to request the display of information in smaller batches and then to repeat the process several
times as needed.

S-ar putea să vă placă și