Changeset 2410
- Timestamp:
- Mar 2, 2010 4:53:30 PM (11 years ago)
- Location:
- coopr.pysp/trunk/coopr/pysp
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
coopr.pysp/trunk/coopr/pysp/phobjective.py
r2405 r2410 397 397 if quad_expression != 0.0: 398 398 instance.active_components(Objective)[objective_name]._quad_subexpr = quad_expression 399 else: 400 instance.active_components(Objective)[objective_name]._quad_subexpr = None 399 401 400 402 return new_instance_attributes -
coopr.pysp/trunk/coopr/pysp/phserver.py
r2406 r2410 29 29 import Pyro.core 30 30 import Pyro.naming 31 from Pyro.errors import PyroError,NamingError 31 32 32 33 # garbage collection control. … … 53 54 54 55 # the obvious stuff! 55 self._instances = scenario_instances 56 self._instances = scenario_instances # a map from scenario name to pyomo model instance 56 57 self._solver = solver 57 58 self._scenario_tree = scenario_tree … … 76 77 def enable_standard_objective(self): 77 78 78 print "RECEIVED REQUEST TO ENABLE STANDARD OBJECTIVE FOR ALL SCENARIOS"79 # print "RECEIVED REQUEST TO ENABLE STANDARD OBJECTIVE FOR ALL SCENARIOS" 79 80 80 81 self._solving_standard_objective = True … … 82 83 def enable_ph_objective(self): 83 84 84 print "RECEIVED REQUEST TO ENABLE PH OBJECTIVE FOR ALL SCENARIOS"85 # print "RECEIVED REQUEST TO ENABLE PH OBJECTIVE FOR ALL SCENARIOS" 85 86 86 87 self._solving_standard_objective = False … … 88 89 def solve(self, scenario_name): 89 90 90 print "RECEIVED REQUEST TO SOLVE SCENARIO INSTANCE="+scenario_name91 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" 95 96 96 97 if scenario_name not in self._instances: … … 98 99 return None 99 100 scenario_instance = self._instances[scenario_name] 100 101 # IMPT: You have to re-presolve, as the simple presolver collects the linear terms together. If you102 # 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()105 101 106 102 # form the desired objective, depending on the solve mode. … … 112 108 self._original_objective_expression[scenario_name], self._scenario_tree, \ 113 109 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 115 116 results = self._solver.solve(scenario_instance) 116 117 … … 124 125 def update_weights_and_averages(self, scenario_name, new_weights, new_averages): 125 126 126 print "RECEIVED REQUEST TO UPDATE WEIGHTS AND AVERAGES FOR SCENARIO=",scenario_name127 # print "RECEIVED REQUEST TO UPDATE WEIGHTS AND AVERAGES FOR SCENARIO=",scenario_name 127 128 128 129 if scenario_name not in self._instances: … … 132 133 133 134 for weight_update in new_weights: 134 weight_update.pprint()135 135 136 136 weight_index = weight_update._index … … 139 139 140 140 for index in weight_index: 141 target_weight_parameter[index] = weight_update[index] 141 target_weight_parameter[index] = weight_update[index]() 142 142 143 143 for average_update in new_averages: 144 average_update.pprint()145 144 146 145 average_index = average_update._index … … 149 148 150 149 for index in average_index: 151 target_average_parameter[index] = average_update[index] 150 target_average_parameter[index] = average_update[index]() 152 151 153 152 def update_rhos(self, scenario_name, new_rhos): 154 153 155 print "RECEIVED REQUEST TO UPDATE RHOS FOR SCENARIO=",scenario_name154 # print "RECEIVED REQUEST TO UPDATE RHOS FOR SCENARIO=",scenario_name 156 155 157 156 if scenario_name not in self._instances: … … 161 160 162 161 for rho_update in new_rhos: 163 rho_update.pprint() 164 162 165 163 rho_index = rho_update._index 166 164 167 165 target_rho_parameter = getattr(scenario_instance, rho_update.name) 168 166 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! 171 169 172 170 def update_tree_node_statistics(self, scenario_name, new_node_minimums, new_node_maximums): 173 171 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 178 173 179 174 for tree_node_name, tree_node_minimums in new_node_minimums.items(): … … 385 380 # each scenario processed by this daemon. 386 381 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 387 390 try: 388 391 solver_daemon.connect(delegator_object, scenario_name) … … 390 393 raise RuntimeError, "Entry in name server already exists for scenario="+scenario_name 391 394 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() 396 402 397 403 end_time = time.time()
Note: See TracChangeset
for help on using the changeset viewer.