transport12 Namespace Reference

Functions

def get_model_text ()
 
def guss_call (dict, mi, solve_statement, opt=None, mi_opt=None, output=None)
 

Variables

 ws = GamsWorkspace(system_directory = sys.argv[1])
 
 cp = ws.add_checkpoint()
 
 t12 = ws.add_job_from_string(get_model_text())
 
 checkpoint
 
 mi = cp.add_modelinstance()
 
list bmultlist = [ 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3 ]
 
 db = ws.add_database()
 
 scen = db.add_set("scen", 1, "")
 
 bmult = db.add_parameter_dc("bmultlist", [scen])
 
 zscen = db.add_parameter_dc("zscen", [scen])
 
int i = 0
 
 value
 
 dict = db.add_set("dict",3,"")
 
 mi2 = cp.add_modelinstance()
 
 db2 = ws.add_database()
 
 scen2 = db2.add_set("scen", 1, "")
 
 zscen2 = db2.add_parameter_dc("zscen", [scen2])
 
 xup = db2.add_parameter("xup", 3, "")
 
 dict2 = db2.add_set("dict", 3, "")
 
 output
 

Function Documentation

◆ get_model_text()

def transport12.get_model_text ( )

Definition at line 12 of file transport12.py.

12def get_model_text():
13 return '''
14 Sets
15 i canning plants / seattle, san-diego /
16 j markets / new-york, chicago, topeka / ;
17
18 Parameters
19
20 a(i) capacity of plant i in cases
21 / seattle 350
22 san-diego 600 /
23
24 b(j) demand at market j in cases
25 / new-york 325
26 chicago 300
27 topeka 275 / ;
28
29 Table d(i,j) distance in thousands of miles
30 new-york chicago topeka
31 seattle 2.5 1.7 1.8
32 san-diego 2.5 1.8 1.4 ;
33
34 Scalar f freight in dollars per case per thousand miles /90/ ;
35 Scalar bmult demand multiplier /1/;
36
37 Parameter c(i,j) transport cost in thousands of dollars per case ;
38
39 c(i,j) = f * d(i,j) / 1000 ;
40
41 Variables
42 x(i,j) shipment quantities in cases
43 z total transportation costs in thousands of dollars ;
44
45 Positive Variable x ;
46
47 Equations
48 cost define objective function
49 supply(i) observe supply limit at plant i
50 demand(j) satisfy demand at market j ;
51
52 cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ;
53
54 supply(i) .. sum(j, x(i,j)) =l= a(i) ;
55
56 demand(j) .. sum(i, x(i,j)) =g= bmult*b(j) ;
57
58 Model transport /all/ ;
59'''
60
61
62# Needs to be called with an uninstantiated GAMSModelInstance
def get_model_text()
Definition: warehouse.py:18

◆ guss_call()

def transport12.guss_call (   dict,
  mi,
  solve_statement,
  opt = None,
  mi_opt = None,
  output = None 
)

Definition at line 63 of file transport12.py.

References markowitz.key.

63def guss_call(dict, mi, solve_statement, opt = None, mi_opt = None, output=None):
64 modifier_list = []
65
66 if dict.dimension != 3:
67 raise GamsException("Dict needs to be 3-dimensional")
68
69 scen_name = dict.first_record((" ", "scenario", " ")).key(0)
70 scen_symbol = dict.database[scen_name]
71
72 for rec in dict:
73 if rec.key(1).lower() == "scenario":
74 continue
75 if rec.key(1).lower() == "param":
76 modifier_dim = dict.database[rec.key(2)].dimension - scen_symbol.dimension
77 if modifier_dim < 0:
78 raise GamsException("Dimension of " + rec.key(2) + " too small")
79 modifier_list.append((GamsModifier(mi.sync_db.add_parameter(rec.key(0), modifier_dim, "")), dict.database[rec.key(2)]))
80 elif (rec.key(1).lower() == "lower") or (rec.key(1).lower() == "upper") or (rec.key(1).lower() == "fixed"):
81 modifier_dim = dict.database[rec.key(2)].dimension - scen_symbol.dimension
82 if modifier_dim < 0:
83 raise GamsException("Dimension of " + rec.key(2) + " too small")
84 modifier_var = None
85 try:
86 modifier_var = dict.database[rec.key(0)]
87 except:
88 modifier_var = mi.sync_db.add_variable(rec.key(0), modifier_dim, VarType.Free, "")
89 if (rec.key(1).lower() == "lower"):
90 modifier_list.append((GamsModifier(modifier_var, UpdateAction.Lower, mi.sync_db.add_parameter(rec.key(2), modifier_dim, "")), dict.database[rec.key(2)]))
91 elif rec.key(1).lower() == "upper":
92 modifier_list.append((GamsModifier(modifier_var, UpdateAction.Upper, mi.sync_db.add_parameter(rec.key(2), modifier_dim, "")), dict.database[rec.key(2)]))
93 else: #fixed
94 modifier_list.append((GamsModifier(modifier_var, UpdateAction.Fixed, mi.sync_db.add_parameter(rec.key(2), modifier_dim, "")), dict.database[rec.key(2)]))
95 elif (rec.key(1).lower() == "level") or (rec.key(1).lower() == "marginal"):
96 # Check that parameter exists in GAMSDatabase, will throw an exception if not
97 x = dict.database[rec.key(2)]
98 else:
99 raise GamsException("Cannot handle UpdateAction " + rec.key(1))
100
101 ml = []
102 for tup in modifier_list:
103 ml.append(tup[0])
104 mi.instantiate(solve_statement, ml, opt)
105
106 out_list = []
107
108 for s in scen_symbol:
109 for tup in modifier_list:
110 p = None
111 pscen = tup[1]
112
113 if tup[0].data_symbol == None:
114 p = tup[0].gams_symbol
115 else:
116 p = tup[0].data_symbol
117
118 # Implemented SymbolUpdateType=BaseCase
119 p.clear()
120
121 rec = None
122 filter = [""]*pscen.dimension
123 for i in range(scen_symbol.dimension):
124 filter[i] = s.key(i)
125 for i in range (scen_symbol.dimension, pscen.dimension):
126 filter[i] = " "
127 try:
128 rec = pscen.first_record(filter)
129 except:
130 continue
131
132 while True:
133 my_keys = []
134 for i in range(p.dimension):
135 my_keys.append(rec.key(scen_symbol.dimension+i))
136 p.add_record(my_keys).value = rec.value
137 if not rec.move_next():
138 break
139
140 mi.solve(SymbolUpdateType.BaseCase, output, mi_opt)
141 if len(out_list) == 0:
142 for rec in dict:
143 if (rec.key(1).lower() == "level") or (rec.key(1).lower() == "marginal"):
144 out_list.append((mi.sync_db[rec.key(0)], dict.database[rec.key(2)], rec.key(1).lower()))
145
146 for tup in out_list:
147 my_keys = [""]*(scen_symbol.dimension + len(tup[0].first_record().keys))
148 for i in range(scen_symbol.dimension):
149 my_keys[i] = s.key(i)
150
151 if (tup[2] == "level") and (isinstance(tup[0],GamsVariable)):
152 for rec in tup[0]:
153 for i in range(len(rec.keys)):
154 my_keys[scen_symbol.dimension + i] = s.key(i)
155 tup[1].add_record(my_keys).value = rec.level
156 elif (tup[2] == "level") and (isinstance(tup[0], GamsEquation)):
157 for rec in tup[0]:
158 for i in range(len(rec.keys)):
159 my_keys[scen_symbol.dimension + i] = s.key(i)
160 tup[1].add_record(my_keys).value = rec.level
161 elif (tup[2] == "marginal") and (isinstance(tup[0], GamsVariable)):
162 for rec in tup[0]:
163 for i in range(len(rec.keys)):
164 my_keys[scen_symbol.dimension + i] = s.key(i)
165 tup[1].add_record(my_keys).value = rec.marginal
166 elif (tup[2] == "marginal") and (isinstance(tup[0], GamsEquation)):
167 for rec in tup[0]:
168 for i in range(len(rec.keys)):
169 my_keys[scen_symbol.dimension + i] = s.key(i)
170 tup[1].add_record(my_keys).value = rec.marginal
171
172
def guss_call(dict, mi, solve_statement, opt=None, mi_opt=None, output=None)
Definition: transport12.py:63

Variable Documentation

◆ bmult

transport12.bmult = db.add_parameter_dc("bmultlist", [scen])

Definition at line 193 of file transport12.py.

◆ bmultlist

list transport12.bmultlist = [ 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3 ]

Definition at line 188 of file transport12.py.

◆ checkpoint

transport12.checkpoint

Definition at line 183 of file transport12.py.

◆ cp

transport12.cp = ws.add_checkpoint()

Definition at line 179 of file transport12.py.

◆ db

transport12.db = ws.add_database()

Definition at line 190 of file transport12.py.

◆ db2

transport12.db2 = ws.add_database()

Definition at line 216 of file transport12.py.

◆ dict

transport12.dict = db.add_set("dict",3,"")

Definition at line 203 of file transport12.py.

◆ dict2

transport12.dict2 = db2.add_set("dict", 3, "")

Definition at line 228 of file transport12.py.

◆ i

int transport12.i = 0

Definition at line 196 of file transport12.py.

◆ mi

transport12.mi = cp.add_modelinstance()

Definition at line 186 of file transport12.py.

◆ mi2

transport12.mi2 = cp.add_modelinstance()

Definition at line 215 of file transport12.py.

◆ output

transport12.output

Definition at line 233 of file transport12.py.

◆ scen

transport12.scen = db.add_set("scen", 1, "")

Definition at line 192 of file transport12.py.

◆ scen2

transport12.scen2 = db2.add_set("scen", 1, "")

Definition at line 218 of file transport12.py.

◆ t12

transport12.t12 = ws.add_job_from_string(get_model_text())

Definition at line 182 of file transport12.py.

◆ value

transport12.value

Definition at line 198 of file transport12.py.

◆ ws

transport12.ws = GamsWorkspace(system_directory = sys.argv[1])

Definition at line 175 of file transport12.py.

◆ xup

transport12.xup = db2.add_parameter("xup", 3, "")

Definition at line 220 of file transport12.py.

◆ zscen

transport12.zscen = db.add_parameter_dc("zscen", [scen])

Definition at line 194 of file transport12.py.

◆ zscen2

transport12.zscen2 = db2.add_parameter_dc("zscen", [scen2])

Definition at line 219 of file transport12.py.