14 i canning plants / seattle, san-diego /
15 j markets / new-york, chicago, topeka / ;
19 a(i) capacity of plant i in cases
23 b(j) demand at market j in cases
28 Table d(i,j) distance in thousands of miles
29 new-york chicago topeka
31 san-diego 2.5 1.8 1.4 ;
33 Scalar f freight in dollars per case per thousand miles /90/ ; '''
43 a(i) capacity of plant i in cases
44 b(j) demand at market j in cases
45 d(i,j) distance in thousands of miles
46 Scalar f freight in dollars per case per thousand miles;
48 $if not set incname $abort 'no include file name for data file provided'
51 Parameter c(i,j) transport cost in thousands of dollars per case ;
53 c(i,j) = f * d(i,j) / 1000 ;
56 x(i,j) shipment quantities in cases
57 z total transportation costs in thousands of dollars ;
62 cost define objective function
63 supply(i) observe supply limit at plant i
64 demand(j) satisfy demand at market j ;
66 cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ;
68 supply(i) .. sum(j, x(i,j)) =l= a(i) ;
70 demand(j) .. sum(i, x(i,j)) =g= b(j) ;
72 Model transport /all/ ;
74 Solve transport using lp minimizing z ;
76 Display x.l, x.m ; '''
79 if __name__ ==
"__main__":
81 ws = GamsWorkspace(system_directory = sys.argv[1])
85 file = open(os.path.join(ws.working_directory,
"tdata.gms"),
"w")
90 opt = ws.add_options()
91 opt.defines[
"incname"] =
"tdata"
93 for rec
in t2.out_db[
"x"]:
94 print(
"x(" + rec.key(0) +
"," + rec.key(1) +
"): level=" + str(rec.level) +
" marginal=" + str(rec.marginal))