Ranging analysis

Top  Previous  Next

Some users are interested in getting ranging output in the form of LP cost and right hand side ranging results.  Unfortunately, the base version of GAMS does not yield such information.  The user wishing such information has two alternatives.  First, one may cause the model to be repeatedly solved under a set of values for the key parameter using the procedures discussed in the Doing a Comparative Analysis with GAMS chapter but this is cumbersome if a lot of parameters are involved.  Second, one can use solver dependent features of GAMS (which currently work with OSL or CPLEX) and retrieve the ranging information following the procedures discussed next.  In turn the ranging information is included in the LST file and can be retrieved into a GAMS parameter.

There is a document on the GAMS web page called Sensitivity Analysis, with GAMS/CPLEX and GAMS/OSL at http://www.gams.com/docs/sensitiv.htm which gives instructions on how to get ranging analyses from the OSL or CPLEX solvers.  Use of this approach requires one to implement a solver options file telling the solver to generate all possible or selected ranging information.  There is also an option one can use which causes the ranging information to be saved in an auxiliary file importable by GAMS, subject to some potential small editing changes.

The steps to using this procedure are as follows

I.When solving an LP type of problem make sure you are using either OSL or CPLEX as the LP solver through the solver selection procedures discussed in the Variables, Equations, Models and Solves chapter.
II.Define an option file of one of two forms
If you wish all the variables and equations to be subjected to ranging then place the following lines in the option file for CPLEX

 

         objrng all

         rhsrng all

 

 or for OSL use

 

         objrng

         rhsrng

 

If you wish only selected items to be ranged enter the commands

 

         objrng variablename1,variablename2

         rhsrng equationname

 

in both OSL and CPLEX where variablename and equationname are named variables and equations in your GAMS model.

These options can be repeated to specify ranging for more than one variable or equation.
One cannot nominate individual cases of a variable or equation.
III.Add lines just before the solve statement that tell GAMS to activate an options file and write a dictionary file

 

 transport.OptFile=1;

 transport.DictFile = 4;

 

IV.One may wish to include these items in the GAMS parameter so they may be used in calculations or report writing.  A file that may be included into GAMS is automatically generated if one adds a line to the options file of the form

 

 rngrestart filename

 

where filename is the name of the include file.

Example:

Suppose we take the problem resource.gms and set it up to do include ranging analysis.  To do this we add the colored lines as below between the model statement and the solve statement creating the file ranging.gms.

 

 MODEL RESALLOC /ALL/;

 option lp=cplex;

 FILE  OPT   Cplex option file  / cplex.OPT /;

 PUT OPT;

 PUT 'objrng all '/

     'rhsrng all '/;

 PUTCLOSE OPT;

 resalloc.optfile=1;

 resalloc.dictfile=4;

 SOLVE RESALLOC USING LP MAXIMIZING PROFIT;

 

These lines choose the solver, write the options file using the procedure discussed in the Solver Option files chapter, activate the options file and write the dictionary file.

 

In turn the LST file output is augmented with the ranging information as follows

 

EQUATION NAME                       LOWER          CURRENT            UPPER

-------------                       -----          -------            -----

OBJT                                 -INF                0             +INF

AVAILABLE(SMLLATHE)               95.6204              140          151.333

AVAILABLE(LRGLATHE)               83.9286               90          112.705

AVAILABLE(CARVER)                 103.093              120             +INF

AVAILABLE(LABOR)                  97.9317              125          175.453

 

 

VARIABLE NAME                       LOWER          CURRENT            UPPER

-------------                       -----          -------            -----

PRODUCTION(FUNCTNORM)            -3.92507                0          27.8421

PRODUCTION(FUNCTMXSML)               -INF                0          11.2991

PRODUCTION(FUNCTMXLRG)               -INF                0          4.07934

PRODUCTION(FANCYNORM)            -4.97175                0          4.42299

PRODUCTION(FANCYMXSML)               -INF                0          8.39683

PRODUCTION(FANCYMXLRG)           -4.29115                0          14.7057

PROFIT                       1.33227e-015                1             +INF

 

In our example adding the line

 

rngrestart rngfile.gms

 

to the options file (rangeinc.gms) causes the file rngfile.gms to be generated that contains the ranging results in parameters.  These parameters are named with the variable and equation names with the letters RNG appended.  They have the same basic set dependency but with an additional set (RNGLIM) added.  That set is assumed to be defined by the user and has the elements lo and up for the upper and lower ranges.  In this case the file looks like

 

PARAMETER  OBJTRNG(RNGLIM) /

LO -INF

UP +INF

/;

PARAMETER  AVAILABLERNG(RESOURCE,RNGLIM) /

SMLLATHE.LO          95.62037037

SMLLATHE.UP          151.3333333

LRGLATHE.LO          83.92857143

LRGLATHE.UP          112.7045827

CARVER.LO          103.0926264

CARVER.UP +INF

LABOR.LO          97.93170732

LABOR.UP          175.4526316

/;

PARAMETER  PRODUCTIONRNG(PROCESS,RNGLIM) /

FUNCTNORM.LO         -3.925065963

FUNCTNORM.UP          27.84210526

FUNCTMXSML.LO -INF

FUNCTMXSML.UP          11.29905545

FUNCTMXLRG.LO -INF

FUNCTMXLRG.UP          4.079341865

FANCYNORM.LO         -4.971748151

FANCYNORM.UP          4.422993062

FANCYMXSML.LO -INF

FANCYMXSML.UP            8.3968312

FANCYMXLRG.LO         -4.291153846

FANCYMXLRG.UP          14.70565635

/;

PARAMETER  PROFITRNG(RNGLIM) /

LO      1.33226763e-015

UP +INF

/;

Notes:

The cost ranges for the variables for all but the variable maximized will always be centered on zero.  This occurs because the model is of the form
MaxZ + 0X

 Z – CX =0

 AX < b

 

 as discussed in the Quick Start Tutorial chapter.

The parameter file of ranging results may be included immediately in the program using the GAMS to GAMS calling procedure as discussed in the Links to Other Programs Including Spreadsheets chapter or as implemented below (rangeinc.gms , incmyranges.gms)

 

MODEL RESALLOC /ALL/;

 option lp=cplex;

 FILE  OPT   Cplex option file  / cplex.OPT /;

 PUT OPT;

$setglobal filename rngfile.gms

 PUT 'objrng all '/

     'rhsrng all '/

     'rngrestart %filename%'/;

 PUTCLOSE OPT;

 resalloc.optfile=1;

 resalloc.dictfile=4;

 SOLVE RESALLOC USING LP MAXIMIZING PROFIT;

 

Set rnglim /lo,up/;

PARAMETER  OBJTRNG(RNGLIM)

PARAMETER  AVAILABLERNG(RESOURCE,RNGLIM)

PARAMETER  PRODUCTIONRNG(PROCESS,RNGLIM)

PARAMETER  PROFITRNG(RNGLIM) ;

execute_unload 'passtorange.gdx',resource,process,rnglim;

execute 'GAMS incmyranges --filename=%filename%'

execute_load 'passtorange.gdx',OBJTRNG,

                               AVAILABLERNG,

                               PRODUCTIONRNG,

                               PROFITRNG;

 

 where a couple of tricks are used

the file name with the ranges are passed using a control variable established with a setglobal, referenced with %varnam% and the – command line parameter as discussed in the Conditional Compilation chapter.
The sets defining the items are unloaded into a GDX file for inclusion into the GAMS program we will call to create a GDX file of results.  Use of GDX commands is discussed in the Using GAMS Data Exchange or GDX Files chapter.
GAMS is executed and the program executed is as follows

set resource,

    process,

    rnglim;

$gdxin passtorange.gdx

$Load resource process rnglim

$include "%filename%"

execute_unload 'passtorange.gdx',OBJTRNG,

                               AVAILABLERNG,

                               PRODUCTIONRNG,

                               PROFITRNG;

 

wherefilename is passed though the – parameter in the execution

the names of the range containing parameters must be known and the appropriate unload commands issued.

 

The resultant range containing parameter names are loaded in.
In a more complex model one may wish to only range parts of the model as illustrated by the option file below that is implemented in the context of the file agreste.gms by the file rangag.gms.

objrng xcrop,xlive,sales

rhsrng labc,landb