comparison python/traffic_engineering.py @ 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 539e2b4cfaa3
children 850ed17c7b2f
comparison
equal deleted inserted replaced
478:d337bffd7283 479:7828fec8bbd2
9 9
10 10
11 ######################### 11 #########################
12 # Simulation 12 # Simulation
13 ######################### 13 #########################
14
15 def generateTimeHeadways(meanTimeHeadway, simulationTime):
16 '''Generates the time headways between arrivals
17 given the meanTimeHeadway and the negative exponential distribution
18 over a time interval of length simulationTime (assumed to be in same time unit as headway'''
19 from random import expovariate
20 headways = []
21 totalTime = 0
22 flow = 1/meanTimeHeadway
23 while totalTime < simulationTime:
24 h = expovariate(flow)
25 headways.append(h)
26 totalTime += h
27 return headways
14 28
15 class Vehicle: 29 class Vehicle:
16 '''Generic vehicle class 30 '''Generic vehicle class
17 1D coordinates for now''' 31 1D coordinates for now'''
18 class PredictedTrajectory1D(prediction.PredictedTrajectory): 32 class PredictedTrajectory1D(prediction.PredictedTrajectory):