changeset 541:048b43654870

added condition on warmup time to load trajectories from vissim files and corrected condition on number of objects
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Mon, 07 Jul 2014 12:30:46 -0400
parents 4fdce0f09ece
children a3add9f751ef
files python/storage.py
diffstat 1 files changed, 11 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/python/storage.py	Fri Jul 04 17:38:25 2014 -0400
+++ b/python/storage.py	Mon Jul 07 12:30:46 2014 -0400
@@ -419,7 +419,7 @@
             finally: self.sechead = None
         else: return self.fp.readline()
 
-def loadTrajectoriesFromVissimFile(filename, simulationStepsPerTimeUnit, nObjects = -1):
+def loadTrajectoriesFromVissimFile(filename, simulationStepsPerTimeUnit, nObjects = -1, warmUpLastInstant = None):
     '''Reads data from VISSIM .fzp trajectory file
     simulationStepsPerTimeUnit is the number of simulation steps per unit of time used by VISSIM
     for example, there seems to be 5 simulation steps per simulated second in VISSIM, 
@@ -428,6 +428,7 @@
 
     Assumed to be sorted over time'''
     objects = {} # dictionary of objects index by their id
+    firstInstants = {}
 
     infile = openCheck(filename, quitting = True)
 
@@ -443,13 +444,15 @@
         s = float(data[4])
         y = float(data[5])
         lane = data[2]+'_'+data[3]
-        if objNum not in objects:
-            objects[objNum] = moving.MovingObject(num = objNum, timeInterval = moving.TimeInterval(instant, instant))
-            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]
+        if objNum not in firstInstants:
+            firstInstants[objNum] = instant
+            if warmUpLastInstant == None or firstInstants[objNum] >= warmUpLastInstant:
+                if nObjects < 0 or len(objects) < nObjects:
+                    objects[objNum] = moving.MovingObject(num = objNum, timeInterval = moving.TimeInterval(instant, instant))
+                    objects[objNum].curvilinearPositions = moving.CurvilinearTrajectory()
+        if (warmUpLastInstant == None or firstInstants[objNum] >= warmUpLastInstant) and objNum in objects:
+            objects[objNum].timeInterval.last = instant
+            objects[objNum].curvilinearPositions.addPosition(s, y, lane)
 
     return objects.values()