Ignore:
Timestamp:
Sep 4, 2010 1:28:07 PM (10 years ago)
Author:
jwatson
Message:

Added option to PySP scripts to allow for output of the scenario tree solutions in CSV file format. Option is --solution-writer=coopr.pysp.csvsolutionwriter.py. This also required some overdue refactoring of the PySP code, plus re-work of how the post-PH extensive form solution is displayed.

File:
1 edited

Legend:

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

    r2986 r2990  
    2929from coopr.opt.parallel import SolverManagerFactory
    3030
     31from pyutilib.component.core import ExtensionPoint
     32from coopr.pysp.solutionwriter import ISolutionWriterExtension
     33
    3134#
    3235# utility method to construct an option parser for ef writer arguments
     
    105108                     type="float",
    106109                     default=None)   
     110   parser.add_option("--solution-writer",
     111                     help="The plugin invoked to write the scenario tree solution. Defaults to the empty list.",
     112                     action="append",
     113                     dest="solution_writer",
     114                     type="string",
     115                     default = [])
    107116   parser.add_option("--output-solver-log",
    108117                     help="Output solver log during the extensive form solve.",
     
    142151      cvar_weight = options.cvar_weight
    143152      risk_alpha = options.risk_alpha
     153
     154   # validate the solution writer plugin exists, to avoid a lot of wasted work.
     155   for solution_writer_name in options.solution_writer:
     156      print "Trying to import solution writer="+solution_writer_name
     157      __import__(solution_writer_name)
     158      print "Module successfully loaded"
    144159
    145160   scenario_tree, binding_instance, scenario_instances = write_ef_from_scratch(os.path.expanduser(options.model_directory),
     
    184199      load_ef_solution(ef_results, binding_instance, scenario_instances)
    185200      scenario_tree.snapshotSolutionFromInstances(scenario_instances)
     201
     202      # handle output of solution from the scenario tree.
    186203      print ""
    187204      print "Extensive form solution:"
     
    190207      print "Extensive form costs:"
    191208      scenario_tree.pprintCosts(scenario_instances)
     209
     210      solution_writer_plugins = ExtensionPoint(ISolutionWriterExtension)
     211      for plugin in solution_writer_plugins:
     212         plugin.write(scenario_tree, "ef")
    192213
    193214def run(args=None):
Note: See TracChangeset for help on using the changeset viewer.