Changeset 2833


Ignore:
Timestamp:
Jul 21, 2010 3:54:51 PM (9 years ago)
Author:
jwatson
Message:

Fixes to pretty-print and solution computation in the PySP scenario tree object to deal with nodes in the same stage that have heterogeneous indices for the same variable name. Comes up in EPA sensor placement formulation. Requires some real thought - runs for now.

File:
1 edited

Legend:

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

    r2810 r2833  
    142142               node_probability = 0.0
    143143               avg = 0.0
     144               num_scenarios_with_index = 0
    144145               for scenario in self._scenarios:
    145146                  scenario_instance = scenario_instance_map[scenario._name]
    146147                  node_probability += scenario._probability
    147                   var_value = getattr(scenario_instance, variable.name)[index].value
    148                   avg += (scenario._probability * var_value)
    149                variable[index].value = avg / node_probability
     148                  scenario_variable = getattr(scenario_instance, variable.name)
     149                  if index in scenario_variable:
     150                     num_scenarios_with_index = num_scenarios_with_index + 1
     151                     var_value = getattr(scenario_instance, variable.name)[index].value
     152                     avg += (scenario._probability * var_value)
     153               if num_scenarios_with_index > 0:
     154                  variable[index].value = avg / node_probability
    150155
    151156   #
     
    780785            else:
    781786               for index in indices:
    782                   if solution_variable[index].active is True:
     787                  if (solution_variable[index].active is True) and (index in solution_variable):
    783788                     value = solution_variable[index]()
    784                      if fabs(value) > epsilon:
     789                     if (value is not None) and (fabs(value) > epsilon):
    785790                        print "\t\t"+variable.name+indexToString(index)+"="+str(value)
    786791         print ""
Note: See TracChangeset for help on using the changeset viewer.