Changeset 2410


Ignore:
Timestamp:
Mar 2, 2010 4:53:30 PM (9 years ago)
Author:
jwatson
Message:

Fixed the PH solver server to automatically deregister a delegator object if it already exists in the name server.

Fixed various bugs in the PH solver server relating to quadratic expression output and weight/rho updates. It now replicates CPLEX results across the server network.

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

Legend:

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

    r2405 r2410  
    397397   if quad_expression != 0.0:
    398398     instance.active_components(Objective)[objective_name]._quad_subexpr = quad_expression
     399   else:
     400     instance.active_components(Objective)[objective_name]._quad_subexpr = None
    399401
    400402   return new_instance_attributes
  • coopr.pysp/trunk/coopr/pysp/phserver.py

    r2406 r2410  
    2929import Pyro.core
    3030import Pyro.naming
     31from Pyro.errors import PyroError,NamingError
    3132
    3233# garbage collection control.
     
    5354
    5455      # the obvious stuff!
    55       self._instances = scenario_instances
     56      self._instances = scenario_instances # a map from scenario name to pyomo model instance
    5657      self._solver = solver
    5758      self._scenario_tree = scenario_tree
     
    7677   def enable_standard_objective(self):
    7778
    78       print "RECEIVED REQUEST TO ENABLE STANDARD OBJECTIVE FOR ALL SCENARIOS"
     79#      print "RECEIVED REQUEST TO ENABLE STANDARD OBJECTIVE FOR ALL SCENARIOS"
    7980
    8081      self._solving_standard_objective = True
     
    8283   def enable_ph_objective(self):
    8384
    84       print "RECEIVED REQUEST TO ENABLE PH OBJECTIVE FOR ALL SCENARIOS"
     85#      print "RECEIVED REQUEST TO ENABLE PH OBJECTIVE FOR ALL SCENARIOS"
    8586
    8687      self._solving_standard_objective = False
     
    8889   def solve(self, scenario_name):
    8990
    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"
     91#      print "RECEIVED REQUEST TO SOLVE SCENARIO INSTANCE="+scenario_name
     92#      if self._solving_standard_objective is True:
     93#         print "OBJECTIVE=STANDARD"
     94#      else:
     95#         print "OBJECTIVE=PH"
    9596         
    9697      if scenario_name not in self._instances:
     
    9899         return None
    99100      scenario_instance = self._instances[scenario_name]
    100 
    101       # IMPT: You have to re-presolve, as the simple presolver collects the linear terms together. If you
    102       # don't do this, you won't see any chance in the output files as you vary the problem parameters!
    103       # ditto for instance fixing!
    104       scenario_instance.preprocess()
    105101
    106102      # form the desired objective, depending on the solve mode.
     
    112108                           self._original_objective_expression[scenario_name], self._scenario_tree, \
    113109                           False, False, False, 0, 0.00001)
    114                            
     110
     111      # IMPT: You have to re-presolve, as the simple presolver collects the linear terms together. If you
     112      # don't do this, you won't see any chance in the output files as you vary the problem parameters!
     113      # ditto for instance fixing!
     114      scenario_instance.preprocess()
     115
    115116      results = self._solver.solve(scenario_instance)
    116117
     
    124125   def update_weights_and_averages(self, scenario_name, new_weights, new_averages):
    125126
    126       print "RECEIVED REQUEST TO UPDATE WEIGHTS AND AVERAGES FOR SCENARIO=",scenario_name
     127#      print "RECEIVED REQUEST TO UPDATE WEIGHTS AND AVERAGES FOR SCENARIO=",scenario_name
    127128
    128129      if scenario_name not in self._instances:
     
    132133     
    133134      for weight_update in new_weights:
    134          weight_update.pprint()
    135135         
    136136         weight_index = weight_update._index
     
    139139
    140140         for index in weight_index:
    141             target_weight_parameter[index] = weight_update[index]
     141            target_weight_parameter[index] = weight_update[index]()
    142142
    143143      for average_update in new_averages:
    144          average_update.pprint()
    145144         
    146145         average_index = average_update._index
     
    149148
    150149         for index in average_index:
    151             target_average_parameter[index] = average_update[index]           
     150            target_average_parameter[index] = average_update[index]()
    152151
    153152   def update_rhos(self, scenario_name, new_rhos):
    154153
    155       print "RECEIVED REQUEST TO UPDATE RHOS FOR SCENARIO=",scenario_name
     154#      print "RECEIVED REQUEST TO UPDATE RHOS FOR SCENARIO=",scenario_name
    156155
    157156      if scenario_name not in self._instances:
     
    161160
    162161      for rho_update in new_rhos:
    163          rho_update.pprint()
    164          
     162
    165163         rho_index = rho_update._index
    166164
    167165         target_rho_parameter = getattr(scenario_instance, rho_update.name)
    168166
    169          for index in rho_index:
    170             target_rho_parameter[index] = rho_update[index]
     167         for index in rho_index: 
     168            target_rho_parameter[index] = rho_update[index]() # the value operator is crucial!
    171169
    172170   def update_tree_node_statistics(self, scenario_name, new_node_minimums, new_node_maximums):
    173171
    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     
     172#      print "RECEIVED REQUEST TO UPDATE TREE NODE STATISTICS SCENARIO=",scenario_name
    178173
    179174      for tree_node_name, tree_node_minimums in new_node_minimums.items():
     
    385380   # each scenario processed by this daemon.
    386381   for scenario_name, scenario_instance in scenario_instances.items():
     382      # first, see if it's already registered - if no, cull the old entry.
     383      # NOTE: This is a hack, as the cleanup / disconnect code doesn't
     384      #       seem to be invoked when the daemon is killed.
     385      try:
     386         ns.unregister(scenario_name)
     387      except NamingError:
     388         pass
     389
    387390      try:
    388391         solver_daemon.connect(delegator_object, scenario_name)
     
    390393         raise RuntimeError, "Entry in name server already exists for scenario="+scenario_name
    391394
    392    while True:
    393       solver_daemon.handleRequests()
    394 
    395    solver_daemon.disconnect()
     395   try:
     396      solver_daemon.requestLoop()
     397   except KeyboardInterrupt, SystemExit:
     398      pass
     399
     400   solver_daemon.disconnect(delegator_object)
     401   solver_daemon.shutdown()
    396402
    397403   end_time = time.time()
Note: See TracChangeset for help on using the changeset viewer.