0% found this document useful (0 votes)
78 views

Introduction To CPLEX 1.0 Overview

investigacion operaciones

Uploaded by

karen dejo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views

Introduction To CPLEX 1.0 Overview

investigacion operaciones

Uploaded by

karen dejo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Introduction to CPLEX

1.0 Overview

There are a number of commercial grade LP solvers


available. An excellent survey of such surveys can be
found at http://lionhrtpub.com/orms/surveys/LP/LP-survey.html.
You can also find a lot of free open source solvers,
see http://www-unix.mcs.anl.gov/otc/Guide/faq/linear-programming-faq.html#free.

Some very convenient solvers for most students


include those with Excel and Matlab.

The standard one that comes with Excel uses a basic


implementation of the primal Simplex method;
however, it is limited to 200 decision variables. To
use it, the Solver add-in must be included (not
installed by default). To add this facility you need to
carry out the following steps:
1. Select the menu option Tools  Add_Ins
2. From the dialogue box presented check the box
for Solver Add-In.
On clicking OK, you will then be able to access the
Solver option from the new menu option Tools 
Solver. If you want to see how to use it, using the LP
example we have been working on, click on
http://www.economicsnetwork.ac.uk/cheer/ch9_3/ch9_3p07.htm.

1
You can also buy commercial add-ons that
significantly improve the power of Excel as an LP
solver. For example, see http://www.solver.com/.

Matlab also has a very easy to use solver. But this


solver may not be the best for industrial applications
because of difficulties in interfacing with Matlab and
because of the solvers themselves may not
necessarily be state-of-art. However, there is an add-
on for Matlab, called Tomlab, which compensates for
this, and we have it at ISU if you want to use it. See
http://tomopt.com/tomlab/about/ for more details
about Tomlab.

There are some other good LP solvers, including, for


example, Lindo and GAMS.

However, market/EMS software vendors in the


power engineering industry mainly use CPLEX
(commercialized by ILOG later purchased by IBM).
These organizations, together with the ISO’s that
they serve, are very interested in hiring people
knowledgeable in mathematical programming (MP),
and the tools available to implement MPs.

If you have already been in industry, if you do not


work with one of these organizations, you may find
yourself interfacing with them, in which case you

2
may also benefit from familiarity with CPLEX. For
the rest of you, CPLEX is an excellent LP/IP-solver
platform, and I can easily make it available to you.

General information about CPLEX can be found at


http://www-
01.ibm.com/software/integration/optimization/cplex-
optimizer/.

Another attractive facility from ILOG is the


capability to integrate solvers into existing code. This
is available if you also acquire ILOG's Optimization
Programming Language (ILOG OPL). A description
at http://www.ilog.com/products/oplstudio/ states:

“The ILOG OPL integrated development environment (IDE)


makes it easy to evaluate different modeling approaches to a
problem and to integrate external data. Debugging and tuning
tools support the development process, and once ready, the
model can be deployed into an external application. ILOG
OPL models can be easily integrated into any application
written in Java, .NET or C++. Alternatively, the ILOG
Optimization Decision Manager (ILOG ODM) extension to
the ILOG OPL-CPLEX Development System can be used to
generate a state-of-the-art decision support application based
on the ILOG OPL model.”

So I need to tell you how to access CPLEX at ISU.

3
2.0 Accessing CPLEX
CPLEX version 10.1.0 resides on an ISU server
called pluto. To access it, you will need to logon to
pluto. To do that, you will need a telnet and ftp
facility. I suggest using the facilities WinSCP2 and
PuTTY. WinSCP2 is an ftp facility. PuTTY is a free
implementation of Telnet and SSH for Win32 and
Unix platforms, along with an xterm terminal
emulator. Links to download both of these programs
is found at http://clue.eng.iastate.edu/downloads.shtml.

The WinSCP2 download page is at


http://winscp.net/eng/download.php#download2,
where you should click on [Download]. Once
installed, when you bring up the program, click on
“New.” In the screen, type into the “Hostname” the a
server name get to one of the servers which has
CPLEX installed. These servers are listed at
http://it.eng.iastate.edu/remote_servers/new.php. For
example, you can type linux-7.ece.iastate.edu.
Also enter you username and password, and then
click “Login.” Once logged in, a navigation screen
for your local machine will appear on your left, and a
navigation screen for the remote machine will appear
on your right. You can click on the “up” directory
towards the top of each screen to move upwards, and
of course just click on a directory to move down into
it.

4
To transfer a file from your local machine to the
remote machine, use the left screen to navigate to the
directory on your local machine where the file
resides. Then click once on the file you want to
transfer. (If you want to transfer multiple files, you
can click once on each file while holding down the
“control” key.)

Now navigate to the directory on your remote


machine where you want to put the file. Once there,
click on the “Files” menu above the left hand screen,
and choose “Copy.” The program will verify that you
want to copy, and if you affirm, it will copy.

To download PuTTY,
1. The PuTTY download page is at
www.chiark.greenend.org.uk/~sgtatham/putty/download.html.
At this page, you will find some alternatives; I used
(successfully) the installer, putty-0.61-installer.exe.

2. Run PuTTY and get the window shown in Fig. 1.


Input “linux-7.ece.iastate.edu” in the Host Name

5
Fig. 1 Run PuTTY
3. Use your ISU username and password to log in.
You will find yourself on a unix terminal emulator.
4. You might like to create a working directory. To
do this, use mkdir DirectoryName, where
DirectoryName is the name of the directory you
want to use. To enter that directory, use
cd DirectoryName. You can see what files reside in
that directory using the command ls .
5. To run CPLEX, type cplex122 .

Although you can use CPLEX from a command line,


I find it is almost always better to prepare a file. It is
probably better to prepare a file on your own
computer, and then port it over to the server.

2.0 A CPLEX Example

To illustrate this process, I will solve the following


problem using CPLEX.

6
max F  5x1  4 x2  3x3
Subject to
2 x1  3x2  x3  5
4 x1 x2  2 x3  11
3x1  4 x2  2 x3  8
x1  0, x2  0, x3  0

The first thing to do is to construct a file containing


the problem. To construct this file, you can use the
program called “notepad” under the “accessories”
selection of the start button in Windows.

Once you open notepad, you can immediately save to


your local directory under the filename “filename.lp.”
You can choose “filename” to be whatever you want,
but you will need the extension “lp.”

To obtain the extension “lp” when you save, you


should do “save as” and then choose “all files.”
Otherwise, it will assign the suffix “.txt” to your file.

Here is what I typed into the file I called “ex2.lp”…

7
maximize
5 x1 + 4 x2 + 3 x3
subject to
2 x1 + 3 x2 + x3 <= 5
4 x1 + x2 + 2x3 <= 11
3 x1 + 4 x2 + 2 x3 <= 8
x1 >= 0
x2 >= 0
x3 >= 0
end

The format of the above file is quite forgiving.


Nonetheless, your first time through, perhaps you
should do it exactly as I have done.

Once I saved the file “ex2.lp” on my local hard drive,


I then used WinSCP to port it over to the server,
where I saved it in a special directory I had set up for
this.
Then I used PuTTY to telnet to the server, where I
then used the “cd” command to go into the directory
where the “ex2.lp” file was located. Once in that
directory, I typed “cplex122” at the command
prompt. The following is the log of my CPLEX
session from this point on:

[jdm@linux-6 458]$ cplex122

8
IBM ILOG License Manager: "IBM ILOG Optimization Suite
for Academic Initiative" is accessing CPLEX 12 with
option(s): "e m b q ".

IBM ILOG CPLEX Optimization Studio Academic Research


Edition
Welcome to IBM(R) ILOG(R) CPLEX(R) Interactive
Optimizer 12.2.0.0
with Simplex, Mixed Integer & Barrier Optimizers
5725-A06 5725-A29 5724-Y48 5724-Y49 5724-Y54 5724-
Y55
Copyright IBM Corp. 1988, 2010. All Rights Reserved.

Type 'help' for a list of available commands.


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

CPLEX> read ex2.lp


Problem 'ex2.lp' read.
Read time = 0.02 sec.
CPLEX> primopt
Tried aggregator 1 time.
LP Presolve eliminated 3 rows and 0 columns.
Reduced LP has 3 rows, 3 columns, and 9 nonzeros.
Presolve time = 0.00 sec.

Iteration log . . .
Iteration: 1 Objective = 12.500000

9
Primal simplex - Optimal: Objective = 1.3000000000e+01
Solution time = 0.00 sec. Iterations = 2 (0)

CPLEX> display solution variables -


Variable Name Solution Value
x1 2.000000
x3 1.000000
All other variables in the range 1-3 are 0.
CPLEX> display solution slacks -
Constraint Name Slack Value
slack c2 1.000000
slack c4 -2.000000
slack c6 -1.000000
All other slacks in the range 1-6 are 0.
CPLEX> display solution dual -
Constraint Name Dual Price
c1 1.000000
c3 1.000000
All other dual prices in the range 1-6 are 0.
CPLEX> quit
[jdm@linux-6 458]$

A few comments about the above might be useful:


1. The command “read ex2.lp” was required to read
the problem. Note that this command reinitializes
CPLEX. Once you solve a problem, it will not
resolve until you reinitialize.

10
2. Once we had read in the problem, we solved it by
issuing the command “primopt” which calls the
primal simplex algorithm. This is the algorithm we
have been studying (there are other algorithms that
you can call with CPLEX as well).
3. The objective function improved to 12.5 after the
first iteration (from 0).
4. The problem solved in the second iteration.
5. The command display solution variables - was used to
display the values of the decision variables at the
solution.
6. The values of the decision variables at the solution
were x1=2, x2=0, x3=1, and at this solution, the
value of the objective function was F=13.
7. Note that CPLEX does not print the values of
decision variables that are zero.
8. The command display solution slacks – was used to
display the values of the slacks at the solution.
9. CPLEX will name the slack variables
c1, c2, …, cm, cm+1,…, cm+n
where there are m constraints and n decision
variables. Therefore the first m slack variables (c1,
c2, …, cm) correspond to the explicit inequality
constraints, and the last n slack variables (cm+1,…,
cm+n) correspond to the nonnegativity constraints
on the decision variables.
10. The values of the slack variables at the solution
were c1=0, c2=1, c3=0, c4=-2, c5=0, c6=-1.

11
11. Note that CPLEX does not print the values of
slack variables that are zero.
12. The fact that c1=0 and c3=0 indicates that the
first and third constraints are binding. That c2=1
indicates the left-hand side of the second constraint
is less than the right-hand-side by 1. Checking
these constraints, we find
Constraint 1:
2 x1  3x2  x3  5
2(2)  3(0)  1  5 √
Constraint 2:
4 x1 x2  2 x3  11
4(2)  0  2(1)  10 √
Constraint 3:
3x1  4 x2  2 x3  8
3(2)  4(0)  2(1)  8 √
13. The fact that c5=0 indicates that the second
inequality constraint is binding, i.e.,
x2  0
which is consistent with the fact that x2=0.
14. The facts that c4=-2, c6=-1 is interesting because
these slacks are negative. This is a result of the fact
that the corresponding constraints are actually

12
“greater than or less to” constraints instead of “less
than or equal to constraints.” The way they are
treated in CPLEX is as follows:
x1  0  x1  c4  0
so that when x1=2, as it is in the solution, c4=-2.
Likewise,
x3  0  x3  c6  0
so that when x3=1, as it is in the solution, c6=-1.

So the above is a very brief and concise introduction


to CPLEX. I have also provided a somewhat more
detailed tutorial (although not overly-detailed) on the
course website to give you a good reference to use
for CPLEX.

13

You might also like