Skip to content

Commit 938b93f

Browse files
committed
update README and demo.py on sample code
- renanme external_node_id to node_id in class Node; - renanme external_from_node to from_node_id and external_to_node to to_node_id in class Link; - renanme internal_node_seq_no_dict to node_id_to_no_dict and external_node_id_dict to node_no_to_id_dict in class Network; - all their instances are updated as well.
1 parent a3ec1e9 commit 938b93f

File tree

5 files changed

+45
-43
lines changed

5 files changed

+45
-43
lines changed

README.md

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ network = pg.read_network(load_demand=False)
279279
print('\nstart accessibility evaluation\n')
280280
st = time()
281281

282-
pg.evaluate_accessiblity(network, multimodal=False)
282+
pg.evaluate_accessibility(network, multimodal=False)
283283
# the default is under mode auto (i.e., p)
284284
# if you would like to evaluate accessibility under a target mode, say walk, then
285285
# pg.evaluate_accessibility(network, multimodal=False, mode='w')
@@ -312,9 +312,9 @@ network.get_accessible_links(1, 15, 'w')
312312
```
313313

314314
### When Time-Dependent Link Travel Time Matters
315-
Link travel time is crucial in calculating accessibility. In the classic accessibility analysis, evalutaion networks are usually considered to be static in terms of link travel time, which is determined by link length and link free-flow speed under a specific mode. The free-flow speed comes from either link.csv or settings.yml (both are denoted as 'free_speed'). When they are different, the minimum of these two will be adopted. The cases demonstrated above are all falling within this category.
315+
Link travel time is crucial in calculating accessibility. In the classic accessibility analysis, evalutaion networks are usually considered to be static in terms of link travel time, which is determined by link length and link free-flow speed under a specific mode. The free-flow speed comes from either link.csv or settings.yml (both are denoted as "free_speed"). When they are different, the minimum of these two will be adopted. The cases demonstrated above are all falling within this category.
316316

317-
Link travel time varies over time so does accessibility. When the time-dependent accessibility is of interested, time-dependent link travel time (i.e., VDF_fftt from a given demand period in link.csv) will come into play by overwriting the static link free-flow speed above. This new feature is now part of v0.7.3 and is illustrated as below.
317+
Link travel time varies over time so does accessibility. When the time-dependent accessibility is of interested, time-dependent link travel time (i.e., VDF_fftt from a given demand period in link.csv) will come into play by overwriting the (static) link free-flow speed. This new feature is now part of v0.7.3 and is illustrated as below.
318318

319319
```python
320320
import path4gmns as pg
@@ -327,25 +327,22 @@ st = time()
327327

328328
# time-dependent accessibility under the default mode auto (i.e., p)
329329
# for demand period 0 (i.e., VDF_fftt1 in link.csv will be used in the evaluation)
330-
pg.evaluate_accessiblity(network, multimodal=False, time_dependent=True)
330+
pg.evaluate_accessibility(network, multimodal=False, time_dependent=True)
331331

332332
# if you would like to evaluate accessibility under a different demand period
333333
# (say 1, which must be defined in settings.yml along with VDF_fftt2 in link.csv), then
334-
# pg.evaluate_accessiblity(network, multimodal=False, time_dependent=True, demand_period_id=1)
334+
pg.evaluate_accessibility(network, multimodal=False, time_dependent=True, demand_period_id=1)
335335

336336
# if you would like to evaluate accessibility under a target mode, say walk, then
337-
# pg.evaluate_accessibility(network, multimodal=False, mode='w', time_dependent=True)
338-
# or equivalently pg.evaluate_accessibility(network, multimodal=False, mode='walk', time_dependent=True)
339-
340-
print('complete accessibility evaluation.\n')
341-
print(f'processing time of accessibility evaluation: {time()-st:.2f} s')
337+
pg.evaluate_accessibility(network, multimodal=False, mode='w', time_dependent=True)
342338
```
343339

344-
While VDF_fftt begins with 1 (i.e., VDF_fftt1), the argument demand_period_id, corresponding to the sequence number of demand period appeared in demand_periods in settings.yml, starts from 0. So 'demand_period_id=1' indicates that 'VDF_fftt2' will be used.
340+
While VDF_fftt begins with 1 (i.e., VDF_fftt1), the argument demand_period_id, corresponding to the sequence number of demand period appeared in demand_periods in settings.yml, starts from 0. So "demand_period_id=0" indicates that VDF_fftt1 will be used (and so on and so forth).
345341

346-
**As VDF_fftt in link.csv can only accommodate one mode, time-dependent accessibility evaluation will require the user to prepare mode-specific link.csv with dedicated VDF_fftt and allowed_uses**. That's the reason that multimodal=False is always enforced in these examples.
342+
**As VDF_fftt in link.csv can only accommodate one mode, time-dependent accessibility evaluation will require the user to prepare a mode-specific link.csv with dedicated VDF_fftt and allowed_uses**. That's the reason that "multimodal=False" is always enforced in these examples.
343+
344+
Retrieve the time-dependent accessible nodes and links is similar to evaluate time-dependent accessibility by simply passing time_dependent and demand_period_id to get_accessible_nodes() and get_accessible_links().
347345

348-
Retrieve the time-dependent accessible nodes and links is similar to evaluate time-dependent accessibility by simply passing time_dependent and demand_period_id to get_accessible_nodes() and get_accessible_links()
349346
```python
350347
import path4gmns as pg
351348

@@ -355,6 +352,7 @@ network = pg.read_network(load_demand=False)
355352
# get accessible nodes and links starting from node 1 with a 5-minitue
356353
# time window for the default mode auto (i.e., 'p') for demand period 0
357354
network.get_accessible_nodes(1, 5, time_dependent=True)
355+
358356
# get accessible nodes and links starting from node 1 with a 5-minitue
359357
# time window for the default mode auto (i.e., 'p') for demand period 1 if it is defined
360358
network.get_accessible_links(1, 5, time_dependent=True, demand_period_id=1)

path4gmns/classes.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212

1313
class Node:
1414

15-
def __init__(self, node_seq_no, external_node_id, zone_id, x='', y=''):
15+
def __init__(self, node_seq_no, node_id, zone_id, x='', y=''):
1616
""" the attributes of node """
17-
# external_node_id: user defined node id from input
18-
self.node_seq_no = node_seq_no
1917
# node_seq_no: internal node index used for calculation
20-
self.external_node_id = external_node_id
18+
self.node_seq_no = node_seq_no
19+
# node_id: user defined node id from input
20+
self.node_id = node_id
2121
self.outgoing_link_list = []
2222
self.incoming_link_list = []
2323
self.zone_id = zone_id
@@ -34,7 +34,7 @@ def get_zone_id(self):
3434
return self.zone_id
3535

3636
def get_node_id(self):
37-
return self.external_node_id
37+
return self.node_id
3838

3939
def get_node_no(self):
4040
return self.node_seq_no
@@ -76,8 +76,8 @@ def __init__(self,
7676
self.link_seq_no = link_seq_no
7777
self.from_node_seq_no = from_node_no
7878
self.to_node_seq_no = to_node_no
79-
self.external_from_node = from_node_id
80-
self.external_to_node = to_node_id
79+
self.from_node_id = from_node_id
80+
self.to_node_id = to_node_id
8181
# length is mile or km
8282
self.length = length
8383
self.lanes = lanes
@@ -117,10 +117,10 @@ def get_seq_no(self):
117117
return self.link_seq_no
118118

119119
def get_from_node_id(self):
120-
return self.external_from_node
120+
return self.from_node_id
121121

122122
def get_to_node_id(self):
123-
return self.external_to_node
123+
return self.to_node_id
124124

125125
def get_length(self):
126126
return self.length
@@ -257,9 +257,9 @@ def __init__(self):
257257
self.link_size = 0
258258
self.agent_size = 0
259259
# key: node id, value: node seq no
260-
self.internal_node_seq_no_dict = {}
260+
self.node_id_to_no_dict = {}
261261
# key: node seq no, value: node id
262-
self.external_node_id_dict = {}
262+
self.node_no_to_id_dict = {}
263263
# map link id to link seq no
264264
self.link_id_dict = {}
265265
# td:time-dependent, key:simulation time interval,
@@ -464,7 +464,7 @@ def get_agent_node_path(self, agent_id, path_only):
464464
path = ''
465465
if agent.node_path:
466466
path = ';'.join(
467-
str(self.external_node_id_dict[x]) for x in reversed(agent.node_path)
467+
str(self.node_no_to_id_dict[x]) for x in reversed(agent.node_path)
468468
)
469469

470470
if path_only:
@@ -517,7 +517,7 @@ def get_nodes_from_zone(self, zone_id):
517517
return self.zone_to_nodes_dict[zone_id]
518518

519519
def get_node_no(self, node_id):
520-
return self.internal_node_seq_no_dict[node_id]
520+
return self.node_id_to_no_dict[node_id]
521521

522522
def get_node_size(self):
523523
return self.node_size
@@ -953,8 +953,8 @@ def __init__(self, base, add_cc=True):
953953
self.base = base
954954
self.node_list = self.base.get_nodes()
955955
self.link_list = self.base.get_links()
956-
self.map_id_to_no = self.base.internal_node_seq_no_dict
957-
self.map_no_to_id = self.base.external_node_id_dict
956+
self.map_id_to_no = self.base.node_id_to_no_dict
957+
self.map_no_to_id = self.base.node_no_to_id_dict
958958
self.node_size = base.get_node_size()
959959
self.link_size = base.get_link_size()
960960
self.centroids = []
@@ -1402,7 +1402,7 @@ def get_node_label_cost(self, node_no):
14021402

14031403
def get_accessible_nodes(self, source_node_id, time_budget,
14041404
mode, time_dependent, tau):
1405-
if source_node_id not in self.network.internal_node_seq_no_dict.keys():
1405+
if source_node_id not in self.network.node_id_to_no_dict.keys():
14061406
raise Exception(f"Node ID: {source_node_id} not in the network")
14071407

14081408
assert(time_budget>=0)

path4gmns/path.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def output_path_sequence(G, to_node_id, type='node'):
248248
Note that this function returns GENERATOR rather than list.
249249
"""
250250
path = []
251-
current_node_seq_no = G.internal_node_seq_no_dict[to_node_id]
251+
current_node_seq_no = G.node_id_to_no_dict[to_node_id]
252252

253253
if type.startswith('node'):
254254
# retrieve the sequence backwards
@@ -257,7 +257,7 @@ def output_path_sequence(G, to_node_id, type='node'):
257257
current_node_seq_no = G.node_predecessor[current_node_seq_no]
258258
# reverse the sequence
259259
for node_seq_no in reversed(path):
260-
yield G.external_node_id_dict[node_seq_no]
260+
yield G.node_no_to_id_dict[node_seq_no]
261261
else:
262262
# retrieve the sequence backwards
263263
current_link_seq_no = G.link_predecessor[current_node_seq_no]
@@ -271,15 +271,15 @@ def output_path_sequence(G, to_node_id, type='node'):
271271

272272

273273
def _get_path_cost(G, to_node_id):
274-
to_node_no = G.internal_node_seq_no_dict[to_node_id]
274+
to_node_no = G.node_id_to_no_dict[to_node_id]
275275

276276
return G.node_label_cost[to_node_no]
277277

278278

279279
def find_shortest_path(G, from_node_id, to_node_id, seq_type='node'):
280-
if from_node_id not in G.internal_node_seq_no_dict.keys():
280+
if from_node_id not in G.node_id_to_no_dict.keys():
281281
raise Exception(f"Node ID: {from_node_id} not in the network")
282-
if to_node_id not in G.internal_node_seq_no_dict.keys():
282+
if to_node_id not in G.node_id_to_no_dict.keys():
283283
raise Exception(f"Node ID: {to_node_id} not in the network")
284284

285285
single_source_shortest_path(G, from_node_id, engine_type='c')
@@ -319,9 +319,9 @@ def find_path_for_agents(G, column_pool, engine_type='c'):
319319
if from_node_id == to_node_id:
320320
continue
321321

322-
if from_node_id not in G.internal_node_seq_no_dict.keys():
322+
if from_node_id not in G.node_id_to_no_dict.keys():
323323
raise Exception(f"Node ID: {from_node_id} not in the network")
324-
if to_node_id not in G.internal_node_seq_no_dict.keys():
324+
if to_node_id not in G.node_id_to_no_dict.keys():
325325
raise Exception(f"Node ID: {to_node_id} not in the network")
326326

327327
# simple caching strategy
@@ -334,7 +334,7 @@ def find_path_for_agents(G, column_pool, engine_type='c'):
334334
node_path = []
335335
link_path = []
336336

337-
current_node_seq_no = G.internal_node_seq_no_dict[to_node_id]
337+
current_node_seq_no = G.node_id_to_no_dict[to_node_id]
338338
# set up the cost
339339
agent.path_cost = G.node_label_cost[current_node_seq_no]
340340

path4gmns/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -555,14 +555,14 @@ def read_network(load_demand='true', input_dir='.'):
555555

556556
read_nodes(input_dir,
557557
network.node_list,
558-
network.internal_node_seq_no_dict,
559-
network.external_node_id_dict,
558+
network.node_id_to_no_dict,
559+
network.node_no_to_id_dict,
560560
network.zone_to_nodes_dict)
561561

562562
read_links(input_dir,
563563
network.link_list,
564564
network.node_list,
565-
network.internal_node_seq_no_dict,
565+
network.node_id_to_no_dict,
566566
network.link_id_dict,
567567
assignm.get_agent_type_count(),
568568
assignm.get_demand_period_count(),

tests/demo.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,14 @@ def test_accessibility():
154154
# time-dependent accessibility under the default mode auto (i.e., p)
155155
# for demand period 0 (i.e., VDF_fftt1 in link.csv will be used in the
156156
# evaluation)
157-
# pg.evaluate_accessiblity(network, multimodal=False, time_dependent=True)
157+
# pg.evaluate_accessibility(network, multimodal=False, time_dependent=True)
158+
159+
# it is equivalent to
160+
# pg.evaluate_accessibility(network, multimodal=False,
161+
# time_dependent=True, demand_period_id=0)
158162

159163
# get accessible nodes and links starting from node 1 with a 5-minitue
160-
# time window for the default mode auto (i.e., 'p') for demand period 0
164+
# time window for the default mode auto (i.e., 'p') for demand period 0
161165
# network.get_accessible_nodes(1, 5, time_dependent=True)
162166

163167
# get accessible nodes and links starting from node 1 with a 15-minitue
@@ -195,4 +199,4 @@ def demo_mode(mode):
195199

196200
if __name__=="__main__":
197201

198-
demo_mode(3)
202+
demo_mode(6)

0 commit comments

Comments
 (0)