Changeset 2129


Ignore:
Timestamp:
Jan 4, 2010 5:41:02 PM (11 years ago)
Author:
jwatson
Message:

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.

File:
1 edited

Legend:

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

    r2099 r2129  
    206206    def __setitem__(self,ndx,val):
    207207        #print "HERE",ndx,val, self._valid_value(val,False), self.domain
    208         if None in self._index:
     208        if (None in self._index) and (ndx is not None): # allow for None indexing if this is truly a singleton
    209209            raise KeyError, "Cannot set an array value in singleton variable "+self.name
    210210        if ndx not in self._index:
Note: See TracChangeset for help on using the changeset viewer.