User Tools

Site Tools


Sensitivity Analysis with GAMS/CPLEX or GAMS/GUROBI


Sensitivity analysis (post-optimality analysis) in linear programming allows one to find out more about an optimal solution for a problem. In particular, objective ranging and right-hand-side ranging give information about how much an objective coefficient or a right-hand-side coefficient can change without changing the optimal basis. In other words, they give information about how sensitive the optimal basis is to a change in the objective function or a right-hand side.

Although not so much used in practical large scale modeling, and not available for mixed-integer models or non-linear models, ranging information can still be of use in some circumstances. This document describes how to produce ranging information when solving models with GAMS/CPLEX or GAMS/GUROBI.

Printing ranging information in the listing file

To include ranging information in the listing file requires an option file. To make use of that you either add the parameter optfile=1 to your command line or add the option to you model, i.e.:

       Model transport /All/;
       Solve transport Using LP Minimizing z;

The OptFile suffix tells GAMS to tell the solver to look for an options file. For GAMS/Cplex, the name of the options file is cplex.opt.


To write objective ranging information for a particular variable, put a line in the options file:

      objrng "variable name"

where “variable name” represents an actual GAMS variable name.

The objrng option can be repeated to specify ranging for more than one variable. To specify ranging for all variables use keyword “all” in GAMS/Cplex.

To write right-hand-side ranging for a particular equation, put a line in the options file as follows:

      rhsrng "equation name"

The option can be repeated just as with the objrng option. To specify ranging for all equations use keyword “all” with GAMS/Cplex.

Example: Solving the model trnsport.gms (from the model library) with GAMS/Cplex using

      objrng all
      rhsrng all

as the contents of cplex.opt, gives the following table in the listing file:

EQUATION NAME                                 LOWER      CURRENT        UPPER
-------------                                 -----      -------        -----
cost                                           -INF            0         +INF
supply(seattle)                                 300          350          625
supply(san-diego)                               550          600         +INF
demand(new-york)                                 50          325          375
demand(chicago)                                  25          300          350
demand(topeka)                                    0          275          325
VARIABLE NAME                                 LOWER      CURRENT        UPPER
-------------                                 -----      -------        -----
x(seattle, new-york)                          0.216        0.225        0.225
x(seattle, chicago)                               0        0.153        0.162
x(seattle, topeka)                            0.126        0.162         +INF
x(san-diego, new-york)                        0.225        0.225        0.234
x(san-diego, chicago)                         0.153        0.162         +INF
x(san-diego, topeka)                              0        0.126        0.162
z                                              -INF            1         +INF

GAMS does not have the notion of an objective row, it only knows about an objective variable. GAMS/CPLEX therefore has added a dummy objective function only with a 1.0 in the position of the objective variable:

                 |                | |                      |
                 |                | |                      |
   original      |                | |                      |
   matrix        |                | |                      |
                 |                | |                      |
   dummy         |       0        |1|          0           |
   objective row +----------------+-+----------------------+


To include ranging information in the , put a line in the options file:

   sensitivity 1   

If you run the trnsport model with GAMS/GUROBI and this option file, your lst file will have theses additional lines:

LP status(2): Model was solved to optimality (subject to tolerances).
Performing sensitivity analysis...

Objective coefficient sensitivity
x(seattle,new-york), 0.225, 0.225, INF
x(seattle,chicago), 0, 0.153, 0.162
x(seattle,topeka), 0.126, 0.162, INF
x(san-diego,new-york), 0, 0.225, 0.225
x(san-diego,chicago), 0.153, 0.162, INF
x(san-diego,topeka), 0, 0.126, 0.162

Variable lower bound sensitivity
x(seattle,new-york), 0, 0, 50
x(seattle,chicago), -INF, 0, 300
x(seattle,topeka), 0, 0, 50
x(san-diego,new-york), -INF, 0, 325
x(san-diego,chicago), -50, 0, 0
x(san-diego,topeka), -INF, 0, 275

Variable upper bound sensitivity
x(seattle,new-york), 0, INF, INF
x(seattle,chicago), 300, INF, INF
x(seattle,topeka), 0, INF, INF
x(san-diego,new-york), 325, INF, INF
x(san-diego,chicago), 0, INF, INF
x(san-diego,topeka), 275, INF, INF

Right-hand-side sensitivity
supply(seattle), 300, 350, INF
supply(san-diego), 600, 600, INF
demand(new-york), 0, 325, 325
demand(chicago), 0, 300, 350
demand(topeka), 0, 275, 275

Ranging information available inside GAMS (GAMS/CPLEX only)

Printed information in the listing file is not always enough. The printed format cannot be changed and the numbers are not accessible for further computations. To address these problems, another CPLEX option is available:

      rngrestart "file name"

where “file name” represents an actual file name. For example, using an options file containing

      rhsrng supply
      rhsrng demand

will result in a file named being written with the following contents:

* Include file with ranging information
* The set RNGLIM /LO,UP/ is assumed to be
* declared.

seattle.LO                 300
seattle.UP                 625
san-diego.LO               550
san-diego.UP              +INF
new-york.LO                 50
new-york.UP                375
chicago.LO                  25
chicago.UP                 350
topeka.LO                    0
topeka.UP                  325

For each equation specified, the ranging information is stored in a newly declared corresponding GAMS parameter. There are a couple of things to note about this parameter.

First, the name of the parameter is based on the name of the equation, but with RNG appended. The user is responsible for ensuring that the original names are 28 or fewer characters long (GAMS names must be 31 or fewer characters long).

Second, the domain list of the new parameter is the same as the domain list for for the corresponding equation plus one new domain on the end. The user is responsible for ensuring that the ranged equations have 19 or fewer domains (GAMS allows 20 or fewer domains per variable or equation).

solver/sensitivity_analysis_with_gams_cplex.txt · Last modified: 2010/03/29 12:55 by support