-
Notifications
You must be signed in to change notification settings - Fork 4
Refactor TrafficLights non-local optimization + add utility functions #301
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 7 commits
cc74e75
8a613d8
42ffb39
d91a895
f451730
7686e0c
6d1567e
595c048
0172dae
ede5e73
f918b9c
79c83a4
eba32ba
ebccd4c
ac08dee
14b5ee9
0180818
93bd95d
5992b91
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 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -134,6 +134,8 @@ namespace dsm { | |||||||||
| /// @brief Decrease the green times of the traffic light for priority streets and increase the green times for non-priority streets | ||||||||||
| /// @param delta Delay, the time to increase or decrease the green times | ||||||||||
| void decreaseGreenTimes(Delay const delta); | ||||||||||
|
|
||||||||||
|
||||||||||
| /// @brief Increase the phase times of the traffic light cycles | |
| /// @param phase Delay, the amount of time to increase the phase for each cycle |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -151,7 +151,7 @@ | |||||||||||||||||||||||||
| higherNLanes = std::max(higherNLanes, nLan); | ||||||||||||||||||||||||||
| lowerNLanes = std::min(lowerNLanes, nLan); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| if (tl.streetPriorities().empty()) { | ||||||||||||||||||||||||||
Check noticeCode scanning / Cppcheck (reported by Codacy) MISRA 14.4 rule Note
MISRA 14.4 rule
|
||||||||||||||||||||||||||
| /************************************************************* | ||||||||||||||||||||||||||
| * 1. Check for street names with multiple occurrences | ||||||||||||||||||||||||||
| * ***********************************************************/ | ||||||||||||||||||||||||||
|
|
@@ -197,8 +197,30 @@ | |||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| if (tl.streetPriorities().empty()) { | ||||||||||||||||||||||||||
| Logger::warning(std::format("Failed to auto-init Traffic Light {}", id)); | ||||||||||||||||||||||||||
| continue; | ||||||||||||||||||||||||||
| /************************************************************* | ||||||||||||||||||||||||||
| * 3. Check for streets with opposite angles | ||||||||||||||||||||||||||
| * ***********************************************************/ | ||||||||||||||||||||||||||
| auto const& streetId = streetAngles.begin()->first; | ||||||||||||||||||||||||||
| auto const& angle = streetAngles.begin()->second; | ||||||||||||||||||||||||||
| for (auto const& [streetId2, angle2] : streetAngles) { | ||||||||||||||||||||||||||
Check noticeCode scanning / Cppcheck (reported by Codacy) MISRA 12.3 rule Note
MISRA 12.3 rule
|
||||||||||||||||||||||||||
| if (std::abs(angle - angle2) > 0.75 * std::numbers::pi) { | ||||||||||||||||||||||||||
Check noticeCode scanning / Cppcheck (reported by Codacy) MISRA 12.1 rule Note
MISRA 12.1 rule
|
||||||||||||||||||||||||||
| tl.addStreetPriority(streetId); | ||||||||||||||||||||||||||
| tl.addStreetPriority(streetId2); | ||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| if (tl.streetPriorities().empty()) { | ||||||||||||||||||||||||||
| Logger::warning( | ||||||||||||||||||||||||||
| std::format("Failed to auto-init Traffic Light {} - going random", id)); | ||||||||||||||||||||||||||
| // Assign first and third keys of capacity map | ||||||||||||||||||||||||||
| auto it = capacities.begin(); | ||||||||||||||||||||||||||
| auto const& firstKey = it->first; | ||||||||||||||||||||||||||
| ++it; | ||||||||||||||||||||||||||
| ++it; | ||||||||||||||||||||||||||
| auto const& thirdKey = it->first; | ||||||||||||||||||||||||||
| tl.addStreetPriority(firstKey); | ||||||||||||||||||||||||||
| tl.addStreetPriority(thirdKey); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // Assign cycles | ||||||||||||||||||||||||||
|
|
@@ -521,7 +543,7 @@ | |||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| auto const& pNode{m_nodes.at(nodeId)}; | ||||||||||||||||||||||||||
| pNode->setCapacity(value); | ||||||||||||||||||||||||||
| value = 0.; | ||||||||||||||||||||||||||
Check noticeCode scanning / Cppcheck (reported by Codacy) MISRA 18.4 rule Note
MISRA 18.4 rule
|
||||||||||||||||||||||||||
| for (const auto& targetId : m_adjacencyMatrix.getRow(nodeId)) { | ||||||||||||||||||||||||||
| auto const streetId{nodeId * N + targetId}; | ||||||||||||||||||||||||||
| auto const& pStreet{m_edges.at(streetId)}; | ||||||||||||||||||||||||||
|
|
@@ -926,6 +948,52 @@ | |||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| Logger::info(std::format("Successfully imported {} edges", nEdges())); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| void RoadNetwork::importTrafficLights(const std::string& fileName) { | ||||||||||||||||||||||||||
| std::ifstream file{fileName}; | ||||||||||||||||||||||||||
| if (!file.is_open()) { | ||||||||||||||||||||||||||
| throw std::invalid_argument( | ||||||||||||||||||||||||||
| Logger::buildExceptionMessage("Cannot find file: " + fileName)); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| std::string line; | ||||||||||||||||||||||||||
| std::getline(file, line); // skip first line | ||||||||||||||||||||||||||
| while (!file.eof()) { | ||||||||||||||||||||||||||
| std::getline(file, line); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
| while (!file.eof()) { | |
| std::getline(file, line); | |
| while (std::getline(file, line)) { |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 12.3 rule Note
Outdated
Copilot
AI
May 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.
storedGreenTimes is reinitialized on every loop iteration, preventing multi-line grouping; move its declaration outside the while to accumulate across all lines.
| while (!file.eof()) { | |
| std::getline(file, line); | |
| if (line.empty()) { | |
| continue; | |
| } | |
| std::unordered_map<Id, Delay> storedGreenTimes; | |
| std::unordered_map<Id, Delay> storedGreenTimes; | |
| while (!file.eof()) { | |
| std::getline(file, line); | |
| if (line.empty()) { | |
| continue; | |
| } |
Check warning on line 966 in src/dsm/sources/RoadNetwork.cpp
Codecov / codecov/patch
src/dsm/sources/RoadNetwork.cpp#L964-L966
Added lines #L964 - L966 were not covered by tests
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 12.3 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.
Add a Doxygen comment describing
importTrafficLights, its expected file format, and behavior on parsing errors.