Mercurial Hosting > traffic-intelligence
changeset 479:7828fec8bbd2
added function to generate headways based on flow or mean headway over some simulation period
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Mon, 31 Mar 2014 16:20:13 -0400 |
parents | d337bffd7283 |
children | f43bc0b0ba74 |
files | python/traffic_engineering.py |
diffstat | 1 files changed, 14 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/python/traffic_engineering.py Thu Mar 27 11:40:28 2014 -0400 +++ b/python/traffic_engineering.py Mon Mar 31 16:20:13 2014 -0400 @@ -12,6 +12,20 @@ # Simulation ######################### +def generateTimeHeadways(meanTimeHeadway, simulationTime): + '''Generates the time headways between arrivals + given the meanTimeHeadway and the negative exponential distribution + over a time interval of length simulationTime (assumed to be in same time unit as headway''' + from random import expovariate + headways = [] + totalTime = 0 + flow = 1/meanTimeHeadway + while totalTime < simulationTime: + h = expovariate(flow) + headways.append(h) + totalTime += h + return headways + class Vehicle: '''Generic vehicle class 1D coordinates for now'''