changeset 198:c91c8fd8bf1e

simple vehicle model with constant acceleration
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Thu, 16 Feb 2012 18:59:12 -0500
parents 2788b2827670
children ca9d9104afba
files python/traffic_engineering.py
diffstat 1 files changed, 40 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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
 #########################