Changeset 3035
- Timestamp:
- Sep 21, 2010 11:49:05 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
coopr.pysp/trunk/scripts/computeconf
r3034 r3035 155 155 reference_model, reference_instance, full_scenario_tree, scenario_tree_instance = load_reference_and_scenario_models(options) 156 156 if (reference_model is None) or (reference_instance is None) or (full_scenario_tree is None) or (scenario_tree_instance is None): 157 print "***ERROR: Failed to initialize reference model/instance pair and/or the scenario tree." 158 sys.exit(1) 157 raise RuntimeError, "***ERROR: Failed to initialize reference model/instance pair and/or the scenario tree." 159 158 160 159 # verify that we're dealing with a minimization problem - the script might be easily made to work with … … 163 162 objective = reference_model.active_components()[Objective][objective_name] 164 163 if objective.sense != minimize: 165 print "***ERROR: Confidence intervals are available only for minimization problems" 166 sys.exit(1) 164 raise RuntimeError, "***ERROR: Confidence intervals are available only for minimization problems" 167 165 168 166 print "Starting confidence interval calculation..." … … 170 168 scenario_count = len(full_scenario_tree._stages[-1]._tree_nodes) 171 169 if len(full_scenario_tree._stages) > 2: 172 print "***ERROR: Confidence intervals are available only for two stage stochastic programs;"+str(len(full_scenario_tree._stages))+" stages specified" 173 sys.exit(1) 170 raise RuntimeError, "***ERROR: Confidence intervals are available only for two stage stochastic programs;"+str(len(full_scenario_tree._stages))+" stages specified" 174 171 175 172 # randomly permute the indices to extract a subset to compute xhat. … … 184 181 num_scenarios_per_sample = int((scenario_count - num_scenarios_for_solution) / n_g) # 'n' in Morton's slides 185 182 wasted_scenarios = scenario_count - num_scenarios_for_solution - n_g * num_scenarios_per_sample 183 184 if num_scenarios_per_sample is 0: 185 raise RuntimeError, "Computed number of scenarios per sample group equals 0 - "+str(scenario_count - num_scenarios_for_solution)+" scenarios cannot be divided into "+str(n_g)+" groups!" 186 186 187 187 print "Problem contains "+str(scenario_count)+" scenarios, of which "+str(num_scenarios_for_solution)+" will be used to find a solution xhat." … … 193 193 # directly, mainly out of convenience - we're leveraging the code in ph_for_bundle to create the 194 194 # scenario tree and scenario instances. 195 print "" 195 196 print "Loading scenario instances and initializing scenario tree for xhat scenario bundle." 196 197 xhat_ph = ph_for_bundle(0, num_scenarios_for_solution, reference_model, full_scenario_tree, reference_instance, scenario_tree_instance, index_list, options) … … 243 244 start_index = num_scenarios_for_solution + (k-1)*num_scenarios_per_sample 244 245 stop_index = start_index + num_scenarios_per_sample - 1 246 print "" 245 247 print "Computing statistics for sample k="+str(k)+"." 246 248 if options.verbose is True: … … 298 300 g_var = g_var / (n_g - 1) # sample var 299 301 print "" 302 print "Raw results:" 300 303 print "g_bar=",g_bar 301 304 print "g_stddev=",math.sqrt(g_var) … … 303 306 304 307 if n_g in t_table_values: 305 print "" 308 print "" 309 print "Results summary:" 306 310 t_table_entries = t_table_values[n_g] 307 311 for key in sorted(t_table_entries.keys()): … … 359 363 scenariobundlelist=scenarios_to_bundle) 360 364 if scenario_tree_for_soln.validate() is False: 361 print "***ERROR: Bundled scenario tree is invalid!!!" 362 sys.exit(1) 365 raise RuntimeError, "***ERROR: Bundled scenario tree is invalid!!!" 363 366 364 367 ph = create_ph_from_scratch(options, reference_model, reference_instance, scenario_tree_for_soln)
Note: See TracChangeset
for help on using the changeset viewer.