-
Notifications
You must be signed in to change notification settings - Fork 4
Add RoadNetwork::shortestPath function
#365
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 |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| #include "PathCollection.hpp" | ||
|
|
||
| std::list<std::vector<dsf::Id>> dsf::mobility::PathCollection::explode( | ||
| Id const sourceId, Id const targetId) const { | ||
| std::list<std::vector<Id>> paths; | ||
|
|
||
| // Base case: if source equals target, return a path with just the source | ||
| if (sourceId == targetId) { | ||
| paths.push_back({sourceId}); | ||
| return paths; | ||
Check noticeCode scanning / Cppcheck (reported by Codacy) MISRA 15.5 rule Note
MISRA 15.5 rule
|
||
| } | ||
|
|
||
| // Check if sourceId exists in the map | ||
| auto it = this->find(sourceId); | ||
| if (it == this->end()) { | ||
| return paths; // No paths available from this source | ||
Check noticeCode scanning / Cppcheck (reported by Codacy) MISRA 15.5 rule Note
MISRA 15.5 rule
|
||
| } | ||
|
|
||
| auto const& nextHops = it->second; | ||
|
|
||
| // For each possible next hop from sourceId | ||
| for (auto const& hop : nextHops) { | ||
| if (hop == targetId) { | ||
| // Direct path found | ||
| paths.push_back({sourceId, targetId}); | ||
| } else { | ||
| // Recursively find paths from hop to target | ||
| auto subPaths = explode(hop, targetId); | ||
Check noticeCode scanning / Cppcheck (reported by Codacy) MISRA 17.2 rule Note
MISRA 17.2 rule
|
||
|
|
||
| // Prepend sourceId to each sub-path | ||
| for (auto& subPath : subPaths) { | ||
| subPath.insert(subPath.begin(), sourceId); | ||
| paths.push_back(std::move(subPath)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return paths; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #pragma once | ||
|
|
||
| #include "../utility/Typedef.hpp" | ||
|
|
||
| #include <list> | ||
| #include <unordered_map> | ||
| #include <vector> | ||
|
|
||
| namespace dsf::mobility { | ||
| class PathCollection : public std::unordered_map<Id, std::vector<Id>> { | ||
Check noticeCode scanning / Cppcheck (reported by Codacy) MISRA 12.3 rule Note
MISRA 12.3 rule
|
||
| public: | ||
| using std::unordered_map<Id, std::vector<Id>>::unordered_map; // Inherit constructors | ||
|
|
||
| /// @brief Explode all possible paths from sourceId to targetId | ||
| /// @param sourceId The starting point of the paths | ||
| /// @param targetId The end point of the paths | ||
| /// @return A list of vectors, each vector representing a path from sourceId to targetId | ||
| std::list<std::vector<Id>> explode(Id const sourceId, Id const targetId) const; | ||
| }; | ||
| } // namespace dsf::mobility | ||
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.
Parameter name mismatch in documentation. The documentation refers to
@param pathCollectionbut the actual parameter name ispath. The documentation should be updated to@param pathto match the function signature.