# HG changeset patch # User Nicolas Saunier # Date 1396297213 14400 # Node ID 7828fec8bbd2bf195476431f6063e84f002431b1 # Parent d337bffd7283a16fc81bbf948a47ffbf0a47b104 added function to generate headways based on flow or mean headway over some simulation period diff -r d337bffd7283 -r 7828fec8bbd2 python/traffic_engineering.py --- 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'''