Mercurial Hosting > traffic-intelligence
annotate trafficintelligence/traffic_engineering.py @ 1275:9f1711a85c56
added code to make sure TTC is replaced of recomputed and not having a value
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 19 Jun 2024 16:11:35 -0400 |
parents | f10e84505443 |
children |
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 |
665
15e244d2a1b5
corrected bug with circular import for VideoFilenameAddable, moved to base module
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
652
diff
changeset
|
4 from math import ceil |
1176
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
5 from numpy import e, log, arange |
1206
770306fef827
moving functions for exams in traffic engineering
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1198
diff
changeset
|
6 from scipy import stats |
1176
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
7 |
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
8 from matplotlib.pyplot import figure,plot,xlabel,ylabel, xlim, ylim |
33
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
9 |
1029
c6cf75a2ed08
reorganization of imports
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1028
diff
changeset
|
10 from trafficintelligence import prediction |
73
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 ######################### |
198
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
13 # Simulation |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
14 ######################### |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
15 |
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
|
16 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
|
17 '''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
|
18 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
|
19 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
|
20 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
|
21 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
|
22 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
|
23 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
|
24 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
|
25 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
|
26 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
|
27 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
|
28 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
|
29 |
665
15e244d2a1b5
corrected bug with circular import for VideoFilenameAddable, moved to base module
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
652
diff
changeset
|
30 class RoadUser(object): |
652
3b13ec964476
removed useless and buggy code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
493
diff
changeset
|
31 '''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
|
32 def __init__(self, position, velocity): |
3b13ec964476
removed useless and buggy code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
493
diff
changeset
|
33 'Both fields are 2D numpy arrays' |
3b13ec964476
removed useless and buggy code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
493
diff
changeset
|
34 self.position = position.astype(float) |
3b13ec964476
removed useless and buggy code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
493
diff
changeset
|
35 self.velocity = velocity.astype(float) |
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 move(self, deltaT): |
3b13ec964476
removed useless and buggy code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
493
diff
changeset
|
38 self.position += deltaT*self.velocity |
3b13ec964476
removed useless and buggy code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
493
diff
changeset
|
39 |
3b13ec964476
removed useless and buggy code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
493
diff
changeset
|
40 def draw(self, init = False): |
3b13ec964476
removed useless and buggy code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
493
diff
changeset
|
41 from matplotlib.pyplot import plot |
3b13ec964476
removed useless and buggy code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
493
diff
changeset
|
42 if init: |
3b13ec964476
removed useless and buggy code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
493
diff
changeset
|
43 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
|
44 else: |
3b13ec964476
removed useless and buggy code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
493
diff
changeset
|
45 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
|
46 |
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
47 |
652
3b13ec964476
removed useless and buggy code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
493
diff
changeset
|
48 class PassengerVehicle(RoadUser): |
3b13ec964476
removed useless and buggy code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
493
diff
changeset
|
49 def getDescriptor(self): |
3b13ec964476
removed useless and buggy code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
493
diff
changeset
|
50 return 'dr' |
300
f65b828e5521
working on trajectory simulation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
206
diff
changeset
|
51 |
652
3b13ec964476
removed useless and buggy code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
493
diff
changeset
|
52 class Pedestrian(RoadUser): |
3b13ec964476
removed useless and buggy code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
493
diff
changeset
|
53 def getDescriptor(self): |
3b13ec964476
removed useless and buggy code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
493
diff
changeset
|
54 return 'xb' |
198
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
55 |
652
3b13ec964476
removed useless and buggy code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
493
diff
changeset
|
56 class Cyclist(RoadUser): |
3b13ec964476
removed useless and buggy code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
493
diff
changeset
|
57 def getDescriptor(self): |
3b13ec964476
removed useless and buggy code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
493
diff
changeset
|
58 return 'og' |
198
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
59 |
790
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
60 ######################### |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
61 # queueing models |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
62 ######################### |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
63 |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
64 class CapacityReduction(object): |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
65 def __init__(self, beta, reductionDuration, demandCapacityRatio = None, demand = None, capacity = None): |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
66 '''reduction duration should be positive |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
67 demandCapacityRatio is demand/capacity (q/s)''' |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
68 if demandCapacityRatio is None and demand is None and capacity is None: |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
69 print('Missing too much information (demand, capacity and ratio)') |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
70 import sys |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
71 sys.exit() |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
72 if 0 <= beta < 1: |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
73 self.beta = beta |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
74 self.reductionDuration = reductionDuration |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
75 |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
76 if demandCapacityRatio is not None: |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
77 self.demandCapacityRatio = demandCapacityRatio |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
78 if demand is not None: |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
79 self.demand = demand |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
80 if capacity is not None: |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
81 self.capacity = capacity |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
82 if capacity is not None and demand is not None: |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
83 self.demandCapacityRatio = float(self.demand)/self.capacity |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
84 if demand <= beta*capacity: |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
85 print('There is no queueing as the demand {} is inferior to the reduced capacity {}'.format(demand, beta*capacity)) |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
86 else: |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
87 print('reduction coefficient (beta={}) is not in [0, 1['.format(beta)) |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
88 |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
89 def queueingDuration(self): |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
90 return self.reductionDuration*(1-self.beta)/(1-self.demandCapacityRatio) |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
91 |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
92 def nArrived(self, t): |
1259
3bfdb2ffd29d
modif for plotting nserved
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1206
diff
changeset
|
93 '''since the beginning of the capacity reduction''' |
3bfdb2ffd29d
modif for plotting nserved
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1206
diff
changeset
|
94 if self.demand is None or t<0: |
790
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
95 print('Missing demand field') |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
96 return None |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
97 return self.demand*t |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
98 |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
99 def nServed(self, t): |
1259
3bfdb2ffd29d
modif for plotting nserved
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1206
diff
changeset
|
100 '''since the beginning of the capacity reduction''' |
3bfdb2ffd29d
modif for plotting nserved
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1206
diff
changeset
|
101 if self.capacity is None or t<0: |
790
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
102 print('Missing capacity field') |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
103 return None |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
104 if 0<=t<=self.reductionDuration: |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
105 return self.beta*self.capacity*t |
1259
3bfdb2ffd29d
modif for plotting nserved
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1206
diff
changeset
|
106 elif self.reductionDuration < t: |
3bfdb2ffd29d
modif for plotting nserved
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1206
diff
changeset
|
107 qDuration = self.queueingDuration() |
3bfdb2ffd29d
modif for plotting nserved
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1206
diff
changeset
|
108 if t <= qDuration: |
3bfdb2ffd29d
modif for plotting nserved
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1206
diff
changeset
|
109 return self.beta*self.capacity*self.reductionDuration+self.capacity*(t-self.reductionDuration) |
3bfdb2ffd29d
modif for plotting nserved
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1206
diff
changeset
|
110 else: |
3bfdb2ffd29d
modif for plotting nserved
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1206
diff
changeset
|
111 return self.beta*self.capacity*self.reductionDuration+self.capacity*(qDuration-self.reductionDuration)+self.demand*(t-qDuration) |
790
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
112 |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
113 def nQueued(self, t): |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
114 return self.nArrived(t)-self.nServed(t) |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
115 |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
116 def maxNQueued(self): |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
117 return self.nQueued(self.reductionDuration) |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
118 |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
119 def totalDelay(self): |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
120 if self.capacity is None: |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
121 print('Missing capacity field') |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
122 return None |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
123 return self.capacity*self.reductionDuration**2*(1-self.beta)*(self.demandCapacityRatio-self.beta)/(2*(1-self.demandCapacityRatio)) |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
124 |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
125 def averageDelay(self): |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
126 return self.reductionDuration*(self.demandCapacityRatio-self.beta)/(2*self.demandCapacityRatio) |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
127 |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
128 def averageNQueued(self): |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
129 return self.totalDelay()/self.queueingDuration() |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
130 |
198
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
131 |
c91c8fd8bf1e
simple vehicle model with constant acceleration
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
116
diff
changeset
|
132 ######################### |
1176
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
133 # fundamental diagrams |
73
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
134 ######################### |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
135 |
665
15e244d2a1b5
corrected bug with circular import for VideoFilenameAddable, moved to base module
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
652
diff
changeset
|
136 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
|
137 ''' ''' |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
138 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
|
139 self.name = name |
1176
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
140 self.kj = None |
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
141 self.kc = None |
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
142 self.vf = None |
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
143 self.qmax = None |
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
144 |
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
145 def getJamDensity(self): |
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
146 return self.kj |
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
147 |
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
148 def getCriticalDensity(self): |
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
149 return self.kc |
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
150 |
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
151 def getCapacity(self): |
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
152 return self.qmax |
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
153 |
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
154 def getFreeFlowSpeed(self): |
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
155 return self.vf |
73
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
156 |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
157 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
|
158 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
|
159 |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
160 @staticmethod |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
161 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
|
162 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
|
163 |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
164 @staticmethod |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
165 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
|
166 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
|
167 |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
168 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
|
169 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
|
170 figure() |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
171 plot(densities, [self.v(k) for k in densities]) |
1176
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
172 xlim(xmin=0) |
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
173 ylim(ymin=0) |
73
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
174 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
|
175 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
|
176 |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
177 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
|
178 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
|
179 figure() |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
180 plot(densities, [self.q(k) for k in densities]) |
1176
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
181 xlim(xmin=0) |
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
182 ylim(ymin=0) |
73
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
183 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
|
184 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
|
185 |
1176
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
186 class GreenshieldsFD(FundamentalDiagram): |
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
187 '''Speed is a linear function of density''' |
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
188 def __init__(self, vf, kj): |
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
189 FundamentalDiagram.__init__(self,'Greenshields') |
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
190 self.vf=vf |
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
191 self.kj=kj |
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
192 self.kc=kj/2 |
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
193 self.qmax=vf*kj/4 |
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
194 |
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
195 def v(self,k): |
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
196 from numpy import log |
1198
fa07a78b29f6
minor modif, change to makefile for repo opencv installation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1176
diff
changeset
|
197 return self.vf*(1-k/self.kj) |
1176
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
198 |
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
199 |
73
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
200 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
|
201 '''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
|
202 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
|
203 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
|
204 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
|
205 self.kj=kj |
1176
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
206 self.qmax = self.kc*self.vc |
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
207 self.kc = self.kj/e |
73
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
208 |
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
209 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
|
210 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
|
211 |
1176
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
212 class TriangularFD(FundamentalDiagram): |
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
213 def __init__(self, vf = None, kc = None, kj = None, qmax = None, w = None): |
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
214 FundamentalDiagram.__init__(self,'Triangular') |
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
215 if vf is not None and qmax is not None and kj is not None: |
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
216 self.vf=vf |
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
217 self.qmax = qmax |
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
218 self.kj = kj |
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
219 self.kc = qmax/vf |
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
220 self.w = qmax/(self.kc-kj) |
73
930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
37
diff
changeset
|
221 |
1176
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
222 def v(self, k): |
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
223 if k<self.kc: |
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
224 return self.vf |
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
225 else: |
5874ece33637
reorganized fundamental diagram and added triangular
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1165
diff
changeset
|
226 return self.vf*self.kc*(self.kj/k-1)/(self.kj-self.kc) |
1206
770306fef827
moving functions for exams in traffic engineering
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1198
diff
changeset
|
227 |
770306fef827
moving functions for exams in traffic engineering
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1198
diff
changeset
|
228 def generateDensities(n, maxDensity): |
770306fef827
moving functions for exams in traffic engineering
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1198
diff
changeset
|
229 return stats.uniform.rvs(size=n)*maxDensity |
770306fef827
moving functions for exams in traffic engineering
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1198
diff
changeset
|
230 |
770306fef827
moving functions for exams in traffic engineering
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1198
diff
changeset
|
231 def generateSpeedVolumes(fd, n, maxDensity, maxHGVProportion = 0, etrucks = 2.5): |
770306fef827
moving functions for exams in traffic engineering
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1198
diff
changeset
|
232 densities = generateDensities(n, maxDensity) |
770306fef827
moving functions for exams in traffic engineering
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1198
diff
changeset
|
233 speeds = [fd.v(k) for k in densities] |
770306fef827
moving functions for exams in traffic engineering
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1198
diff
changeset
|
234 volumes = [fd.q(k) for k in densities] |
770306fef827
moving functions for exams in traffic engineering
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1198
diff
changeset
|
235 if maxHGVProportion > 0: |
770306fef827
moving functions for exams in traffic engineering
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1198
diff
changeset
|
236 hgvProportions = stats.uniform.rvs(size=n)*maxHGVProportion # en pourcent |
770306fef827
moving functions for exams in traffic engineering
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1198
diff
changeset
|
237 volumes = [v/(1+(etrucks-1)*p/100) for v,p in zip(volumes, hgvProportions)] |
770306fef827
moving functions for exams in traffic engineering
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1198
diff
changeset
|
238 else: |
770306fef827
moving functions for exams in traffic engineering
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1198
diff
changeset
|
239 hgvProportions = None |
770306fef827
moving functions for exams in traffic engineering
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1198
diff
changeset
|
240 return speeds, volumes, hgvProportions |
770306fef827
moving functions for exams in traffic engineering
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1198
diff
changeset
|
241 |
1262
f10e84505443
modif for highway level of service
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1259
diff
changeset
|
242 higwayMaxDensityLOS = {'A':7, 'B':11, 'C':16, 'D':22, 'E': 28} |
f10e84505443
modif for highway level of service
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1259
diff
changeset
|
243 |
1206
770306fef827
moving functions for exams in traffic engineering
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1198
diff
changeset
|
244 def highwayLOS(k): |
770306fef827
moving functions for exams in traffic engineering
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1198
diff
changeset
|
245 'returns the highway level of service for density k in veh/km' |
1262
f10e84505443
modif for highway level of service
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1259
diff
changeset
|
246 for los, kmax in higwayMaxDensityLOS.items(): |
f10e84505443
modif for highway level of service
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1259
diff
changeset
|
247 if k<kmax: return los |
f10e84505443
modif for highway level of service
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1259
diff
changeset
|
248 return 'F' |
f10e84505443
modif for highway level of service
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1259
diff
changeset
|
249 |
33
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
250 ######################### |
116
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
251 # intersection |
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
252 ######################### |
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
253 |
665
15e244d2a1b5
corrected bug with circular import for VideoFilenameAddable, moved to base module
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
652
diff
changeset
|
254 class FourWayIntersection(object): |
116
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
255 '''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
|
256 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
|
257 self.dimension = dimension |
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
258 self.coordX = coordX |
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
259 self.coordY = coordY |
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
260 |
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
261 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
|
262 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
|
263 |
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
264 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
|
265 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
|
266 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
|
267 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
|
268 |
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
269 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
|
270 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
|
271 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
|
272 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
|
273 axis('equal') |
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
274 |
2bf5b76320c0
moved intersection plotting and added markers for scatter plots
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
87
diff
changeset
|
275 ######################### |
33
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
276 # traffic signals |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
277 ######################### |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
278 |
665
15e244d2a1b5
corrected bug with circular import for VideoFilenameAddable, moved to base module
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
652
diff
changeset
|
279 class Volume(object): |
33
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
280 '''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
|
281 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
|
282 '''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
|
283 |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
284 # check the sizes of the lists |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
285 if sum(proportions) == 1: |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
286 self.volume = volume |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
287 self.types = types |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
288 self.proportions = proportions |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
289 self.equivalents = equivalents |
314
539e2b4cfaa3
modified for 4740 tps
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
302
diff
changeset
|
290 self.nLanes = nLanes |
33
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
291 else: |
302
9d88a4d97473
corrected bug in compute-homography
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
300
diff
changeset
|
292 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
|
293 pass |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
294 |
314
539e2b4cfaa3
modified for 4740 tps
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
302
diff
changeset
|
295 def checkProtected(self, opposedThroughMvt): |
539e2b4cfaa3
modified for 4740 tps
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
302
diff
changeset
|
296 '''Checks if this left movement should be protected, |
539e2b4cfaa3
modified for 4740 tps
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
302
diff
changeset
|
297 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
|
298 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
|
299 |
205
aeaaf5579b46
minor changes to traffic engineering
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
198
diff
changeset
|
300 def getPCUVolume(self): |
33
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
301 '''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
|
302 v = 0 |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
303 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
|
304 v += p*e |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
305 return v*self.volume |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
306 |
665
15e244d2a1b5
corrected bug with circular import for VideoFilenameAddable, moved to base module
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
652
diff
changeset
|
307 class IntersectionMovement(object): |
33
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
308 '''Represents an intersection movement |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
309 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
|
310 and an equivalent for movement type''' |
205
aeaaf5579b46
minor changes to traffic engineering
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
198
diff
changeset
|
311 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
|
312 self.volume = volume |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
313 self.mvtEquivalent = mvtEquivalent |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
314 |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
315 def getTVUVolume(self): |
205
aeaaf5579b46
minor changes to traffic engineering
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
198
diff
changeset
|
316 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
|
317 |
665
15e244d2a1b5
corrected bug with circular import for VideoFilenameAddable, moved to base module
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
652
diff
changeset
|
318 class LaneGroup(object): |
33
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
319 '''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
|
320 |
34 | 321 def __init__(self, movements, nLanes): |
322 self.movements = movements | |
323 self.nLanes = nLanes | |
33
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
324 |
34 | 325 def getTVUVolume(self): |
326 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
|
327 |
206
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
328 def getCharge(self, saturationVolume): |
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
329 return self.getTVUVolume()/(self.nLanes*saturationVolume) |
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
330 |
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
331 def optimalCycle(lostTime, criticalCharge): |
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
332 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
|
333 |
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
334 def minimumCycle(lostTime, criticalCharge, degreeSaturation=1.): |
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
335 '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
|
336 return lostTime/(1-criticalCharge/degreeSaturation) |
34 | 337 |
665
15e244d2a1b5
corrected bug with circular import for VideoFilenameAddable, moved to base module
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
652
diff
changeset
|
338 class Cycle(object): |
34 | 339 '''Class to compute optimal cycle and the split of effective green times''' |
340 def __init__(self, phases, lostTime, saturationVolume): | |
341 '''phases is a list of phases | |
342 a phase is a list of lanegroups''' | |
343 self.phases = phases | |
344 self.lostTime = lostTime | |
345 self.saturationVolume = saturationVolume | |
33
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
346 |
206
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
347 def computeCriticalCharges(self): |
314
539e2b4cfaa3
modified for 4740 tps
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
302
diff
changeset
|
348 self.criticalCharges = [max([lg.getCharge(self.saturationVolume) for lg in phase]) for phase in self.phases] |
34 | 349 self.criticalCharge = sum(self.criticalCharges) |
206
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
350 |
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
351 def computeOptimalCycle(self): |
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
352 self.computeCriticalCharges() |
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
353 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
|
354 return self.C |
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
355 |
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
356 def computeMinimumCycle(self, degreeSaturation=1.): |
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
357 self.computeCriticalCharges() |
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
358 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
|
359 return self.C |
34 | 360 |
361 def computeEffectiveGreen(self): | |
314
539e2b4cfaa3
modified for 4740 tps
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
302
diff
changeset
|
362 #from numpy import round |
206
82b4101d9a2f
re-arranged and commnted signal cycle calculations
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
205
diff
changeset
|
363 #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
|
364 effectiveGreenTime = self.C-self.lostTime |
34 | 365 self.effectiveGreens = [round(c*effectiveGreenTime/self.criticalCharge,1) for c in self.criticalCharges] |
366 return self.effectiveGreens | |
367 | |
33
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
368 |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
369 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
|
370 '''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
|
371 Deceleration is positive |
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
372 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
|
373 if deceleration > 0: |
36 | 374 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
|
375 else: |
992
2cd1ce245024
update to python 3
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
796
diff
changeset
|
376 print('Issue deceleration should be strictly positive') |
33
4bd7cc69b6cd
added traffic engineering utilities with first version of LaneGroups
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
377 return None |
37
911b52744ceb
added uniform delay function
Nicolas Saunier <nico@confins.net>
parents:
36
diff
changeset
|
378 |
911b52744ceb
added uniform delay function
Nicolas Saunier <nico@confins.net>
parents:
36
diff
changeset
|
379 def uniformDelay(cycleLength, effectiveGreen, saturationDegree): |
911b52744ceb
added uniform delay function
Nicolas Saunier <nico@confins.net>
parents:
36
diff
changeset
|
380 '''Computes the uniform delay''' |
796 | 381 return 0.5*cycleLength*(1-float(effectiveGreen)/cycleLength)**2/(1-float(effectiveGreen*saturationDegree)/cycleLength) |
382 | |
383 def randomDelay(volume, saturationDegree): | |
384 '''Computes the random delay = queueing time for M/D/1''' | |
385 return saturationDegree**2/(2*volume*(1-saturationDegree)) | |
87
f234154207d4
distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
73
diff
changeset
|
386 |
790
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
387 def incrementalDelay(T, X, c, k=0.5, I=1): |
944949c8ef3e
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
789
diff
changeset
|
388 '''Computes the incremental delay (HCM) |
493
850ed17c7b2f
added some computation of delay
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
479
diff
changeset
|
389 T in hours |
850ed17c7b2f
added some computation of delay
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
479
diff
changeset
|
390 c capacity of the lane group |
850ed17c7b2f
added some computation of delay
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
479
diff
changeset
|
391 k default for fixed time signal |
850ed17c7b2f
added some computation of delay
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
479
diff
changeset
|
392 I=1 for isolated intersection (Poisson arrival)''' |
850ed17c7b2f
added some computation of delay
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
479
diff
changeset
|
393 from math import sqrt |
850ed17c7b2f
added some computation of delay
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
479
diff
changeset
|
394 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
|
395 |
87
f234154207d4
distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
73
diff
changeset
|
396 ######################### |
f234154207d4
distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
73
diff
changeset
|
397 # misc |
f234154207d4
distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
73
diff
changeset
|
398 ######################### |
f234154207d4
distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
73
diff
changeset
|
399 |
f234154207d4
distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
73
diff
changeset
|
400 def timeChangingSpeed(v0, vf, a, TPR): |
789 | 401 'for decelerations, a < 0' |
402 return TPR-(vf-v0)/a | |
87
f234154207d4
distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
73
diff
changeset
|
403 |
f234154207d4
distance and time to change speed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
73
diff
changeset
|
404 def distanceChangingSpeed(v0, vf, a, TPR): |
789 | 405 'for decelerations, a < 0' |
1165
c5863e04d302
corrected bug
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1029
diff
changeset
|
406 return TPR*v0+(vf**2-v0**2)/(2*a) |