Mercurial Hosting > traffic-intelligence
annotate python/traffic_engineering.py @ 87:f234154207d4
distance and time to change speed
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Thu, 28 Apr 2011 15:07:21 -0400 |
parents | 930a6282c9a9 |
children | 2bf5b76320c0 |
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 ######################### |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
10 # 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
|
11 ######################### |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
12 |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
13 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
|
14 ''' ''' |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
15 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
|
16 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
|
17 |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
18 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
|
19 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
|
20 |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
21 @staticmethod |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
22 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
|
23 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
|
24 |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
25 @staticmethod |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
26 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
|
27 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
|
28 |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
29 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
|
30 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
|
31 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
|
32 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
|
33 figure() |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
34 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
|
35 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
|
36 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
|
37 |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
38 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
|
39 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
|
40 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
|
41 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
|
42 figure() |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
43 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
|
44 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
|
45 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
|
46 |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
47 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
|
48 '''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
|
49 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
|
50 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
|
51 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
|
52 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
|
53 |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
54 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
|
55 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
|
56 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
|
57 |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
58 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
|
59 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
|
60 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
|
61 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
|
62 |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
63 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
|
64 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
|
65 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
|
66 |
33
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
67 ######################### |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
68 # traffic signals |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
69 ######################### |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
70 |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
71 class Volume: |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
72 '''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
|
73 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
|
74 '''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
|
75 |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
76 # check the sizes of the lists |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
77 if sum(proportions) == 1: |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
78 self.volume = volume |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
79 self.types = types |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
80 self.proportions = proportions |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
81 self.equivalents = equivalents |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
82 self.nLanes = nLanes |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
83 else: |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
84 pass |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
85 |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
86 def getPCEVolume(self): |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
87 '''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
|
88 v = 0 |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
89 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
|
90 v += p*e |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
91 return v*self.volume |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
92 |
34 | 93 class IntersectionMovement: |
33
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
94 '''Represents an intersection movement |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
95 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
|
96 and an equivalent for movement type''' |
34 | 97 def __init__(self, volume, type, mvtEquivalent = 1): |
33
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
98 self.volume = volume |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
99 self.type = type |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
100 self.mvtEquivalent = mvtEquivalent |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
101 |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
102 def getTVUVolume(self): |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
103 return self.mvtEquivalent*self.volume.getPCEVolume() |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
104 |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
105 class IntersectionApproach: |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
106 def __init__(self, leftTurnVolume, throughVolume, rightTurnVolume): |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
107 self.leftTurnVolume = leftTurnVolume |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
108 self.throughVolume = throughVolume |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
109 self.rightTurnVolume = rightTurnVolume |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
110 |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
111 def getTVUVolume(self, leftTurnEquivalent = 1, throughEquivalent = 1, rightTurnEquivalent = 1): |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
112 return self.leftTurnVolume.getPCEVolume()*leftTurnEquivalent+self.throughVolume.getPCEVolume()*throughEquivalent+self.rightTurnVolume.getPCEVolume()*rightTurnEquivalent |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
113 |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
114 class LaneGroup: |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
115 '''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
|
116 |
34 | 117 def __init__(self, movements, nLanes): |
118 self.movements = movements | |
119 self.nLanes = nLanes | |
33
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
120 |
34 | 121 def getTVUVolume(self): |
122 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
|
123 |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
124 def checkProtectedLeftTurn(leftMvt, opposedThroughMvt): |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
125 '''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
|
126 The lane groups should contain left and through movement''' |
34 | 127 return leftMvt.volume >= 200 or leftMvt.volume*opposedThroughMvt.volume/opposedThroughMvt.nLanes > 50000 |
128 | |
129 def optimalCycle(lostTime, criticalCharge, rounding=True): | |
130 if rounding: | |
131 return ceil((1.5*lostTime+5)/(1-criticalCharge)) | |
132 else: | |
133 return (1.5*lostTime+5)/(1-criticalCharge) | |
134 | |
135 class Cycle: | |
136 '''Class to compute optimal cycle and the split of effective green times''' | |
137 def __init__(self, phases, lostTime, saturationVolume): | |
138 '''phases is a list of phases | |
139 a phase is a list of lanegroups''' | |
140 self.phases = phases | |
141 self.lostTime = lostTime | |
142 self.saturationVolume = saturationVolume | |
33
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
143 |
34 | 144 def computeCycle(self): |
145 self.criticalCharges = [] | |
146 for phase in self.phases: | |
147 self.criticalCharges.append(max([lg.getTVUVolume() for lg in phase])/(lg.nLanes*self.saturationVolume)) | |
148 | |
149 self.criticalCharge = sum(self.criticalCharges) | |
150 self.C0 = optimalCycle(self.lostTime, self.criticalCharge) | |
151 return self.C0 | |
152 | |
153 def computeEffectiveGreen(self): | |
154 from numpy import round | |
155 self.computeCycle() # in case it was not done before | |
156 effectiveGreenTime = self.C0-self.lostTime | |
157 self.effectiveGreens = [round(c*effectiveGreenTime/self.criticalCharge,1) for c in self.criticalCharges] | |
158 return self.effectiveGreens | |
159 | |
33
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
160 |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
161 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
|
162 '''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
|
163 Deceleration is positive |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
164 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
|
165 if deceleration > 0: |
36 | 166 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
|
167 else: |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
168 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
|
169 return None |
37
911b52744ceb
added uniform delay function
Nicolas Saunier <nico@confins.net>
parents:
36
diff
changeset
|
170 |
911b52744ceb
added uniform delay function
Nicolas Saunier <nico@confins.net>
parents:
36
diff
changeset
|
171 def uniformDelay(cycleLength, effectiveGreen, saturationDegree): |
911b52744ceb
added uniform delay function
Nicolas Saunier <nico@confins.net>
parents:
36
diff
changeset
|
172 '''Computes the uniform delay''' |
911b52744ceb
added uniform delay function
Nicolas Saunier <nico@confins.net>
parents:
36
diff
changeset
|
173 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
|
174 |
f234154207d4
distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
73
diff
changeset
|
175 ######################### |
f234154207d4
distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
73
diff
changeset
|
176 # misc |
f234154207d4
distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
73
diff
changeset
|
177 ######################### |
f234154207d4
distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
73
diff
changeset
|
178 |
f234154207d4
distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
73
diff
changeset
|
179 def timeChangingSpeed(v0, vf, a, TPR): |
f234154207d4
distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
73
diff
changeset
|
180 return TPR+(vf-v0)/a |
f234154207d4
distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
73
diff
changeset
|
181 |
f234154207d4
distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
73
diff
changeset
|
182 def distanceChangingSpeed(v0, vf, a, TPR): |
f234154207d4
distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
73
diff
changeset
|
183 return TPR*v0+(vf*vf-v0*v0)/(2*a) |