clear all

% read in the raw data for the trnsport model
trdata

Is.name = 'I';
Is.ts   = 'canning plants';
Is.val  = [ linspace(1,pN,pN) ]';
Is.type = 'set';
Is.form = 'sparse';
Is.uels = {'seattle', 'san-diego'};

Js.name = 'J';
Js.ts   = 'markets';
Js.val  = [ linspace(1,dN,dN) ]';
Js.type = 'set';
Js.form = 'sparse';
Js.uels = {'new-york', 'chicago', 'topeka'};

caps.name = 'a';
caps.ts   = 'capacity of plant i in cases';
caps.type = 'parameter';
caps.val = cap';
caps.form = 'full';
caps.dim = 1;
caps.uels = Is.uels;

dems.name = 'b';
dems.ts   = 'demand at market j in cases';
dems.type = 'parameter';
dems.val = dem';
dems.form = 'full';
dems.dim = 1;
dems.uels = Js.uels;

dists.name = 'd';
dists.ts   = 'distance in thousands of miles';
dists.type = 'parameter';
dists.val = distance;
dists.form = 'full';
dists.dim = 2;
dists.uels{1} = Is.uels;
dists.uels{2} = Js.uels;

fs.name = 'f';
fs.ts   = 'freight in dollars per case per thousand miles';
fs.type = 'parameter';
fs.val = f;
fs.form = 'full';
fs.dim = 0;

dataFile = 'tr5Data';
solFile = 'tr5Solu';

wgdx (dataFile, Is, Js, caps, dems, dists, fs);

gams_output = 'std';
gams([ 'tr45_mod --INFILE=', dataFile, ' --OUTFILE=', solFile ]);

% now get the outputs from the GDX file produced by the GAMS run
rs = struct('name','modelStat','form','full');
r = rgdx (solFile, rs);
modelstat = r.val;

rs.name = 'solveStat';
r = rgdx (solFile, rs);
solvestat = r.val;

rs.name = 'z';
rs.field = 'l';
r = rgdx (solFile, rs);
z = r.val;

rs.name = 'x';
rs.uels{1} = Is.uels;
rs.uels{2} = Js.uels;
r = rgdx (solFile, rs);
x = r.val;

fprintf('modelstat = %d (1 = optimal solution)\n', modelstat);
fprintf('solvestat = %d (1 = normal completion)\n\n', solvestat);
fprintf('optimal value = %g\n\n', z);
