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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.