Pulic Methods

def __init__ (self)
 
def solve (self, mult)
 

Static Public Member Functions

def get_model_text ()
 

Static Public Attributes

 ws = None
 

Detailed Description

Definition at line 13 of file transport14.py.

Constructors

◆ __init__()

def transport14.Optimizer.__init__ (   self)

Definition at line 16 of file transport14.py.

16 def __init__(self):
17 if Optimizer.ws == None:
18 if len(sys.argv) > 1:
19 Optimizer.ws = GamsWorkspace(system_directory = sys.argv[1])
20 else:
21 Optimizer.ws = GamsWorkspace()
22

Methods

◆ get_model_text()

def transport14.Optimizer.get_model_text ( )
static

Definition at line 35 of file transport14.py.

35 def get_model_text():
36 return '''
37 Sets
38 i canning plants / seattle, san-diego /
39 j markets / new-york, chicago, topeka / ;
40
41 Parameters
42
43 a(i) capacity of plant i in cases
44 / seattle 350
45 san-diego 600 /
46
47 b(j) demand at market j in cases
48 / new-york 325
49 chicago 300
50 topeka 275 / ;
51
52 Table d(i,j) distance in thousands of miles
53 new-york chicago topeka
54 seattle 2.5 1.7 1.8
55 san-diego 2.5 1.8 1.4 ;
56
57 Scalar f freight in dollars per case per thousand miles;
58
59$if not set gdxincname $abort 'no include file name for data file provided'
60$gdxin %gdxincname%
61$load f
62$gdxin
63
64 Parameter c(i,j) transport cost in thousands of dollars per case ;
65
66 c(i,j) = f * d(i,j) / 1000 ;
67
68 Variables
69 x(i,j) shipment quantities in cases
70 z total transportation costs in thousands of dollars ;
71
72 Positive Variable x ;
73
74 Equations
75 cost define objective function
76 supply(i) observe supply limit at plant i
77 demand(j) satisfy demand at market j ;
78
79 cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ;
80
81 supply(i) .. sum(j, x(i,j)) =l= a(i) ;
82
83 demand(j) .. sum(i, x(i,j)) =g= b(j) ;
84
85 Model transport /all/ ;
86
87 Solve transport using lp minimizing z ;
88
89 Display x.l, x.m ; '''
90
91
def get_model_text()
Definition: warehouse.py:17

◆ solve()

def transport14.Optimizer.solve (   self,
  mult 
)

Definition at line 23 of file transport14.py.

23 def solve(self, mult):
24 db = Optimizer.ws.add_database()
25 f = db.add_parameter("f", 0, "freight in dollars per case per thousand miles")
26 f.add_record().value = 90 * mult
27 job = Optimizer.ws.add_job_from_string(Optimizer.get_model_text())
28 opt = Optimizer.ws.add_options()
29 opt.defines["gdxincname"] = db.name
30 job.run(opt,databases=db)
31
32 return job.out_db.get_variable("z").first_record().level
33

Member Data Documentation

◆ ws

transport14.Optimizer.ws = None
static

Definition at line 14 of file transport14.py.