4848
4949"""
5050from __future__ import print_function
51+
5152# Inputs directory relative to the location of this script.
5253inputs_dir = "inputs"
5354# ScenarioStructure.dat and RootNode.dat will be saved to a
5859stage_list = ["Investment" , "Operation" ]
5960stage_vars = {
6061 "Investment" : ["BuildGen" , "BuildLocalTD" , "BuildTx" ],
61- "Operation" : ["DispatchGen" , "GenFuelUseRate" ]
62+ "Operation" : ["DispatchGen" , "GenFuelUseRate" ],
6263}
6364# List of scenario names
64- scenario_list = [
65- "LowFuelCosts" , "MediumFuelCosts" , "HighFuelCosts" ]
65+ scenario_list = ["LowFuelCosts" , "MediumFuelCosts" , "HighFuelCosts" ]
6666
6767###########################################################
6868
8282instance = model .load_inputs (inputs_dir = inputs_dir )
8383print ("inputs successfully loaded..." )
8484
85+
8586def save_dat_files ():
8687
8788 if not os .path .exists (os .path .join (inputs_dir , pysp_subdir )):
@@ -92,8 +93,9 @@ def save_dat_files():
9293
9394 dat_file = os .path .join (inputs_dir , pysp_subdir , "RootNode.dat" )
9495 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+ )
9799
98100 #######################
99101 # ScenarioStructure.dat
@@ -117,7 +119,7 @@ def save_dat_files():
117119
118120 f .write ("param NodeStage := RootNode {}\n " .format (stage_list [0 ]))
119121 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 ]))
121123 f .write (";\n \n " )
122124
123125 f .write ("set Children[RootNode] := " )
@@ -127,7 +129,7 @@ def save_dat_files():
127129
128130 f .write ("param ConditionalProbability := RootNode 1.0" )
129131 # 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 )
131133 # The remaining probability is lumped in the last scenario to avoid rounding issues
132134 probs .append (1.0 - sum (probs ))
133135 for (s , p ) in zip (scenario_list , probs ):
@@ -150,14 +152,16 @@ def write_var_name(f, cname):
150152 if hasattr (instance , cname ):
151153 dimen = getattr (instance , cname ).index_set ().dimen
152154 if dimen == 0 :
153- f .write (" {cn}\n " .format (cn = cname ))
155+ f .write (" {cn}\n " .format (cn = cname ))
154156 else :
155- indexing = ( "," .join (["*" ]* dimen ) )
157+ indexing = "," .join (["*" ] * dimen )
156158 f .write (" {cn}[{dim}]\n " .format (cn = cname , dim = indexing ))
157159 else :
158160 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+ )
161165
162166 for st in stage_list :
163167 f .write ("set StageVariables[{}] := \n " .format (st ))
@@ -171,8 +175,9 @@ def write_var_name(f, cname):
171175 f .write (" Operation OperationCost\n " )
172176 f .write (";" )
173177
178+
174179####################
175180
176- if __name__ == ' __main__' :
181+ if __name__ == " __main__" :
177182 # If the script is executed on the command line, then the .dat files are created.
178183 save_dat_files ()
0 commit comments