Skip to content

Support adjust_node_capacity in C++ mode and define threads on World for both modes - #347

Merged
toruseo merged 2 commits into
toruseo:mainfrom
toruseoagent:pr/adjust-node-capacity-and-threads
Jul 16, 2026
Merged

Support adjust_node_capacity in C++ mode and define threads on World for both modes#347
toruseo merged 2 commits into
toruseo:mainfrom
toruseoagent:pr/adjust-node-capacity-and-threads

Conversation

@toruseoagent

Copy link
Copy Markdown
Contributor

Summary

Two follow-up changes for the C++ mode:

  1. adjust_node_capacity support in C++ mode — ports the feature added for the Python mode in add adjust_node_capacity option #344 to the C++ engine, so World(cpp=True, adjust_node_capacity=True) behaves the same as the Python mode.
  2. threads defined on World for both modes — the threads argument introduced in Parallelize the C++ engine with deterministic OpenMP while keeping the AoS data layout #341 was a cpp-mode-only extension of the wrapper, so World(cpp=False, threads=N) raised TypeError. It is now a regular World.__init__ parameter documented in uxsim.py; the Python mode accepts and simply ignores it.

Details

adjust_node_capacity (commit 1)

  • Node::adjust_node_capacity() in the C++ engine mirrors the Python implementation line by line: if flow_capacity is unset (C++ sentinel -1.0 corresponding to Python None) and the node has both in- and out-links, it sets flow_capacity = (max(inlink capacities) + max(outlink capacities)) / 2, updates flow_capacity_remain = flow_capacity * DELTAT, and derives number_of_lanes = ceil(flow_capacity / 0.8) when lanes are unset (flagging flag_lanes_automatically_determined).
  • Applied to all nodes at scenario finalization (initialize_adj_matrix), the same timing as the Python mode's finalize_scenario. Idempotent once flow_capacity >= 0.
  • The wrapper exposes CppNode.adjust_node_capacity() and syncs the wrapper-side node attributes after finalization.
  • Validation: on a 6x6 grid mixing 2-lane major and 1-lane minor roads (8000 vehicles, 5 seeds), the resulting flow_capacity and number_of_lanes of every node are identical between Python and C++ modes; TTT differs by +0.89% on average (expected RNG-sequence effect).

threads on World (commit 2)

  • threads: int=1 is inserted in World.__init__ immediately before cpp, matching the positional layout of the wrapper's CppWorld.__init__, with a numpydoc entry (default 1; N≥1 threads; -1 = all cores; ignored when cpp=False).
  • The Python mode performs no validation and stores nothing — the argument simply has no effect there. The C++ mode keeps the existing validation (bool rejected, ValueError for 0 / ≤ -2) and forwarding to the engine.

Tests

  • tests/test_cpp_mode.py: 217 passed — three adjust_node_capacity tests ported from tests/test_verification_node.py (merge capacity, major/minor free-flow, major/minor congested), and test_threads_parameter extended with a Python-mode block asserting World(cpp=False) with threads=4 / threads=-1 runs and produces results identical to omitting the argument.
  • tests/test_other_functions.py: 28 passed (1 pre-existing environment-only failure: osmnx not installed).

Part of #297

🤖 Generated with Claude Code

toruseoagent and others added 2 commits July 16, 2026 10:05
Ports the adjust_node_capacity feature (toruseo#344) to the C++
engine: Node::adjust_node_capacity() derives flow_capacity from connected
link capacities at scenario finalization, matching the Python semantics.
Wrapper syncs node attributes and exposes CppNode.adjust_node_capacity().
Three tests are ported from test_verification_node.py.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…ode)

The threads argument was previously a cpp-mode-only extension of the
wrapper, so World(cpp=False, threads=N) raised TypeError. It is now a
regular World.__init__ parameter documented in uxsim.py; the Python mode
accepts and simply ignores it, while the C++ mode keeps its validation
and forwards it to the engine.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@toruseoagent
toruseoagent force-pushed the pr/adjust-node-capacity-and-threads branch from 25f5957 to d4c1e6e Compare July 16, 2026 10:05
@toruseo
toruseo enabled auto-merge July 16, 2026 10:07
toruseoagent added a commit to toruseoagent/UXsim that referenced this pull request Jul 16, 2026
…plicity lesson)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@toruseo
toruseo merged commit 459d658 into toruseo:main Jul 16, 2026
10 checks passed
@toruseoagent
toruseoagent deleted the pr/adjust-node-capacity-and-threads branch July 16, 2026 10:19
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.

2 participants