source: coopr.pyomo/stable/scripts/pyomo @ 3285

Last change on this file since 3285 was 3285, checked in by wehart, 10 years ago

Merged revisions 3184-3284 via svnmerge from
https://software.sandia.gov/svn/public/coopr/coopr.pyomo/trunk

........

r3188 | jwatson | 2010-10-29 08:09:35 -0600 (Fri, 29 Oct 2010) | 3 lines


Eliminating initial domain check when constructing numeric constants and the default domain (Reals) is specified.

........

r3203 | jwatson | 2010-10-29 14:46:18 -0600 (Fri, 29 Oct 2010) | 3 lines


Fixing bugs in has_discrete_variables() method of PyomoModel?.

........

r3211 | jdsiiro | 2010-11-01 14:49:11 -0600 (Mon, 01 Nov 2010) | 4 lines


bugfixes for Blocks:

  • avoid infinite loop when adding a block to a model
  • support pretty printing of user-defined components

........

r3212 | jdsiiro | 2010-11-02 15:17:13 -0600 (Tue, 02 Nov 2010) | 5 lines


  • cleaning up the management of Block._parent_block and Component.model attributes. Adding & removing blocks now updates the model attribute on all children
  • renaming Block._setattr_exec -> Block._add_component

........

r3213 | jdsiiro | 2010-11-03 10:47:06 -0600 (Wed, 03 Nov 2010) | 2 lines


Bugfix to the PyomoLogHandler? for python 2.4 compatibility

........

r3214 | jdsiiro | 2010-11-03 15:20:47 -0600 (Wed, 03 Nov 2010) | 3 lines


There is no point logging a warning when the problem is encountered
generating a logging.info message: log the warning at the info level.

........

r3215 | wehart | 2010-11-04 23:05:17 -0600 (Thu, 04 Nov 2010) | 3 lines


Adding a simple knapsack example to illustrate the difference between
a concrete and abstract model.

........

r3216 | jwatson | 2010-11-05 09:39:19 -0600 (Fri, 05 Nov 2010) | 3 lines


Fixing error diagnostic when indexing a variable with a bad index.

........

r3219 | jwatson | 2010-11-05 16:01:23 -0600 (Fri, 05 Nov 2010) | 3 lines


Supressing a validation test with NumericConstant?. If the user specifies a value, we are (now) assuming it is actually a numeric value - otherwise, the domain check significantly inflates the run-time associated with expression tree creation. This needs to be revisited in the Coopr 2.5 re-write.

........

r3226 | wehart | 2010-11-06 21:32:59 -0600 (Sat, 06 Nov 2010) | 2 lines


Setting up example, which was never converted.

........

r3233 | wehart | 2010-11-12 15:56:28 -0700 (Fri, 12 Nov 2010) | 4 lines


Migrating OS-specific functionality into coopr.os


Adding coopr.os to the dev.ini config file.

........

r3242 | wehart | 2010-11-13 01:28:57 -0700 (Sat, 13 Nov 2010) | 4 lines


Type fix.


Updating error message.

........

r3244 | wehart | 2010-11-13 10:44:26 -0700 (Sat, 13 Nov 2010) | 2 lines


Skipping OSiL writer when not defined.

........

r3246 | wehart | 2010-11-13 10:54:15 -0700 (Sat, 13 Nov 2010) | 2 lines


bug fix.

........

r3247 | wehart | 2010-11-13 11:14:01 -0700 (Sat, 13 Nov 2010) | 2 lines


Bug fix.

........

r3248 | jwatson | 2010-11-17 13:51:47 -0700 (Wed, 17 Nov 2010) | 3 lines


Interim fixes to output of quadratic terms in LP writer - more to do, but at least the basic examples now work.

........

r3254 | jwatson | 2010-11-19 13:19:19 -0700 (Fri, 19 Nov 2010) | 3 lines


Fixed bug in LP writer involving quadratic terms involving two distinct variables. Added two new quadratic examples.

........

r3257 | jwatson | 2010-11-19 13:59:35 -0700 (Fri, 19 Nov 2010) | 3 lines


Fixing diagnostic error message when attempting to solve quadratic programs with GLPK - code for generating message was not syntatically legal.

........

r3268 | jwatson | 2010-12-01 15:08:28 -0700 (Wed, 01 Dec 2010) | 3 lines


Fixing issues with the Piecewise construct when breakpoints and slopes are generated via rules. Works now (on a sample of size 1 - the newly added example5.py) for non-indexed rules, likely broken for indexed breakpoint/slope rules.

........

r3272 | jwatson | 2010-12-02 13:53:51 -0700 (Thu, 02 Dec 2010) | 3 lines


Adding omitted pprint() method for SOS constraints - identified while debugging a piecewise issue.

........

r3274 | jwatson | 2010-12-02 16:32:29 -0700 (Thu, 02 Dec 2010) | 3 lines


Adding example of Piecewise construct using breakpoint and slope rules, as opposed to explicit/direct lists.

........

r3276 | jwatson | 2010-12-03 14:06:40 -0700 (Fri, 03 Dec 2010) | 3 lines


Some progress toward functional indexed Piecewise components.

........

  • Property svn:executable set to *
File size: 3.1 KB
Line 
1#! /usr/bin/env python
2#
3# A script that runs a solver to optimize a pyomo model:
4#
5#   pyomo <model.py> <model.dat>
6#
7#  _________________________________________________________________________
8#
9#  Coopr: A COmmon Optimization Python Repository
10#  Copyright (c) 2008 Sandia Corporation.
11#  This software is distributed under the BSD License.
12#  Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
13#  the U.S. Government retains certain rights in this software.
14#  For more information, see the FAST README.txt file.
15#  _________________________________________________________________________
16
17import sys
18
19if sys.version_info[0:2] < (2, 4):
20    # Not choosing a bug fix revision b/c some distros don't update, but patch
21    print "\nERROR: Pyomo requires Python 2.4 or newer"
22    sys.exit(1)
23
24from os.path import abspath, dirname
25import logging
26import os
27
28Logger = logging.getLogger('Pyomo')
29
30
31sys.path.insert(0, dirname(dirname(abspath(__file__))))
32sys.path.append(".")
33currdir = dirname(abspath(__file__))
34coopr_path = dirname(currdir)
35pyutilib_path = dirname(coopr_path)+os.sep+"pyutilib"
36sys.path.append(coopr_path)
37sys.path.append(pyutilib_path)
38sys.path.append(abspath(os.getcwd()))
39#
40# Adjust the user path if it looks like this script is being used
41# from an Acro build (adds the Acro bin directory, if it exists).
42#
43# Recurse up the current path, looking for a subdirectory that
44# contains 'python' and 'bin'
45#
46curr = os.path.abspath(os.getcwd())
47while os.sep in curr:
48    if os.path.exists(curr+os.sep+"python") and                               \
49       os.path.exists(curr+os.sep+"bin"):
50        os.environ["PATH"] = curr+os.sep+"bin:"+os.environ["PATH"]
51        break
52    if os.path.basename(curr) == "":
53        break
54    curr = os.path.dirname(curr)
55
56import coopr.pyomo.scripting.pyomo
57
58class PyomoLogHandler ( logging.Handler ):
59    def __init__ ( self, base, *args, **kwargs ):
60        import logging  # why?  Shouldn't the import above be enough?
61        logging.Handler.__init__(self, *args, **kwargs )
62
63        self.basepath = base
64
65    def emit(self, record):
66        import sys   # why?  Isn't this imported above?
67                     # Doesn't work w/o it though ... ?
68
69        level    = record.levelname
70        filename = record.pathname  # file path
71        lineno   = record.lineno
72        msg      = record.getMessage()
73        try:
74            function = record.funcName
75        except AttributeError:
76            function = '(unknown)'
77
78        filename = filename.replace( self.basepath, '[coopr base]' )
79
80        sys.stderr.write('%(level)s: "%(fpath)s", %(lineno)d, '               \
81                         '%(caller)s\n\t%(msg)s\n' % \
82            {
83              'level'  : level,
84              'fpath'  : filename,
85              'lineno' : lineno,
86              'caller' : function,
87              'msg'    : msg,
88            }
89        )
90
91
92try:
93    Logger.addHandler( PyomoLogHandler(coopr_path) )
94    Logger.setLevel( 30 )  # magic number to be updated via conf file soon.
95    # 1 = lowest possible output.  i.e. everything
96
97    coopr.pyomo.scripting.pyomo.run(args=sys.argv[1:])
98except SystemExit:
99    pass
Note: See TracBrowser for help on using the repository browser.