Skip to content

Commit 75dc853

Browse files
committed
Check that all centroids can be accessed at network validation stage
1 parent 9b2cedf commit 75dc853

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

Scripts/utils/validate_network.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,24 @@ def validate(network, fares=None):
6262
unofficial_nodes = set()
6363
nr_links = 0
6464
nr_zero_gradients = 0
65+
66+
# Make sure that cars, pedestrians cyclists can access all centroids
67+
unaccessible_centroids = []
68+
69+
required_modes = {'a', 'f', 'c'} # Modes for pedestrians, cyclists, and cars
70+
71+
for centroid in network.centroids():
72+
accessible_modes = {mode for link in centroid.incoming_links() for mode in link.modes}
73+
74+
if not required_modes.issubset(accessible_modes):
75+
unaccessible_centroids.append(centroid.id)
76+
77+
if unaccessible_centroids:
78+
msg = f"Centroids {unaccessible_centroids} are not accessible by pedestrians, cyclists and/or passenger cars."
79+
log.error(msg)
80+
raise ValueError(msg)
81+
82+
6583
for link in network.links():
6684
nr_links += 1
6785
if not link.modes:
@@ -132,13 +150,13 @@ def validate(network, fares=None):
132150
raise ValueError(msg)
133151

134152
try:
135-
if link['@kaltevuus'] == 0:
153+
if link['@kaltevuus'] == 0 and not link.i_node.is_centroid and not link.j_node.is_centroid:
136154
nr_zero_gradients += 1
137155
except KeyError:
138-
raise ValueError("Gradients not defined. Use an extra_links file with @kaltevuus,\
139-
or create extra attribute @kaltevuus with zeros.\
140-
@kaltevuus is used to model the effect of hills on bicycle route choice,\
141-
setting @kaltevuus to 0 on links will ignore hills.")
156+
raise ValueError("Gradients not defined. Use an extra_links file with @kaltevuus, " +
157+
"or create extra attribute @kaltevuus with zeros. " +
158+
"@kaltevuus is used to model the effect of hills on bicycle route choice, " +
159+
"setting @kaltevuus to 0 on links will ignore hills.")
142160
zero_gradient_ratio = (nr_zero_gradients/nr_links)*100
143161
if zero_gradient_ratio > 20:
144162
msg = "{} % of links have a gradient of 0.".format(zero_gradient_ratio)

0 commit comments

Comments
 (0)