-
Notifications
You must be signed in to change notification settings - Fork 4
Rework next streetid computation #370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #370 +/- ##
==========================================
- Coverage 83.56% 83.34% -0.23%
==========================================
Files 51 52 +1
Lines 5216 5207 -9
Branches 602 593 -9
==========================================
- Hits 4359 4340 -19
- Misses 845 855 +10
Partials 12 12
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:
|
| std::optional<Id> m_nextStreetId(std::unique_ptr<Agent> const& pAgent, | ||
| Id NodeId, | ||
| std::optional<Id> streetId = std::nullopt); | ||
| std::optional<Id> m_nextStreetId(const std::unique_ptr<Agent>& pAgent, |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 12.3 rule Note
| static_cast<double>(this->time_step() - pAgent->spawnTime())}); | ||
| --m_nAgents; | ||
| return std::move(pAgent); | ||
| return pAgent; |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 15.5 rule Note
| // Get current street information | ||
| std::optional<Id> previousNodeId = std::nullopt; | ||
| std::set<Id> forbiddenTurns; | ||
| double speedCurrent = 1.0; |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 12.3 rule Note
| std::optional<Id> previousNodeId = std::nullopt; | ||
| std::set<Id> forbiddenTurns; | ||
| double speedCurrent = 1.0; | ||
| if (pAgent->streetId().has_value()) { |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 14.4 rule Note
src/dsf/mobility/RoadDynamics.hpp
Outdated
| pathTargets = it->second->path().at(pNode->id()); | ||
| } catch (const std::out_of_range&) { | ||
| throw std::runtime_error(std::format("No path found for itinerary {} at node {}", | ||
| pAgent->itineraryId(), |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 12.3 rule Note
| allowedTargets.insert(pathTargets.begin(), pathTargets.end()); | ||
| hasItineraryConstraints = true; | ||
| for (const auto outEdgeId : outgoingEdges) { | ||
| if (forbiddenTurns.contains(outEdgeId)) { |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 14.4 rule Note
| if (possibleEdgeIds.empty()) { | ||
| // Select street based on weighted probabilities | ||
| if (transitionProbabilities.empty()) { |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 14.4 rule Note
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR refactors the m_nextStreetId computation to consolidate the street selection logic into a unified probability-based approach. The changes eliminate separate code paths for random vs. non-random agents, moving several simple getter methods from .cpp files to inline implementations in headers for potential performance improvements.
- Unified street selection algorithm using weighted probabilities for all agent types
- Moved simple accessor methods to inline header implementations with
noexceptandautoreturn types - Updated function signatures to pass node objects directly instead of node IDs
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| src/dsf/mobility/Street.hpp | Added noexcept to isStochastic() virtual methods and attempted to add constexpr (incorrectly) |
| src/dsf/mobility/RoadJunction.hpp | Converted virtual method declarations to inline implementations with attempted constexpr (incorrectly) |
| src/dsf/mobility/RoadJunction.cpp | Removed implementations now defined inline in header |
| src/dsf/mobility/RoadDynamics.hpp | Complete rework of m_nextStreetId to use unified probability-based selection; updated function signature; removed redundant std::move calls |
| src/dsf/mobility/Road.hpp | Converted getter methods to inline implementations using auto return type |
| src/dsf/mobility/Road.cpp | Removed implementations now defined inline in header |
| src/dsf/mobility/Agent.hpp | Attempted to add constexpr to isRandom() method (incorrectly) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/dsf/mobility/RoadDynamics.hpp
Outdated
| if (outgoingEdges.size() == 1) { | ||
| auto const& pStreetOut{this->graph().edge(outgoingEdges[0])}; | ||
| if (!pNode->isRoundabout() && pStreetOut->target() == pStreetOut->source()) { | ||
| return std::nullopt; | ||
| } | ||
| return outgoingEdges[0]; | ||
| } |
Copilot
AI
Nov 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The early return for single outgoing edge bypasses important validation checks. It doesn't verify:
- Whether the edge is in
forbiddenTurnsfor the current street - Whether the edge is a valid path target for non-random agents with itineraries
This could lead to agents taking forbidden or invalid paths. Consider moving this check after gathering forbidden turns and path targets, or at minimum validating these conditions before the early return.
src/dsf/mobility/RoadDynamics.hpp
Outdated
| if (forbiddenTargetNodes.count(targetNode)) { | ||
| continue; | ||
| // Apply error probability for non-random agents | ||
| if (this->m_errorProbability.has_value() && pathTargets.empty()) { |
Copilot
AI
Nov 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition on line 563 appears incorrect. It should check !pathTargets.empty() instead of pathTargets.empty() to apply error probability only when path targets exist (i.e., for non-random agents). The current logic applies error probability when pathTargets is empty, which doesn't match the intended behavior.
| if (this->m_errorProbability.has_value() && pathTargets.empty()) { | |
| if (this->m_errorProbability.has_value() && !pathTargets.empty()) { |
| } catch (const std::out_of_range&) { | ||
| if (!m_itineraries.contains(pAgent->itineraryId())) { | ||
| throw std::runtime_error( | ||
| std::format("No itinerary found with id {}", pAgent->itineraryId())); |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 14.4 rule Note
| // For non-random agents, get allowed targets from itinerary | ||
| std::unordered_set<Id> allowedTargets; | ||
| bool hasItineraryConstraints = false; | ||
| for (const auto outEdgeId : outgoingEdges) { |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 15.5 rule Note
| if (possibleEdgeIds.size() == 1) { | ||
| return possibleEdgeIds[0]; | ||
| if (transitionProbabilities.size() == 1) { | ||
| return transitionProbabilities.cbegin()->first; |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 15.5 rule Note
| } | ||
| } | ||
| // Return last one as fallback | ||
| return std::prev(transitionProbabilities.cend())->first; |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 15.5 rule Note
| template <typename delay_t> | ||
| requires(is_numeric_v<delay_t>) | ||
| void RoadDynamics<delay_t>::m_evolveAgents() { | ||
| if (m_agents.empty()) { |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 14.4 rule Note
No description provided.