Support adjust_node_capacity in C++ mode and define threads on World for both modes - #347
Merged
toruseo merged 2 commits intoJul 16, 2026
Conversation
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
force-pushed
the
pr/adjust-node-capacity-and-threads
branch
from
July 16, 2026 10:05
25f5957 to
d4c1e6e
Compare
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>
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
Two follow-up changes for the C++ mode:
adjust_node_capacitysupport in C++ mode — ports the feature added for the Python mode in addadjust_node_capacityoption #344 to the C++ engine, soWorld(cpp=True, adjust_node_capacity=True)behaves the same as the Python mode.threadsdefined onWorldfor both modes — thethreadsargument 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, soWorld(cpp=False, threads=N)raisedTypeError. It is now a regularWorld.__init__parameter documented inuxsim.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: ifflow_capacityis unset (C++ sentinel-1.0corresponding to PythonNone) and the node has both in- and out-links, it setsflow_capacity = (max(inlink capacities) + max(outlink capacities)) / 2, updatesflow_capacity_remain = flow_capacity * DELTAT, and derivesnumber_of_lanes = ceil(flow_capacity / 0.8)when lanes are unset (flaggingflag_lanes_automatically_determined).initialize_adj_matrix), the same timing as the Python mode'sfinalize_scenario. Idempotent onceflow_capacity >= 0.CppNode.adjust_node_capacity()and syncs the wrapper-side node attributes after finalization.flow_capacityandnumber_of_lanesof 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=1is inserted inWorld.__init__immediately beforecpp, matching the positional layout of the wrapper'sCppWorld.__init__, with a numpydoc entry (default 1; N≥1 threads; -1 = all cores; ignored whencpp=False).ValueErrorfor 0 / ≤ -2) and forwarding to the engine.Tests
tests/test_cpp_mode.py: 217 passed — threeadjust_node_capacitytests ported fromtests/test_verification_node.py(merge capacity, major/minor free-flow, major/minor congested), andtest_threads_parameterextended with a Python-mode block assertingWorld(cpp=False)withthreads=4/threads=-1runs and produces results identical to omitting the argument.tests/test_other_functions.py: 28 passed (1 pre-existing environment-only failure:osmnxnot installed).Part of #297
🤖 Generated with Claude Code