21 a(i) capacity of plant i in cases
22 b(j) demand at market j in cases
23 d(i,j) distance in thousands of miles
24 Scalar f freight in dollars per case per thousand miles;
26 $if not set gdxincname $abort 'no include file name for data file provided'
31 Parameter c(i,j) transport cost in thousands of dollars per case ;
33 c(i,j) = f * d(i,j) / 1000 ;
36 x(i,j) shipment quantities in cases
37 z total transportation costs in thousands of dollars ;
42 cost define objective function
43 supply(i) observe supply limit at plant i
44 demand(j) satisfy demand at market j ;
46 cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ;
48 supply(i) .. sum(j, x(i,j)) =l= a(i) ;
50 demand(j) .. sum(i, x(i,j)) =g= b(j) ;
52 Model transport /all/ ;
54 Solve transport using lp minimizing z ;
56 Display x.l, x.m ; '''
59 if __name__ ==
"__main__":
61 ws = GamsWorkspace(system_directory = sys.argv[1])
65 plants = np.array([[
"Seattle",
""], [
"San-Diego",
""]])
66 markets = np.array([[
"New-York",
""], [
"Chicago",
""], [
"Topeka",
""]])
67 capacity = np.array([[
"Seattle", 350.0], [
"San-Diego", 600.0]], dtype=object)
68 demand = np.array([[
"New-York", 325.0], [
"Chicago", 300.0], [
"Topeka", 275.0]], dtype=object)
69 distance = np.array([[
"Seattle",
"New-York", 2.5],
70 [
"Seattle",
"Chicago", 1.7],
71 [
"Seattle",
"Topeka", 1.8],
72 [
"San-Diego",
"New-York", 2.5],
73 [
"San-Diego",
"Chicago", 1.8],
74 [
"San-Diego",
"Topeka", 1.4]], dtype=object)
76 db = ws.add_database()
77 g2np = gams2numpy.Gams2Numpy(ws.system_directory)
79 i = db.add_set(
"i", 1,
"canning plants")
80 g2np.gmdFillSymbolStr(db, i, plants)
82 j = db.add_set(
"j", 1,
"markets")
83 g2np.gmdFillSymbolStr(db, j, markets)
85 a = db.add_parameter_dc(
"a", [i],
"capacity of plant i in cases")
86 g2np.gmdFillSymbolStr(db, a, capacity)
88 b = db.add_parameter_dc(
"b", [j],
"demand at market j in cases")
89 g2np.gmdFillSymbolStr(db, b, demand)
91 d = db.add_parameter_dc(
"d", [i,j],
"distance in thousands of miles")
92 g2np.gmdFillSymbolStr(db, d, distance)
94 f = db.add_parameter(
"f", 0,
"freight in dollars per case per thousand miles")
95 g2np.gmdFillSymbolStr(db, f, np.array([[90]]))
98 opt = ws.add_options()
100 opt.defines[
"gdxincname"] = db.name
101 opt.all_model_types =
"xpress"
103 job.run(opt, databases = db)
104 for rec
in g2np.gmdReadSymbolStr(job.out_db,
"x"):
105 print(
"x({},{}): level={}, marginal={}".format(*rec[0:-3]))