48
48
49
49
"""
50
50
from __future__ import print_function
51
+
51
52
# Inputs directory relative to the location of this script.
52
53
inputs_dir = "inputs"
53
54
# ScenarioStructure.dat and RootNode.dat will be saved to a
58
59
stage_list = ["Investment" , "Operation" ]
59
60
stage_vars = {
60
61
"Investment" : ["BuildGen" , "BuildLocalTD" , "BuildTx" ],
61
- "Operation" : ["DispatchGen" , "GenFuelUseRate" ]
62
+ "Operation" : ["DispatchGen" , "GenFuelUseRate" ],
62
63
}
63
64
# List of scenario names
64
- scenario_list = [
65
- "LowFuelCosts" , "MediumFuelCosts" , "HighFuelCosts" ]
65
+ scenario_list = ["LowFuelCosts" , "MediumFuelCosts" , "HighFuelCosts" ]
66
66
67
67
###########################################################
68
68
82
82
instance = model .load_inputs (inputs_dir = inputs_dir )
83
83
print ("inputs successfully loaded..." )
84
84
85
+
85
86
def save_dat_files ():
86
87
87
88
if not os .path .exists (os .path .join (inputs_dir , pysp_subdir )):
@@ -92,8 +93,9 @@ def save_dat_files():
92
93
93
94
dat_file = os .path .join (inputs_dir , pysp_subdir , "RootNode.dat" )
94
95
print ("creating and saving {}..." .format (dat_file ))
95
- utilities .save_inputs_as_dat (model , instance , save_path = dat_file ,
96
- sorted_output = model .options .sorted_output )
96
+ utilities .save_inputs_as_dat (
97
+ model , instance , save_path = dat_file , sorted_output = model .options .sorted_output
98
+ )
97
99
98
100
#######################
99
101
# ScenarioStructure.dat
@@ -117,7 +119,7 @@ def save_dat_files():
117
119
118
120
f .write ("param NodeStage := RootNode {}\n " .format (stage_list [0 ]))
119
121
for s in scenario_list :
120
- f .write (" {scen} {st}\n " .format (scen = s ,st = stage_list [1 ]))
122
+ f .write (" {scen} {st}\n " .format (scen = s , st = stage_list [1 ]))
121
123
f .write (";\n \n " )
122
124
123
125
f .write ("set Children[RootNode] := " )
@@ -127,7 +129,7 @@ def save_dat_files():
127
129
128
130
f .write ("param ConditionalProbability := RootNode 1.0" )
129
131
# All scenarios have the same probability in this example
130
- probs = [1.0 / len (scenario_list )] * (len (scenario_list ) - 1 )
132
+ probs = [1.0 / len (scenario_list )] * (len (scenario_list ) - 1 )
131
133
# The remaining probability is lumped in the last scenario to avoid rounding issues
132
134
probs .append (1.0 - sum (probs ))
133
135
for (s , p ) in zip (scenario_list , probs ):
@@ -150,14 +152,16 @@ def write_var_name(f, cname):
150
152
if hasattr (instance , cname ):
151
153
dimen = getattr (instance , cname ).index_set ().dimen
152
154
if dimen == 0 :
153
- f .write (" {cn}\n " .format (cn = cname ))
155
+ f .write (" {cn}\n " .format (cn = cname ))
154
156
else :
155
- indexing = ( "," .join (["*" ]* dimen ) )
157
+ indexing = "," .join (["*" ] * dimen )
156
158
f .write (" {cn}[{dim}]\n " .format (cn = cname , dim = indexing ))
157
159
else :
158
160
raise ValueError (
159
- "Variable '{}' is not a component of the model. Did you make a typo?" .
160
- format (cname ))
161
+ "Variable '{}' is not a component of the model. Did you make a typo?" .format (
162
+ cname
163
+ )
164
+ )
161
165
162
166
for st in stage_list :
163
167
f .write ("set StageVariables[{}] := \n " .format (st ))
@@ -171,8 +175,9 @@ def write_var_name(f, cname):
171
175
f .write (" Operation OperationCost\n " )
172
176
f .write (";" )
173
177
178
+
174
179
####################
175
180
176
- if __name__ == ' __main__' :
181
+ if __name__ == " __main__" :
177
182
# If the script is executed on the command line, then the .dat files are created.
178
183
save_dat_files ()
0 commit comments