9.9 KiB
9.9 KiB
Valhalla Routing Engine Complete 1:1 Pure Rust Port (valhalla-rs)
Comprehensive Execution Plan for Remaining Subsystems & Feature Gaps
Date: July 27, 2026
Target Repository: https://gitdab.com/andodeki/nigig-org.git (crates/apps/valhalla/*)
Reference C++ Engine: Valhalla Routing Engine (https://github.com/valhalla/valhalla.git)
Objective: Bridge the remaining ~25% feature gap to achieve 100% 1:1 functional, algorithmic, and data parity with C++ Valhalla.
1. Subsystem Gap Analysis & Target Architecture
To transition from the current 75% operational foundation to a 100% complete 1:1 production port, six dedicated completion tranches have been defined:
┌────────────────────────────────────────────────────────────────────────┐
│ VALHALLA 1:1 PORT COMPLETION ROADMAP │
│ │
│ TRANCHE 1: Complex Turn Restrictions & Time Domains (baldr/thor) │
│ TRANCHE 2: Multi-Level Hierarchy Transition Edges (tilehierarchy) │
│ TRANCHE 3: Historical & Predictive Traffic Profile Tables (baldr) │
│ TRANCHE 4: GTFS Public Transit & MultiModal A* Engine (thor/sif) │
│ TRANCHE 5: Direct Native OSM PBF Binary Stream Decoder (mjolnir) │
│ TRANCHE 6: Multi-Language Narrative & Voice Localization (odin) │
└────────────────────────────────────────────────────────────────────────┘
2. Detailed Technical Execution Plan by Tranche
Tranche 1: Complex Turn Restrictions & Time-Dependent Restrictions
- Reference C++ Headers:
valhalla/baldr/complexrestriction.h,valhalla/baldr/accessrestriction.h,valhalla/baldr/timedomain.h,valhalla/mjolnir/complexrestrictionbuilder.h - Target Crate:
valhalla-core&valhalla-path
Technical Implementation Details:
- Data Model (
valhalla-core::baldr::complexrestriction):- Implement
ComplexRestrictionstruct reading fromcomplex_restriction_forward_offsetandcomplex_restriction_reverse_offsetinGraphTileHeader. - Multi-edge sequence tracking:
from_edge,via_edgeslist, andto_edge. TimeDomainbitmask parser: day of week, hours of day, conditional vehicle mode masks (e.g., "No left turn between 07:00–09:00 for non-buses").
- Implement
- Search Integration (
valhalla-path::astar):- Maintain
restriction_idxonEdgeLabel. - During
A^*edge expansion, check if the current edge sequence matches an activeComplexRestriction. If matched and time condition applies, prune the expansion path.
- Maintain
- Unit & Integration Test Strategy:
- Port unit tests from
valhalla/test/complexrestriction.ccandvalhalla/test/datetime.cc.
- Port unit tests from
Tranche 2: Multi-Level Hierarchy Transition Edges & Level Hopping
- Reference C++ Headers:
valhalla/baldr/tilehierarchy.h,valhalla/mjolnir/hierarchybuilder.h,valhalla/sif/hierarchylimits.h - Target Crate:
valhalla-core&valhalla-path
Technical Implementation Details:
- Hierarchy Level Specification (
valhalla-core::baldr::tilehierarchy):- Level 0: Highway / Interstate network (
4.0^\circ \times 4.0^\circtiles). - Level 1: Arterial road network (
1.0^\circ \times 1.0^\circtiles). - Level 2: Local street network (
0.25^\circ \times 0.25^\circtiles).
- Level 0: Highway / Interstate network (
- Transition Edge Handling (
valhalla-path::astar):- Implement
TransitionEdgestate handling: Upward transitions (Level 2 -> Level 1 -> Level 0) during initial search expansion, and Downward transitions (Level 0 -> Level 1 -> Level 2) as destination search frontier approaches. HierarchyLimits: Adaptive search radius thresholds preventing search from dropping down to local level during long-distance interstate searches (>500\text{km}).
- Implement
- Performance Impact:
- Accelerates continent-scale route search latency from
300\text{ms}down to<15\text{ms}.
- Accelerates continent-scale route search latency from
- Unit & Integration Test Strategy:
- Port unit tests from
valhalla/test/tilehierarchy.ccandvalhalla/test/hierarchylimits.cc.
- Port unit tests from
Tranche 3: Historical & Predictive Traffic Profile Tables
- Reference C++ Headers:
valhalla/baldr/predictedspeeds.h,valhalla/mjolnir/add_predicted_speeds.h,valhalla/baldr/traffictile.h - Target Crate:
valhalla-core&valhalla-cost
Technical Implementation Details:
- Predicted Speed Table Parser (
valhalla-core::baldr::predictedspeeds):- Read from
predictedspeeds_offsetinGraphTileHeader. - Each entry contains 5-minute time bucket speed profiles (
288buckets per day, 7 days a week).
- Read from
- Dynamic Cost Integration (
valhalla-cost::autocost):- Evaluate departure time timestamp: calculate
bucket_index = (day_of_week * 288) + (seconds_since_midnight / 300). - Retrieve predicted speed for
bucket_indexand override static free-flow speed inAutoCost::edge_cost().
- Evaluate departure time timestamp: calculate
- Unit & Integration Test Strategy:
- Port unit tests from
valhalla/test/predictedspeeds.ccandvalhalla/test/predictive_traffic.cc.
- Port unit tests from
Tranche 4: GTFS Public Transit Engine & MultiModal A*
- Reference C++ Headers:
valhalla/baldr/transitstop.h,transitdeparture.h,transitroute.h,transitschedule.h,valhalla/thor/multimodal_astar.h,valhalla/sif/transitcost.h - Target Crate:
valhalla-core,valhalla-cost,valhalla-path
Technical Implementation Details:
- Transit Data Models (
valhalla-core::baldr::transit):TransitStop: Platform, station, in/egress location, stop name.TransitDeparture: Schedule departure time, trip ID, route ID, headsign.TransitRoute&TransitSchedule: Service calendar and GTFS route definitions.
- Transit Costing & Search (
valhalla-cost::transitcost&valhalla-path::multimodal_astar):TransitCost: Waiting time penalty, transfer penalty, mode change penalty (pedestrian\leftrightarrowtransit).MultiModalAStar: Time-dependent schedule expansion finding shortest multi-modal trips (Walk\toBus\toWalk\toTrain\toWalk).
- Unit & Integration Test Strategy:
- Port unit tests from
valhalla/test/transitstop.cc,transitdeparture.cc,servicedays.cc, andmultimodal_astar.cc.
- Port unit tests from
Tranche 5: Direct Native OSM PBF Binary Stream Decoder
- Reference C++ Headers:
valhalla/mjolnir/pbfgraphparser.h,pbfadminparser.h - Target Crate:
valhalla-builder
Technical Implementation Details:
- PBF Stream Reader (
valhalla-builder::pbf_reader):- Use Pure Rust
osmpbfcrate to decodeBlobHeader,Blob, andPrimitiveBlockchunks directly from raw.osm.pbffile streams. - Parallel node/way processing via
rayonworker pool.
- Use Pure Rust
- Graph Tile Partitioning:
- Extract nodes (
lat,lon, tags), ways (highway,maxspeed,access,oneway,surface,bridge,tunnel,turnlanes), and relations (complex turn restrictions, route relations). - Group entities by
GraphIdtile bounding boxes and compile directly into binary.gtiGraphTiles viaGraphTileCompiler.
- Extract nodes (
- Unit & Integration Test Strategy:
- Port unit tests from
valhalla/test/graphparser.ccandvalhalla/test/graphbuilder.cc.
- Port unit tests from
Tranche 6: Multi-Language Narrative & Voice Localization Engine
- Reference C++ Headers:
valhalla/odin/narrative_dictionary.h,verbal_text_formatter.h,locales/*.json - Target Crate:
valhalla-narrative
Technical Implementation Details:
- Narrative Dictionary (
valhalla-narrative::dictionary):- Port Valhalla's ICU narrative JSON dictionaries (
locales/en-US.json,locales/sw-KE.json,locales/fr-FR.json,locales/es-ES.json). - Instruction templates for turn maneuvers, roundabout exits, highway merges, and destination arrival.
- Port Valhalla's ICU narrative JSON dictionaries (
- Verbal Text Formatter (
valhalla-narrative::verbal):- Phonetic text formatting for text-to-speech (TTS) voice instruction strings (e.g. Swahili: "Baada ya mita mia mbili, pinda kulia kwenye Barabara kuu ya Uhuru").
- Unit & Integration Test Strategy:
- Port unit tests from
valhalla/test/narrative_dictionary.ccandvalhalla/test/verbal_text_formatter.cc.
- Port unit tests from
3. Milestones & Delivery Schedule
| Tranche | Deliverables & Scope | Target Crate | Estimated Complexity | Target Timeline |
|---|---|---|---|---|
| Tranche 1 | Complex Turn Restrictions & TimeDomains | valhalla-core, valhalla-path |
Medium | Weeks 1–2 |
| Tranche 2 | Multi-Level Hierarchy Transitions & Level Hopping | valhalla-core, valhalla-path |
High | Weeks 3–4 |
| Tranche 3 | Historical & Predictive Traffic Profile Lookup Tables | valhalla-core, valhalla-cost |
Medium | Weeks 5–6 |
| Tranche 4 | GTFS Public Transit Models & MultiModal A* | valhalla-core, valhalla-cost, valhalla-path |
High | Weeks 7–8 |
| Tranche 5 | Direct Native .osm.pbf Reader & Compiler |
valhalla-builder |
Medium | Weeks 9–10 |
| Tranche 6 | Multi-Language Narrative & Voice Formatter (Swahili/French/etc) | valhalla-narrative |
Low | Weeks 11–12 |
4. Verification & Quality Assurance Governance
- Unit Testing Ratchet: Every new tranche must add isolated unit tests under
src/passingTEST_TARGET=valhalla ./tools/test-rust-clean.sh. - Differential Parity Ratchet (
valhalla-diff): Outputs must be verified against C++ Valhalla daemon outputs for complex queries (multi-level routes, GTFS transit, time-dependent traffic) with strict assertions:- Polyline decoding match:
\le 1\times 10^{-5}\text{ deg} - Duration match:
\le 1\% - Distance match:
\le 1\text{m}
- Polyline decoding match:
- Zero Security Warnings: All code must remain clean under
cargo fmt --checkandcargo clippy --all-targets -- -D warnings.