sens01.gms : sensitivity / ranging test

Description

Tests GMS / GDX export of post-optimality sensitivity (or ranging) information
of solvers that support this feature.

Contributor: Renke Kuhlmann, October 2020


Small Model of Type : GAMS


Category : GAMS Test library


Main file : sens01.gms

$TITLE 'sensitivity / ranging test' (SENS01,SEQ=833)
$if not '%GAMS.lp%' == '' $set solver %GAMS.lp%
$if not set solver        $set solver cplex
$onText
Tests GMS / GDX export of post-optimality sensitivity (or ranging) information
of solvers that support this feature.

Contributor: Renke Kuhlmann, October 2020
$offText

$call gamslib -q 1
$include trnsport.gms

$ifThenI %solver% == gurobi
$echo sensitivity 1 > %solver%.opt
$elseIfI %solver% == cplex
$echo rhsrng all > %solver%.opt
$echo objrng all >> %solver%.opt
$echo bndrng all >> %solver%.opt
$else
$abort 'choose solver that supports sensitivity analysis';
$endIf

$call =gams trnsport lo=%GAMS.lo% solver=%solver% optfile=1

$call =grep -q "LOWER.*CURRENT.*UPPER" "trnsport.lst"
$if errorlevel 1 $abort 'problem with obj/rhsrng option in lst file';
$call =grep -q "cost.*-INF.*NA.*INF" "trnsport.lst"
$if errorlevel 1 $abort 'problem with obj/rhsrng option in lst file';
$call =grep -q "z.*-INF.*NA.*INF" "trnsport.lst"
$if errorlevel 1 $abort 'problem with obj/rhsrng option in lst file';

$ifThenI %solver% == gurobi
$echo sensitivity 1 > %solver%.opt
$echo rngrestart rng.gms >> %solver%.opt
$elseIfI %solver% == cplex
$echo rhsrng all > %solver%.opt
$echo objrng all >> %solver%.opt
$echo bndrng all >> %solver%.opt
$echo rngrestart rng.gms >> %solver%.opt
$else
$abort 'choose solver that supports sensitivity analysis';
$endIf

$call =gams trnsport lo=%GAMS.lo% solver=%solver% optfile=1

$ifThenI %solver% == gurobi
$echo sensitivity 1 > %solver%.opt
$echo rngrestart rng.gdx >> %solver%.opt
$elseIfI %solver% == cplex
$echo rhsrng all > %solver%.opt
$echo objrng all >> %solver%.opt
$echo bndrng all >> %solver%.opt
$echo rngrestart rng.gdx >> %solver%.opt
$else
$abort 'choose solver that supports sensitivity analysis';
$endIf

$call =gams trnsport lo=%GAMS.lo% solver=%solver% optfile=1

Set RNGLIM / LO, CUR, UP /;

$include rng.gms

abort$(cost_RHSRNG('LO') <> -INF or cost_RHSRNG('UP') <> INF) 'false ranging value (cost_RHSRNG)';
abort$(sum(i, supply_RHSRNG(i,'LO') > supply_RHSRNG(i,'CUR') or supply_RHSRNG(i,'CUR') > supply_RHSRNG(i,'UP'))) 'false ranging value (supply_RHSRNG)';
abort$(sum(j, demand_RHSRNG(j,'LO') > demand_RHSRNG(j,'CUR') or demand_RHSRNG(j,'CUR') > demand_RHSRNG(j,'UP'))) 'false ranging value (demand_RHSRNG)';
abort$(sum((i,j), x_OBJRNG(i,j,'LO') > x_OBJRNG(i,j,'CUR') or x_OBJRNG(i,j,'CUR') > x_OBJRNG(i,j,'UP'))) 'false ranging value (x_OBJRNG)';
abort$(z_OBJRNG('LO') <> -INF or z_OBJRNG('UP') <> INF) 'false ranging value (z_OBJRNG)';
abort$(sum((i,j), x_LBRNG(i,j,'LO') > x_LBRNG(i,j,'CUR') or x_LBRNG(i,j,'CUR') > x_LBRNG(i,j,'UP'))) 'false ranging value (x_LBRNG)';
abort$(z_LBRNG('LO') <> -INF or z_LBRNG('UP') <> INF) 'false ranging value (z_LBRNG)';
abort$(sum((i,j), x_UBRNG(i,j,'LO') > x_UBRNG(i,j,'CUR') or x_UBRNG(i,j,'CUR') > x_UBRNG(i,j,'UP'))) 'false ranging value (x_UBRNG)';
abort$(z_UBRNG('LO') <> -INF or z_UBRNG('UP') <> INF) 'false ranging value (z_UBRNG)';

Parameter cost_RHSRNG2(RNGLIM), supply_RHSRNG2(i,RNGLIM), demand_RHSRNG2(j,RNGLIM),
    x_OBJRNG2(i,j,RNGLIM), z_OBJRNG2(RNGLIM), x_LBRNG2(i,j,RNGLIM), z_LBRNG2(RNGLIM),
    x_UBRNG2(i,j,RNGLIM), z_UBRNG2(RNGLIM);
cost_RHSRNG2(RNGLIM) = cost_RHSRNG(RNGLIM);
supply_RHSRNG2(i,RNGLIM) = supply_RHSRNG(i,RNGLIM);
demand_RHSRNG2(j,RNGLIM) = demand_RHSRNG(j,RNGLIM);
x_OBJRNG2(i,j,RNGLIM) = x_OBJRNG(i,j,RNGLIM);
z_OBJRNG2(RNGLIM) = z_OBJRNG(RNGLIM);
x_LBRNG2(i,j,RNGLIM) = x_LBRNG(i,j,RNGLIM);
z_LBRNG2(RNGLIM) = z_LBRNG(RNGLIM);
x_UBRNG2(i,j,RNGLIM) = x_UBRNG(i,j,RNGLIM);
z_UBRNG2(RNGLIM) = z_UBRNG(RNGLIM);
cost_RHSRNG(RNGLIM) = NA;
supply_RHSRNG(i,RNGLIM) = NA;
demand_RHSRNG(j,RNGLIM) = NA;
x_OBJRNG(i,j,RNGLIM) = NA;
z_OBJRNG(RNGLIM) = NA;
x_LBRNG(i,j,RNGLIM) = NA;
z_LBRNG(RNGLIM) = NA;
x_UBRNG(i,j,RNGLIM) = NA;
z_UBRNG(RNGLIM) = NA;

execute_load 'rng.gdx', cost_RHSRNG, supply_RHSRNG, demand_RHSRNG, x_OBJRNG, z_OBJRNG, x_LBRNG, z_LBRNG, x_UBRNG, z_UBRNG;

abort$(cost_RHSRNG('LO') <> -INF or cost_RHSRNG('UP') <> INF) 'false ranging value (cost_RHSRNG)';
abort$(sum(i, supply_RHSRNG(i,'LO') > supply_RHSRNG(i,'CUR') or supply_RHSRNG(i,'CUR') > supply_RHSRNG(i,'UP'))) 'false ranging value (supply_RHSRNG)';
abort$(sum(j, demand_RHSRNG(j,'LO') > demand_RHSRNG(j,'CUR') or demand_RHSRNG(j,'CUR') > demand_RHSRNG(j,'UP'))) 'false ranging value (demand_RHSRNG)';
abort$(sum((i,j), x_OBJRNG(i,j,'LO') > x_OBJRNG(i,j,'CUR') or x_OBJRNG(i,j,'CUR') > x_OBJRNG(i,j,'UP'))) 'false ranging value (x_OBJRNG)';
abort$(z_OBJRNG('LO') <> -INF or z_OBJRNG('UP') <> INF) 'false ranging value (z_OBJRNG)';
abort$(sum((i,j), x_LBRNG(i,j,'LO') > x_LBRNG(i,j,'CUR') or x_LBRNG(i,j,'CUR') > x_LBRNG(i,j,'UP'))) 'false ranging value (x_LBRNG)';
abort$(z_LBRNG('LO') <> -INF or z_LBRNG('UP') <> INF) 'false ranging value (z_LBRNG)';
abort$(sum((i,j), x_UBRNG(i,j,'LO') > x_UBRNG(i,j,'CUR') or x_UBRNG(i,j,'CUR') > x_UBRNG(i,j,'UP'))) 'false ranging value (x_UBRNG)';
abort$(z_UBRNG('LO') <> -INF or z_UBRNG('UP') <> INF) 'false ranging value (z_UBRNG)';

abort$(cost_RHSRNG('LO') <> cost_RHSRNG2('LO') or cost_RHSRNG('CUR') <> cost_RHSRNG2('CUR') or cost_RHSRNG('UP') <> cost_RHSRNG2('UP')) 'false ranging value (cost_RHSRNG)';
abort$(sum(i, supply_RHSRNG(i,'LO') <> supply_RHSRNG2(i,'LO') or supply_RHSRNG(i,'CUR') <> supply_RHSRNG2(i,'CUR') or supply_RHSRNG(i,'UP') <> supply_RHSRNG2(i,'UP'))) 'false ranging value (supply_RHSRNG)';
abort$(sum(j, demand_RHSRNG(j,'LO') <> demand_RHSRNG2(j,'LO') or demand_RHSRNG(j,'CUR') <> demand_RHSRNG2(j,'CUR') or demand_RHSRNG(j,'UP') <> demand_RHSRNG2(j,'UP'))) 'false ranging value (demand_RHSRNG)';
abort$(sum((i,j), x_OBJRNG(i,j,'LO') <> x_OBJRNG2(i,j,'LO') or x_OBJRNG(i,j,'CUR') <> x_OBJRNG2(i,j,'CUR') or x_OBJRNG(i,j,'UP') <> x_OBJRNG2(i,j,'UP'))) 'false ranging value (x_OBJRNG)';
abort$(z_OBJRNG('LO') <> z_OBJRNG2('LO') or z_OBJRNG('CUR') <> z_OBJRNG2('CUR') or z_OBJRNG('UP') <> z_OBJRNG2('UP')) 'false ranging value (z_OBJRNG)';
abort$(sum((i,j), x_LBRNG(i,j,'LO') <> x_LBRNG2(i,j,'LO') or x_LBRNG(i,j,'CUR') <> x_LBRNG2(i,j,'CUR') or x_LBRNG(i,j,'UP') <> x_LBRNG2(i,j,'UP'))) 'false ranging value (x_LBRNG)';
abort$(z_LBRNG('LO') <> z_LBRNG2('LO') or z_LBRNG('CUR') <> z_LBRNG2('CUR') or z_LBRNG('UP') <> z_LBRNG2('UP')) 'false ranging value (z_LBRNG)';
abort$(sum((i,j), x_UBRNG(i,j,'LO') <> x_UBRNG2(i,j,'LO') or x_UBRNG(i,j,'CUR') <> x_UBRNG2(i,j,'CUR') or x_UBRNG(i,j,'UP') <> x_UBRNG2(i,j,'UP'))) 'false ranging value (x_UBRNG)';
abort$(z_UBRNG('LO') <> z_UBRNG2('LO') or z_UBRNG('CUR') <> z_UBRNG2('CUR') or z_UBRNG('UP') <> z_UBRNG2('UP')) 'false ranging value (z_UBRNG)';