Repository navigation
network_from_sumo: support networks built with --no-internal-links - #60
Open
henrigrossmann wants to merge 1 commit into
Open
henrigrossmann wants to merge 1 commit into
henrigrossmann wants to merge 1 commit into
Conversation
Converting a network built by netconvert with --no-internal-links aborted with
TypeError: argument of type 'NoneType' is not a container or iterable
network_from_sumo.py:124, in create_nodes_and_edges_from_xml
if "_" in internalEdge_id:
because such a network has no internal edges and its <connection> elements
therefore carry no "via" attribute, so connection.get("via") returns None.
Guarding the None and skipping those connections is not enough: the connection
loop is what creates the connector edges between the per-edge start/end node
pairs, so skipping them leaves every SUMO edge as an isolated two-node
component and no request can be routed at all. When there are no internal
links, the end node of the incoming edge and the start node of the outgoing
edge are the same junction, so a zero-length connector is the correct
representation. Its id gets a leading ":" so that
SUMOFleetPyServer._transform_route_fp_to_sumo() drops it from the route it
sends to SUMO, which already skips ids starting with ":" -- turns are implicit
at junctions in SUMO and a synthetic edge id would be rejected.
Two further problems in the same loop:
- The "find internal edge element for id" loop left edge_element pointing at
the last <edge> of the network when no id matched, instead of reporting a
miss, so the connector silently got that unrelated edge's length and speed.
It now looks the element up in a dict and skips on a miss. This is the only
intended behaviour change for networks that do have internal links.
- That lookup re-ran root_node.findall("edge") once per connection, i.e.
O(#connections * #edges). On a city network (~38k connections, ~22k edges)
that is ~850M iterations. The edge elements are now indexed once up front.
Verified on a 34 MB no-internal-links network of Zurich (VMOD, 22453 edges,
37681 connections): conversion now completes in 35 s and yields 43416 nodes /
56350 edges with 34642 zero-length connectors, 92.9 % of the nodes in the
largest strongly connected component. For networks with internal links whose
connections all resolve, the returned nodes and edges are unchanged.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Problem
network_from_sumo.pycannot convert a network thatnetconvertbuilt with--no-internal-links. It aborts with:Such a network holds no internal edges, so its
<connection>elements carry noviaattribute and
connection.get("via")returnsNone.Minimal reproduction
A two-edge network with one connection and no internal links is enough:
Why guarding the
Noneis not enoughThe connection loop is what creates the connector edges between the per-edge start/end
node pairs. Simply skipping connections without a
vialeaves every SUMO edge as anisolated two-node component, so no request can be routed at all — the simulation
runs and serves nothing.
Without internal links, the end node of the incoming edge and the start node of the
outgoing edge are the same junction, so a zero-length connector is the correct
representation. Its id gets a leading
:so thatSUMOFleetPyServer._transform_route_fp_to_sumo()drops it from the route sent to SUMO —that function already skips ids starting with
:. Turns are implicit at junctions inSUMO, so a synthetic edge id would otherwise be rejected.
Two further problems in the same loop
#find internal edge element for idloop leftedge_elementpointing at the last<edge>of the network when no id matched,so the connector silently got that unrelated edge's length and speed. It is now a dict
lookup that skips on a miss. This is the only intended behaviour change for networks
that do have internal links.
root_node.findall("edge")once perconnection, i.e.
O(#connections * #edges)— about 850M iterations on a city network(~38k connections, ~22k edges). The edge elements are now indexed once up front.
Verification
connected (
A: 0->1,:c_A__B: 1->2,B: 2->3).--no-internal-linksnetwork of Zurich (22453 edges, 37681 connections)converts in 35 s to 43416 nodes / 56350 edges with 34642 zero-length connectors,
92.9 % of nodes in the largest strongly connected component.
nodesandedgesdicts are identical to those produced by the module before this change(compared object-by-object against the pre-patch version).
🤖 Generated with Claude Code