Loading...
Searching...
No Matches
transport12 Namespace Reference

Functions

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

Variables

str GAMS_MODEL
 
sys sys_dir = sys.argv[1] if len(sys.argv) > 1 else None
 
GamsWorkspace ws = GamsWorkspace(system_directory=sys_dir)
 
GamsWorkspace cp = ws.add_checkpoint()
 
GamsWorkspace job = ws.add_job_from_string(GAMS_MODEL)
 
 checkpoint
 
GamsWorkspace mi = cp.add_modelinstance()
 
list bmult_list = [0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3]
 
GamsWorkspace db = ws.add_database()
 
GamsWorkspace scen = db.add_set("scen", 1, "")
 
GamsWorkspace bmult = db.add_parameter_dc("bmultlist", [scen])
 
GamsWorkspace zscen = db.add_parameter_dc("zscen", [scen])
 
 value
 
GamsWorkspace scenario_dict = db.add_set("scenario_dict", 3, "")
 
GamsWorkspace mi2 = cp.add_modelinstance()
 
GamsWorkspace db2 = ws.add_database()
 
GamsWorkspace scen2 = db2.add_set("scen", 1, "")
 
GamsWorkspace zscen2 = db2.add_parameter_dc("zscen", [scen2])
 
GamsWorkspace xup = db2.add_parameter("xup", 3, "")
 
GamsWorkspace scenario_dict2 = db2.add_set("scenario_dict", 3, "")
 
 output
 

Function Documentation

◆ guss_call()

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

Definition at line 68 of file transport12.py.

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

Variable Documentation

◆ bmult

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

Definition at line 196 of file transport12.py.

◆ bmult_list

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

Definition at line 193 of file transport12.py.

◆ checkpoint

transport12.checkpoint

Definition at line 189 of file transport12.py.

◆ cp

GamsWorkspace transport12.cp = ws.add_checkpoint()

Definition at line 185 of file transport12.py.

◆ db

GamsWorkspace transport12.db = ws.add_database()

Definition at line 194 of file transport12.py.

◆ db2

GamsWorkspace transport12.db2 = ws.add_database()

Definition at line 214 of file transport12.py.

◆ GAMS_MODEL

str transport12.GAMS_MODEL

Definition at line 19 of file transport12.py.

◆ job

GamsWorkspace transport12.job = ws.add_job_from_string(GAMS_MODEL)

Definition at line 188 of file transport12.py.

◆ mi

GamsWorkspace transport12.mi = cp.add_modelinstance()

Definition at line 192 of file transport12.py.

◆ mi2

GamsWorkspace transport12.mi2 = cp.add_modelinstance()

Definition at line 213 of file transport12.py.

◆ output

transport12.output

Definition at line 231 of file transport12.py.

◆ scen

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

Definition at line 195 of file transport12.py.

◆ scen2

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

Definition at line 216 of file transport12.py.

◆ scenario_dict

GamsWorkspace transport12.scenario_dict = db.add_set("scenario_dict", 3, "")

Definition at line 203 of file transport12.py.

◆ scenario_dict2

GamsWorkspace transport12.scenario_dict2 = db2.add_set("scenario_dict", 3, "")

Definition at line 226 of file transport12.py.

◆ sys_dir

sys transport12.sys_dir = sys.argv[1] if len(sys.argv) > 1 else None

Definition at line 182 of file transport12.py.

◆ value

transport12.value

Definition at line 200 of file transport12.py.

◆ ws

GamsWorkspace transport12.ws = GamsWorkspace(system_directory=sys_dir)

Definition at line 183 of file transport12.py.

◆ xup

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

Definition at line 218 of file transport12.py.

◆ zscen

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

Definition at line 197 of file transport12.py.

◆ zscen2

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

Definition at line 217 of file transport12.py.