1function transport7(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 'Scalar bmult demand multiplier /1/; '
35 'Parameter c(i,j) transport cost in thousands of dollars per case ; '
36 ' c(i,j) = f * d(i,j) / 1000 ; '
39 ' x(i,j) shipment quantities in cases '
40 ' z total transportation costs in thousands of dollars ; '
42 'Positive Variable x ; '
45 ' cost define objective function '
46 ' supply(i) observe supply limit at plant i '
47 ' demand(j) satisfy demand at market j ; '
49 ' cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ; '
51 ' supply(i) .. sum(j, x(i,j)) =l= a(i) ; '
53 ' demand(j) .. sum(i, x(i,j)) =g= bmult*b(j) ; '
55 'Model transport /all/ ; '
57 model = sprintf(
'%s\n', model{:});
60 cp = ws.addCheckpoint();
62 % initialize a checkpoint by running a job
63 t7 = ws.addJobFromString(model);
66 % create a ModelInstance and solve it multiple times with different scalar bmult
67 mi = cp.addModelInstance();
68 bmult = mi.syncDB.addParameter(
'bmult',
'demand multiplier');
69 opt = ws.addOptions();
70 opt.setAllModelTypes(
'cplex');
72 % instantiate the ModelInstance and pass a model definition and Modifier to declare bmult
mutable
73 mi.instantiate(
'transport use lp min z', opt, gams.control.Modifier(bmult));
75 rec = bmult.addRecord();
77 bmultlist = [0.6, 0.7 , 0.8, 0.9, 1.0, 1.1, 1.2, 1.3];
79 for i = 1:numel(bmultlist)
80 rec.value = bmultlist(i);
83 fprintf(
'Scenario bmult=%f:\n', bmultlist(i));
84 fprintf(
' Modelstatus: %s\n', mi.modelStatus.select);
85 fprintf(
' Solvestatus: %s\n', mi.solveStatus.select);
86 fprintf(
' Obj: %f\n', mi.syncDB.getVariable(
'z').record.level);
92 % create a ModelInstance and solve it with single links in the network blocked
93 mi = cp.addModelInstance();
95 x = mi.syncDB.addVariable(
'x', 2, gams.control.globals.VarType.POSITIVE,
'');
96 xup = mi.syncDB.addParameter(
'xup', 2,
'upper bound on x');
98 % instantiate the ModelInstance and pass a model definition and Modifier to declare upper bound of X
mutable
99 mi.instantiate(
'transport use lp min z', gams.control.Modifier(x, gams.control.globals.UpdateAction.UPPER, xup));
101 for i = t7.outDB.getSet(
'i').records
102 for j = t7.outDB.getSet(
'j').records
104 keys = {i{1}.key(1), j{1}.key(1)};
105 rec = xup.addRecord(keys);
109 fprintf(
'Scenario link blocked: %s - %s\n', keys{:});
110 fprintf(
' Modelstatus: %s\n', mi.modelStatus.select);
111 fprintf(
' Solvestatus: %s\n', mi.solveStatus.select);
112 fprintf(
' Obj: %f\n', mi.syncDB.getVariable(
'z').record.level);
116 % clear ModelInstance
122 %
remove working directory
123 rmdir(ws.workingDirectory,
's');