Mercurial Hosting > traffic-intelligence
changeset 73:930a6282c9a9
added class for fundamental diagram (including plotting) with implementation of Greenberg model
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Mon, 17 Jan 2011 16:46:48 -0500 |
parents | 575340e6fce3 |
children | d3e1a7cf3375 |
files | python/traffic_engineering.py |
diffstat | 1 files changed, 60 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/python/traffic_engineering.py Fri Jan 14 19:49:20 2011 -0500 +++ b/python/traffic_engineering.py Mon Jan 17 16:46:48 2011 -0500 @@ -1,10 +1,69 @@ #! /usr/bin/env python -''' Traffic Engineering Tools.''' +''' Traffic Engineering Tools and Examples''' from math import ceil __metaclass__ = type + +######################### +# fundamental diagram +######################### + +class FundamentalDiagram: + ''' ''' + def __init__(self, name): + self.name = name + + def q(self, k): + return k*self.v(k) + + @staticmethod + def meanHeadway(k): + return 1/k + + @staticmethod + def meanSpacing(q): + return 1/q + + def plotVK(self, language='fr', units={}): + from numpy import arange + from matplotlib.pyplot import figure,plot,xlabel,ylabel + densities = [k for k in arange(1, self.kj+1)] + figure() + plot(densities, [self.v(k) for k in densities]) + xlabel('Densite (veh/km)') # todo other languages and adapt to units + ylabel('Vitesse (km/h)') + + def plotQK(self, language='fr', units={}): + from numpy import arange + from matplotlib.pyplot import figure,plot,xlabel,ylabel + densities = [k for k in arange(1, self.kj+1)] + figure() + plot(densities, [self.q(k) for k in densities]) + xlabel('Densite (veh/km)') # todo other languages and adapt to units + ylabel('Debit (km/h)') + +class GreenbergFD(FundamentalDiagram): + '''Speed is the logarithm of density''' + def __init__(self, vc, kj): + FundamentalDiagram.__init__(self,'Greenberg') + self.vc=vc + self.kj=kj + + def v(self,k): + from numpy import log + return self.vc*log(self.kj/k) + + def criticalDensity(self): + from numpy import e + self.kc = self.kj/e + return self.kc + + def capacity(self): + self.qmax = self.kc*self.vc + return self.qmax + ######################### # traffic signals #########################