Ignore:
Timestamp:
Nov 5, 2010 1:29:42 PM (10 years ago)
Author:
jwatson
Message:

Various updates to support heteogeneous index sets in PH for different nodes in the scenario tree - more work / testing remains.

File:
1 edited

Legend:

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

    r3156 r3217  
    109109      cvar_eta_variable.construct()               
    110110
    111       first_stage.add_variable(cvar_eta_variable, "*", [None])
     111      first_stage.add_variable(cvar_eta_variable, "*")
    112112
    113113      cvar_excess_variable_name = "CVAR_EXCESS"
     
    115115      cvar_excess_variable.construct()
    116116
    117       second_stage.add_variable(cvar_excess_variable, "*", [None])
     117      second_stage.add_variable(cvar_excess_variable, "*")
    118118
    119119      # create the eta and excess variable on a per-scenario basis,
     
    166166
    167167      # first loop is to create master (blended) variables across all stages but the last.
    168       for (stage_variable, index_template, stage_variable_indices) in stage._variables:
     168      for (stage_reference_variable, index_template) in stage._variables:
    169169
    170170         if verbose_output is True:
    171             print "Creating master variable and blending constraints for decision variable="+stage_variable.name+", indices="+str(index_template)
     171            print "Creating master variable and blending constraints for decision variable="+stage_reference_variable.name+", indices="+str(index_template)
    172172
    173173         for tree_node in stage._tree_nodes:
     
    175175            if stage != scenario_tree._stages[-1]:     
    176176
    177                master_variable_name = stage_variable.name               
     177               stage_variable_name = stage_reference_variable.name
     178
     179               stage_variable_indices = tree_node._variable_indices[stage_variable_name]
    178180
    179181               # because there may be a single stage variable and multiple indices, check
     
    182184               master_variable = None
    183185               try:
    184                   master_variable = getattr(binding_instance, master_variable_name)
     186                  master_variable = getattr(binding_instance, stage_variable_name)
    185187               except:
    186                   new_master_variable_index = stage_variable._index
     188                  new_master_variable_index = getattr(scenario_instances[tree_node._scenarios[0]._name], stage_variable_name)._index
    187189                  new_master_variable = None
    188190                  if (len(new_master_variable_index) is 1) and (None in new_master_variable_index):
    189                      new_master_variable = Var(name=stage_variable.name)
     191                     new_master_variable = Var(name=stage_variable_name)
    190192                  else:
    191                      new_master_variable = Var(new_master_variable_index, name=stage_variable.name)
     193                     new_master_variable = Var(new_master_variable_index, name=stage_variable_name)
    192194                  new_master_variable.construct()
    193195                  new_master_variable._model = binding_instance
    194                   setattr(binding_instance, master_variable_name, new_master_variable)
     196                  setattr(binding_instance, stage_variable_name, new_master_variable)
    195197
    196198                  master_variable = new_master_variable
     
    202204                  for scenario in tree_node._scenarios:
    203205                     instance = scenario_instances[scenario._name]
    204                      if getattr(instance,stage_variable.name)[index].status == VarStatus.unused:
     206                     if getattr(instance,stage_variable_name)[index].status == VarStatus.unused:
    205207                        is_used = False
    206208
     
    208210                  for scenario in tree_node._scenarios:
    209211                     instance = scenario_instances[scenario._name]
    210                      if getattr(instance,stage_variable.name)[index].fixed is True:
     212                     if getattr(instance,stage_variable_name)[index].fixed is True:
    211213                        is_fixed = True
    212214
     
    215217                     for scenario in tree_node._scenarios:
    216218                        scenario_instance = scenario_instances[scenario._name]
    217                         scenario_variable = getattr(scenario_instance, stage_variable.name)
    218                         new_constraint_name = scenario._name + "_" + master_variable_name + "_" + str(index)
     219                        scenario_variable = getattr(scenario_instance, stage_variable_name)
     220                        new_constraint_name = scenario._name + "_" + stage_variable_name + "_" + str(index)
    219221                        new_constraint = Constraint(name=new_constraint_name)
    220222                        new_expr = master_variable[index] - scenario_variable[index]
     
    633635      gc.enable()
    634636
     637   # with the scenario instances now available, have the scenario tree compute the
     638   # variable match indices at each node.
     639   scenario_tree.defineVariableIndexSets(scenario_instances)     
     640
    635641   print "Creating extensive form binding instance"
    636642
Note: See TracChangeset for help on using the changeset viewer.