9 from gams
import GamsWorkspace
16 i canning plants / seattle, san-diego /
17 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
33 san-diego 2.5 1.8 1.4 ;
35 Scalar f freight in dollars per case per thousand miles /90/ ; '''
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'
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 ;
65 cost define objective function
66 supply(i) observe supply limit at plant i
67 demand(j) satisfy demand at market j ;
69 cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ;
71 supply(i) .. sum(j, x(i,j)) =l= a(i) ;
73 demand(j) .. sum(i, x(i,j)) =g= b(j) ;
75 Model transport /all/ ;
77 Solve transport using lp minimizing z ;
79 Display x.l, x.m ; '''
82 if __name__ ==
"__main__":
84 ws = GamsWorkspace(system_directory = sys.argv[1])
90 t3.out_db.export(os.path.join(ws.working_directory,
"tdata.gdx"))
93 opt = ws.add_options()
94 opt.defines[
"gdxincname"] =
"tdata"
95 opt.all_model_types =
"xpress"
97 for rec
in t3.out_db[
"x"]:
98 print(
"x(" + rec.key(0) +
"," + rec.key(1) +
"): level=" + str(rec.level) +
" marginal=" + str(rec.marginal))
103 opt.defines[
"gdxincname"] = t3a.out_db.name
104 t3b.run(opt, databases=t3a.out_db)
105 for rec
in t3b.out_db[
"x"]:
106 print(
"x(" + rec.key(0) +
"," + rec.key(1) +
"): level=" + str(rec.level) +
" marginal=" + str(rec.marginal))