Changeset 3218


Ignore:
Timestamp:
Nov 5, 2010 2:35:51 PM (10 years ago)
Author:
jwatson
Message:

More changes associated with generalizing the PySP index structures from per-stage to per-node.

Location:
coopr.pysp/trunk/coopr/pysp
Files:
3 edited

Legend:

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

    r3217 r3218  
    727727         #       explicitly.
    728728         for (variable_name, reference_variable) in stage_variables.items():
     729           
    729730            for tree_node in stage._tree_nodes:
    730731
    731                new_min_index = reference_variable._index
     732               new_variable_index = getattr(self._instances[tree_node._scenarios[0]._name], variable_name)._index
     733
     734               new_min_index = new_variable_index
    732735               new_min_parameter_name = "NODEMIN_"+reference_variable.name
    733736               # this bit of ugliness is due to Pyomo not correctly handling the Param construction
     
    743746               tree_node._minimums[reference_variable.name] = new_min_parameter
    744747
    745                new_avg_index = reference_variable._index
     748               new_avg_index = new_variable_index
    746749               new_avg_parameter_name = "NODEAVG_"+reference_variable.name
    747750               new_avg_parameter = None
     
    754757               tree_node._averages[reference_variable.name] = new_avg_parameter
    755758
    756                new_max_index = reference_variable._index
     759               new_max_index = new_variable_index
    757760               new_max_parameter_name = "NODEMAX_"+reference_variable.name
    758761               new_max_parameter = None
     
    13801383
    13811384      if self._output_scenario_tree_solution is True:
    1382          self._scenario_tree.snapshotSolutionFromAverages()
     1385         self._scenario_tree.snapshotSolutionFromAverages(self._instances)
    13831386         print "Final solution (scenario tree format):"
    13841387         self._scenario_tree.pprintSolution()
  • coopr.pysp/trunk/coopr/pysp/phobjective.py

    r3217 r3218  
    242242   # the quadratic expression is really treated as just a list - eventually should be treated as a full expression.
    243243   quad_expression = 0.0
     244
     245#   print "ORIGINAL OBJECTIVE EXPRESSION:"
     246#   original_objective_expression.pprint()
     247
     248#   print "CLONED OBJECTIVE EXPRESSION:"
     249#   objective_expression.pprint()
     250
     251#   foobar
    244252
    245253   # for each blended variable (i.e., those not appearing in the final stage),
  • coopr.pysp/trunk/coopr/pysp/scenariotree.py

    r3217 r3218  
    2626   # variable/match-template/variable-index triple.
    2727   #
    28    def _update_solution_map(self, variable, match_template):
    29 
    30       variable_indices = self._variable_indices[variable.name]
     28   def _update_solution_map(self, variable, match_template, scenario_instance_map):
     29
     30
    3131
    3232      # don't bother copying bounds for variables, as the values stored
     
    3434      # ensuring feasibility. this also leaves room for specifying infeasible
    3535      # or partial solutions.
    36       new_variable_index = variable._index
    37       new_variable_name = variable.name
     36      new_variable_name = variable.name     
     37      new_variable_index = getattr(scenario_instance_map[self._scenarios[0]._name], variable.name)._index
    3838      new_variable = None
    3939      if (len(new_variable_index) is 1) and (None in new_variable_index):
     
    4343      new_variable.construct()
    4444
     45      variable_indices = self._variable_indices[variable.name]     
     46
    4547      # by default, deactive all variable values - we're copying the
    4648      # full index set of a variable, which is necessarily wasteful and
     
    5961   #
    6062
    61    def _initialize_solution_map(self):
     63   def _initialize_solution_map(self, scenario_instance_map):
    6264
    6365      # clear whatever was there before.
     
    7274      # is an issue (space is the most likely issue)
    7375      for variable, match_template in self._stage._variables:
    74          self._update_solution_map(variable, match_template)
     76         self._update_solution_map(variable, match_template, scenario_instance_map)
    7577
    7678      self._solution_map_initialized = True
     
    7981   """ Constructor
    8082   """
    81    def __init__(self, name, conditional_probability, stage, initialize_solution=False):
     83   def __init__(self, name, conditional_probability, stage, initialize_solution=False, scenario_instance_map={}):
    8284
    8385      self._name = name
     
    114116
    115117      if initialize_solution is True:
    116          self._initialize_solution_map()
     118         self._initialize_solution_map(scenario_instance_map)
    117119
    118120   #
     
    145147   #
    146148
    147    def snapshotSolutionFromAverages(self):
     149   def snapshotSolutionFromAverages(self, scenario_instance_map):
    148150
    149151      if self._solution_map_initialized is False:
    150          self._initialize_solution_map()
     152         self._initialize_solution_map(scenario_instance_map)
    151153
    152154      for variable_name, variable in self._solutions.items():
     
    172174
    173175      if self._solution_map_initialized is False:
    174          self._initialize_solution_map()
     176         self._initialize_solution_map(scenario_instance_map)
    175177
    176178      for variable_name, variable in self._solutions.items():
     
    717719   #
    718720
    719    def snapshotSolutionFromAverages(self):
    720 
    721       for tree_node in self._tree_nodes:
    722 
    723          tree_node.snapshotSolutionFromAverages()
     721   def snapshotSolutionFromAverages(self, scenario_instance_map):
     722
     723      for tree_node in self._tree_nodes:
     724
     725         tree_node.snapshotSolutionFromAverages(scenario_instance_map)
    724726
    725727   #
Note: See TracChangeset for help on using the changeset viewer.