1function transport3(varargin)
4 workingDirectory = fullfile(pwd,
'transport3');
5 mkdir(workingDirectory);
8 wsInfo = gams.control.WorkspaceInfo();
9 wsInfo.workingDirectory = workingDirectory;
11 wsInfo.systemDirectory = varargin{1};
13 ws = gams.control.Workspace(wsInfo);
17 ' i canning plants / seattle, san-diego / '
18 ' j markets / new-york, chicago, topeka / ; '
21 ' a(i) capacity of plant i in cases '
25 ' b(j) demand at market j in cases '
30 'Table d(i,j) distance in thousands of miles '
31 ' new-york chicago topeka '
32 ' seattle 2.5 1.7 1.8 '
33 ' san-diego 2.5 1.8 1.4 ; '
35 'Scalar f freight in dollars per case per thousand miles /90/ ;'};
36 data = sprintf(
'%s\n', data{:});
44 ' a(i) capacity of plant i in cases '
45 ' b(j) demand at market j in cases '
46 ' d(i,j) distance in thousands of miles '
47 ' Scalar f freight in dollars per case per thousand miles; '
49 '$if not set gdxincname $abort ''no include file name for data file provided'''
50 '$gdxin %gdxincname% '
54 ' Parameter c(i,j) transport cost in thousands of dollars per case ; '
56 ' c(i,j) = f * d(i,j) / 1000 ; '
59 ' x(i,j) shipment quantities in cases '
60 ' z total transportation costs in thousands of dollars ; '
62 ' Positive Variable x ; '
66 ' cost define objective function '
67 ' supply(i) observe supply limit at plant i '
68 ' demand(j) satisfy demand at market j ; '
70 ' cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ; '
72 ' supply(i) .. sum(j, x(i,j)) =l= a(i) ; '
74 ' demand(j) .. sum(i, x(i,j)) =g= b(j) ; '
76 ' Model transport /all/ ; '
78 ' Solve transport using lp minimizing z ; '
80 ' Display x.l, x.m ; '};
81 model = sprintf(
'%s\n', model{:});
83 % create and run a job from a data file, then explicitly export to a GDX file
84 t3 = ws.addJobFromString(data);
86 t3.outDB.export(fullfile(ws.workingDirectory,
'tdata.gdx'));
91 % run a job
using an instance of Options that defines the data include file
92 t3 = ws.addJobFromString(model);
93 opt = ws.addOptions();
94 opt.defines(
'gdxincname',
'tdata');
97 % retrieve Variable
'x' from Job
's output databases
98 for x = t3.outDB.getVariable('x
').records
99 fprintf('x(%s,%s): level=%g marginal=%g\n
', x{1}.keys{:}, x{1}.level, x{1}.marginal);
105 % similar to the previous run but without exporting database into a file
106 t3a = ws.addJobFromString(data);
107 t3b = ws.addJobFromString(model);
108 opt = ws.addOptions();
110 opt.defines('gdxincname
', t3a.outDB.name);
111 t3b.run(opt, t3a.outDB);
113 % retrieve Variable 'x
' from Job's output databases
114 for x = t3b.outDB.getVariable(
'x').records
115 fprintf(
'x(%s,%s): level=%g marginal=%g\n', x{1}.keys{:}, x{1}.level, x{1}.marginal);
118 % clear option and database
123 %
remove working directory
124 rmdir(ws.workingDirectory,
's');