source: coopr.pysp/trunk/scripts/runph @ 1979

Last change on this file since 1979 was 1979, checked in by jwatson, 10 years ago

Biggest enhancement: The efwriter command-line script now has the option to output a CVaR-weighted objective term. Not extensively tested, but behaves sane on a number of small test cases.

Improved exception handling and error diagnostics in both the runph and efwriter scripts.

  • Property svn:executable set to *
File size: 2.1 KB
Line 
1#! /usr/bin/env python
2#
3# A script that controls execution of PH on a problem instance, optionally solving the extensive form upon termination.
4#  _________________________________________________________________________
5#
6#  Coopr: A COmmon Optimization Python Repository
7#  Copyright (c) 2009 Sandia Corporation.
8#  This software is distributed under the BSD License.
9#  Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
10#  the U.S. Government retains certain rights in this software.
11#  For more information, see the FAST README.txt file.
12#  _________________________________________________________________________
13
14import traceback
15import sys
16if sys.version_info[0:2] < (2,4):
17   print ""
18   print "ERROR: Pyomo requires Python 2.4 or newer"
19   sys.exit(1)
20from os.path import abspath, dirname
21import os
22import pyutilib.common 
23sys.path.insert(0, dirname(dirname(abspath(__file__))))
24sys.path.append(".")
25currdir = dirname(abspath(__file__))
26coopr_path = dirname(currdir)
27pyutilib_path = dirname(coopr_path)+os.sep+"pyutilib"
28sys.path.append(coopr_path)
29sys.path.append(pyutilib_path)
30sys.path.append(abspath(os.getcwd()))
31
32#
33# Adjust the user path if it looks like this script is being used
34# from an Acro build (adds the Acro bin directory, if it exists).
35#
36# Recurse up the current path, looking for a subdirectory that
37# contains 'python' and 'bin'
38#
39curr = os.path.abspath(os.getcwd())
40while os.sep in curr:
41    if os.path.exists(curr+os.sep+"python") and os.path.exists(curr+os.sep+"bin"):
42        os.environ["PATH"] = curr+os.sep+"bin:"+os.environ["PATH"]
43        break
44    if os.path.basename(curr) == "":
45        break
46    curr = os.path.dirname(curr)
47
48import coopr.pysp.ph_script
49
50try:
51    coopr.pysp.ph_script.run()
52except ValueError, str:
53    print "VALUE ERROR:"
54    print str
55except IOError, str:
56    print "IO ERROR:"
57    print str
58except pyutilib.common.ApplicationError, str:
59    print "APPLICATION ERROR:"
60    print str
61except RuntimeError, str:
62    print "RUN-TIME ERROR:"   
63    print str       
64except:
65   print "Encountered unhandled exception"
66   traceback.print_exc()
Note: See TracBrowser for help on using the repository browser.