1function transport2(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();
14 ' i canning plants / seattle, san-diego / '
15 ' j markets / new-york, chicago, topeka / ; '
18 ' a(i) capacity of plant i in cases '
22 ' b(j) demand at market j in cases '
27 'Table d(i,j) distance in thousands of miles '
28 ' new-york chicago topeka '
29 ' seattle 2.5 1.7 1.8 '
30 ' san-diego 2.5 1.8 1.4 ; '
32 'Scalar f freight in dollars per case per thousand miles /90/'};
33 data = sprintf(
'%s\n', data{:});
41 ' a(i) capacity of plant i in cases '
42 ' b(j) demand at market j in cases '
43 ' d(i,j) distance in thousands of miles '
44 'Scalar f freight in dollars per case per thousand miles; '
46 '$if not set incname $abort ''no include file name for data file provided'''
49 ' Parameter c(i,j) transport cost in thousands of dollars per case ; '
51 ' c(i,j) = f * d(i,j) / 1000 ; '
54 ' x(i,j) shipment quantities in cases '
55 ' z total transportation costs in thousands of dollars ; '
57 ' Positive Variable x ; '
61 ' cost define objective function '
62 ' supply(i) observe supply limit at plant i '
63 ' demand(j) satisfy demand at market j ; '
65 ' cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ; '
67 ' supply(i) .. sum(j, x(i,j)) =l= a(i) ; '
69 ' demand(j) .. sum(i, x(i,j)) =g= b(j) ; '
71 ' Model transport /all/ ; '
73 ' Solve transport using lp minimizing z ; '
77 model = sprintf(
'%s\n', model{:});
79 % write
'data' into file
'tdata.gms' under Workspace
's working directory
80 fid = fopen(fullfile(ws.workingDirectory, 'tdata.gms
'), 'w
');
84 % create Job 't2
' from the 'model
' string variable
85 t2 = ws.addJobFromString(model);
86 % create Option 'opt
' and define 'incname
' as 'tdata
'
87 opt = ws.addOptions();
88 opt.defines('incname
', 'tdata
');
89 % run Job 't2
' with Options 'opt
'
92 % retrieve Variable 'x
' from Job's output databases
93 for x = t2.outDB.getVariable(
'x').records
94 fprintf(
'x(%s,%s): level=%g marginal=%g\n', x{1}.keys{:}, x{1}.level, x{1}.marginal);
97 % clear option and database
101 %
remove working directory
102 rmdir(ws.workingDirectory,
's');