$Title Transport LP with non-indexed GDX data interface
$ontext
We solve the transport model in GAMS. Data input and output are both done
using standard (i.e. non-indexed) GDX files. In this example, the input
for this model was created in Matlab and the output will go back to
Matlab, but the format of the GDX files is not specific to Matlab at
all.
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_tr1_run.m if file trdat1.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 trdat1.gdx
$ call %WHICH% matlab
$ ifThen.echeck errorLevel 1
$ clearError
$ abort.noerror 'Matlab is not available!';
$ else.echeck
$ call =matlab -r "cd %GAMS.cdir%;gdxmrw_tr1_run,exit" -logfile gdxmrw_tr1_run.log -nosplash -nodisplay -nojvm %WAIT%
$ endIf.echeck
$endIf
$if NOT exist trdat1.gdx $abort File trdat1.gdx does not exist: did you run gdxmrw_tr1_run from Matlab to create it?
$gdxin trdat1
$load i j 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;
modelStat = transport.modelstat;
solveStat = transport.solvestat;
execute_unload 'trsol1', modelStat, solveStat, z, x;