8from gams
import GamsWorkspace, SolveLink
16 a(i)
'capacity of plant i in cases'
17 b(j)
'demand at market j in cases'
18 d(i,j)
'distance in thousands of miles';
20Scalar f
'freight in dollars per case per thousand miles';
22$
if not set dbIn1 $abort
'no file name for in-database 1 file provided'
27$
if not set dbIn2 $abort
'no file name for in-database 2 file provided'
32Parameter c(i,j)
'transport cost in thousands of dollars per case';
33c(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';
46cost.. z =e= sum((i,j), c(i,j)*x(i,j));
48supply(i).. sum(j, x(i,j)) =l= a(i);
50demand(j).. sum(i, x(i,j)) =g= b(j);
54solve transport using lp minimizing z;
56$
if not set dbOut1 $abort
'no file name for out-database 1 file provided'
57execute_unload
'%dbOut1%', x, z;
63 self.
_ws = GamsWorkspace(system_directory=system_directory)
66 self.
_dbin1 = self.
_ws.add_database(in_model_name=
"dbIn1")
67 self.
_dbin2 = self.
_ws.add_database(in_model_name=
"dbIn2")
69 self.
opt.solvelink = SolveLink.LoadLibrary
70 self.
opt.all_model_types =
"Cplex"
71 self.
opt.defines[
"dbOut1"] =
"dbOut1"
73 self.
i = self.
_dbin1.add_set(
"i", 1,
"canning plants")
74 self.
j = self.
_dbin1.add_set(
"j", 1,
"markets")
76 "a", [self.
i],
"capacity of plant i in cases"
79 "b", [self.
j],
"demand at market j in cases"
82 "d", [self.
i, self.
j],
"distance in thousands of miles"
85 "f", 0,
"freight in dollars per case per thousand miles"
90 self.
_job = self.
_ws.add_job_from_string(GAMS_MODEL)
92 def run(self, checkpoint=None, output=None):
96 self.
opt.defines[
"dbOut1"] +
".gdx"
def __init__(self, system_directory)
def run(self, checkpoint=None, output=None)