Changeset 2127


Ignore:
Timestamp:
Jan 4, 2010 12:39:26 AM (11 years ago)
Author:
jwatson
Message:

Added pre iteration k callback to support CVaR plugin. Cleaned up a variety of reporting logic in PH that didn't work properly when unary (non-indexed) variables were blended. Apparently, we don't have test cases (and nor do our users) that do this!

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

Legend:

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

    r2039 r2127  
    10281028
    10291029                  if is_used is True:
    1030                      tree_node._minimums[variable.name][index] = min
    1031                      tree_node._averages[variable.name][index] = avg / node_probability
    1032                      tree_node._maximums[variable.name][index] = max                       
     1030
     1031                     if index is None:
     1032                        tree_node._minimums[variable.name].value = min
     1033                        tree_node._averages[variable.name].value = avg / node_probability
     1034                        tree_node._maximums[variable.name].value = max                                               
     1035                     else:
     1036                        tree_node._minimums[variable.name][index] = min
     1037                        tree_node._averages[variable.name][index] = avg / node_probability
     1038                        tree_node._maximums[variable.name][index] = max                       
    10331039
    10341040                     # distribute the newly computed average to the xbar variable in
     
    10381044                        instance = self._instances[scenario._name]
    10391045                        avg_parameter = getattr(instance, avg_parameter_name)
    1040                         avg_parameter[index] = avg / node_probability
     1046                        if index is None:
     1047                           avg_parameter.value = avg / node_probability
     1048                        else:
     1049                           avg_parameter[index] = avg / node_probability
    10411050
    10421051      end_time = time.time()
     
    14111420         # penalty-weighted objective is no longer fixed. thus, we need to
    14121421         # create the objectives each PH iteration.
    1413          self.form_iteration_k_objectives()           
    1414 
     1422         self.form_iteration_k_objectives()
     1423
     1424         # let plugins know if they care.
     1425         for plugin in self._ph_plugins:
     1426            plugin.pre_iteration_k_solves(self)
     1427
     1428         # do the actual solves.
    14151429         self.iteration_k_solve()
    14161430
     
    15871601                     if ((output_fixed is True) and (is_fixed is True)) or (is_used is True):
    15881602
    1589                            minimum_value = tree_node._minimums[variable_name][index]()
    1590                            maximum_value = tree_node._maximums[variable_name][index]()
     1603                           minimum_value = None
     1604                           maximum_value = None
     1605
     1606                           if index is None:
     1607                              minimum_value = tree_node._minimums[variable_name]
     1608                              maximum_value = tree_node._maximums[variable_name]
     1609                           else:
     1610                              minimum_value = tree_node._minimums[variable_name][index]()
     1611                              maximum_value = tree_node._maximums[variable_name][index]()
    15911612
    15921613                           num_outputs_this_stage = num_outputs_this_stage + 1                           
     
    15951616
    15961617                           if num_outputs_this_variable == 1:
    1597                               print "\t\tVariable=",variable_name
     1618                              print "\t\tVariable=" + variable_name
    15981619
    15991620                           if num_outputs_this_index == 1:
    1600                               print "\t\t\tIndex:", indexToString(index)                             
    1601 
    1602                            print "\t\t\t\tTree Node=",tree_node._name,"\t\t (Scenarios: ",                             
     1621                              if index is not None:
     1622                                 print "\t\t\tIndex:", indexToString(index)                             
     1623
     1624                           print "\t\t\t\tTree Node="+tree_node._name+"\t\t (Scenarios: ",                             
    16031625                           for scenario in tree_node._scenarios:
    16041626                              print scenario._name," ",
  • coopr.pysp/trunk/coopr/pysp/testphextension.py

    r1778 r2127  
    2626    def post_iteration_0(self, ph):
    2727        """ Called after the iteration 0 solves, averages computation, and weight computation"""
    28         print "POST ITERATION 0 PH CALLBACK INVOKED"               
     28        print "POST ITERATION 0 PH CALLBACK INVOKED"
     29
     30    def pre_iteration_k_solves(self, ph):
     31        """ Called immediately before the iteration k solves!"""
     32        print "PRE ITERATION K SOLVE PH CALLBACK INVOKED"                       
    2933
    3034    def post_iteration_k_solves(self, ph):
     
    3337
    3438    def post_iteration_k(self, ph):
    35         """ Called after the iteration k is finished!"""
     39        """ Called after the iteration k is finished, after weights have been updated!"""
    3640        print "POST ITERATION K PH CALLBACK INVOKED"                       
    3741
  • coopr.pysp/trunk/coopr/pysp/wwphextension.py

    r2035 r2127  
    410410         print "Setting mipgap to "+str(gap)
    411411         ph._mipgap = gap
     412
     413#==================================================         
     414
     415    def pre_iteration_k_solves(self, ph):
     416        """ Called immediately before the iteration k solves!"""
     417        # we don't muck with the PH objectives
     418        pass
    412419
    413420#==================================================
Note: See TracChangeset for help on using the changeset viewer.