Mercurial Hosting > traffic-intelligence
comparison python/events.py @ 487:e04b22ce2fcd
generalized createInteractions to 2 lists of objects (for cars and pedestrians for example)
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Fri, 04 Apr 2014 17:43:56 -0400 |
parents | 62d05436099d |
children | 000bddf84ad0 |
comparison
equal
deleted
inserted
replaced
485:a5847c0ca27c | 487:e04b22ce2fcd |
---|---|
146 | 146 |
147 def addInteractionType(self,interactionType): | 147 def addInteractionType(self,interactionType): |
148 ''' interaction types: conflict or collision if they are known''' | 148 ''' interaction types: conflict or collision if they are known''' |
149 self.interactionType= interactionType | 149 self.interactionType= interactionType |
150 | 150 |
151 def createInteractions(objects): | 151 def createInteractions(objects, _others = None): |
152 '''Create all interactions of two co-existing road users | 152 '''Create all interactions of two co-existing road users''' |
153 | 153 if _others != None: |
154 todo add test to compute categories?''' | 154 others = _others |
155 | |
155 interactions = [] | 156 interactions = [] |
156 num = 0 | 157 num = 0 |
157 for i in xrange(len(objects)): | 158 for i in xrange(len(objects)): |
158 for j in xrange(i): | 159 if _others == None: |
160 others = objects[:i] | |
161 for j in xrange(len(others)): | |
159 commonTimeInterval = objects[i].commonTimeInterval(objects[j]) | 162 commonTimeInterval = objects[i].commonTimeInterval(objects[j]) |
160 if not commonTimeInterval.empty(): | 163 if not commonTimeInterval.empty(): |
161 interactions.append(Interaction(num, commonTimeInterval, objects[i].num, objects[j].num, objects[i], objects[j])) | 164 interactions.append(Interaction(num, commonTimeInterval, objects[i].num, objects[j].num, objects[i], objects[j])) |
162 num += 1 | 165 num += 1 |
163 return interactions | 166 return interactions |