Mercurial Hosting > traffic-intelligence
comparison python/event.py @ 294:1f253f218b9f
evolution of indicators and their computation in interactions
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Fri, 08 Feb 2013 18:35:24 -0500 |
parents | ee3302528cdc |
children |
comparison
equal
deleted
inserted
replaced
293:ee3302528cdc | 294:1f253f218b9f |
---|---|
15 class Interaction(moving.STObject): | 15 class Interaction(moving.STObject): |
16 '''Class for an interaction between two road users | 16 '''Class for an interaction between two road users |
17 or a road user and an obstacle | 17 or a road user and an obstacle |
18 | 18 |
19 link to the moving objects | 19 link to the moving objects |
20 contains the indicators in a dictionary with the names as keys | |
20 ''' | 21 ''' |
21 | 22 |
22 categories = {'headon': 0, | 23 categories = {'headon': 0, |
23 'rearend': 1, | 24 'rearend': 1, |
24 'side': 2, | 25 'side': 2, |
28 moving.STObject.__init__(self, num, timeInterval) | 29 moving.STObject.__init__(self, num, timeInterval) |
29 self.roaduserNumbers = set([roaduserNum1, roaduserNum2]) | 30 self.roaduserNumbers = set([roaduserNum1, roaduserNum2]) |
30 self.movingObject1 = movingObject1 | 31 self.movingObject1 = movingObject1 |
31 self.movingObject2 = movingObject2 | 32 self.movingObject2 = movingObject2 |
32 self.categoryNum = categoryNum | 33 self.categoryNum = categoryNum |
34 self.indicators = {} | |
33 | 35 |
34 def getIndicator(self, indicatorName): | 36 def getIndicator(self, indicatorName): |
35 if hasattr(self, 'indicators'): | 37 return self.indicators[indicatorName] |
36 for i in self.indicators: | 38 |
37 if i.name == indicatorName: | 39 def addIndicator(self, indicator): |
38 return i | 40 self.indicators[indicator.name] = indicator |
39 else: | |
40 return None | |
41 | 41 |
42 def computeIndicators(self): | 42 def computeIndicators(self): |
43 '''Computes the collision course cosine only if the cosine is positive''' | 43 '''Computes the collision course cosine only if the cosine is positive''' |
44 collisionCourseDotProduct = [0]*int(self.timeInterval.length()) | 44 collisionCourseDotProducts = {}#[0]*int(self.timeInterval.length()) |
45 collisionCourseCosine = {} | 45 collisionCourseCosines = {} |
46 distances = [0]*int(self.timeInterval.length()) | 46 distances = {}#[0]*int(self.timeInterval.length()) |
47 for i,instant in enumerate(self.timeInterval): | 47 speedDifferentials = {} |
48 for instant in self.timeInterval: | |
48 deltap = self.movingObject1.getPositionAtInstant(instant)-self.movingObject2.getPositionAtInstant(instant) | 49 deltap = self.movingObject1.getPositionAtInstant(instant)-self.movingObject2.getPositionAtInstant(instant) |
49 deltav = self.movingObject2.getVelocityAtInstant(instant)-self.movingObject1.getVelocityAtInstant(instant) | 50 deltav = self.movingObject2.getVelocityAtInstant(instant)-self.movingObject1.getVelocityAtInstant(instant) |
50 collisionCourseDotProduct[i] = moving.Point.dot(deltap, deltav) | 51 collisionCourseDotProduct[instant] = moving.Point.dot(deltap, deltav) |
51 distances[i] = deltap.norm2() | 52 distances[instant] = deltap.norm2() |
52 if collisionCourseDotProduct[i] > 0: | 53 speedDifferentials[instant] = deltav.norm2() |
53 collisionCourseCosine[instant] = collisionCourseDotProduct[i]/(distances[i]*deltav.norm2()) | 54 if collisionCourseDotProduct[instant] > 0: |
54 self.indicators = [moving.SeverityIndicator('Collision Course Dot Product', collisionCourseDotProduct, self.timeInterval), | 55 collisionCourseCosine[instant] = collisionCourseDotProduct[instant]/(distances[instant]*speedDifferentials[instant]) |
55 moving.SeverityIndicator('Distances', distances, self.timeInterval), | 56 # todo shorten the time intervals based on the interaction definition |
56 moving.SeverityIndicator('Collision Course Cosine', collisionCourseCosine)] | 57 self.addIndicator(moving.SeverityIndicator('Collision Course Dot Product', collisionCourseDotProducts)) |
58 self.addIndicator(moving.SeverityIndicator('Distance', distances)) | |
59 self.addIndicator(moving.SeverityIndicator('Speed Differential', speedDifferentials)) | |
60 self.addIndicator(moving.SeverityIndicator('Collision Course Cosine', collisionCourseCosines)) | |
57 | 61 |
58 | 62 |
59 def createInteractions(objects): | 63 def createInteractions(objects): |
60 '''Create all interactions of two co-existing road users | 64 '''Create all interactions of two co-existing road users |
61 | 65 |