Changeset 2406


Ignore:
Timestamp:
Feb 26, 2010 10:54:23 PM (10 years ago)
Author:
jwatson
Message:

More tweaks to the PH solver manager/servers.

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

Legend:

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

    r2405 r2406  
    306306               rhos_to_transmit.append(getattr(scenario_instance, rho_parameter_name))
    307307
    308          self._solver_manager.transmit_rhos(scenario_instance, rhos_to_transmit)         
     308         self._solver_manager.transmit_rhos(scenario_instance, rhos_to_transmit)
     309
     310   #
     311   # a utility to transmit - across the PH solver manager - the current scenario
     312   # tree node statistics to each of my problem instances. done prior to each
     313   # PH iteration k.
     314   #
     315
     316   def _transmit_tree_node_statistics(self):
     317
     318      for scenario_name, scenario_instance in self._instances.items():
     319
     320         tree_node_minimums = {}
     321         tree_node_maximums = {}
     322
     323         scenario = self._scenario_tree._scenario_map[scenario_name]
     324
     325         for tree_node in scenario._node_list:
     326
     327            tree_node_minimums[tree_node._name] = tree_node._minimums
     328            tree_node_maximums[tree_node._name] = tree_node._maximums
     329
     330         self._solver_manager.transmit_tree_node_statistics(scenario_instance, tree_node_minimums, tree_node_maximums)         
     331
     332   #
     333   # a utility to enable - across the PH solver manager - weighted penalty objectives.
     334   #
     335
     336   def _enable_ph_objectives(self):
     337
     338      for scenario_name, scenario_instance in self._instances.items():
     339
     340         self._solver_manager.enable_ph_objective(scenario_instance)
    309341         
    310342
     
    964996      solve_start_time = time.time()
    965997
    966       # STEP -1: if using a PH solver manager, propagate current weights to the appropriate solver servers.
     998      # STEP -1: if using a PH solver manager, propagate current weights/averages to the appropriate solver servers.
     999      #          ditto the tree node statistics, which are necessary if linearizing (so an optimization could be
     1000      #          performed here).
    9671001      # NOTE: We aren't currently propagating rhos, as they generally don't change - we need to
    9681002      #       have a flag, though, indicating whether the rhos have changed, so they can be
     
    9701004      if self._solver_manager_type == "ph":
    9711005         self._transmit_weights_and_averages()
     1006         self._transmit_tree_node_statistics()
    9721007
    9731008      # STEP 0: set up all global solver options.
     
    11171152      if self._solver_manager_type == "ph":
    11181153         self._transmit_rhos()
     1154         self._enable_ph_objectives()
    11191155
    11201156      # checkpoint if it's time - which it always is after iteration 0,
  • coopr.pysp/trunk/coopr/pysp/phserver.py

    r2405 r2406  
    6969
    7070      # the server is in one of two modes - solve the baseline instances, or
    71       # those augmented with the PH penalty terms. default is baseline.
     71      # those augmented with the PH penalty terms. default is standard.
    7272      # NOTE: This is currently a global flag for all scenarios handled
    7373      #       by this server - easy enough to extend if we want.
    74       self._solving_baseline_objective = True
     74      self._solving_standard_objective = True
    7575
    7676   def enable_standard_objective(self):
    7777
    78       self._solving_baseline_objective = True
     78      print "RECEIVED REQUEST TO ENABLE STANDARD OBJECTIVE FOR ALL SCENARIOS"
     79
     80      self._solving_standard_objective = True
    7981
    8082   def enable_ph_objective(self):
    8183
    82       self._solving_baseline_objective = False
     84      print "RECEIVED REQUEST TO ENABLE PH OBJECTIVE FOR ALL SCENARIOS"
     85
     86      self._solving_standard_objective = False
    8387
    8488   def solve(self, scenario_name):
    8589
     90      print "RECEIVED REQUEST TO SOLVE SCENARIO INSTANCE="+scenario_name
     91      if self._solving_standard_objective is True:
     92         print "OBJECTIVE=STANDARD"
     93      else:
     94         print "OBJECTIVE=PH"
     95         
    8696      if scenario_name not in self._instances:
    8797         print "***ERROR: Requested instance to solve not in PH solver server instance collection!"
     
    95105
    96106      # form the desired objective, depending on the solve mode.
    97       if self._solving_baseline_objective is True:
     107      if self._solving_standard_objective is True:
    98108         form_standard_objective(scenario_name, scenario_instance, self._original_objective_expression[scenario_name], self._scenario_tree)         
    99109      else:
    100110         # TBD - command-line drive the various options (integer tolerance, breakpoint strategies, etc.)
    101111         form_ph_objective(scenario_name, scenario_instance, \
    102                            self._original_objective_expression[instance_name], self._scenario_tree, \
     112                           self._original_objective_expression[scenario_name], self._scenario_tree, \
    103113                           False, False, False, 0, 0.00001)
    104114                           
     
    106116
    107117      print "Successfully solved scenario instance="+scenario_name
    108       print "RESULTS:"
    109       results.write(num=1)
     118#      print "RESULTS:"
     119#      results.write(num=1)
    110120      encoded_results = pickle.dumps(results)
    111121     
     
    159169         for index in rho_index:
    160170            target_rho_parameter[index] = rho_update[index]
     171
     172   def update_tree_node_statistics(self, scenario_name, new_node_minimums, new_node_maximums):
     173
     174      print "RECEIVED REQUEST TO UPDATE TREE NODE STATISTICS SCENARIO=",scenario_name
     175
     176      print "TREE NODE MINS=",new_node_minimums
     177      print "TREE NODE MAXS=",new_node_maximums     
     178
     179      for tree_node_name, tree_node_minimums in new_node_minimums.items():
     180
     181         tree_node = self._scenario_tree._tree_node_map[tree_node_name]
     182         tree_node._minimums = tree_node_minimums
     183
     184      for tree_node_name, tree_node_maximums in new_node_maximums.items():
     185
     186         tree_node = self._scenario_tree._tree_node_map[tree_node_name]
     187         tree_node._maximums = tree_node_maximums         
     188     
    161189           
    162190#
  • coopr.pysp/trunk/coopr/pysp/phsolvermanager.py

    r2405 r2406  
    137137       proxy.update_rhos(scenario_instance.name, new_rhos)
    138138
     139    def transmit_tree_node_statistics(self, scenario_instance, tree_node_minimums, tree_node_maximums):
     140       
     141       proxy = self._identify_proxy(scenario_instance.name)
     142       proxy.update_tree_node_statistics(scenario_instance.name, tree_node_minimums, tree_node_maximums)   
     143
    139144SolverManagerRegistration("ph", PHSolverManager)
Note: See TracChangeset for help on using the changeset viewer.