Ignore:
Timestamp:
Mar 22, 2010 9:18:10 PM (9 years ago)
Author:
jwatson
Message:

Added --output-scenario-tree-solution option to PySP runph script, which will:
1) Create a solution from the node averages in a scenario tree -and-
2) Output the full solution in scenario tree format (which includes the leaf nodes).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • coopr.pysp/trunk/coopr/pysp/ph.py

    r2442 r2446  
    372372      self._output_solver_results = False
    373373      self._output_times = False
     374      self._output_scenario_tree_solution = False
    374375
    375376      # PH run-time variables
     
    498499            self._breakpoint_strategy = kwds[key]
    499500         elif key == "checkpoint_interval":
    500             self._checkpoint_interval = kwds[key]           
     501            self._checkpoint_interval = kwds[key]
     502         elif key == "output_scenario_tree_solution":
     503            self._output_scenario_tree_solution = kwds[key]                       
    501504         else:
    502505            print "Unknown option=" + key + " specified in call to PH constructor"
     
    674677         print "Creating variable statistic (min/avg/max) parameter vectors for scenario tree nodes"
    675678
    676       for stage in self._scenario_tree._stages[:-1]:
     679      # do this for all stages, simply for completeness, i.e., to create a fully populated scenario tree.
     680      for stage in self._scenario_tree._stages:
    677681
    678682         # first, gather all unique variables referenced in this stage
     
    882886      start_time = time.time()
    883887     
    884       for stage in self._scenario_tree._stages[:-1]: # no blending over the final stage
     888      # compute statistics over all stages, even the last. this is necessary in order to
     889      # successfully snapshot a scenario tree solution from the average values.
     890      for stage in self._scenario_tree._stages:
    885891         
    886892         for tree_node in stage._tree_nodes:
     
    925931                     for scenario in tree_node._scenarios:
    926932                        instance = self._instances[scenario._name]
    927                         avg_parameter = getattr(instance, avg_parameter_name)
    928                         avg_parameter[index] = avg / node_probability
     933                        try:
     934                           avg_parameter = getattr(instance, avg_parameter_name)
     935                           avg_parameter[index] = avg / node_probability
     936                        except:
     937                           pass
    929938
    930939      end_time = time.time()
     
    12771286
    12781287      # update the fixed variable statistics - the plugins might have done something.
    1279       (self._total_fixed_discrete_vars,self._total_fixed_continuous_vars) = self.compute_fixed_variable_counts()                       
     1288      (self._total_fixed_discrete_vars,self._total_fixed_continuous_vars) = self.compute_fixed_variable_counts()
     1289
     1290      self._solve_end_time = time.time()     
    12801291
    12811292      print "PH complete"
     
    12931304      self._scenario_tree.pprintCosts(self._instances)
    12941305
    1295       self._solve_end_time = time.time()
     1306      if self._output_scenario_tree_solution is True:
     1307         self._scenario_tree.snapshotSolutionFromAverages()
     1308         print "Final solution (scenario tree format):"
     1309         self._scenario_tree.pprintSolution()
    12961310
    12971311      if (self._verbose is True) and (self._output_times is True):
Note: See TracChangeset for help on using the changeset viewer.