Inheritance diagram for transport14.Optimizer:

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 14 of file transport14.py.

Constructors

◆ __init__()

def transport14.Optimizer.__init__ (   self)

Definition at line 17 of file transport14.py.

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

Methods

◆ get_model_text()

def transport14.Optimizer.get_model_text ( )
static

Definition at line 36 of file transport14.py.

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

◆ solve()

def transport14.Optimizer.solve (   self,
  mult 
)

Definition at line 24 of file transport14.py.

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

Member Data Documentation

◆ ws

transport14.Optimizer.ws = None
static

Definition at line 15 of file transport14.py.