Changeset 2385
 Timestamp:
 Feb 22, 2010 1:14:18 AM (11 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

coopr.pyomo/trunk/coopr/pyomo/base/sets.py
r2369 r2385 18 18 import types 19 19 import copy 20 import bidict 20 try: 21 import bidict 22 using_bidict=True 23 except: 24 using_bidict=False 21 25 22 26 log = pyutilib.component.core.PluginGlobals.env().log … … 71 75 self.ordered=False 72 76 self.order=[] 73 self.order_dict = bidict.bidict() 77 if using_bidict: 78 self.order_dict = bidict.bidict() 79 else: 80 self.order_dict = {} 81 self.order_dict_inv = {} 74 82 self.domain=None 75 83 self.dimen = None … … 290 298 raise TypeError, "Cannot clear virtual Set object `"+self.name+"'" 291 299 self.value.clear() 292 self.order_dict=bidict.bidict() 300 if using_bidict: 301 self.order_dict = bidict.bidict() 302 else: 303 self.order_dict = {} 304 self.order_dict_inv = {} 293 305 294 306 def check_values(self): … … 315 327 raise ValueError, "Element "+str(tmp)+" already exists in ordered set "+self.name 316 328 self.order.append(tmp) 317 self.order_dict[tmp:] = len(self.order) 329 if using_bidict: 330 self.order_dict[tmp:] = len(self.order) 331 else: 332 self.order_dict[tmp] = len(self.order) 333 self.order_dict_inv[len(self.order)] = tmp 318 334 319 335 … … 333 349 id = self.order_dict[element]1 334 350 for i in xrange(id+1,len(self.order)): 335 self.order_dict[self.order[i]] = i1 351 if using_bidict: 352 self.order_dict[self.order[i]] = i1 353 else: 354 self.order_dict[self.order[i]] = i1 355 self.order_dict_inv[i1] = self.order[i] 336 356 del self.order[id] 337 357 … … 361 381 def member(self, key): 362 382 if self.ordered: 363 return self.order_dict .inv[key]383 return self.order_dict_inv[key] 364 384 # 365 385 # If the set is not ordered, then we use the intrinsic ordering imposed by the set.
Note: See TracChangeset
for help on using the changeset viewer.