9from gams
import GamsWorkspace
13 i 'canning plants' / seattle, san-diego /
14 j
'markets' / new-york, chicago, topeka /;
17 a(i)
'capacity of plant i in cases'
21 b(j)
'demand at market j in cases'
26Table d(i,j)
'distance in thousands of miles'
27 new-york chicago topeka
29 san-diego 2.5 1.8 1.4;
32 f
'freight in dollars per case per thousand miles' / 90 /
33 bmult
'demand multiplier' / 1 /;
35Parameter c(i,j)
'transport cost in thousands of dollars per case';
36c(i,j) = f*d(i,j)/1000;
39 x(i,j)
'shipment quantities in cases'
40 z
'total transportation costs in thousands of dollars';
45 cost
'define objective function'
46 supply(i)
'observe supply limit at plant i'
47 demand(j)
'satisfy demand at market j';
49cost.. z =e= sum((i,j), c(i,j)*x(i,j));
51supply(i).. sum(j, x(i,j)) =l= a(i);
53demand(j).. sum(i, x(i,j)) =g= bmult*b(j);
57Scalar ms
'model status', ss
'solve status';
60if __name__ == "__main__":
61 sys_dir = sys.argv[1] if len(sys.argv) > 1
else None
62 ws = GamsWorkspace(system_directory=sys_dir)
64 cp = ws.add_checkpoint()
67 job = ws.add_job_from_string(GAMS_MODEL)
68 job.run(checkpoint=cp)
70 bmult = [0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3]
74 job = ws.add_job_from_string(
75 f
"bmult={b}; solve transport min z use lp; ms=transport.modelstat; ss=transport.solvestat;",
79 print(f
"Scenario bmult={b}:")
80 print(f
" Modelstatus: {job.out_db['ms'].find_record().value}")
81 print(f
" Solvestatus: {job.out_db['ss'].find_record().value}")
82 print(f
" Obj: {job.out_db['z'].find_record().level}")