Changeset 5774


Ignore:
Timestamp:
May 13, 2012 10:30:51 PM (7 years ago)
Author:
wehart
Message:

Collapsing the nested dictionaries used to manage suffix data.

For large models, with many variables, this should have a BIG impact on memory.

Location:
coopr.pyomo/trunk/coopr/pyomo/base
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • coopr.pyomo/trunk/coopr/pyomo/base/indexed_component.py

    r5769 r5774  
    166166        # generate this attribute for all variables
    167167        #
    168         if len(self._data) > 0:
    169             self._suffix_value[suffix] = {}
     168        #if len(self._data) > 0:
     169            #self._suffix_value[suffix] = {}
    170170
    171171    def suffix_defined(self, suffix):
     
    176176
    177177    def get_suffix_value(self, suffix, index=None):
    178         _value = self._suffix_value[suffix]
    179         if not index in _value:
     178        try:
     179            return self._suffix_value[suffix, index]
     180        except KeyError:
    180181            default = self._suffix_declaration[suffix]
    181182            if not default[0] is None:
     
    183184            if not default[1] is None:
    184185                val = default[1](self)
    185                 _value[index] = val
     186                self._suffix_value[suffix, index] = val
    186187                return val
    187188            return None
    188         return _value[index]
    189189
    190190    def set_suffix_value(self, suffix, value, index=None, define=False):
    191         if define and suffix not in self._suffix_value:
     191        if define and suffix not in self._suffix_declaration:
    192192            self.declare_suffix(suffix)
    193         self._suffix_value[suffix][index] = value
     193        self._suffix_value[suffix, index] = value
    194194
  • coopr.pyomo/trunk/coopr/pyomo/base/var.py

    r5769 r5774  
    293293
    294294        #Handle within=not_pyomo_object
    295         if not hasattr(self.domain,'virtual') or not self.domain.virtual:
     295        if not getattr(self.domain, 'virtual', False):
    296296            if self.domain == [] or self.domain == set([]):
    297297                raise ValueError,"Attempting to set a variable's domain to an empty set"
Note: See TracChangeset for help on using the changeset viewer.