Changeset 3096
- Timestamp:
- Oct 13, 2010 10:32:35 PM (11 years ago)
- Location:
- coopr.pysp/trunk/coopr/pysp
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
coopr.pysp/trunk/coopr/pysp/ph.py
r3093 r3096 1119 1119 # the "value" attribute is a pre-defined feature of any solution - it is relative to whatever 1120 1120 # objective was selected during optimization, which of course should be the PH objective. 1121 ph_objective_values[instance.name] = float(results.solution(0).objective['f'].value) 1121 try: 1122 ph_objective_values[instance.name] = float(results.solution(0).objective['f'].value) 1123 except AttributeError: 1124 # some solvers (e.g., through the SOL interface) don't report objective function values. 1125 ph_objective_values[instance.name] = 0.0 1122 1126 1123 1127 num_results_so_far = num_results_so_far + 1 -
coopr.pysp/trunk/coopr/pysp/scenariotree.py
r3084 r3096 172 172 # IMPT: This implicitly assumes convergence across the scenarios - if not, garbage results. 173 173 instance = scenario_instance_map[self._scenarios[0]._name] 174 my_cost = instance.active_components(Var)[self._stage._cost_variable[0].name][self._stage._cost_variable[1]].value 174 stage_cost_variable = instance.active_components(Var)[self._stage._cost_variable[0].name][self._stage._cost_variable[1]] 175 if stage_cost_variable.value is not None: 176 my_cost = stage_cost_variable.value 177 else: 178 # depending on the situation (and the model), the stage cost variables might not have values. 179 my_cost = 0.0 175 180 child_cost = 0.0 176 181 for child in self._children: … … 529 534 aggregate_cost = 0.0 530 535 for stage in self._stages: 531 instance_cost_variable = instance.active_components(Var)[stage._cost_variable[0].name][stage._cost_variable[1]].value 532 aggregate_cost += instance_cost_variable 536 instance_cost_variable = instance.active_components(Var)[stage._cost_variable[0].name][stage._cost_variable[1]] 537 if instance_cost_variable.value is not None: 538 # depending on the situation (and the model), the stage cost variables might not have values. 539 aggregate_cost += instance_cost_variable 533 540 return aggregate_cost 534 541 … … 951 958 aggregate_cost = 0.0 952 959 for stage in self._stages: 953 instance_cost_variable = instance.active_components(Var)[stage._cost_variable[0].name][stage._cost_variable[1]].value 954 print "\tStage=%20s Cost=%10.4f" % (stage._name, instance_cost_variable) 955 aggregate_cost += instance_cost_variable 960 instance_cost_variable = instance.active_components(Var)[stage._cost_variable[0].name][stage._cost_variable[1]] 961 if instance_cost_variable.value is not None: 962 print "\tStage=%20s Cost=%10.4f" % (stage._name, instance_cost_variable.value) 963 cost = instance_cost_variable.value 964 else: 965 print "\tStage=%20s Cost=%10s" % (stage._name, "Not Rprted.") 966 cost = 0.0 967 aggregate_cost += cost 956 968 print "\tTotal scenario cost=%10.4f" % aggregate_cost 957 969 print ""
Note: See TracChangeset
for help on using the changeset viewer.