gdxmrw_tr2.gms : Transport LP with indexed GDX data interface

Description

We solve the transport model in GAMS.  Data input and output are both done
using indexed GDX files.

Intended use: call Matlab in batch-mode

Contributor: Steve


Category : GAMS Data Utilities library


Main file : gdxmrw_tr2.gms   includes :  trdata.m  gdxmrw_tr2.gms  gdxmrw_tr2_run.m

$Title Transport LP with indexed GDX data interface

$ontext
We solve the transport model in GAMS.  Data input and output are both done
using indexed GDX files.

Intended use: call Matlab in batch-mode

Contributor: Steve

$offtext

sets
  i   'canning plants'
  j   'markets'
  ;
parameters
  a(i)   'capacity of plant i in cases'
  b(j)   'demand at market j in cases'
  d(i,j) 'distance in thousands of miles'
  f      'freight in dollars per case per thousand miles'
  c(i,j) 'transport cost in thousands of dollars per case'
  ;
*Try to run gdxmrw_tr2_run.m if file trdat2.gdx does not exist
$set WAIT
$set WHICH which
$if not %system.filesys% == UNIX $set WAIT -wait
$if not %system.filesys% == UNIX $set WHICH where
$ifThen NOT exist trdat2.gdx
$ call %WHICH% matlab
$ ifThen.echeck errorLevel 1
$  clearError
$  abort.noerror 'Matlab is not available!';
$ else.echeck
$  call =matlab -r "cd %GAMS.cdir%;gdxmrw_tr2_run,exit" -logfile gdxmrw_tr2_run.log -nosplash -nodisplay -nojvm %WAIT%
$ endIf.echeck
$endIf
$if NOT exist trdat2.gdx  $abort File trdat2.gdx does not exist: did you run gdxmrw_tr2_run from Matlab to create it?
$gdxin trdat2
$loadIdx a b d f
$gdxin

c(i,j) = f * d(i,j) / 1000 ;

positive variables  x(i,j)  shipment quantities in cases;
free variable       z       total transportation costs in thousands of dollars;

equations
  cost        define objective function
  supply(i)   observe supply limit at plant i
  demand(j)   satisfy demand at market j
  ;
cost..        z  =e=  sum{(i,j), c(i,j)*x(i,j)};
supply(i)..   sum{j, x(i,j)}  =l=  a(i);
demand(j)..   sum{i, x(i,j)}  =g=  b(j);

model transport /all/;
solve transport using lp minimizing z;

scalars modelStat, solveStat, zz;
parameter xx(i,j);
modelStat = transport.modelstat;
solveStat = transport.solvestat;
zz = z.l;
xx(i,j) = x.l(i,j);

execute_unloadIdx 'trsol2', modelStat, solveStat, zz, xx;