comparison python/traffic_engineering.py @ 790:944949c8ef3e dev

minor name change
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 13 Apr 2016 23:03:43 -0400
parents 3666342dabe2
children 9f8e9fb5621b
comparison
equal deleted inserted replaced
789:3666342dabe2 790:944949c8ef3e
52 52
53 class Cyclist(RoadUser): 53 class Cyclist(RoadUser):
54 def getDescriptor(self): 54 def getDescriptor(self):
55 return 'og' 55 return 'og'
56 56
57 #########################
58 # queueing models
59 #########################
60
61 class CapacityReduction(object):
62 def __init__(self, beta, reductionDuration, demandCapacityRatio = None, demand = None, capacity = None):
63 '''reduction duration should be positive
64 demandCapacityRatio is demand/capacity (q/s)'''
65 if demandCapacityRatio is None and demand is None and capacity is None:
66 print('Missing too much information (demand, capacity and ratio)')
67 import sys
68 sys.exit()
69 if 0 <= beta < 1:
70 self.beta = beta
71 self.reductionDuration = reductionDuration
72
73 if demandCapacityRatio is not None:
74 self.demandCapacityRatio = demandCapacityRatio
75 if demand is not None:
76 self.demand = demand
77 if capacity is not None:
78 self.capacity = capacity
79 if capacity is not None and demand is not None:
80 self.demandCapacityRatio = float(self.demand)/self.capacity
81 if demand <= beta*capacity:
82 print('There is no queueing as the demand {} is inferior to the reduced capacity {}'.format(demand, beta*capacity))
83 else:
84 print('reduction coefficient (beta={}) is not in [0, 1['.format(beta))
85
86 def queueingDuration(self):
87 return self.reductionDuration*(1-self.beta)/(1-self.demandCapacityRatio)
88
89 def nArrived(self, t):
90 if self.demand is None:
91 print('Missing demand field')
92 return None
93 return self.demand*t
94
95 def nServed(self, t):
96 if self.capacity is None:
97 print('Missing capacity field')
98 return None
99 if 0<=t<=self.reductionDuration:
100 return self.beta*self.capacity*t
101 elif self.reductionDuration < t <= self.queueingDuration():
102 return self.beta*self.capacity*self.reductionDuration+self.capacity*(t-self.reductionDuration)
103
104 def nQueued(self, t):
105 return self.nArrived(t)-self.nServed(t)
106
107 def maxNQueued(self):
108 return self.nQueued(self.reductionDuration)
109
110 def totalDelay(self):
111 if self.capacity is None:
112 print('Missing capacity field')
113 return None
114 return self.capacity*self.reductionDuration**2*(1-self.beta)*(self.demandCapacityRatio-self.beta)/(2*(1-self.demandCapacityRatio))
115
116 def averageDelay(self):
117 return self.reductionDuration*(self.demandCapacityRatio-self.beta)/(2*self.demandCapacityRatio)
118
119 def averageNQueued(self):
120 return self.totalDelay()/self.queueingDuration()
121
57 122
58 ######################### 123 #########################
59 # fundamental diagram 124 # fundamental diagram
60 ######################### 125 #########################
61 126
244 309
245 def uniformDelay(cycleLength, effectiveGreen, saturationDegree): 310 def uniformDelay(cycleLength, effectiveGreen, saturationDegree):
246 '''Computes the uniform delay''' 311 '''Computes the uniform delay'''
247 return 0.5*cycleLength*(1-float(effectiveGreen)/cycleLength)/(1-float(effectiveGreen*saturationDegree)/cycleLength) 312 return 0.5*cycleLength*(1-float(effectiveGreen)/cycleLength)/(1-float(effectiveGreen*saturationDegree)/cycleLength)
248 313
249 def overflowDelay(T, X, c, k=0.5, I=1): 314 def incrementalDelay(T, X, c, k=0.5, I=1):
250 '''Computes the overflow delay (HCM) 315 '''Computes the incremental delay (HCM)
251 T in hours 316 T in hours
252 c capacity of the lane group 317 c capacity of the lane group
253 k default for fixed time signal 318 k default for fixed time signal
254 I=1 for isolated intersection (Poisson arrival)''' 319 I=1 for isolated intersection (Poisson arrival)'''
255 from math import sqrt 320 from math import sqrt