Mercurial Hosting > traffic-intelligence
annotate python/traffic_engineering.py @ 648:da665302c88d
added some tutorial code as tests to avoid tutorial to become out of sync with code changes
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 15 Apr 2015 18:17:50 +0200 |
parents | 850ed17c7b2f |
children | 3b13ec964476 |
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 |
302
9d88a4d97473
corrected bug in compute-homography
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
300
diff
changeset
|
6 import prediction |
9d88a4d97473
corrected bug in compute-homography
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
300
diff
changeset
|
7 |
33
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
8 __metaclass__ = type |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
9 |
73
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
10 |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
11 ######################### |
198
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
12 # Simulation |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
13 ######################### |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
14 |
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
|
15 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
|
16 '''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
|
17 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
|
18 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
|
19 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
|
20 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
|
21 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
|
22 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
|
23 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
|
24 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
|
25 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
|
26 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
|
27 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
|
28 |
198
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
29 class Vehicle: |
302
9d88a4d97473
corrected bug in compute-homography
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
300
diff
changeset
|
30 '''Generic vehicle class |
9d88a4d97473
corrected bug in compute-homography
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
300
diff
changeset
|
31 1D coordinates for now''' |
300
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
32 class PredictedTrajectory1D(prediction.PredictedTrajectory): |
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
33 def __init__(self, initialPosition, initialSpeed, control, maxSpeed = None): |
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
34 self.control = control |
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
35 self.maxSpeed = maxSpeed |
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
36 self.probability = None |
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
37 self.predictedPositions = {0: moving.Point(initialPosition)} |
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
38 self.predictedSpeedOrientations = {0: moving.NormAngle(initialSpeed, 0)} |
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
39 |
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
40 def setAcceleration(self, acceleration): |
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
41 self.control = moving.NormAngle(acceleration, 0) |
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
42 |
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
43 def getControl(self): |
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
44 return self.control |
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
45 |
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
46 |
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
47 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
|
48 self.positions = PredictedTrajectory1D(initialPosition, initialSpeed) |
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
49 |
198
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
50 self.prt = prt |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
51 self.leader = leader |
300
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
52 # todo add microModel (Treiber) |
198
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
53 |
300
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
54 def setAcceleration(self, acceleration): |
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
55 self.positions.setAcceleration(acceleration) |
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
56 |
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
57 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
|
58 speed = self.speed |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
59 self.speed += self.acceleration*dt |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
60 self.position += speed*dt |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
61 if self.log: |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
62 self.positions.append(self.position) |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
63 self.speeds.append(self.speed) |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
64 self.accelerations.append(self.acceleration) |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
65 |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
66 def updateAcceleration(self, dt): |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
67 '''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
|
68 and other factors''' |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
69 pass |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
70 |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
71 def update(self, dt): |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
72 self.updatePosition(dt) |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
73 self.updateAcceleration(dt) # function of leader |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
74 |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
75 def printStats(self): |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
76 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
|
77 |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
78 ######################### |
73
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
79 # 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
|
80 ######################### |
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 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
|
83 ''' ''' |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
84 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
|
85 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
|
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 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
|
88 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
|
89 |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
90 @staticmethod |
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 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
|
92 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
|
93 |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
94 @staticmethod |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
95 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
|
96 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
|
97 |
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 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
|
99 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
|
100 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
|
101 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
|
102 figure() |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
103 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
|
104 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
|
105 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
|
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 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
|
108 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
|
109 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
|
110 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
|
111 figure() |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
112 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
|
113 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
|
114 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
|
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 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
|
117 '''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
|
118 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
|
119 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
|
120 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
|
121 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
|
122 |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
123 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
|
124 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
|
125 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
|
126 |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
127 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
|
128 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
|
129 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
|
130 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
|
131 |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
132 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
|
133 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
|
134 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
|
135 |
33
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
136 ######################### |
116
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
137 # intersection |
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 |
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
140 class FourWayIntersection: |
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
141 '''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
|
142 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
|
143 self.dimension = dimension |
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
144 self.coordX = coordX |
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
145 self.coordY = coordY |
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
146 |
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
147 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
|
148 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
|
149 |
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
150 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
|
151 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
|
152 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
|
153 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
|
154 |
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
155 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
|
156 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
|
157 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
|
158 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
|
159 axis('equal') |
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
160 |
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
161 ######################### |
33
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
162 # traffic signals |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
163 ######################### |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
164 |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
165 class Volume: |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
166 '''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
|
167 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
|
168 '''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
|
169 |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
170 # check the sizes of the lists |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
171 if sum(proportions) == 1: |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
172 self.volume = volume |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
173 self.types = types |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
174 self.proportions = proportions |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
175 self.equivalents = equivalents |
314
539e2b4cfaa3
modified for 4740 tps
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
302
diff
changeset
|
176 self.nLanes = nLanes |
33
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
177 else: |
302
9d88a4d97473
corrected bug in compute-homography
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
300
diff
changeset
|
178 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
|
179 pass |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
180 |
314
539e2b4cfaa3
modified for 4740 tps
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
302
diff
changeset
|
181 def checkProtected(self, opposedThroughMvt): |
539e2b4cfaa3
modified for 4740 tps
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
302
diff
changeset
|
182 '''Checks if this left movement should be protected, |
539e2b4cfaa3
modified for 4740 tps
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
302
diff
changeset
|
183 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
|
184 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
|
185 |
205
aeaaf5579b46
minor changes to traffic engineering
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
198
diff
changeset
|
186 def getPCUVolume(self): |
33
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
187 '''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
|
188 v = 0 |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
189 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
|
190 v += p*e |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
191 return v*self.volume |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
192 |
34 | 193 class IntersectionMovement: |
33
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
194 '''Represents an intersection movement |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
195 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
|
196 and an equivalent for movement type''' |
205
aeaaf5579b46
minor changes to traffic engineering
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
198
diff
changeset
|
197 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
|
198 self.volume = volume |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
199 self.mvtEquivalent = mvtEquivalent |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
200 |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
201 def getTVUVolume(self): |
205
aeaaf5579b46
minor changes to traffic engineering
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
198
diff
changeset
|
202 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
|
203 |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
204 class LaneGroup: |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
205 '''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
|
206 |
34 | 207 def __init__(self, movements, nLanes): |
208 self.movements = movements | |
209 self.nLanes = nLanes | |
33
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
210 |
34 | 211 def getTVUVolume(self): |
212 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
|
213 |
206
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
214 def getCharge(self, saturationVolume): |
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
215 return self.getTVUVolume()/(self.nLanes*saturationVolume) |
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 optimalCycle(lostTime, criticalCharge): |
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
218 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
|
219 |
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
220 def minimumCycle(lostTime, criticalCharge, degreeSaturation=1.): |
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
221 '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
|
222 return lostTime/(1-criticalCharge/degreeSaturation) |
34 | 223 |
224 class Cycle: | |
225 '''Class to compute optimal cycle and the split of effective green times''' | |
226 def __init__(self, phases, lostTime, saturationVolume): | |
227 '''phases is a list of phases | |
228 a phase is a list of lanegroups''' | |
229 self.phases = phases | |
230 self.lostTime = lostTime | |
231 self.saturationVolume = saturationVolume | |
33
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
232 |
206
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
233 def computeCriticalCharges(self): |
314
539e2b4cfaa3
modified for 4740 tps
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
302
diff
changeset
|
234 self.criticalCharges = [max([lg.getCharge(self.saturationVolume) for lg in phase]) for phase in self.phases] |
34 | 235 self.criticalCharge = sum(self.criticalCharges) |
206
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
236 |
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
237 def computeOptimalCycle(self): |
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
238 self.computeCriticalCharges() |
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
239 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
|
240 return self.C |
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
241 |
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
242 def computeMinimumCycle(self, degreeSaturation=1.): |
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
243 self.computeCriticalCharges() |
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
244 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
|
245 return self.C |
34 | 246 |
247 def computeEffectiveGreen(self): | |
314
539e2b4cfaa3
modified for 4740 tps
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
302
diff
changeset
|
248 #from numpy import round |
206
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
249 #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
|
250 effectiveGreenTime = self.C-self.lostTime |
34 | 251 self.effectiveGreens = [round(c*effectiveGreenTime/self.criticalCharge,1) for c in self.criticalCharges] |
252 return self.effectiveGreens | |
253 | |
33
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
254 |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
255 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
|
256 '''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
|
257 Deceleration is positive |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
258 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
|
259 if deceleration > 0: |
36 | 260 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
|
261 else: |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
262 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
|
263 return None |
37
911b52744ceb
added uniform delay function
Nicolas Saunier <nico@confins.net>
parents:
36
diff
changeset
|
264 |
911b52744ceb
added uniform delay function
Nicolas Saunier <nico@confins.net>
parents:
36
diff
changeset
|
265 def uniformDelay(cycleLength, effectiveGreen, saturationDegree): |
911b52744ceb
added uniform delay function
Nicolas Saunier <nico@confins.net>
parents:
36
diff
changeset
|
266 '''Computes the uniform delay''' |
911b52744ceb
added uniform delay function
Nicolas Saunier <nico@confins.net>
parents:
36
diff
changeset
|
267 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
|
268 |
493
850ed17c7b2f
added some computation of delay
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
479
diff
changeset
|
269 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
|
270 '''Computes the overflow delay (HCM) |
850ed17c7b2f
added some computation of delay
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
479
diff
changeset
|
271 T in hours |
850ed17c7b2f
added some computation of delay
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
479
diff
changeset
|
272 c capacity of the lane group |
850ed17c7b2f
added some computation of delay
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
479
diff
changeset
|
273 k default for fixed time signal |
850ed17c7b2f
added some computation of delay
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
479
diff
changeset
|
274 I=1 for isolated intersection (Poisson arrival)''' |
850ed17c7b2f
added some computation of delay
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
479
diff
changeset
|
275 from math import sqrt |
850ed17c7b2f
added some computation of delay
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
479
diff
changeset
|
276 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
|
277 |
87
f234154207d4
distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
73
diff
changeset
|
278 ######################### |
f234154207d4
distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
73
diff
changeset
|
279 # misc |
f234154207d4
distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
73
diff
changeset
|
280 ######################### |
f234154207d4
distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
73
diff
changeset
|
281 |
f234154207d4
distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
73
diff
changeset
|
282 def timeChangingSpeed(v0, vf, a, TPR): |
f234154207d4
distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
73
diff
changeset
|
283 return TPR+(vf-v0)/a |
f234154207d4
distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
73
diff
changeset
|
284 |
f234154207d4
distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
73
diff
changeset
|
285 def distanceChangingSpeed(v0, vf, a, TPR): |
f234154207d4
distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
73
diff
changeset
|
286 return TPR*v0+(vf*vf-v0*v0)/(2*a) |