Mercurial Hosting > traffic-intelligence
annotate python/traffic_engineering.py @ 300:f65b828e5521
working on trajectory simulation
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 13 Feb 2013 18:26:49 -0500 |
parents | 82b4101d9a2f |
children | 9d88a4d97473 |
rev | line source |
---|---|
33
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
1 #! /usr/bin/env python |
73
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
2 ''' Traffic Engineering Tools and Examples''' |
33
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
3 |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
4 from math import ceil |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
5 |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
6 __metaclass__ = type |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
7 |
73
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
8 |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
9 ######################### |
198
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
10 # Simulation |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
11 ######################### |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
12 |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
13 class Vehicle: |
300
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
14 'Generic vehicle class |
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
15 1D coordinates for now' |
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
16 class PredictedTrajectory1D(prediction.PredictedTrajectory): |
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
17 def __init__(self, initialPosition, initialSpeed, control, maxSpeed = None): |
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
18 self.control = control |
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
19 self.maxSpeed = maxSpeed |
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
20 self.probability = None |
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
21 self.predictedPositions = {0: moving.Point(initialPosition)} |
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
22 self.predictedSpeedOrientations = {0: moving.NormAngle(initialSpeed, 0)} |
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
23 |
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
24 def setAcceleration(self, acceleration): |
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
25 self.control = moving.NormAngle(acceleration, 0) |
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
26 |
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
27 def getControl(self): |
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
28 return self.control |
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
29 |
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
30 |
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
31 def __init__(self, initialPosition = 0, initialSpeed = 0, acceleration = 0, prt = 2.5, leader = None): |
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
32 self.positions = PredictedTrajectory1D(initialPosition, initialSpeed) |
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
33 |
198
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
34 self.prt = prt |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
35 self.leader = leader |
300
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
36 # todo add microModel (Treiber) |
198
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
37 |
300
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
38 def setAcceleration(self, acceleration): |
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
39 self.positions.setAcceleration(acceleration) |
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
40 |
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
41 def updatePosition(self, dt): # knowledge of time outside of vehicle ?? |
198
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
42 speed = self.speed |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
43 self.speed += self.acceleration*dt |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
44 self.position += speed*dt |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
45 if self.log: |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
46 self.positions.append(self.position) |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
47 self.speeds.append(self.speed) |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
48 self.accelerations.append(self.acceleration) |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
49 |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
50 def updateAcceleration(self, dt): |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
51 '''Updates acceleration and speed as a function of leader |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
52 and other factors''' |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
53 pass |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
54 |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
55 def update(self, dt): |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
56 self.updatePosition(dt) |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
57 self.updateAcceleration(dt) # function of leader |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
58 |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
59 def printStats(self): |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
60 print('{0} {1} {2}'.format(self.position, self.speed, self.acceleration)) |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
61 |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
62 ######################### |
73
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
63 # fundamental diagram |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
64 ######################### |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
65 |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
66 class FundamentalDiagram: |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
67 ''' ''' |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
68 def __init__(self, name): |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
69 self.name = name |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
70 |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
71 def q(self, k): |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
72 return k*self.v(k) |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
73 |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
74 @staticmethod |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
75 def meanHeadway(k): |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
76 return 1/k |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
77 |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
78 @staticmethod |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
79 def meanSpacing(q): |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
80 return 1/q |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
81 |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
82 def plotVK(self, language='fr', units={}): |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
83 from numpy import arange |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
84 from matplotlib.pyplot import figure,plot,xlabel,ylabel |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
85 densities = [k for k in arange(1, self.kj+1)] |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
86 figure() |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
87 plot(densities, [self.v(k) for k in densities]) |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
88 xlabel('Densite (veh/km)') # todo other languages and adapt to units |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
89 ylabel('Vitesse (km/h)') |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
90 |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
91 def plotQK(self, language='fr', units={}): |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
92 from numpy import arange |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
93 from matplotlib.pyplot import figure,plot,xlabel,ylabel |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
94 densities = [k for k in arange(1, self.kj+1)] |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
95 figure() |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
96 plot(densities, [self.q(k) for k in densities]) |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
97 xlabel('Densite (veh/km)') # todo other languages and adapt to units |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
98 ylabel('Debit (km/h)') |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
99 |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
100 class GreenbergFD(FundamentalDiagram): |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
101 '''Speed is the logarithm of density''' |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
102 def __init__(self, vc, kj): |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
103 FundamentalDiagram.__init__(self,'Greenberg') |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
104 self.vc=vc |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
105 self.kj=kj |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
106 |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
107 def v(self,k): |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
108 from numpy import log |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
109 return self.vc*log(self.kj/k) |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
110 |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
111 def criticalDensity(self): |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
112 from numpy import e |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
113 self.kc = self.kj/e |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
114 return self.kc |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
115 |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
116 def capacity(self): |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
117 self.qmax = self.kc*self.vc |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
118 return self.qmax |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
119 |
33
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
120 ######################### |
116
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
121 # intersection |
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
122 ######################### |
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
123 |
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
124 class FourWayIntersection: |
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
125 '''Simple class for simple intersection outline''' |
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
126 def __init__(self, dimension, coordX, coordY): |
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
127 self.dimension = dimension |
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
128 self.coordX = coordX |
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
129 self.coordY = coordY |
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
130 |
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
131 def plot(self, options = 'k'): |
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
132 from matplotlib.pyplot import plot, axis |
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
133 |
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
134 minX = min(self.dimension[0]) |
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
135 maxX = max(self.dimension[0]) |
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
136 minY = min(self.dimension[1]) |
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
137 maxY = max(self.dimension[1]) |
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
138 |
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
139 plot([minX, self.coordX[0], self.coordX[0]], [self.coordY[0], self.coordY[0], minY],options) |
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
140 plot([self.coordX[1], self.coordX[1], maxX], [minY, self.coordY[0], self.coordY[0]],options) |
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
141 plot([minX, self.coordX[0], self.coordX[0]], [self.coordY[1], self.coordY[1], maxY],options) |
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
142 plot([self.coordX[1], self.coordX[1], maxX], [maxY, self.coordY[1], self.coordY[1]],options) |
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
143 axis('equal') |
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
144 |
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
145 ######################### |
33
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
146 # traffic signals |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
147 ######################### |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
148 |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
149 class Volume: |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
150 '''Class to represent volumes with varied vehicule types ''' |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
151 def __init__(self, volume, types = ['pc'], proportions = [1], equivalents = [1], nLanes = 1): |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
152 '''mvtEquivalent is the equivalent if the movement is right of left turn''' |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
153 |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
154 # check the sizes of the lists |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
155 if sum(proportions) == 1: |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
156 self.volume = volume |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
157 self.types = types |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
158 self.proportions = proportions |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
159 self.equivalents = equivalents |
206
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
160 self.nLanes = nLanes # unused |
33
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
161 else: |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
162 pass |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
163 |
205
aeaaf5579b46
minor changes to traffic engineering
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
198
diff
changeset
|
164 def getPCUVolume(self): |
33
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
165 '''Returns the passenger-car equivalent for the input volume''' |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
166 v = 0 |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
167 for p, e in zip(self.proportions, self.equivalents): |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
168 v += p*e |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
169 return v*self.volume |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
170 |
34 | 171 class IntersectionMovement: |
33
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
172 '''Represents an intersection movement |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
173 with a volume, a type (through, left or right) |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
174 and an equivalent for movement type''' |
205
aeaaf5579b46
minor changes to traffic engineering
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
198
diff
changeset
|
175 def __init__(self, volume, mvtEquivalent = 1): |
33
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
176 self.volume = volume |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
177 self.mvtEquivalent = mvtEquivalent |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
178 |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
179 def getTVUVolume(self): |
205
aeaaf5579b46
minor changes to traffic engineering
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
198
diff
changeset
|
180 return self.mvtEquivalent*self.volume.getPCUVolume() |
33
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
181 |
206
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
182 class IntersectionApproach: # should probably not be used |
33
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
183 def __init__(self, leftTurnVolume, throughVolume, rightTurnVolume): |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
184 self.leftTurnVolume = leftTurnVolume |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
185 self.throughVolume = throughVolume |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
186 self.rightTurnVolume = rightTurnVolume |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
187 |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
188 def getTVUVolume(self, leftTurnEquivalent = 1, throughEquivalent = 1, rightTurnEquivalent = 1): |
205
aeaaf5579b46
minor changes to traffic engineering
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
198
diff
changeset
|
189 return self.leftTurnVolume.getPCUVolume()*leftTurnEquivalent+self.throughVolume.getPCUVolume()*throughEquivalent+self.rightTurnVolume.getPCUVolume()*rightTurnEquivalent |
33
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
190 |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
191 class LaneGroup: |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
192 '''Class that represents a group of mouvements''' |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
193 |
34 | 194 def __init__(self, movements, nLanes): |
195 self.movements = movements | |
196 self.nLanes = nLanes | |
33
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
197 |
34 | 198 def getTVUVolume(self): |
199 return sum([mvt.getTVUVolume() for mvt in self.movements]) | |
33
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
200 |
206
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
201 def getCharge(self, saturationVolume): |
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
202 return self.getTVUVolume()/(self.nLanes*saturationVolume) |
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
203 |
33
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
204 def checkProtectedLeftTurn(leftMvt, opposedThroughMvt): |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
205 '''Checks if one of the main two conditions on left turn is verified |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
206 The lane groups should contain left and through movement''' |
34 | 207 return leftMvt.volume >= 200 or leftMvt.volume*opposedThroughMvt.volume/opposedThroughMvt.nLanes > 50000 |
208 | |
206
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
209 def optimalCycle(lostTime, criticalCharge): |
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
210 return (1.5*lostTime+5)/(1-criticalCharge) |
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
211 |
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
212 def minimumCycle(lostTime, criticalCharge, degreeSaturation=1.): |
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
213 'degree of saturation can be used as the peak hour factor too' |
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
214 return lostTime/(1-criticalCharge/degreeSaturation) |
34 | 215 |
216 class Cycle: | |
217 '''Class to compute optimal cycle and the split of effective green times''' | |
218 def __init__(self, phases, lostTime, saturationVolume): | |
219 '''phases is a list of phases | |
220 a phase is a list of lanegroups''' | |
221 self.phases = phases | |
222 self.lostTime = lostTime | |
223 self.saturationVolume = saturationVolume | |
33
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
224 |
206
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
225 def computeCriticalCharges(self): |
34 | 226 self.criticalCharges = [] |
227 for phase in self.phases: | |
206
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
228 self.criticalCharges.append(max([lg.getCharge(self.saturationVolume) for lg in phase])) |
34 | 229 self.criticalCharge = sum(self.criticalCharges) |
206
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
230 |
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
231 def computeOptimalCycle(self): |
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
232 self.computeCriticalCharges() |
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
233 self.C = optimalCycle(self.lostTime, self.criticalCharge) |
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
234 return self.C |
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
235 |
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
236 def computeMinimumCycle(self, degreeSaturation=1.): |
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
237 self.computeCriticalCharges() |
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
238 self.C = minimumCycle(self.lostTime, self.criticalCharge, degreeSaturation) |
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
239 return self.C |
34 | 240 |
241 def computeEffectiveGreen(self): | |
242 from numpy import round | |
206
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
243 #self.computeCycle() # in case it was not done before |
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
244 effectiveGreenTime = self.C-self.lostTime |
34 | 245 self.effectiveGreens = [round(c*effectiveGreenTime/self.criticalCharge,1) for c in self.criticalCharges] |
246 return self.effectiveGreens | |
247 | |
33
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
248 |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
249 def computeInterGreen(perceptionReactionTime, initialSpeed, intersectionLength, vehicleAverageLength = 6, deceleration = 3): |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
250 '''Computes the intergreen time (yellow/amber plus all red time) |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
251 Deceleration is positive |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
252 All variables should be in the same units''' |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
253 if deceleration > 0: |
36 | 254 return [perceptionReactionTime+float(initialSpeed)/(2*deceleration), float(intersectionLength+vehicleAverageLength)/initialSpeed] |
33
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
255 else: |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
256 print 'Issue deceleration should be strictly positive' |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
257 return None |
37
911b52744ceb
added uniform delay function
Nicolas Saunier <nico@confins.net>
parents:
36
diff
changeset
|
258 |
911b52744ceb
added uniform delay function
Nicolas Saunier <nico@confins.net>
parents:
36
diff
changeset
|
259 def uniformDelay(cycleLength, effectiveGreen, saturationDegree): |
911b52744ceb
added uniform delay function
Nicolas Saunier <nico@confins.net>
parents:
36
diff
changeset
|
260 '''Computes the uniform delay''' |
911b52744ceb
added uniform delay function
Nicolas Saunier <nico@confins.net>
parents:
36
diff
changeset
|
261 return 0.5*cycleLength*(1-float(effectiveGreen)/cycleLength)/(1-float(effectiveGreen*saturationDegree)/cycleLength) |
87
f234154207d4
distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
73
diff
changeset
|
262 |
f234154207d4
distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
73
diff
changeset
|
263 ######################### |
f234154207d4
distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
73
diff
changeset
|
264 # misc |
f234154207d4
distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
73
diff
changeset
|
265 ######################### |
f234154207d4
distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
73
diff
changeset
|
266 |
f234154207d4
distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
73
diff
changeset
|
267 def timeChangingSpeed(v0, vf, a, TPR): |
f234154207d4
distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
73
diff
changeset
|
268 return TPR+(vf-v0)/a |
f234154207d4
distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
73
diff
changeset
|
269 |
f234154207d4
distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
73
diff
changeset
|
270 def distanceChangingSpeed(v0, vf, a, TPR): |
f234154207d4
distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
73
diff
changeset
|
271 return TPR*v0+(vf*vf-v0*v0)/(2*a) |