Changeset 3071


Ignore:
Timestamp:
Oct 4, 2010 12:13:16 PM (11 years ago)
Author:
wehart
Message:

Bug fixes to param management.

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

Legend:

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

    r2994 r3071  
    4040    if obj is None:
    4141        return None
    42     elif type(obj) in [bool,int,long,float]:
     42    elif type(obj) in [bool,int,long,float,str]:
    4343        return obj
    4444    if not isinstance(obj, NumericValue):
  • coopr.pyomo/trunk/coopr/pyomo/base/param.py

    r3068 r3071  
    154154            return self._default.value
    155155
    156         msg = "Unknown index '%s' in parameter '%s"
    157         raise KeyError, msg % (str(ndx), self.name )
     156        msg = "Unknown index '%s' in parameter '%s: keys=%s"
     157        raise KeyError, msg % (str(ndx), self.name, str(self._index.data()) )
    158158
    159159    def __setitem__(self,ndx,val):
     
    186186            raise KeyError, msg % ( self.name, str(ndx) )
    187187        #
    188         if not self._valid_indexed_value(val,ndx,False):
    189             msg = "Invalid parameter value: %s[%s] = '%s'"
    190             raise ValueError, msg % ( self.name, str(ndx), str(val) )
    191         #
    192188        if self.mutable:
    193189            if ndx in self._paramval:
     
    201197        else:
    202198            self._paramval[ndx] = val
     199        #
     200        # This is at the end, so the user can write their validation
     201        # tests as if the data was already added.
     202        #
     203        if not self._valid_indexed_value(val,ndx,False):
     204            msg = "Invalid parameter value: %s[%s] = '%s'"
     205            raise ValueError, msg % ( self.name, str(ndx), str(val) )
    203206
    204207    def construct(self, data=None):
     
    325328
    326329           if index is not None:
    327               tmp = tmp + list(index)
     330              if type(index) is tuple:
     331                 tmp = tmp + list(index)
     332              else:
     333                 tmp = tmp + [ index ]
    328334
    329335           tmp.append(self.model)
Note: See TracChangeset for help on using the changeset viewer.