Mercurial Hosting > traffic-intelligence
changeset 1151:658f87232536
extended creation of interactions to non simultaneous objects for PET calculations
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 01 Jul 2020 11:02:52 -0400 |
parents | 14140b55e580 |
children | f52844c71454 |
files | trafficintelligence/events.py trafficintelligence/tests/events.txt |
diffstat | 2 files changed, 13 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/trafficintelligence/events.py Thu May 28 01:03:45 2020 -0400 +++ b/trafficintelligence/events.py Wed Jul 01 11:02:52 2020 -0400 @@ -295,7 +295,7 @@ def getCrossingZones(self): return self.crossingZones -def createInteractions(objects, _others = None): +def createInteractions(objects, _others = None, maxDurationApart = 0): '''Create all interactions of two co-existing road users''' if _others is not None: others = _others @@ -307,7 +307,7 @@ others = objects[:i] for j in range(len(others)): commonTimeInterval = objects[i].commonTimeInterval(others[j]) - if not commonTimeInterval.empty(): + if not commonTimeInterval.empty() or (maxDurationApart > 0 and objects[i].getTimeInterval().distance(objects[j].getTimeInterval()) < maxDurationApart): interactions.append(Interaction(num, commonTimeInterval, objects[i].num, others[j].num, objects[i], others[j])) num += 1 return interactions
--- a/trafficintelligence/tests/events.txt Thu May 28 01:03:45 2020 -0400 +++ b/trafficintelligence/tests/events.txt Wed Jul 01 11:02:52 2020 -0400 @@ -6,10 +6,21 @@ >>> interactions = createInteractions(objects) >>> len([i for i in interactions if len(i.roadUserNumbers) == 1]) 0 +>>> len(interactions) +45 >>> objects2 = [MovingObject(num = i, timeInterval = TimeInterval(0,10)) for i in range(100, 110)] >>> interactions = createInteractions(objects, objects2) >>> len([i for i in interactions if len(i.roadUserNumbers) == 1]) 0 +>>> objects3 = [MovingObject(num = i, timeInterval = TimeInterval(12,22)) for i in range(100, 110)] +>>> interactions = createInteractions(objects, objects3) +>>> len(interactions) +0 +>>> interactions = createInteractions(objects, objects3, 3) +>>> len(interactions) +100 +>>> interactions[0].getTimeInterval().empty() +True >>> o1 = MovingObject.generate(1, Point(-5.,0.), Point(0.,0.), TimeInterval(0,10)) >>> o2 = MovingObject.generate(2, Point(0.,-5.), Point(0.,1.), TimeInterval(0,10))