changeset 206:82b4101d9a2f

re-arranged and commnted signal cycle calculations
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Tue, 03 Apr 2012 01:11:29 -0400
parents aeaaf5579b46
children 48f83ff769fd d9855499fc88
files python/traffic_engineering.py
diffstat 1 files changed, 25 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/python/traffic_engineering.py	Tue Mar 20 22:32:38 2012 -0400
+++ b/python/traffic_engineering.py	Tue Apr 03 01:11:29 2012 -0400
@@ -144,7 +144,7 @@
             self.types = types
             self.proportions = proportions
             self.equivalents = equivalents
-            self.nLanes = nLanes
+            self.nLanes = nLanes # unused
         else:
             pass
 
@@ -166,7 +166,7 @@
     def getTVUVolume(self):
         return self.mvtEquivalent*self.volume.getPCUVolume()    
 
-class IntersectionApproach:
+class IntersectionApproach: # should probably not be used
     def __init__(self, leftTurnVolume, throughVolume, rightTurnVolume):
         self.leftTurnVolume = leftTurnVolume
         self.throughVolume = throughVolume
@@ -185,16 +185,20 @@
     def getTVUVolume(self):
         return sum([mvt.getTVUVolume() for mvt in self.movements])
 
+    def getCharge(self, saturationVolume):
+        return self.getTVUVolume()/(self.nLanes*saturationVolume)
+
 def checkProtectedLeftTurn(leftMvt, opposedThroughMvt):
     '''Checks if one of the main two conditions on left turn is verified
     The lane groups should contain left and through movement'''
     return leftMvt.volume >= 200 or leftMvt.volume*opposedThroughMvt.volume/opposedThroughMvt.nLanes > 50000
 
-def optimalCycle(lostTime, criticalCharge, rounding=True):
-    if rounding:
-        return ceil((1.5*lostTime+5)/(1-criticalCharge))
-    else:
-        return (1.5*lostTime+5)/(1-criticalCharge)
+def optimalCycle(lostTime, criticalCharge):
+    return (1.5*lostTime+5)/(1-criticalCharge)
+
+def minimumCycle(lostTime, criticalCharge, degreeSaturation=1.):
+    'degree of saturation can be used as the peak hour factor too'
+    return lostTime/(1-criticalCharge/degreeSaturation)
 
 class Cycle:
     '''Class to compute optimal cycle and the split of effective green times'''
@@ -205,19 +209,26 @@
         self.lostTime = lostTime
         self.saturationVolume = saturationVolume
 
-    def computeCycle(self):
+    def computeCriticalCharges(self):
         self.criticalCharges = []
         for phase in self.phases:
-            self.criticalCharges.append(max([lg.getTVUVolume() for lg in phase])/(lg.nLanes*self.saturationVolume))
-
+            self.criticalCharges.append(max([lg.getCharge(self.saturationVolume) for lg in phase]))
         self.criticalCharge = sum(self.criticalCharges)
-        self.C0 = optimalCycle(self.lostTime, self.criticalCharge)
-        return self.C0
+        
+    def computeOptimalCycle(self):
+        self.computeCriticalCharges()
+        self.C = optimalCycle(self.lostTime, self.criticalCharge)
+        return self.C
+
+    def computeMinimumCycle(self, degreeSaturation=1.):
+        self.computeCriticalCharges()
+        self.C = minimumCycle(self.lostTime, self.criticalCharge, degreeSaturation)
+        return self.C
 
     def computeEffectiveGreen(self):
         from numpy import round
-        self.computeCycle() # in case it was not done before
-        effectiveGreenTime = self.C0-self.lostTime
+        #self.computeCycle() # in case it was not done before
+        effectiveGreenTime = self.C-self.lostTime
         self.effectiveGreens = [round(c*effectiveGreenTime/self.criticalCharge,1) for c in self.criticalCharges]
         return self.effectiveGreens