Fix threshold usage in shortest path computation#438
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #438 +/- ##
==========================================
+ Coverage 87.26% 87.31% +0.05%
==========================================
Files 52 52
Lines 6523 6628 +105
Branches 732 765 +33
==========================================
+ Hits 5692 5787 +95
- Misses 809 817 +8
- Partials 22 24 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| graph.addStreets(s1, s2, s3, s4, s5); | ||
|
|
||
| auto const& pathMap = | ||
| graph.allPathsTo(4, [](auto const& pEdge) { return pEdge.length(); }, 0.7); |
|
|
||
| auto const& pathMap = | ||
| graph.allPathsTo(4, [](auto const& pEdge) { return pEdge.length(); }, 0.7); | ||
| CHECK_EQ(pathMap.at(0).size(), 2); |
| auto const& pathMap = | ||
| graph.allPathsTo(4, [](auto const& pEdge) { return pEdge.length(); }, 0.7); | ||
| CHECK_EQ(pathMap.at(0).size(), 2); | ||
| } |
| graph.allPathsTo(4, [](auto const& pEdge) { return pEdge.length(); }, 0.7); | ||
| CHECK_EQ(pathMap.at(0).size(), 2); | ||
| } | ||
|
|
| // Best path: 0 -> 1 -> 2 -> 5 = 10.0 | ||
| // Alternative: 0 -> 1 -> 3 -> 5 = 10.89 (within 10%) | ||
| // Over-budget path: 0 -> 1 -> 3 -> 4 -> 5 = 11.39 (must be excluded) | ||
| Street s01(0, std::make_pair(0, 1), 1.0); |
| path[3] == 5) { | ||
| foundBestPath = true; | ||
| } | ||
| if (path.size() == 4 && path[0] == 0 && path[1] == 1 && path[2] == 3 && |
| path[3] == 5) { | ||
| foundValidAlternative = true; | ||
| } | ||
| if (path.size() == 5 && path[0] == 0 && path[1] == 1 && path[2] == 3 && |
| path[3] == 4 && path[4] == 5) { | ||
| foundOverBudgetPath = true; | ||
| } | ||
| } |
|
|
||
| CHECK(foundBestPath); | ||
| CHECK(foundValidAlternative); | ||
| CHECK_FALSE(foundOverBudgetPath); |
| CHECK(foundBestPath); | ||
| CHECK(foundValidAlternative); | ||
| CHECK_FALSE(foundOverBudgetPath); | ||
| } |
There was a problem hiding this comment.
Pull request overview
This PR updates the road-network pathfinding “threshold” semantics so the tolerance is applied against the total source→target (or node→target) path cost, rather than being applied step-by-step at each hop. This affects both C++ pathfinding behavior and its test coverage, plus a small Python-docstring clarification.
Changes:
- Refactors
RoadNetwork::allPathsTo()/RoadNetwork::shortestPath()to compute strict distances-to-target first, then filter next-hops using a full-path budget rule. - Adds new tests covering deeper alternative paths and ensuring over-budget full paths are excluded.
- Updates
FirstOrderDynamicstest usage and Python binding docstrings to match the clarified threshold meaning.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/dsf/mobility/RoadNetwork.hpp |
Refactors pathfinding to enforce full-path budget threshold via distances-to-target and new filtering/recursion logic. |
test/mobility/Test_graph.cpp |
Adds new unit tests for full-path threshold behavior (deep alternatives + budget exclusion). |
test/mobility/Test_dynamics.cpp |
Adjusts weight-function threshold usage in a dynamics test to avoid unintended alternatives under new semantics. |
src/dsf/bindings.cpp |
Clarifies Python docstring: threshold is relative tolerance on full source→target cost. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
f1e9f1a to
5adaeba
Compare
5adaeba to
c94bcff
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…p-by-step