feat(cost): add route cost models - #5
Merged
Merged
Conversation
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
Implements Phase 4 of the Roadrunner roadmap by separating graph topology from the routing objective used to evaluate an edge.
Edgewith validatedMetersandSecondsattributesRoutingContextRouteCostandCostKindCostModel: Send + SyncboundaryDistanceCostTravelTimeCostCost model contract
CostModel::edge_costaccepts an edge and routing context and returns a validatedRouteCost. It returnsResultso future dynamic or external cost models cannot silently introduce negative, NaN, or infinite values into routing algorithms.DistanceCostselectsEdge::distance()in meters.TravelTimeCostselectsEdge::base_travel_time()in seconds. Neither model changes graph topology or mutates its context.Unit safety
Each
RouteCostcarries aCostKinddiscriminator:distancetravel_timeCosts reject negative and non-finite values at construction and deserialization. Costs with different kinds cannot be added or ordered against each other. Same-kind addition revalidates the result so floating-point overflow is reported instead of propagated.
Phase boundary
This PR introduces cost calculation but no path search, predecessor tracking, or route reconstruction. Dijkstra remains Phase 5.
RoutingContextis intentionally empty for static Phase 4 models and provides the extension seam for later departure-time and traffic state.Tests
New tests verify:
Validation
cargo fmt --all -- --checkcargo clippy --workspace --all-targets --all-features --locked -- -D warningscargo test --workspace --all-features --locked— 33 tests passcargo bench -p roadrunner-core --bench graph_traversal --no-run --lockedRUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-deps --lockedgit diff --check main...HEAD