transport_class.Transport Class Reference

Pulic Methods

def __init__ (self, ws)
 
def get_model_source (self)
 
def run (self, checkpoint=None, output=None)
 

Public Attributes

 opt
 
 i
 
 j
 
 a
 
 b
 
 d
 
 f
 
 x
 
 z
 

Detailed Description

Definition at line 10 of file transport_class.py.

Constructors

◆ __init__()

def transport_class.Transport.__init__ (   self,
  ws 
)

Definition at line 12 of file transport_class.py.

References cutstock_class.Cutstock._ws, and transport_class.Transport._ws.

12 def __init__(self, ws):
13
14 self._ws = ws
15 self.opt = ws.add_options()
16
17 self._dbin1 = ws.add_database(in_model_name = "dbIn1")
18 self._dbin2 = ws.add_database(in_model_name = "dbIn2")
19
20 self.opt.solvelink = SolveLink.LoadLibrary
21 self.opt.all_model_types = "Cplex"
22 self.opt.defines["dbOut1"] = "dbOut1"
23
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")
30 self.x = None
31 self.z = None
32
33
34
35 self._job = ws.add_job_from_string(self.get_model_source())
36

Methods

◆ get_model_source()

def transport_class.Transport.get_model_source (   self)

Definition at line 37 of file transport_class.py.

37 def get_model_source(self):
38 return '''
39 Sets
40 i canning plants
41 j markets
42
43 Parameters
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;
48
49$if not set dbIn1 $abort 'no file name for in-database 1 file provided'
50$gdxin %dbIn1%
51$load i j a b d
52
53$if not set dbIn2 $abort 'no file name for in-database 2 file provided'
54$gdxin %dbIn2%
55$load f
56$gdxin
57
58 Parameter c(i,j) transport cost in thousands of dollars per case ;
59
60 c(i,j) = f * d(i,j) / 1000 ;
61
62 Variables
63 x(i,j) shipment quantities in cases
64 z total transportation costs in thousands of dollars ;
65
66 Positive Variable x ;
67
68 Equations
69 cost define objective function
70 supply(i) observe supply limit at plant i
71 demand(j) satisfy demand at market j ;
72
73 cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ;
74
75 supply(i) .. sum(j, x(i,j)) =l= a(i) ;
76
77 demand(j) .. sum(i, x(i,j)) =g= b(j) ;
78
79 Model transport /all/ ;
80
81 Solve transport using lp minimizing z ;
82
83$if not set dbOut1 $abort 'no file name for out-database 1 file provided'
84 execute_unload '%dbOut1%', x, z;
85'''
86

◆ run()

def transport_class.Transport.run (   self,
  checkpoint = None,
  output = None 
)

Definition at line 87 of file transport_class.py.

References transport_class.Transport._dbin1, transport_class.Transport._dbin2, transport_class.Transport._dbout1, cutstock_class.Cutstock._job, transport_class.Transport._job, cutstock_class.Cutstock._ws, transport_class.Transport._ws, cutstock_class.Cutstock.opt, transport_class.Transport.opt, transport_class.Transport.x, and transport_class.Transport.z.

87 def run(self, checkpoint=None, output=None):
88 self._job.run(self.opt, checkpoint, output, False, [self._dbin1, self._dbin2])
89
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")
93

Member Data Documentation

◆ a

transport_class.Transport.a

Definition at line 26 of file transport_class.py.

◆ b

transport_class.Transport.b

Definition at line 27 of file transport_class.py.

◆ d

transport_class.Transport.d

Definition at line 28 of file transport_class.py.

◆ f

transport_class.Transport.f

Definition at line 29 of file transport_class.py.

◆ i

transport_class.Transport.i

Definition at line 24 of file transport_class.py.

◆ j

transport_class.Transport.j

Definition at line 25 of file transport_class.py.

◆ opt

transport_class.Transport.opt

Definition at line 15 of file transport_class.py.

Referenced by transport_class.Transport.run().

◆ x

transport_class.Transport.x

Definition at line 30 of file transport_class.py.

Referenced by transport_class.Transport.run().

◆ z

transport_class.Transport.z

Definition at line 31 of file transport_class.py.

Referenced by transport_class.Transport.run().