annotate python/traffic_engineering.py @ 665:15e244d2a1b5

corrected bug with circular import for VideoFilenameAddable, moved to base module
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 20 May 2015 13:57:47 +0200
parents 3b13ec964476
children 3666342dabe2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
302
9d88a4d97473 corrected bug in compute-homography
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 300
diff changeset
4 import prediction
9d88a4d97473 corrected bug in compute-homography
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 300
diff changeset
5
665
15e244d2a1b5 corrected bug with circular import for VideoFilenameAddable, moved to base module
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 652
diff changeset
6 from math import ceil
33
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
479
7828fec8bbd2 added function to generate headways based on flow or mean headway over some simulation period
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 314
diff changeset
13 def generateTimeHeadways(meanTimeHeadway, simulationTime):
7828fec8bbd2 added function to generate headways based on flow or mean headway over some simulation period
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 314
diff changeset
14 '''Generates the time headways between arrivals
7828fec8bbd2 added function to generate headways based on flow or mean headway over some simulation period
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 314
diff changeset
15 given the meanTimeHeadway and the negative exponential distribution
7828fec8bbd2 added function to generate headways based on flow or mean headway over some simulation period
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 314
diff changeset
16 over a time interval of length simulationTime (assumed to be in same time unit as headway'''
7828fec8bbd2 added function to generate headways based on flow or mean headway over some simulation period
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 314
diff changeset
17 from random import expovariate
7828fec8bbd2 added function to generate headways based on flow or mean headway over some simulation period
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 314
diff changeset
18 headways = []
7828fec8bbd2 added function to generate headways based on flow or mean headway over some simulation period
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 314
diff changeset
19 totalTime = 0
7828fec8bbd2 added function to generate headways based on flow or mean headway over some simulation period
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 314
diff changeset
20 flow = 1/meanTimeHeadway
7828fec8bbd2 added function to generate headways based on flow or mean headway over some simulation period
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 314
diff changeset
21 while totalTime < simulationTime:
7828fec8bbd2 added function to generate headways based on flow or mean headway over some simulation period
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 314
diff changeset
22 h = expovariate(flow)
7828fec8bbd2 added function to generate headways based on flow or mean headway over some simulation period
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 314
diff changeset
23 headways.append(h)
7828fec8bbd2 added function to generate headways based on flow or mean headway over some simulation period
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 314
diff changeset
24 totalTime += h
7828fec8bbd2 added function to generate headways based on flow or mean headway over some simulation period
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 314
diff changeset
25 return headways
7828fec8bbd2 added function to generate headways based on flow or mean headway over some simulation period
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 314
diff changeset
26
665
15e244d2a1b5 corrected bug with circular import for VideoFilenameAddable, moved to base module
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 652
diff changeset
27 class RoadUser(object):
652
3b13ec964476 removed useless and buggy code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 493
diff changeset
28 '''Simple example of inheritance to plot different road users '''
3b13ec964476 removed useless and buggy code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 493
diff changeset
29 def __init__(self, position, velocity):
3b13ec964476 removed useless and buggy code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 493
diff changeset
30 'Both fields are 2D numpy arrays'
3b13ec964476 removed useless and buggy code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 493
diff changeset
31 self.position = position.astype(float)
3b13ec964476 removed useless and buggy code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 493
diff changeset
32 self.velocity = velocity.astype(float)
3b13ec964476 removed useless and buggy code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 493
diff changeset
33
3b13ec964476 removed useless and buggy code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 493
diff changeset
34 def move(self, deltaT):
3b13ec964476 removed useless and buggy code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 493
diff changeset
35 self.position += deltaT*self.velocity
3b13ec964476 removed useless and buggy code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 493
diff changeset
36
3b13ec964476 removed useless and buggy code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 493
diff changeset
37 def draw(self, init = False):
3b13ec964476 removed useless and buggy code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 493
diff changeset
38 from matplotlib.pyplot import plot
3b13ec964476 removed useless and buggy code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 493
diff changeset
39 if init:
3b13ec964476 removed useless and buggy code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 493
diff changeset
40 self.plotLine = plot(self.position[0], self.position[1], self.getDescriptor())[0]
3b13ec964476 removed useless and buggy code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 493
diff changeset
41 else:
3b13ec964476 removed useless and buggy code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 493
diff changeset
42 self.plotLine.set_data(self.position[0], self.position[1])
300
f65b828e5521 working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 206
diff changeset
43
f65b828e5521 working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 206
diff changeset
44
652
3b13ec964476 removed useless and buggy code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 493
diff changeset
45 class PassengerVehicle(RoadUser):
3b13ec964476 removed useless and buggy code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 493
diff changeset
46 def getDescriptor(self):
3b13ec964476 removed useless and buggy code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 493
diff changeset
47 return 'dr'
300
f65b828e5521 working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 206
diff changeset
48
652
3b13ec964476 removed useless and buggy code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 493
diff changeset
49 class Pedestrian(RoadUser):
3b13ec964476 removed useless and buggy code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 493
diff changeset
50 def getDescriptor(self):
3b13ec964476 removed useless and buggy code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 493
diff changeset
51 return 'xb'
198
c91c8fd8bf1e simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 116
diff changeset
52
652
3b13ec964476 removed useless and buggy code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 493
diff changeset
53 class Cyclist(RoadUser):
3b13ec964476 removed useless and buggy code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 493
diff changeset
54 def getDescriptor(self):
3b13ec964476 removed useless and buggy code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 493
diff changeset
55 return 'og'
198
c91c8fd8bf1e simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 116
diff changeset
56
c91c8fd8bf1e simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 116
diff changeset
57
c91c8fd8bf1e simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 116
diff changeset
58 #########################
73
930a6282c9a9 added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 37
diff changeset
59 # 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
60 #########################
930a6282c9a9 added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 37
diff changeset
61
665
15e244d2a1b5 corrected bug with circular import for VideoFilenameAddable, moved to base module
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 652
diff changeset
62 class FundamentalDiagram(object):
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 ''' '''
930a6282c9a9 added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 37
diff changeset
64 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
65 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
66
930a6282c9a9 added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 37
diff changeset
67 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
68 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
69
930a6282c9a9 added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 37
diff changeset
70 @staticmethod
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 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
72 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
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 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
76 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
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 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
79 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
80 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
81 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
82 figure()
930a6282c9a9 added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 37
diff changeset
83 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
84 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
85 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
86
930a6282c9a9 added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 37
diff changeset
87 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
88 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
89 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
90 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
91 figure()
930a6282c9a9 added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 37
diff changeset
92 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
93 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
94 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
95
930a6282c9a9 added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 37
diff changeset
96 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
97 '''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
98 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
99 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
100 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
101 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
102
930a6282c9a9 added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 37
diff changeset
103 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
104 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
105 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
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 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
108 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
109 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
110 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
111
930a6282c9a9 added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 37
diff changeset
112 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
113 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
114 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
115
33
4bd7cc69b6cd added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff changeset
116 #########################
116
2bf5b76320c0 moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 87
diff changeset
117 # intersection
2bf5b76320c0 moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 87
diff changeset
118 #########################
2bf5b76320c0 moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 87
diff changeset
119
665
15e244d2a1b5 corrected bug with circular import for VideoFilenameAddable, moved to base module
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 652
diff changeset
120 class FourWayIntersection(object):
116
2bf5b76320c0 moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 87
diff changeset
121 '''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
122 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
123 self.dimension = dimension
2bf5b76320c0 moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 87
diff changeset
124 self.coordX = coordX
2bf5b76320c0 moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 87
diff changeset
125 self.coordY = coordY
2bf5b76320c0 moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 87
diff changeset
126
2bf5b76320c0 moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 87
diff changeset
127 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
128 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
129
2bf5b76320c0 moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 87
diff changeset
130 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
131 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
132 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
133 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
134
2bf5b76320c0 moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 87
diff changeset
135 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
136 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
137 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
138 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
139 axis('equal')
2bf5b76320c0 moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 87
diff changeset
140
2bf5b76320c0 moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 87
diff changeset
141 #########################
33
4bd7cc69b6cd added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff changeset
142 # traffic signals
4bd7cc69b6cd added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff changeset
143 #########################
4bd7cc69b6cd added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff changeset
144
665
15e244d2a1b5 corrected bug with circular import for VideoFilenameAddable, moved to base module
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 652
diff changeset
145 class Volume(object):
33
4bd7cc69b6cd added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff changeset
146 '''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
147 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
148 '''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
149
4bd7cc69b6cd added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff changeset
150 # check the sizes of the lists
4bd7cc69b6cd added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff changeset
151 if sum(proportions) == 1:
4bd7cc69b6cd added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff changeset
152 self.volume = volume
4bd7cc69b6cd added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff changeset
153 self.types = types
4bd7cc69b6cd added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff changeset
154 self.proportions = proportions
4bd7cc69b6cd added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff changeset
155 self.equivalents = equivalents
314
539e2b4cfaa3 modified for 4740 tps
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 302
diff changeset
156 self.nLanes = nLanes
33
4bd7cc69b6cd added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff changeset
157 else:
302
9d88a4d97473 corrected bug in compute-homography
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 300
diff changeset
158 print('Proportions do not sum to 1')
33
4bd7cc69b6cd added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff changeset
159 pass
4bd7cc69b6cd added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff changeset
160
314
539e2b4cfaa3 modified for 4740 tps
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 302
diff changeset
161 def checkProtected(self, opposedThroughMvt):
539e2b4cfaa3 modified for 4740 tps
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 302
diff changeset
162 '''Checks if this left movement should be protected,
539e2b4cfaa3 modified for 4740 tps
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 302
diff changeset
163 ie if one of the main two conditions on left turn is verified'''
539e2b4cfaa3 modified for 4740 tps
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 302
diff changeset
164 return self.volume >= 200 or self.volume*opposedThroughMvt.volume/opposedThroughMvt.nLanes > 50000
539e2b4cfaa3 modified for 4740 tps
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 302
diff changeset
165
205
aeaaf5579b46 minor changes to traffic engineering
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 198
diff changeset
166 def getPCUVolume(self):
33
4bd7cc69b6cd added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff changeset
167 '''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
168 v = 0
4bd7cc69b6cd added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff changeset
169 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
170 v += p*e
4bd7cc69b6cd added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff changeset
171 return v*self.volume
4bd7cc69b6cd added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff changeset
172
665
15e244d2a1b5 corrected bug with circular import for VideoFilenameAddable, moved to base module
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 652
diff changeset
173 class IntersectionMovement(object):
33
4bd7cc69b6cd added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff changeset
174 '''Represents an intersection movement
4bd7cc69b6cd added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff changeset
175 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
176 and an equivalent for movement type'''
205
aeaaf5579b46 minor changes to traffic engineering
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 198
diff changeset
177 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
178 self.volume = volume
4bd7cc69b6cd added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff changeset
179 self.mvtEquivalent = mvtEquivalent
4bd7cc69b6cd added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff changeset
180
4bd7cc69b6cd added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff changeset
181 def getTVUVolume(self):
205
aeaaf5579b46 minor changes to traffic engineering
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 198
diff changeset
182 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
183
665
15e244d2a1b5 corrected bug with circular import for VideoFilenameAddable, moved to base module
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 652
diff changeset
184 class LaneGroup(object):
33
4bd7cc69b6cd added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff changeset
185 '''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
186
34
388a5a25fe92 Code for lab5 works
Nicolas Saunier <nico@confins.net>
parents: 33
diff changeset
187 def __init__(self, movements, nLanes):
388a5a25fe92 Code for lab5 works
Nicolas Saunier <nico@confins.net>
parents: 33
diff changeset
188 self.movements = movements
388a5a25fe92 Code for lab5 works
Nicolas Saunier <nico@confins.net>
parents: 33
diff changeset
189 self.nLanes = nLanes
33
4bd7cc69b6cd added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff changeset
190
34
388a5a25fe92 Code for lab5 works
Nicolas Saunier <nico@confins.net>
parents: 33
diff changeset
191 def getTVUVolume(self):
388a5a25fe92 Code for lab5 works
Nicolas Saunier <nico@confins.net>
parents: 33
diff changeset
192 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
193
206
82b4101d9a2f re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 205
diff changeset
194 def getCharge(self, saturationVolume):
82b4101d9a2f re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 205
diff changeset
195 return self.getTVUVolume()/(self.nLanes*saturationVolume)
82b4101d9a2f re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 205
diff changeset
196
82b4101d9a2f re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 205
diff changeset
197 def optimalCycle(lostTime, criticalCharge):
82b4101d9a2f re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 205
diff changeset
198 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
199
82b4101d9a2f re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 205
diff changeset
200 def minimumCycle(lostTime, criticalCharge, degreeSaturation=1.):
82b4101d9a2f re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 205
diff changeset
201 '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
202 return lostTime/(1-criticalCharge/degreeSaturation)
34
388a5a25fe92 Code for lab5 works
Nicolas Saunier <nico@confins.net>
parents: 33
diff changeset
203
665
15e244d2a1b5 corrected bug with circular import for VideoFilenameAddable, moved to base module
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 652
diff changeset
204 class Cycle(object):
34
388a5a25fe92 Code for lab5 works
Nicolas Saunier <nico@confins.net>
parents: 33
diff changeset
205 '''Class to compute optimal cycle and the split of effective green times'''
388a5a25fe92 Code for lab5 works
Nicolas Saunier <nico@confins.net>
parents: 33
diff changeset
206 def __init__(self, phases, lostTime, saturationVolume):
388a5a25fe92 Code for lab5 works
Nicolas Saunier <nico@confins.net>
parents: 33
diff changeset
207 '''phases is a list of phases
388a5a25fe92 Code for lab5 works
Nicolas Saunier <nico@confins.net>
parents: 33
diff changeset
208 a phase is a list of lanegroups'''
388a5a25fe92 Code for lab5 works
Nicolas Saunier <nico@confins.net>
parents: 33
diff changeset
209 self.phases = phases
388a5a25fe92 Code for lab5 works
Nicolas Saunier <nico@confins.net>
parents: 33
diff changeset
210 self.lostTime = lostTime
388a5a25fe92 Code for lab5 works
Nicolas Saunier <nico@confins.net>
parents: 33
diff changeset
211 self.saturationVolume = saturationVolume
33
4bd7cc69b6cd added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff changeset
212
206
82b4101d9a2f re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 205
diff changeset
213 def computeCriticalCharges(self):
314
539e2b4cfaa3 modified for 4740 tps
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 302
diff changeset
214 self.criticalCharges = [max([lg.getCharge(self.saturationVolume) for lg in phase]) for phase in self.phases]
34
388a5a25fe92 Code for lab5 works
Nicolas Saunier <nico@confins.net>
parents: 33
diff changeset
215 self.criticalCharge = sum(self.criticalCharges)
206
82b4101d9a2f re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 205
diff changeset
216
82b4101d9a2f re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 205
diff changeset
217 def computeOptimalCycle(self):
82b4101d9a2f re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 205
diff changeset
218 self.computeCriticalCharges()
82b4101d9a2f re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 205
diff changeset
219 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
220 return self.C
82b4101d9a2f re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 205
diff changeset
221
82b4101d9a2f re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 205
diff changeset
222 def computeMinimumCycle(self, degreeSaturation=1.):
82b4101d9a2f re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 205
diff changeset
223 self.computeCriticalCharges()
82b4101d9a2f re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 205
diff changeset
224 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
225 return self.C
34
388a5a25fe92 Code for lab5 works
Nicolas Saunier <nico@confins.net>
parents: 33
diff changeset
226
388a5a25fe92 Code for lab5 works
Nicolas Saunier <nico@confins.net>
parents: 33
diff changeset
227 def computeEffectiveGreen(self):
314
539e2b4cfaa3 modified for 4740 tps
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 302
diff changeset
228 #from numpy import round
206
82b4101d9a2f re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 205
diff changeset
229 #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
230 effectiveGreenTime = self.C-self.lostTime
34
388a5a25fe92 Code for lab5 works
Nicolas Saunier <nico@confins.net>
parents: 33
diff changeset
231 self.effectiveGreens = [round(c*effectiveGreenTime/self.criticalCharge,1) for c in self.criticalCharges]
388a5a25fe92 Code for lab5 works
Nicolas Saunier <nico@confins.net>
parents: 33
diff changeset
232 return self.effectiveGreens
388a5a25fe92 Code for lab5 works
Nicolas Saunier <nico@confins.net>
parents: 33
diff changeset
233
33
4bd7cc69b6cd added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff changeset
234
4bd7cc69b6cd added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff changeset
235 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
236 '''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
237 Deceleration is positive
4bd7cc69b6cd added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff changeset
238 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
239 if deceleration > 0:
36
571b11304ec9 corrected bug
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 34
diff changeset
240 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
241 else:
4bd7cc69b6cd added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff changeset
242 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
243 return None
37
911b52744ceb added uniform delay function
Nicolas Saunier <nico@confins.net>
parents: 36
diff changeset
244
911b52744ceb added uniform delay function
Nicolas Saunier <nico@confins.net>
parents: 36
diff changeset
245 def uniformDelay(cycleLength, effectiveGreen, saturationDegree):
911b52744ceb added uniform delay function
Nicolas Saunier <nico@confins.net>
parents: 36
diff changeset
246 '''Computes the uniform delay'''
911b52744ceb added uniform delay function
Nicolas Saunier <nico@confins.net>
parents: 36
diff changeset
247 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
248
493
850ed17c7b2f added some computation of delay
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 479
diff changeset
249 def overflowDelay(T, X, c, k=0.5, I=1):
850ed17c7b2f added some computation of delay
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 479
diff changeset
250 '''Computes the overflow delay (HCM)
850ed17c7b2f added some computation of delay
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 479
diff changeset
251 T in hours
850ed17c7b2f added some computation of delay
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 479
diff changeset
252 c capacity of the lane group
850ed17c7b2f added some computation of delay
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 479
diff changeset
253 k default for fixed time signal
850ed17c7b2f added some computation of delay
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 479
diff changeset
254 I=1 for isolated intersection (Poisson arrival)'''
850ed17c7b2f added some computation of delay
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 479
diff changeset
255 from math import sqrt
850ed17c7b2f added some computation of delay
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 479
diff changeset
256 return 900*T*(X - 1 + sqrt((X - 1)**2 + 8*k*I*X/(c*T)))
850ed17c7b2f added some computation of delay
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 479
diff changeset
257
87
f234154207d4 distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 73
diff changeset
258 #########################
f234154207d4 distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 73
diff changeset
259 # misc
f234154207d4 distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 73
diff changeset
260 #########################
f234154207d4 distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 73
diff changeset
261
f234154207d4 distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 73
diff changeset
262 def timeChangingSpeed(v0, vf, a, TPR):
f234154207d4 distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 73
diff changeset
263 return TPR+(vf-v0)/a
f234154207d4 distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 73
diff changeset
264
f234154207d4 distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 73
diff changeset
265 def distanceChangingSpeed(v0, vf, a, TPR):
f234154207d4 distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 73
diff changeset
266 return TPR*v0+(vf*vf-v0*v0)/(2*a)