Changeset 3263


Ignore:
Timestamp:
Dec 1, 2010 12:47:21 PM (10 years ago)
Author:
jwatson
Message:

Corrected issue with cvar generation introduced a while back.

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

Legend:

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

    r3261 r3263  
    9595         print ""
    9696
    97       # update the scenario tree with cvar-specific variable names, so
    98       # they will get cloned accordingly in the master instance.
    99       first_stage = scenario_tree._stages[0]
    100       second_stage = scenario_tree._stages[1]
    101       root_node = first_stage._tree_nodes[0]
    102 
    103       # NOTE: because we currently don't have access to the reference
    104       #       instance in this method, temporarily (and largely orphaned)
    105       #       variables are constructed to supply to the scenario tree.
    106       #       this decision should be ultimately revisited.
    107       cvar_eta_variable_name = "CVAR_ETA"
    108       cvar_eta_variable = Var(name=cvar_eta_variable_name)
    109       cvar_eta_variable.construct()               
    110 
    111       first_stage.add_variable(cvar_eta_variable, "*")
    112 
    113       cvar_excess_variable_name = "CVAR_EXCESS"
    114       cvar_excess_variable = Var(name=cvar_excess_variable_name)
    115       cvar_excess_variable.construct()
    116 
    117       second_stage.add_variable(cvar_excess_variable, "*")
    118 
    11997      # create the eta and excess variable on a per-scenario basis,
    12098      # in addition to the constraint relating to the two.
     
    146124         # to just preprocess those newly added variables and constraints.
    147125         scenario_instance.preprocess()
     126
     127      # update the scenario tree with cvar-specific variable names, so
     128      # they will get cloned accordingly in the master instance.
     129      first_stage = scenario_tree._stages[0]
     130      second_stage = scenario_tree._stages[1]
     131      root_node = first_stage._tree_nodes[0]
     132
     133      # NOTE: because we currently don't have access to the reference
     134      #       instance in this method, temporarily (and largely orphaned)
     135      #       variables are constructed to supply to the scenario tree.
     136      #       this decision should be ultimately revisited.
     137      cvar_eta_variable_name = "CVAR_ETA"
     138      cvar_eta_variable = Var(name=cvar_eta_variable_name)
     139      cvar_eta_variable.construct()               
     140
     141      first_stage.add_variable(cvar_eta_variable, "*", scenario_instances)
     142
     143      cvar_excess_variable_name = "CVAR_EXCESS"
     144      cvar_excess_variable = Var(name=cvar_excess_variable_name)
     145      cvar_excess_variable.construct()
     146
     147      second_stage.add_variable(cvar_excess_variable, "*", scenario_instances)
    148148
    149149   #
  • coopr.pysp/trunk/coopr/pysp/scenariotree.py

    r3261 r3263  
    2929   #
    3030   def _update_solution_map(self, variable, match_template, scenario_instance_map):
    31 
    32 
    3331
    3432      # don't bother copying bounds for variables, as the values stored
     
    237235   # add a new variable to the stage, which will include updating the solution maps for each associated ScenarioTreeNode.
    238236   #
    239    def add_variable(self, variable, match_template):
     237   def add_variable(self, variable, match_template, scenario_instance_map):
    240238
    241239      self._variables.append((variable, match_template))
     240      match_indices = extractVariableIndices(variable, match_template)
    242241
    243242      for tree_node in self._tree_nodes:
    244          tree_node._update_solution_map(variable, match_template)
     243         tree_node._variable_indices[variable.name] = match_indices
     244         tree_node._update_solution_map(variable, match_template, scenario_instance_map)
    245245
    246246class Scenario(object):
Note: See TracChangeset for help on using the changeset viewer.