Changeset 3048


Ignore:
Timestamp:
Sep 27, 2010 10:33:53 AM (11 years ago)
Author:
jwatson
Message:

Modifying PySP CSV solution writer to eliminate leading and trailing parantheses from index names, change embedded commas with colons, and eliminate embedded spaces.

File:
1 edited

Legend:

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

    r2990 r3048  
    1414from coopr.pysp.scenariotree import *
    1515
     16import string
     17
     18#
     19# a simple utility to munge the index name into something a bit more csv-friendly and
     20# in general more readable. at the current time, we just eliminate any leading and trailing
     21# parantheses and change commas to colons - the latter because it's a csv file!
     22#
     23
     24def index_to_string(index):
     25
     26    result = str(index)
     27    result = result.lstrip('(').rstrip(')')
     28    result = result.replace(',',':')
     29    result = result.replace(' ','')
     30
     31    return result
    1632
    1733class CSVSolutionWriter(SingletonPlugin):
     
    3349             for var_name, var in tree_node._solutions.items():
    3450                for idx in var:
    35                    print >>output_file, stage_name, ",", tree_node_name, ",", var_name, ",", idx, ",", var[idx]()
     51                   print >>output_file, stage_name, ",", tree_node_name, ",", var_name, ",", index_to_string(idx), ",", var[idx]()
    3652
    3753       output_file.close()
    3854
    3955       print "Scenario tree solution written to file="+output_filename
    40 
    41        
Note: See TracChangeset for help on using the changeset viewer.