Commits

Nicolas Saunier committed 21bdeb2

corrected bug in initialization of lists and loading trajectories from vissim files

Comments (0)

Files changed (4)

                 lists.append(j.num)
         return lists
     
-    def getCPlist(self,indicatorThreshold=99999):
+    def getCPlist(self,indicatorThreshold=float('Inf')):
         lists = []
         for j in self.pairs:
             if(j.hasCP):
                         lists.append([k,j.CP[k][0]])
         return lists
      
-    def getCZlist(self,indicatorThreshold=99999):
+    def getCZlist(self,indicatorThreshold=float('Inf')):
         lists = []
         for j in self.pairs:
             if(j.hasCZ):
     Either the initialCentroids or k are passed'''
     pass
 
-def assignCluster(data, similarFunc, initialCentroids = [], shuffleData = True):
+def assignCluster(data, similarFunc, initialCentroids = None, shuffleData = True):
     '''k-means algorithm with similarity function
     Two instances should be in the same cluster if the sameCluster function returns true for two instances. It is supposed that the average centroid of a set of instances can be computed, using the function. 
     The number of clusters will be determined accordingly
     localdata = copy(data) # shallow copy to avoid modifying data
     if shuffleData:
         shuffle(localdata)
-    if initialCentroids:
+    if initialCentroids == None:
+        centroids = [Centroid(localdata[0])]
+    else:
         centroids = deepcopy(initialCentroids)
-    else:
-        centroids = [Centroid(localdata[0])]
     for instance in localdata[1:]:
         i = 0
         while i<len(centroids) and not similarFunc(centroids[i].instance, instance):
 
     def __getitem__(self, i):
         if not self.empty():
-            return self.first+i
+            if isinstance(i, int):
+                return self.first+i
+            else:
+                raise TypeError, "Invalid argument type."
+            #elif isinstance( key, slice ):
 
     def __iter__(self):
         self.iterInstantNum = -1
     def length(self):
         return self.__len__()
 
+    def __getitem__(self, i):
+        if isinstance(i, int):
+            return Point(self.positions[0][i], self.positions[1][i])
+        else:
+            raise TypeError, "Invalid argument type."
+            #elif isinstance( key, slice ):
+
     def __str__(self):
         return ' '.join([self.__getitem__(i).__str__() for i in xrange(self.length())])
 
     def __repr__(self):
-        return str(self)
-
-    def __getitem__(self, i):
-        return Point(self.positions[0][i], self.positions[1][i])
+        return self.__str__()
 
     def __iter__(self):
         self.iterInstantNum = 0
                 return True
         return False
 
-
     def wiggliness(self):
         return self.cumulatedDisplacement()/float(Point.distanceNorm2(self.__getitem__(0),self.__getitem__(self.length()-1)))
 
     longitudinal coordinate is stored as first coordinate (exterior name S)
     lateral coordiante is stored as second coordinate'''
 
-    def __init__(self, S = [], Y = [], lanes = []):
-        self.positions = [S,Y]
-        self.lanes = lanes
+    def __init__(self, S = None, Y = None, lanes = None):
+        if S == None or Y == None:
+            self.positions = [[],[]]
+        else:
+            self.positions = [S,Y]
+        if lanes == None:
+            self.lanes = []
+        else:
+            self.lanes = lanes
         
     def __getitem__(self,i): 
-        return [self.positions[0][i], self.positions[1][i], self.lanes[i]]
+        if isinstance(i, int):
+            return [self.positions[0][i], self.positions[1][i], self.lanes[i]]
+        else:
+            raise TypeError, "Invalid argument type."
+            #elif isinstance( key, slice ):
 
     def getSCoordinates(self):
         return self.getXCoordinates()

python/storage.py

             objects[objNum].curvilinearPositions = moving.CurvilinearTrajectory()
         objects[objNum].timeInterval.last = instant
         objects[objNum].curvilinearPositions.addPosition(s, y, lane)
+        if nObjects > 0 and len(objects) > nObjects:
+            return objects.values()[:nObjects]
 
     return objects.values()