Skip to content

routing: add a real heuristic to public route search#19

Merged
blackopsrepl merged 1 commit intomainfrom
issue/6-add-real-routing-heuristic
Mar 21, 2026
Merged

routing: add a real heuristic to public route search#19
blackopsrepl merged 1 commit intomainfrom
issue/6-add-real-routing-heuristic

Conversation

@blackopsrepl
Copy link
Copy Markdown
Contributor

Summary

The public routing entry points were still calling astar with a zero heuristic, so route search behaved like Dijkstra even though the API and docs implied A*-style search.

This change adds admissible straight-line lower bounds to every public A* route search:

  • travel-time routing uses haversine distance divided by the fastest observed network edge speed
  • distance routing uses haversine distance directly
  • focused tests cover both objectives and confirm the optimal path is unchanged

Validation

  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo test

Notes

The repository does not currently have a dedicated route-search benchmark harness, so this PR implements the heuristic change and correctness coverage but does not add benchmark artifacts.

Fixes #6

@blackopsrepl blackopsrepl merged commit 6f609ac into main Mar 21, 2026
3 checks passed
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1ec700ecca

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

let Some(to_node) = self.graph.node_weight(to) else {
return 0.0;
};
haversine_distance(from_node.coord(), to_node.coord())
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid non-admissible heuristics on from_test_data graphs

When a graph comes from from_test_data or any other synthetic source where distance_m / travel_time_s are not derived from the node coordinates, haversine_distance is not a safe lower bound. from_test_data explicitly accepts arbitrary weights (the example in this file uses nodes ~28 km apart with a 1 km edge), so distance_lower_bound_between and time_lower_bound_between can exceed the true remaining cost. Because src/routing/algo.rs::astar returns on the first goal pop, these new heuristics can now make route* return a non-optimal path on custom/test networks, whereas the previous zero-heuristic behavior stayed correct.

Useful? React with 👍 / 👎.

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.

routing: add a real heuristic to public route search

1 participant