Mercurial Hosting > traffic-intelligence
changeset 291:9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
author | Paul@BEAST-III |
---|---|
date | Tue, 05 Feb 2013 15:45:33 -0500 |
parents | df58d361f19e |
children | 8b2c8a4015f1 |
files | python/event.py python/prediction.py |
diffstat | 2 files changed, 94 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/python/event.py Tue Jan 29 18:23:47 2013 -0500 +++ b/python/event.py Tue Feb 05 15:45:33 2013 -0500 @@ -4,9 +4,98 @@ #import utils; import moving +import prediction __metaclass__ = type +## Subsumes createInteractions(objects) with a VehPair Object +class VehPairs(): + def __init__(self,objects): + ''' + Create all pairs of two co-existing road users + TODO: add test to compute categories? + ''' + #print(' -------------') #Disabled for traffic-intelligence trunk + #print(' Generating vehicle pairs...') #Disabled for traffic-intelligence trunk + + self.pairs = [] + num = 0 + for i in xrange(len(objects)): + for j in xrange(i): + commonTimeInterval = objects[i].commonTimeInterval(objects[j]) + if not commonTimeInterval.empty(): + self.pairs.append(event.Interaction(num, commonTimeInterval, objects[i].num, objects[j].num, objects[i], objects[j])) + num += 1 + + def calculateIndicators(self,predParam,frameRate=15,collisionDistanceThreshold=1.8,timeHorizonMultiplier=5): + #print(' -------------') #Disabled for traffic-intelligence trunk + #print(' Calculating time-to-collision...') #Disabled for traffic-intelligence trunk + + timeHorizon = frameRate*timeHorizonMultiplier # prediction time Horizon = 1.5 s (reaction time) (5 second) + + for params in [predParam]: + + #prog = Tools.ProgressBar(0, len(self.pairs), 77) #Disabled for traffic-intelligence trunk (PVA Tools dependancy) + for j in xrange(len(self.pairs)): + #prog.updateAmount(j) #Disabled for traffic-intelligence trunk (PVA Tools dependancy) + + collisionPoints, crossingZones = prediction.computeCrossingsCollisions(self.pairs[j].movingObject1, self.pairs[j].movingObject2, predParam, collisionDistanceThreshold, timeHorizon) + + # Ignore empty collision points + empty = 1 + for i in collisionPoints: + if(collisionPoints[i] != []): + empty = 0 + if(empty == 1): + self.pairs[j].hasCP = 0 + else: + self.pairs[j].hasCP = 1 + self.pairs[j].CP = collisionPoints + + # Ignore empty crossing zones + empty = 1 + for i in crossingZones: + if(crossingZones[i] != []): + empty = 0 + if(empty == 1): + self.pairs[j].hasCZ = 0 + else: + self.pairs[j].hasCZ = 1 + self.pairs[j].CZ = crossingZones + return + + def getPairsWCP(self): + lists = [] + for j in self.pairs: + if(j.hasCP): + lists.append(j.num) + return lists + + def getPairsWCZ(self): + lists = [] + for j in self.pairs: + if(j.hasCZ): + lists.append(j.num) + return lists + + def getCPlist(self): + lists = [] + for j in self.pairs: + if(j.hasCP): + for k in j.CP: + if(j.CP[k] != []): + lists.append(j.CP[k]) + return lists + + def getCZlist(self): + lists = [] + for j in self.pairs: + if(j.hasCZ): + for k in j.CZ: + if(j.CZ[k] != []): + lists.append(j.CZ[k]) + return lists + class Interaction(moving.STObject): '''Class for an interaction between two road users or a road user and an obstacle @@ -50,6 +139,8 @@ moving.SeverityIndicator('Distances', distances, self.timeInterval), moving.SeverityIndicator('Collision Course Cosine', collisionCourseCosine)] + +######====>BEGIN LEGACY CODE def createInteractions(objects): '''Create all interactions of two co-existing road users @@ -63,6 +154,9 @@ interactions.append(Interaction(num, commonTimeInterval, objects[i].num, objects[j].num, objects[i], objects[j])) num += 1 return interactions +#<====END LEGACY CODE##### + + class Crossing(moving.STObject): '''Class for the event of a street crossing
--- a/python/prediction.py Tue Jan 29 18:23:47 2013 -0500 +++ b/python/prediction.py Tue Feb 05 15:45:33 2013 -0500 @@ -248,7 +248,6 @@ else: commonTimeInterval = obj1.commonTimeInterval(obj2) for i in list(commonTimeInterval)[:-1]: # do not look at the 1 last position/velocities, often with errors - print(obj1.num, obj2.num, i) collisionPoints[i], crossingZones[i] = computeCrossingsCollisionsAtInstant(i, obj1, obj2, predictionParameters, collisionDistanceThreshold, timeHorizon, debug) return collisionPoints, crossingZones