Changeset 3053


Ignore:
Timestamp:
Sep 29, 2010 2:51:03 PM (11 years ago)
Author:
jwatson
Message:

Fixing implementation of next() method, which never worked and wasn't actually exercised until Fernando just tried :(

File:
1 edited

Legend:

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

    r3051 r3053  
    7575
    7676        self.order=[]
     77        # IMPT: order_dict keys are 1-based.
    7778        if using_bidict:
    7879            self.order_dict = bidict.bidict()
     
    457458
    458459    def next(self, match_element, k=1):
    459         return self.order[self.order_dict[element]+k]
     460        # NOTE: we currently aren't consist (and don't actually deal with) w.r.t. unordered sets - see the implementation of member() above.
     461        try:
     462           element_position = self.order_dict[match_element]
     463        except KeyError:
     464           raise KeyError, "Cannot obtain next() member of set="+self.name+"; input element="+str(match_element)+" is not a member of the set!"
     465
     466        try:
     467           return self.order[element_position+k-1] # "order" is a list, accessed 0-based.
     468        except KeyError:
     469           raise KeyError, "Cannot obtain next() member of set="+self.name+"; failed to access item in position="+str(element_position+k-1)
    460470
    461471    def nextw(self, match_element, k=1):
Note: See TracChangeset for help on using the changeset viewer.