Changeset 3096


Ignore:
Timestamp:
Oct 13, 2010 10:32:35 PM (11 years ago)
Author:
jwatson
Message:

Enhancements to PySP to deal with reporting issues caused by the lack of objective function values in SOL files (in general, and those produced by ipopt in particular).

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

Legend:

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

    r3093 r3096  
    11191119         # the "value" attribute is a pre-defined feature of any solution - it is relative to whatever
    11201120         # 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
    11221126
    11231127         num_results_so_far = num_results_so_far + 1
  • coopr.pysp/trunk/coopr/pysp/scenariotree.py

    r3084 r3096  
    172172      # IMPT: This implicitly assumes convergence across the scenarios - if not, garbage results.
    173173      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
    175180      child_cost = 0.0
    176181      for child in self._children:
     
    529534      aggregate_cost = 0.0
    530535      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
    533540      return aggregate_cost
    534541
     
    951958         aggregate_cost = 0.0
    952959         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
    956968         print "\tTotal scenario cost=%10.4f" % aggregate_cost
    957969         print ""
Note: See TracChangeset for help on using the changeset viewer.