-
Notifications
You must be signed in to change notification settings - Fork 4
Add throw_on_empty param to updatePaths
#374
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -191,7 +191,10 @@ | |||||||||||||||||||||||||
| void resetTurnCounts(); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| /// @brief Update the paths of the itineraries based on the given weight function | ||||||||||||||||||||||||||
| void updatePaths(); | ||||||||||||||||||||||||||
| /// @param throw_on_empty If true, throws an exception if an itinerary has an empty path (default is true) | ||||||||||||||||||||||||||
| /// If false, removes the itinerary with empty paths and the associated node from the origin/destination nodes | ||||||||||||||||||||||||||
| /// @throws std::runtime_error if throw_on_empty is true and an itinerary has an empty path | ||||||||||||||||||||||||||
| void updatePaths(bool const throw_on_empty = true); | ||||||||||||||||||||||||||
Check noticeCode scanning / Cppcheck (reported by Codacy) MISRA 17.8 rule Note
MISRA 17.8 rule
Check noticeCode scanning / Cppcheck (reported by Codacy) MISRA 13.4 rule Note
MISRA 13.4 rule
|
||||||||||||||||||||||||||
| /// @brief Add agents uniformly on the road network | ||||||||||||||||||||||||||
| /// @param nAgents The number of agents to add | ||||||||||||||||||||||||||
| /// @param itineraryId The id of the itinerary to use (default is std::nullopt) | ||||||||||||||||||||||||||
|
|
@@ -413,7 +416,6 @@ | |||||||||||||||||||||||||
| for (auto const& [nodeId, weight] : this->m_destinationNodes) { | ||||||||||||||||||||||||||
| m_itineraries.emplace(nodeId, std::make_unique<Itinerary>(nodeId, nodeId)); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| // updatePaths(); | ||||||||||||||||||||||||||
| std::for_each( | ||||||||||||||||||||||||||
| this->graph().edges().cbegin(), | ||||||||||||||||||||||||||
| this->graph().edges().cend(), | ||||||||||||||||||||||||||
|
|
@@ -470,12 +472,6 @@ | |||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| auto const& path{this->graph().allPathsTo( | ||||||||||||||||||||||||||
| pItinerary->destination(), m_weightFunction, m_weightTreshold)}; | ||||||||||||||||||||||||||
| if (path.empty()) { | ||||||||||||||||||||||||||
| throw std::runtime_error( | ||||||||||||||||||||||||||
| std::format("No path found for itinerary {} with destination node {}", | ||||||||||||||||||||||||||
| pItinerary->id(), | ||||||||||||||||||||||||||
| pItinerary->destination())); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| pItinerary->setPath(path); | ||||||||||||||||||||||||||
| auto const newSize{pItinerary->path().size()}; | ||||||||||||||||||||||||||
| if (oldSize > 0 && newSize != oldSize) { | ||||||||||||||||||||||||||
|
|
@@ -972,7 +968,7 @@ | |||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| ++it; | ||||||||||||||||||||||||||
| continue; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
Check noticeCode scanning / Cppcheck (reported by Codacy) MISRA 15.5 rule Note
MISRA 15.5 rule
|
||||||||||||||||||||||||||
| if (!m_turnCounts.empty() && pAgent->streetId().has_value()) { | ||||||||||||||||||||||||||
| ++m_turnCounts[*(pAgent->streetId())][nextStreet->id()]; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
@@ -1250,12 +1246,39 @@ | |||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| template <typename delay_t> | ||||||||||||||||||||||||||
| requires(is_numeric_v<delay_t>) | ||||||||||||||||||||||||||
| void RoadDynamics<delay_t>::updatePaths() { | ||||||||||||||||||||||||||
| void RoadDynamics<delay_t>::updatePaths(bool const throw_on_empty) { | ||||||||||||||||||||||||||
| spdlog::debug("Init updating paths..."); | ||||||||||||||||||||||||||
| tbb::concurrent_vector<Id> emptyItineraries; | ||||||||||||||||||||||||||
| tbb::parallel_for_each( | ||||||||||||||||||||||||||
| this->itineraries().cbegin(), | ||||||||||||||||||||||||||
| this->itineraries().cend(), | ||||||||||||||||||||||||||
| [this](auto const& pair) -> void { this->m_updatePath(pair.second); }); | ||||||||||||||||||||||||||
| [this, throw_on_empty, &emptyItineraries](auto const& pair) -> void { | ||||||||||||||||||||||||||
| auto const& pItinerary{pair.second}; | ||||||||||||||||||||||||||
| this->m_updatePath(pItinerary); | ||||||||||||||||||||||||||
| if (pItinerary->empty()) { | ||||||||||||||||||||||||||
Check noticeCode scanning / Cppcheck (reported by Codacy) MISRA 14.4 rule Note
MISRA 14.4 rule
|
||||||||||||||||||||||||||
| if (!throw_on_empty) { | ||||||||||||||||||||||||||
| spdlog::warn("No path found for itinerary {} with destination node {}", | ||||||||||||||||||||||||||
| pItinerary->id(), | ||||||||||||||||||||||||||
| pItinerary->destination()); | ||||||||||||||||||||||||||
| emptyItineraries.push_back(pItinerary->id()); | ||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| throw std::runtime_error( | ||||||||||||||||||||||||||
| std::format("No path found for itinerary {} with destination node {}", | ||||||||||||||||||||||||||
| pItinerary->id(), | ||||||||||||||||||||||||||
| pItinerary->destination())); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||
| if (!emptyItineraries.empty()) { | ||||||||||||||||||||||||||
| spdlog::warn("Removing {} itineraries with no valid path from the dynamics.", | ||||||||||||||||||||||||||
| emptyItineraries.size()); | ||||||||||||||||||||||||||
| for (auto const& id : emptyItineraries) { | ||||||||||||||||||||||||||
| auto const destination = m_itineraries.at(id)->destination(); | ||||||||||||||||||||||||||
| m_destinationNodes.erase(destination); | ||||||||||||||||||||||||||
| m_originNodes.erase(destination); | ||||||||||||||||||||||||||
|
Comment on lines
+1277
to
+1278
|
||||||||||||||||||||||||||
| m_destinationNodes.erase(destination); | |
| m_originNodes.erase(destination); | |
| // Only erase destination/origin nodes if no other itinerary uses this destination | |
| bool destinationStillUsed = std::any_of( | |
| m_itineraries.begin(), m_itineraries.end(), | |
| [id, destination](const auto& pair) { | |
| return pair.first != id && pair.second->destination() == destination; | |
| }); | |
| if (!destinationStillUsed) { | |
| m_destinationNodes.erase(destination); | |
| m_originNodes.erase(destination); | |
| } |
Uh oh!
There was an error while loading. Please reload this page.