Changeset 1751


Ignore:
Timestamp:
Oct 20, 2009 10:01:14 PM (11 years ago)
Author:
jwatson
Message:

Fixed bug in logic associated with index validation in ProductSets? occuring in situations where one of the member sets has dimension > 1.

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

Legend:

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

    r1711 r1751  
    144144              self._paramval[ndx]= _ParamValue(name=self.name+"["+str(ndx)+"]",domain=self.domain,value=val)
    145145           return
    146        
     146
    147147        if None in self._index:
    148148           raise KeyError, "Cannot set an array value in the simple parameter "+self.name
     
    158158    def _construct(self, model, data):
    159159        """ Apply the rule to construct values in this set """
    160        ## print "HERE _construct",data,self._initialize
    161160        self._model=model
    162161        if pyomo.debug("verbose"):      #pragma:nocover
     
    183182        #
    184183        if data is not None or type(self._initialize) is not types.FunctionType:
    185            #print "HERE Z",type(self._index),data,self._initialize
    186184           #
    187185           # Singleton parameter
     
    221219              #
    222220              elif self._initialize is not None:
    223                 ## print "HERE ZZ"
    224221                 if type(self._initialize) is dict:
    225                    ## print "HERE XX"
    226222                    for key in self._initialize:
    227223                      self._paramval[key] = _ParamValue(name=_name+"["+str(key)+"]",domain=_domain,value=self._initialize[key])
    228224                      self._valid_indexed_value(self._initialize[key],key,True)
    229225                 else:
    230                    ## print "HERE YY"
    231226                    for key in self._index:
    232227                      self._paramval[key] = _ParamValue(name=_name+"["+str(key)+"]",domain=_domain,value=self._initialize)
     
    274269        elif self.domain is None or value in self.domain:
    275270           return True
    276         ##print "HERE",value,type(value),self.domain
    277271        if use_exception:           #pragma:nocover
    278272           raise ValueError, "Invalid value "+str(value)+" for parameter "+self.name
  • trunk/coopr/pyomo/base/sets.py

    r1715 r1751  
    142142
    143143    def _verify(self,element,use_exception=True):
    144         #print "HERE x",element
    145         #print "ZZZZ",self.domain
    146         sys.stdout.flush()
    147144        # A utility routine that is used to verify if the element
    148145        # is valid for this set.
     
    436433    def __contains__(self, element):
    437434        """Report whether an element is a member of this set.
    438 
    439435        (Called in response to the expression 'element in self'.)
    440436        """
     
    824820           #print "HERE z1",element, tmp, self.virtual
    825821           return tmp
    826         i=0
    827         for val in element:
    828           #print "HERE a",element,val,self.set_tuple[i]
    829           if val not in self.set_tuple[i]:
     822
     823        next_tuple_index = 0
     824        member_set_index = 0
     825        for member_set in self.set_tuple:
     826           tuple_slice = element[next_tuple_index:next_tuple_index + member_set.dimen]
     827           if member_set.dimen == 1:
     828              tuple_slice = tuple_slice[0]
     829           if tuple_slice not in member_set:
    830830             return False
    831           i += 1
     831           member_set_index += 1
     832           next_tuple_index += member_set.dimen
    832833        return True
    833834       
Note: See TracChangeset for help on using the changeset viewer.