source: coopr.pyomo/stable/2.2/coopr/pyomo/base/indexed_component.py @ 2194

Revision 2194, 2.6 KB checked in by wehart, 4 years ago (diff)

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

........

r2122 | wehart | 2010-01-02 23:44:52 -0700 (Sat, 02 Jan 2010) | 2 lines


Adding methods to clear objective/constraint data.

........

r2125 | wehart | 2010-01-03 17:00:33 -0700 (Sun, 03 Jan 2010) | 10 lines


Extended collection of linear terms to ignore identity expressions in a
ProductExpression?.


Misc documentation update in Pyomo.


If there is no rule, then Constraint.construct() does _not_ clear the constraint
set. This had the unfortunate side-effect that user-added constraints are
cleared!

........

r2128 | wehart | 2010-01-03 23:59:03 -0700 (Sun, 03 Jan 2010) | 4 lines


Adding the @set_options decorator, which can be used
to specify options for temporary sets that are defined by
index functions.

........

r2129 | jwatson | 2010-01-04 15:41:02 -0700 (Mon, 04 Jan 2010) | 7 lines


I have changed the setitem interface for the variable base class to allow invocations of the following form:


var[None] = some_value


In cases where the variable Var is a singleton, i.e., non-indexed. This slight abuse of syntax is extremely useful in PH (and anywhere else where we have automated manipulation of variable values), as it avoids the needs for around 15 if-then statements.

........

r2130 | jwatson | 2010-01-04 16:03:42 -0700 (Mon, 04 Jan 2010) | 3 lines


Mirroring previous commit for singleton (non-indexed) parameters, allowing set via param[None].

........

r2133 | wehart | 2010-01-07 08:03:46 -0700 (Thu, 07 Jan 2010) | 2 lines


A draft implementation of expressions for intrinsic functions.

........

r2142 | wehart | 2010-01-11 18:47:07 -0700 (Mon, 11 Jan 2010) | 2 lines


Bug fix. Parameter indices do not have a keys() attribute.

........

r2145 | wehart | 2010-01-11 22:03:47 -0700 (Mon, 11 Jan 2010) | 6 lines


A stab at refactoring the pyomo command-line script, to make
it easier to write related scripts.


Unfortunately, I started doing this with a Jython installation, which
has some issues running PyUtilib?. Thus, this is not well-tested.

........

r2146 | wehart | 2010-01-11 22:19:42 -0700 (Mon, 11 Jan 2010) | 2 lines


Other updates from my laptop...

........

r2147 | wehart | 2010-01-11 22:44:35 -0700 (Mon, 11 Jan 2010) | 2 lines


Fixing bugs

........

r2148 | wehart | 2010-01-11 23:16:37 -0700 (Mon, 11 Jan 2010) | 2 lines


Bug fixes and pyomo command tests.

........

r2159 | wehart | 2010-01-13 14:59:23 -0700 (Wed, 13 Jan 2010) | 2 lines


Updates to reconfigure how files are written out by Pyomo.

........

r2160 | wehart | 2010-01-13 16:09:28 -0700 (Wed, 13 Jan 2010) | 6 lines


Adding the pyomo2lp and pyomo2nl commands.
Setting up the convert.py module, which is used in these commands.
Various fixes to scripting utilities: fixed management of
traceback functions, and reworked the processing of the save_model
option.

........

r2161 | jwatson | 2010-01-13 22:38:15 -0700 (Wed, 13 Jan 2010) | 3 lines


Cut the run-time of the PyomoModel? _load_solution method by 2/3 - it's still taking too long, but even this improvement is noticeable.

........

r2163 | wehart | 2010-01-19 22:08:40 -0700 (Tue, 19 Jan 2010) | 2 lines


Adding diagnostic output.

........

r2166 | jwatson | 2010-01-24 13:51:15 -0700 (Sun, 24 Jan 2010) | 5 lines


Allowing PyomoModel? to load a solver results object with a status equal to "Warning" - the old version threw an exception if the solver status wasn't OK.


The new version does print a warning message indicating that you are loading a solver with a warning, and that the user should take a look.

........

r2170 | wehart | 2010-01-25 16:35:49 -0700 (Mon, 25 Jan 2010) | 6 lines


A rework of the NL/LP file writers. This now uses the
canonical expression representation. I'm pretty sure that the LP writer
is OK, but much less sure about the NL writer. Also, it's clear that we don't
have adequate tests of the writers to ensure that all different types of
models are written correctly.

........

Line 
1
2from component import Component
3from sets import _BaseSet, Set, set_options
4
5def set_options(**kwds):
6    def decorator(func):
7        func.set_options = kwds
8        return func
9    return decorator
10
11
12class IndexedComponent(Component):
13
14    def __init__(self, *args, **kwds):
15        if 'ctype' not in kwds:
16            raise ValueError, "Must specify a class for the component type!"
17        Component.__init__(self, kwds['ctype'])
18        self._ndim=0
19        self._index_set=None
20        self._index={}
21        if len(args) == 0:
22            self._index={None:None}
23        elif len(args) == 1:
24            if isinstance(args[0],_BaseSet):
25                self._index=args[0]
26            elif isinstance(args[0],IndexedComponent):
27                    raise ValueError, "Cannot index a component with a non-set component"
28            else:
29                try:
30                    options = getattr(args[0],'set_options')
31                    options['initialize'] = args[0]
32                    self._index=Set(**options)
33                except:
34                    self._index=Set(initialize=args[0])
35        else:
36            tmp = []
37            for arg in args:
38                if isinstance(arg,_BaseSet):
39                    tmp.append(arg)
40                elif isinstance(arg,IndexedComponent):
41                    raise ValueError, "Cannot index a component with a non-set component"
42                else:
43                    try:
44                        options = getattr(arg,'set_options')
45                        options['initialize'] = arg
46                        tmp.append( Set(**options) )
47                    except:
48                        tmp.append( Set(initialize=arg) )
49            self._index_set=tuple(tmp)
50        self._compute_dim()
51
52    def index(self):
53        return self._index
54
55    def _compute_dim(self):
56        if self._ndim is None or self._ndim is 0:
57            if self._index_set is None:
58                if type(self._index) is dict:
59                    if len(self._index) is 0:
60                        self._ndim = 0
61                    else:
62                        val = self._index[self._index.keys()[0]]
63                        if type(val) is tuple:
64                            self._ndim = len(val)
65                        elif val is None:
66                            self._ndim = 0
67                        else:
68                            self._ndim = 1
69                else:
70                    self._ndim = self._index.dimen
71            else:
72                self._ndim = 0
73                for iset in self._index_set:
74                    self._ndim += iset.dimen
75
76
Note: See TracBrowser for help on using the repository browser.