Skip to content

feat(graph): add adjacency-list road network - #3

Merged
404khai merged 1 commit into
mainfrom
feat/phase-2-graph
Sep 1, 2026
Merged

feat(graph): add adjacency-list road network#3
404khai merged 1 commit into
mainfrom
feat/phase-2-graph

Conversation

@404khai

@404khai 404khai commented Sep 1, 2026

Copy link
Copy Markdown
Owner

Summary

Implements Phase 2 of the Roadrunner roadmap with a manually owned, directed adjacency-list graph in roadrunner-core.

  • adds distinct opaque NodeId and EdgeId types with stable serialization
  • adds topology-only Node and directed Edge domain types
  • adds adjacency-list Graph storage with a separate edge identity index
  • adds typed graph construction, lookup, removal, and invariant errors
  • adds a generated-graph breadth-first traversal benchmark using Criterion

Graph operations

The graph now supports:

  • add_node
  • add_edge
  • remove_edge
  • neighbors
  • node and edge lookup
  • node_count and edge_count
  • contains_node

Edges are stored once in their source node's outgoing adjacency list. One-way roads use one directed edge; bidirectional roads use reciprocal edges. Duplicate node and edge identities are rejected, while parallel edges with distinct EdgeId values are allowed as specified in Phase 0.

Phase boundary

Node intentionally contains only its identity in Phase 2. Validated coordinates and geographic units arrive in Phase 3, avoiding raw latitude/longitude values in the graph API. Edge distance and travel-time attributes remain deferred to the geographic and cost-model phases. No shortest-path implementation is included.

Tests

The graph tests cover:

  • empty graphs
  • single-node graphs
  • directed/one-way edges
  • reciprocal/bidirectional edges
  • cycles
  • disconnected components
  • invalid source and destination nodes
  • duplicate nodes and edges
  • allowed parallel edges
  • edge lookup and removal
  • adjacency/count consistency after mutation

Benchmark

graph_traversal constructs deterministic directed ring-lattice graphs with fan-out 3 and traverses them breadth-first from node 0.

  • graph sizes: 1K, 10K, and 100K nodes
  • sample size: 20
  • throughput unit: visited nodes
  • command: cargo bench -p roadrunner-core --bench graph_traversal --locked

The benchmark was compiled and executed locally at all three sizes. This PR makes no cross-machine performance claim and does not commit generated Criterion output.

Validation

  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings
  • cargo test --workspace --all-features --locked
  • cargo bench -p roadrunner-core --bench graph_traversal --no-run --locked
  • cargo bench -p roadrunner-core --bench graph_traversal --locked
  • git diff --check main...HEAD

@404khai
404khai merged commit b3db25c into main Sep 1, 2026
4 checks passed
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