Skip to content

Add scenario-aware speed modifiers - #406

Open
FlxPo wants to merge 1 commit into
mainfrom
feature/scenario-speed-modifiers
Open

Add scenario-aware speed modifiers#406
FlxPo wants to merge 1 commit into
mainfrom
feature/scenario-speed-modifiers

Conversation

@FlxPo

@FlxPo FlxPo commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Motivation

Road network modifiers only accepted fixed values. Border penalties, speed limits, lane changes, and new roads could therefore not change by scenario or model iteration.

Passing a ParameterValue directly also left it unresolved when the graph was built, which caused serialization errors.

Changes

  • Allow every speed modifier setting to use ParameterValue and SensitivityValue, including geometry paths and extract dates.
  • Add parameter models for border crossings, limited-speed zones, lane changes, and new roads.
  • Resolve routing parameters and speed modifiers for each scenario and iteration before creating path graph assets.
  • Create lightweight resolved transport mode and generalized-cost variants so graph hashes and cached results match the selected inputs.
  • Keep graph construction lazy: resolving an iteration does not start GIS or R work until the asset is requested.
  • Raise a clear error when an unresolved modifier is used directly.
  • Document scenario-aware speed modifiers and their parameter models.
  • Add tests for scenario discovery, scalar defaults, missing geometry, unresolved values, congestion and free-flow graphs, and graph dependency rebinding.

Example (if relevant)

speed_zone = mobility.LimitedSpeedZonesModifier(
    zones_geometry_file_path=inputs/speed-zones.gpkg,
    max_speed=mobility.ParameterValue.by_scenario_and_iteration(
        default=50.0,
        safer_streets={
            1: 50.0,
            5: 30.0,
        },
    ),
)

car = mobility.CarMode(
    transport_zones,
    speed_modifiers=[speed_zone],
)

AI-assisted contribution

Select one:

  • No AI assistance
  • AI used for minor help only (for example: phrasing, small refactors, or suggestions)
  • AI used for substantial parts of the contribution

AI assistance covered the architecture, implementation, tests, documentation, and PR draft. The resulting resolved variants, lazy asset behavior, scalar compatibility, public attributes, and cache inputs were reviewed.

Validation included:

  • 623 passing unit tests
  • The existing scenario-iteration integration test
  • 19 focused transport graph and mode tests
  • A successful Grand Genève scenario run
  • A clean git diff --check

Checklist

  • I have reviewed the code and documentation changes.
  • I understand the changes and can maintain them.
  • I have added or updated tests where needed.
  • The relevant tests and checks pass.

@codecov

codecov Bot commented Aug 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.64286% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.33%. Comparing base (d172ef4) to head (a740293).

Files with missing lines Patch % Lines
mobility/transport/costs/generalized_cost.py 91.66% 1 Missing ⚠️
mobility/transport/costs/travel_costs_asset.py 50.00% 1 Missing ⚠️
...nsport/graphs/modified/modifiers/speed_modifier.py 98.30% 1 Missing ⚠️
...pool/detailed/detailed_carpool_generalized_cost.py 75.00% 1 Missing ⚠️
mobility/transport/modes/core/transport_mode.py 94.44% 1 Missing ⚠️
...lic_transport/public_transport_generalized_cost.py 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #406      +/-   ##
==========================================
+ Coverage   83.20%   83.33%   +0.12%     
==========================================
  Files         234      235       +1     
  Lines       16294    16371      +77     
==========================================
+ Hits        13558    13643      +85     
+ Misses       2736     2728       -8     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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