-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlink.py
More file actions
162 lines (103 loc) · 3.89 KB
/
Copy pathlink.py
File metadata and controls
162 lines (103 loc) · 3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# -*- coding: utf-8 -*-
"""
abstract link class
includes methods for updating parameters using parameter EnKF estimates
@author: cesny
"""
# link parameters, here common for all links, can be different, read in readLinks
critDen = 100.0 # (veh/km)
linkType = 'CTM' # specifies the link type
ffs = 100.0 # free flow speed in km/hr
jamDen = 300.0 # veh/km
qcap = ffs * critDen # veh/hr (assuming triangular FD)
bws = (ffs * critDen) / (jamDen - critDen) # backward wave speed (km/hr)
length = 1.5 # km
timeStep = 10 # seconds (needed to define num cells in case of CTM, delx=ufdelt)
params = {'critDen':critDen, 'ffs':ffs, 'jamDen': jamDen, 'qcap': qcap,
'bws':bws, 'length':length, 'timeStep': timeStep, 'linkType': 'CTM'}
class Link:
"""
this class is for link objects
upstreamPathCount is a dict of dicts, time: subdict
subdict is a dict of paths and their flow values
"""
def __init__(self, linkID, unode, dnode, params):
self.ID = linkID
self.unode = unode # upstream node object
self.dnode = dnode
self.params = params
self.params['qcap'] = params['ffs'] * params['critDen'] # cap in veh/hr
self.params['bws'] = (self.params['ffs'] * self.params['critDen']) / (self.params['jamDen'] - self.params['critDen']) # backward wave speed in km/hr
self._upstreamCounts = dict() # records cumulative counts across time steps
self._downstreamCounts = dict()
self.inFlow = 0
self.outFlow = 0 # current inFlow and outFlow into the link
def calculateSendingFlow(self, time, timeStep):
"""
overwrite in subclass
"""
pass
def calculateReceivingFlow(self, time, timeStep):
"""
overwrite in subclass
"""
pass
def linkUpdate(self, time):
"""
performs any internal calculations, puts flows on links, and
removes flows from downstream end of link
"""
self.flowIn(time)
self.flowOut(time)
return None
def upstreamCount(self, time):
"""
return the cumulative entries to a link up to time t
"""
if time < 0:
return 0
return self._upstreamCounts(time)
def downstreamCount(self, time):
"""
returns the cumulative exists from a link
"""
if time < 0:
return 0
return self._downstreamCounts(time)
def vehiclesOnLink(self, time):
"""
returns vehicles on link
"""
return self.upstreamCount(time) - self.downstreamCount(time)
def flowIn(self, time):
"""
adds flow to link based on inFlows from
transitionFlows
"""
self._upstreamCounts[time] = self.inFlow # I believe that this should be +=self.inflow but for our purposes it does not matter
return None
def flowOut(self, time):
"""
removes flow from the downstream end of the link
based on outFlow from transitionFlows
"""
self._downstreamCounts[time] = self.outFlow
return None
def linkDensity(self, time=None):
"""
overwriten in cell transmission model to return
density at every cell
"""
return self.vehiclesOnLink(time) / self.params['length'] # density in veh/km
def updateVmaxCritDen(self, newVmax, newCritDen):
"""
update the maximum speed
note assuming that the backward wave speed is fixed
"""
if newVmax > 110:
print('.. WARNING! CFL condition violated ...')
self.params['ffs'] = newVmax
self.params['critDen'] = newCritDen
self.params['qcap'] = newVmax * newCritDen
# self.params['bws'] = (newVmax * self.params['critDen']) / (self.params['jamDen'] - self.params['critDen']) # remains fixed across iterations
return None