# HG changeset patch # User Nicolas Saunier # Date 1329436752 18000 # Node ID c91c8fd8bf1ee588efc92514c4afbb77f02166b7 # Parent 2788b282767043b71b6de8830cee3e678369dc03 simple vehicle model with constant acceleration diff -r 2788b2827670 -r c91c8fd8bf1e python/traffic_engineering.py --- a/python/traffic_engineering.py Wed Feb 08 15:02:30 2012 -0500 +++ b/python/traffic_engineering.py Thu Feb 16 18:59:12 2012 -0500 @@ -7,6 +7,46 @@ ######################### +# Simulation +######################### + +class Vehicle: + 'Generic vehicle class' + def __init__(self, position = 0, speed = 0, acceleration = 0, prt = 2.5, leader = None, log=True): + self.position = position + self.speed = speed + self.acceleration = acceleration + self.prt = prt + self.leader = leader + self.log = log + if log: + self.positions = [position] + self.speeds = [speed] + self.accelerations = [acceleration] + # todo add microModel + + def updatePosition(self, dt): + speed = self.speed + self.speed += self.acceleration*dt + self.position += speed*dt + if self.log: + self.positions.append(self.position) + self.speeds.append(self.speed) + self.accelerations.append(self.acceleration) + + def updateAcceleration(self, dt): + '''Updates acceleration and speed as a function of leader + and other factors''' + pass + + def update(self, dt): + self.updatePosition(dt) + self.updateAcceleration(dt) # function of leader + + def printStats(self): + print('{0} {1} {2}'.format(self.position, self.speed, self.acceleration)) + +######################### # fundamental diagram #########################