Go to the documentation of this file.
8 from gams
import SolveLink
15 self.
opt = ws.add_options()
17 self.
_dbin1 = ws.add_database(in_model_name =
"dbIn1")
18 self.
_dbin2 = ws.add_database(in_model_name =
"dbIn2")
20 self.
opt.solvelink = SolveLink.LoadLibrary
21 self.
opt.all_model_types =
"Cplex"
22 self.
opt.defines[
"dbOut1"] =
"dbOut1"
24 self.
i = self.
_dbin1.add_set(
"i", 1,
"canning plants")
25 self.
j = self.
_dbin1.add_set(
"j", 1,
"markets")
26 self.
a = self.
_dbin1.add_parameter_dc(
"a", [self.
i],
"capacity of plant i in cases")
27 self.
b = self.
_dbin1.add_parameter_dc(
"b", [self.
j],
"demand at market j in cases")
28 self.
d = self.
_dbin1.add_parameter_dc(
"d", [self.
i, self.
j],
"distance in thousands of miles")
29 self.
f = self.
_dbin2.add_parameter(
"f", 0,
"freight in dollars per case per thousand miles")
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 dbIn1 $abort 'no file name for in-database 1 file provided'
53 $if not set dbIn2 $abort 'no file name for in-database 2 file provided'
58 Parameter c(i,j) transport cost in thousands of dollars per case ;
60 c(i,j) = f * d(i,j) / 1000 ;
63 x(i,j) shipment quantities in cases
64 z total transportation costs in thousands of dollars ;
69 cost define objective function
70 supply(i) observe supply limit at plant i
71 demand(j) satisfy demand at market j ;
73 cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ;
75 supply(i) .. sum(j, x(i,j)) =l= a(i) ;
77 demand(j) .. sum(i, x(i,j)) =g= b(j) ;
79 Model transport /all/ ;
81 Solve transport using lp minimizing z ;
83 $if not set dbOut1 $abort 'no file name for out-database 1 file provided'
84 execute_unload '%dbOut1%', x, z;
87 def run(self, checkpoint=None, output=None):
90 self.
_dbout1 = self.
_ws.add_database_from_gdx(self.
opt.defines[
"dbOut1"] +
".gdx")
91 self.
x = self.
_dbout1.get_variable(
"x")
92 self.
z = self.
_dbout1.get_variable(
"z")
def run(self, checkpoint=None, output=None)
def get_model_source(self)