Skip to content

network_from_sumo: support networks built with --no-internal-links - #60

Open
henrigrossmann wants to merge 1 commit into
TUM-VT:dev/merge_to_masterfrom
henrigrossmann:henri/sumo-net-no-internal-links
Open

henrigrossmann wants to merge 1 commit into
TUM-VT:dev/merge_to_masterfrom
henrigrossmann:henri/sumo-net-no-internal-links

Conversation

@henrigrossmann

Copy link
Copy Markdown

Problem

network_from_sumo.py cannot convert a network that netconvert built with
--no-internal-links. It aborts 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:

Such a network holds no internal edges, so its <connection> elements carry no via
attribute and connection.get("via") returns None.

Minimal reproduction

A two-edge network with one connection and no internal links is enough:

<net version="1.16">
    <edge id="A" from="n1" to="n2" priority="1">
        <lane id="A_0" index="0" speed="13.89" length="100.00" shape="0,0 100,0"/>
    </edge>
    <edge id="B" from="n2" to="n3" priority="1">
        <lane id="B_0" index="0" speed="13.89" length="100.00" shape="100,0 200,0"/>
    </edge>
    <junction id="n1" type="dead_end"  x="0"   y="0" incLanes=""    intLanes="" shape="0,0"/>
    <junction id="n2" type="priority"  x="100" y="0" incLanes="A_0" intLanes="" shape="100,0"/>
    <junction id="n3" type="dead_end"  x="200" y="0" incLanes="B_0" intLanes="" shape="200,0"/>
    <connection from="A" to="B" fromLane="0" toLane="0" dir="s" state="M"/>
</net>
python network_from_sumo.py mini.net.xml -n mini -a "passenger,taxi"

Why guarding the None is not enough

The connection loop is what creates the connector edges between the per-edge start/end
node pairs. Simply skipping connections without a via leaves every SUMO edge as an
isolated 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 that
SUMOFleetPyServer._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 in
SUMO, so a synthetic edge id would otherwise be rejected.

Two further problems in the same loop

  • Leaked loop variable. The #find internal edge element for id loop left
    edge_element pointing 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.
  • Quadratic lookup. That search re-ran root_node.findall("edge") once per
    connection, 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

  • The minimal network above converts instead of crashing, and the resulting graph is
    connected (A: 0->1, :c_A__B: 1->2, B: 2->3).
  • A 34 MB --no-internal-links network 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.
  • Regression: for two networks with internal links, the returned nodes and
    edges dicts are identical to those produced by the module before this change
    (compared object-by-object against the pre-patch version).

🤖 Generated with Claude Code

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant