Using PySP from script

180 views
Skip to first unread message

JolleG

unread,
Mar 18, 2015, 5:55:24 AM3/18/15
to pyomo...@googlegroups.com
Hi,

I'm starting to use PySP and so far I have only made runs from the command window. Now I'd like to use PySP from a script, so that I can afterwards process the solution. How would I do this?

Best,
Jonatan

David Woodruff

unread,
Mar 18, 2015, 11:51:54 AM3/18/15
to pyomo...@googlegroups.com
Hi Jonatan,
 If you want to process the solution, then you could write your own "solution writer." There is an example in
pyomo/src/pyomo/pyomo/pysp/plugins/csvsolutionwriter.py
the method for using it (i.e. calling it) is documented in the Getting Started online document.
   Best,
     Dave

--
You received this message because you are subscribed to the Google Groups "Pyomo Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jonatan Rantzer

unread,
Mar 19, 2015, 5:23:25 AM3/19/15
to pyomo...@googlegroups.com
Hi David and all,

I checked out the CSV soution writer and I guess it would be a possibility either to use it as it is, or to modify it for my purposes. But my follow up question would be: how can I then use it inside a script. I guess it would be something like:

instanceWriter = CSVSolutionWriter(?)
instanceWriter.write(myScenarioTree, myResult)

This question is a part of my more general question: how do I solve a stochastic programming problem from a script and process the solution? I guess I could somehow find out from studying the source code, but I'm hoping to get some guidance, since for the ordinary deterministic optimization problems there was some documentation on how to solve them using own-written scripts.

Thanks for the help,
Jonatan

--
You received this message because you are subscribed to a topic in the Google Groups "Pyomo Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pyomo-forum/J5Dhc2BD680/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pyomo-forum...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
/ Jonatan Rantzer

David Woodruff

unread,
Mar 19, 2015, 2:13:00 PM3/19/15
to pyomo...@googlegroups.com
Hi Jonatan,
   There is no documentation because the APIs for scripting pysp are not yet stable enough (beyond creating your own output plugin).  Let's take this conversation off-line and see if there is something we can do to help you.
Dave

Christopher Hagmann

unread,
Mar 19, 2015, 4:23:12 PM3/19/15
to pyomo...@googlegroups.com
This is not supported, but the way I do scripting with PySP is to run it in the command line via the script using the `os` module. My code is below:

def command_line(command, tee=False):
    '''
    Run command line commands in Python Script and return stdout as list.
    '''
    stdin,stdout = os.popen2(command)
    stdin.close()
    lines = stdout.readlines()
    stdout.close()
    lines = [line.strip('\n') for line in lines]

    if tee:
        print '\n'.join(lines)

    return lines

EXAMPLE:
>>> command_line('chdir')
['C:\\User\\Chris']

After you get the output, you can write whatever you like to parse the output.

Jonatan Rantzer

unread,
Mar 26, 2015, 10:57:43 AM3/26/15
to pyomo...@googlegroups.com
Thank you for this idea Christopher, it seems like a practical strategy.
Jonatan

--
You received this message because you are subscribed to a topic in the Google Groups "Pyomo Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pyomo-forum/J5Dhc2BD680/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pyomo-forum...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
/ Jonatan Rantzer
Reply all
Reply to author
Forward
0 new messages