Go to the documentation of this file.
15 i(*) canning plants / /
19 a(i) capacity of plant i in cases / /
20 b(j) demand at market j in cases / /
21 d(i,j) distance in thousands of miles / /
22 Scalar f freight in dollars per case per thousand miles /0/;
24 Parameter c(i,j) transport cost in thousands of dollars per case ;
26 c(i,j) = f * d(i,j) / 1000 ;
29 x(i,j) shipment quantities in cases
30 z total transportation costs in thousands of dollars ;
35 cost define objective function
36 supply(i) observe supply limit at plant i
37 demand(j) satisfy demand at market j ;
39 cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ;
41 supply(i) .. sum(j, x(i,j)) =l= a(i) ;
43 demand(j) .. sum(i, x(i,j)) =g= b(j) ;
45 Model transport /all/ ;
47 Solve transport using lp minimizing z ; '''
51 $if not set gdxincname $abort 'no include file name for data file provided'
57 Display x.l, x.m ; '''
61 ws = GamsWorkspace(os.path.dirname(cp_file_name), sys.argv[1])
63 ws = GamsWorkspace(os.path.dirname(cp_file_name))
66 opt = ws.add_options()
68 opt.action = Action.CompileOnly
69 cp = ws.add_checkpoint(os.path.basename(cp_file_name))
74 if __name__ ==
"__main__":
77 w_dir = os.path.join(
".",
"tmp")
80 plants = [
"Seattle",
"San-Diego" ]
81 markets = [
"New-York",
"Chicago",
"Topeka" ]
82 capacity = {
"Seattle": 350.0,
"San-Diego": 600.0 }
83 demand = {
"New-York": 325.0,
"Chicago": 300.0,
"Topeka": 275.0 }
85 distance = { (
"Seattle",
"New-York") : 2.5,
86 (
"Seattle",
"Chicago") : 1.7,
87 (
"Seattle",
"Topeka") : 1.8,
88 (
"San-Diego",
"New-York") : 2.5,
89 (
"San-Diego",
"Chicago") : 1.8,
90 (
"San-Diego",
"Topeka") : 1.4
94 ws = GamsWorkspace(w_dir, sys.argv[1])
96 ws = GamsWorkspace(w_dir)
98 db = ws.add_database()
101 i = db.add_set(
"i", 1,
"canning plants")
105 j = db.add_set(
"j", 1,
"markets")
109 a = db.add_parameter_dc(
"a", [i],
"capacity of plant i in cases")
111 a.add_record(p).value = capacity[p]
113 b = db.add_parameter_dc(
"b", [j],
"demand at market j in cases")
115 b.add_record(m).value = demand[m]
117 d = db.add_parameter_dc(
"d", [i,j],
"distance in thousands of miles")
118 for k, v
in iter(distance.items()):
119 d.add_record(k).value = v
121 f = db.add_parameter(
"f", 0,
"freight in dollars per case per thousand miles")
122 f.add_record().value = 90
125 cp_base = ws.add_checkpoint(
"tbase")
127 opt = ws.add_options()
128 opt.defines[
"gdxincname"] = db.name
129 opt.all_model_types =
"xpress"
130 t4.run(opt, databases=db)
132 for rec
in t4.out_db[
"x"]:
133 print(
"x(" + rec.key(0) +
"," + rec.key(1) +
"): level=" + str(rec.level) +
" marginal=" + str(rec.marginal))
def get_base_model_text()
def create_save_restart(cp_file_name)