Mercurial Hosting > traffic-intelligence
comparison python/traffic_engineering.py @ 652:3b13ec964476
removed useless and buggy code
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Fri, 24 Apr 2015 17:02:47 +0200 |
parents | 850ed17c7b2f |
children | 15e244d2a1b5 |
comparison
equal
deleted
inserted
replaced
651:335f6641bf7a | 652:3b13ec964476 |
---|---|
24 h = expovariate(flow) | 24 h = expovariate(flow) |
25 headways.append(h) | 25 headways.append(h) |
26 totalTime += h | 26 totalTime += h |
27 return headways | 27 return headways |
28 | 28 |
29 class Vehicle: | 29 class RoadUser: |
30 '''Generic vehicle class | 30 '''Simple example of inheritance to plot different road users ''' |
31 1D coordinates for now''' | 31 def __init__(self, position, velocity): |
32 class PredictedTrajectory1D(prediction.PredictedTrajectory): | 32 'Both fields are 2D numpy arrays' |
33 def __init__(self, initialPosition, initialSpeed, control, maxSpeed = None): | 33 self.position = position.astype(float) |
34 self.control = control | 34 self.velocity = velocity.astype(float) |
35 self.maxSpeed = maxSpeed | 35 |
36 self.probability = None | 36 def move(self, deltaT): |
37 self.predictedPositions = {0: moving.Point(initialPosition)} | 37 self.position += deltaT*self.velocity |
38 self.predictedSpeedOrientations = {0: moving.NormAngle(initialSpeed, 0)} | 38 |
39 | 39 def draw(self, init = False): |
40 def setAcceleration(self, acceleration): | 40 from matplotlib.pyplot import plot |
41 self.control = moving.NormAngle(acceleration, 0) | 41 if init: |
42 | 42 self.plotLine = plot(self.position[0], self.position[1], self.getDescriptor())[0] |
43 def getControl(self): | 43 else: |
44 return self.control | 44 self.plotLine.set_data(self.position[0], self.position[1]) |
45 | 45 |
46 | 46 |
47 def __init__(self, initialPosition = 0, initialSpeed = 0, acceleration = 0, prt = 2.5, leader = None): | 47 class PassengerVehicle(RoadUser): |
48 self.positions = PredictedTrajectory1D(initialPosition, initialSpeed) | 48 def getDescriptor(self): |
49 | 49 return 'dr' |
50 self.prt = prt | 50 |
51 self.leader = leader | 51 class Pedestrian(RoadUser): |
52 # todo add microModel (Treiber) | 52 def getDescriptor(self): |
53 | 53 return 'xb' |
54 def setAcceleration(self, acceleration): | 54 |
55 self.positions.setAcceleration(acceleration) | 55 class Cyclist(RoadUser): |
56 | 56 def getDescriptor(self): |
57 def updatePosition(self, dt): # knowledge of time outside of vehicle ?? | 57 return 'og' |
58 speed = self.speed | 58 |
59 self.speed += self.acceleration*dt | |
60 self.position += speed*dt | |
61 if self.log: | |
62 self.positions.append(self.position) | |
63 self.speeds.append(self.speed) | |
64 self.accelerations.append(self.acceleration) | |
65 | |
66 def updateAcceleration(self, dt): | |
67 '''Updates acceleration and speed as a function of leader | |
68 and other factors''' | |
69 pass | |
70 | |
71 def update(self, dt): | |
72 self.updatePosition(dt) | |
73 self.updateAcceleration(dt) # function of leader | |
74 | |
75 def printStats(self): | |
76 print('{0} {1} {2}'.format(self.position, self.speed, self.acceleration)) | |
77 | 59 |
78 ######################### | 60 ######################### |
79 # fundamental diagram | 61 # fundamental diagram |
80 ######################### | 62 ######################### |
81 | 63 |