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

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

◆ guss_call()

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

Definition at line 62 of file transport12.py.

References markowitz.key.

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

Variable Documentation

◆ bmult

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

Definition at line 192 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 187 of file transport12.py.

◆ checkpoint

transport12.checkpoint

Definition at line 182 of file transport12.py.

◆ cp

transport12.cp = ws.add_checkpoint()

Definition at line 178 of file transport12.py.

◆ db

transport12.db = ws.add_database()

Definition at line 189 of file transport12.py.

◆ db2

transport12.db2 = ws.add_database()

Definition at line 215 of file transport12.py.

◆ dict

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

Definition at line 202 of file transport12.py.

◆ dict2

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

Definition at line 227 of file transport12.py.

◆ i

int transport12.i = 0

Definition at line 195 of file transport12.py.

◆ mi

transport12.mi = cp.add_modelinstance()

Definition at line 185 of file transport12.py.

◆ mi2

transport12.mi2 = cp.add_modelinstance()

Definition at line 214 of file transport12.py.

◆ output

transport12.output

Definition at line 232 of file transport12.py.

◆ scen

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

Definition at line 191 of file transport12.py.

◆ scen2

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

Definition at line 217 of file transport12.py.

◆ t12

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

Definition at line 181 of file transport12.py.

◆ value

transport12.value

Definition at line 197 of file transport12.py.

◆ ws

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

Definition at line 174 of file transport12.py.

◆ xup

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

Definition at line 219 of file transport12.py.

◆ zscen

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

Definition at line 193 of file transport12.py.

◆ zscen2

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

Definition at line 218 of file transport12.py.