Cut edge types before the isochrone reachability search - #229
Closed
yu-ta-sato wants to merge 1 commit into
Closed
Conversation
create_isochrone() applied cut_edge_types after the shortest-path computation, so the cut edges were still traversed and were merely dropped from the geometry that was drawn. Nodes reachable only through a cut edge stayed inside the isochrone, and for the hull-based methods, which build the polygon from node coordinates alone, the parameter had no effect at all. The listed edge types are now removed from the graph before the distance computation, in both the scalar and the layered threshold paths, so cut_edge_types=[t] matches never supplying t in edges. Also match parallel edges by key when filtering a multigraph. Edges were collected as (u, v) pairs, and NetworkX removes an arbitrary parallel edge for such a pair, so a walking edge could be removed in place of the transit edge running alongside it. Prepare v1.0.1 and drop cut_edge_types from the walk-plus-transit cell of the GTFS example, which cut the transit edges it means to show.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
create_isochrone()appliedcut_edge_typesafter the reachability search rather than before it._compute_center_node_distances()and_build_reachable_subgraph()ran on the full graph, and_filter_edges_by_type()was applied only to the resulting subgraph, so the cut edges were still traversed and were merely removed from the geometry that got drawn. Nodes reachable only through a cut edge stayed inside the isochrone. For the hull-based methods, which build the polygon from node coordinates alone, the parameter had no effect whatsoever. The docstring already described the intended behaviour: "edge types to remove from the graph before processing".The filtering now runs once on the prepared graph before the distance computation, covering both the scalar and the layered threshold paths, so
cut_edge_types=[t]gives the same isochrone as never supplyingtinedges.This PR also fixes a second defect in
_filter_edges_by_type(): parallel edges were collected as(u, v)pairs, and NetworkX removes an arbitrary parallel edge for such a pair, so on a multigraph a walking edge could be removed in place of the transit edge running alongside it. Parallel edges are now matched by key.Reproduction, on a straight walking chain from x=0 to x=600 (4.8 km/h, so 75 s per 100 m) with two stops joined by one 30-second transit edge, 120-second threshold from x=0:
cut_edge_types=[transit](before)cut_edge_types=[transit](after)edgesCutting the transit type now agrees exactly with never supplying it.
Behaviour change. Isochrones computed with
cut_edge_typeson 1.0.0 and earlier will change: cutting a transit edge type now yields the area reachable without transit, rather than the transit-assisted area with the transit lines erased. This is released as1.0.1, withpyproject.toml,CITATION.cff, and the CHANGELOG updated accordingly.Related issues
Not applicable.
Testing
uv run --group dev --extra cpu pytest -q— 940 passed.uv run --group dev --extra cpu pre-commit run --all-files— clean.test_isochrone_disconnected_componentsasserted aMultiPolygon, which was the bug itself: cluster 2 was reached through the cut transit edge and only that edge's geometry was dropped. It is replaced bytest_isochrone_cut_edges_are_not_traversed, which asserts cluster 2 is excluded when the type is cut and reached when it is not. Two tests are added:test_isochrone_cut_edge_types_matches_omitting_edge_type(the equivalence above) andtest_isochrone_cut_edge_types_multigraph_keeps_parallel_edges. All three fail against the pre-fix source and pass after it.Documentation
cut_edge_typesin thecreate_isochrone()docstring now states that removal precedes the reachability search and that nodes reachable only through those edges fall outside the isochrone.cut_edge_typesfrom the walk-plus-transit isochrone cell ofdocs/examples/gtfs.ipynb. That cell computes a multimodal isochrone but cut the transit edge type. The parameter had no effect on itsconcave_hull_knnoutput before this change and would now remove the transit reach the section exists to demonstrate. The stored outputs remain correct, becauseconcave_hull_knnbuilds its hull from node coordinates only.1.0.1section.Reviewer notes
Worth a second opinion on the release framing: this is a bug fix, so it is filed as a patch, but it does change the output of existing
cut_edge_typescalls. If that warrants a minor bump instead, the version metadata is the only thing to adjust.