GAMS [ Home | Downloads | Documentation | Solvers | APIs | Tools | Model Libraries | Resources | Sales | Support | Contact Us | Search ]

transport_class.Transport Class Reference
Inheritance diagram for transport_class.Transport:

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 11 of file transport_class.py.

Constructors

◆ __init__()

def transport_class.Transport.__init__ (   self,
  ws 
)

Definition at line 13 of file transport_class.py.

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

13  def __init__(self, ws):
14 
15  self._ws = ws
16  self.opt = ws.add_options()
17 
18  self._dbin1 = ws.add_database(in_model_name = "dbIn1")
19  self._dbin2 = ws.add_database(in_model_name = "dbIn2")
20 
21  self.opt.solvelink = SolveLink.LoadLibrary
22  self.opt.all_model_types = "Cplex"
23  self.opt.defines["dbOut1"] = "dbOut1"
24 
25  self.i = self._dbin1.add_set("i", 1, "canning plants")
26  self.j = self._dbin1.add_set("j", 1, "markets")
27  self.a = self._dbin1.add_parameter_dc("a", [self.i], "capacity of plant i in cases")
28  self.b = self._dbin1.add_parameter_dc("b", [self.j], "demand at market j in cases")
29  self.d = self._dbin1.add_parameter_dc("d", [self.i, self.j], "distance in thousands of miles")
30  self.f = self._dbin2.add_parameter("f", 0, "freight in dollars per case per thousand miles")
31  self.x = None
32  self.z = None
33 
34 
35 
36  self._job = ws.add_job_from_string(self.get_model_source())
37 

Methods

◆ get_model_source()

def transport_class.Transport.get_model_source (   self)

Definition at line 38 of file transport_class.py.

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

◆ run()

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

Definition at line 88 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, gams::options::GamsOptions.opt, TransportSeq::Transport.opt, cutstock_class.Cutstock.opt, transport_class.Transport.opt, TransportSeq::Transport.x, transport_class.Transport.x, TransportSeq::Transport.z, and transport_class.Transport.z.

88  def run(self, checkpoint=None, output=None):
89  self._job.run(self.opt, checkpoint, output, False, [self._dbin1, self._dbin2])
90 
91  self._dbout1 = self._ws.add_database_from_gdx(self.opt.defines["dbOut1"] + ".gdx")
92  self.x = self._dbout1.get_variable("x")
93  self.z = self._dbout1.get_variable("z")
94 

Member Data Documentation

◆ a

transport_class.Transport.a

Definition at line 27 of file transport_class.py.

◆ b

transport_class.Transport.b

Definition at line 28 of file transport_class.py.

◆ d

transport_class.Transport.d

Definition at line 29 of file transport_class.py.

◆ f

transport_class.Transport.f

Definition at line 30 of file transport_class.py.

◆ i

transport_class.Transport.i

Definition at line 25 of file transport_class.py.

◆ j

transport_class.Transport.j

Definition at line 26 of file transport_class.py.

◆ opt

transport_class.Transport.opt

Definition at line 16 of file transport_class.py.

Referenced by transport_class.Transport.run().

◆ x

transport_class.Transport.x

Definition at line 31 of file transport_class.py.

Referenced by transport_class.Transport.run().

◆ z

transport_class.Transport.z

Definition at line 32 of file transport_class.py.

Referenced by transport_class.Transport.run().