1function transport_gdx(varargin)
3 % check workspace info from arguments
5 wsInfo = gams.control.WorkspaceInfo();
6 wsInfo.systemDirectory = varargin{1};
7 ws = gams.control.Workspace(wsInfo);
9 ws = gams.control.Workspace();
13 plants = {
'Seattle',
'San-Diego'};
14 markets = {
'New-York',
'Chicago',
'Topeka'};
15 capacity = containers.Map();
16 capacity(
'Seattle') = 350;
17 capacity(
'San-Diego') = 600;
18 demand = containers.Map();
19 demand(
'New-York') = 325;
20 demand(
'Chicago') = 300;
21 demand(
'Topeka') = 275;
22 distance = containers.Map();
23 distance(
'Seattle.New-York') = 2.5;
24 distance(
'Seattle.Chicago') = 1.7;
25 distance(
'Seattle.Topeka') = 1.8;
26 distance(
'San-Diego.New-York') = 2.5;
27 distance(
'San-Diego.Chicago') = 1.8;
28 distance(
'San-Diego.Topeka') = 1.4;
30 % add a database and add input data into the database
31 db = ws.addDatabase();
33 i = db.addSet(
'i', 1,
'canning plants');
38 j = db.addSet(
'j', 1,
'markets');
43 a = db.addParameter(
'a',
'capacity of plant i in cases', i);
45 rec = a.addRecord(p{1});
46 rec.value = capacity(p{1});
49 b = db.addParameter(
'b',
'demand at market j in cases', j);
51 rec = b.addRecord(m{1});
52 rec.value = demand(m{1});
55 d = db.addParameter(
'd',
'distance in thousands of miles', i, j);
58 rec = d.addRecord(p{1}, m{1});
59 rec.value = distance([p{1},
'.', m{1}]);
63 f = db.addParameter(
'f',
'freight in dollars per case per thousand miles');
67 % export the Database to a GDX file with name
'data.gdx' located in the
'workingDirectory' of the Workspace
68 db.export(
'data.gdx');
70 % add a
new Database and initialize it from the GDX file just created
71 gdxdb = ws.addDatabaseFromGDX(
'data.gdx');
73 % read symbol data from the database and fill them into Matlab data structures
75 for rec = gdxdb.getSet(
'i').records
76 gdxPlants{end+1} = rec{1}.key(1);
80 for rec = gdxdb.getSet(
'j').records
81 gdxMarkets{end+1} = rec{1}.key(1);
84 gdxCapacity = containers.Map();
85 for rec = gdxdb.getParameter(
'a').records
86 gdxCapacity(rec{1}.key(1)) = rec{1}.value;
89 gdxDemand = containers.Map();
90 for rec = gdxdb.getParameter(
'b').records
91 gdxDemand(rec{1}.key(1)) = rec{1}.value;
94 gdxDistance = containers.Map();
95 for rec = gdxdb.getParameter(
'd').records
96 gdxDistance([rec{1}.key(1),
'.', rec{1}.key(2)]) = rec{1}.value;
99 gdxFreight = gdxdb.getParameter(
'f').record.value;
101 % print out data read from GDX file
102 fprintf(
'Data read from data.gdx\n');
103 fprintf(
'Set i: %s\n', gdxdb.getSet(
'i').text);
105 fprintf(
' %s\n', p{1});
108 fprintf(
'Set j: %s\n', gdxdb.getSet(
'j').text);
110 fprintf(
' %s\n', m{1});
113 fprintf(
'Parameter a: %s\n', gdxdb.getParameter(
'a').text);
114 for a = keys(gdxCapacity)
115 fprintf(
' %s: %g\n', a{1}, gdxCapacity(a{1}));
118 fprintf(
'Parameter b: %s\n', gdxdb.getParameter(
'b').text);
119 for b = keys(gdxDemand)
120 fprintf(
' %s: %g\n', b{1}, gdxDemand(b{1}));
123 fprintf(
'Parameter d: %s\n', gdxdb.getParameter(
'd').text);
124 for d = keys(gdxDistance)
125 fprintf(
' %s: %g\n', d{1}, gdxDistance(d{1}));
128 fprintf(
'Scalar f: %s\n %g\n', gdxdb.getParameter(
'f').text, gdxFreight);