Skip to content

Commit 427a1b0

Browse files
committed
Add minGreenTime function to TrafficLight
1 parent 770c363 commit 427a1b0

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/dsm/headers/TrafficLight.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,22 @@ namespace dsm {
9898
return maxTime;
9999
}
100100

101+
Delay TrafficLight::minGreenTime(bool priorityStreets) const {
102+
Delay minTime{std::numeric_limits<Delay>::max()};
103+
for (auto const& [streetId, cycles] : m_cycles) {
104+
if (priorityStreets && m_streetPriorities.contains(streetId)) {
105+
for (auto const& cycle : cycles) {
106+
minTime = std::min(minTime, cycle.greenTime());
107+
}
108+
} else {
109+
for (auto const& cycle : cycles) {
110+
minTime = std::min(minTime, cycle.greenTime());
111+
}
112+
}
113+
}
114+
return minTime;
115+
}
116+
101117
void TrafficLight::increaseGreenTimes(Delay const delta) {
102118
for (auto& [streetId, cycles] : m_cycles) {
103119
if (m_streetPriorities.contains(streetId)) {

src/dsm/headers/TrafficLight.hpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,21 @@ namespace dsm {
5959
: Intersection{node}, m_cycleTime{cycleTime}, m_counter{counter} {}
6060

6161
TrafficLight& operator++();
62-
62+
/// @brief Get the maximum green time of every cycle
63+
/// @param priorityStreets bool, if true, only the priority streets are considered;
64+
/// if false, only the non-priority streets are considered
65+
/// @return Delay The maximum green time
66+
/// @details The maximum green time is the maximum green time of all the cycles for
67+
/// the priority streets if priorityStreets is true, or for the non-priority
68+
/// streets if priorityStreets is false.
6369
Delay maxGreenTime(bool priorityStreets) const;
70+
/// @brief Get the minimum green time of every cycle
71+
/// @param priorityStreets bool, if true, only the priority streets are considered;
72+
/// if false, only the non-priority streets are considered
73+
/// @return Delay The minimum green time
74+
/// @details The minimum green time is the minimum green time of all the cycles for
75+
/// the priority streets if priorityStreets is true, or for the non-priority
76+
Delay minGreenTime(bool priorityStreets) const;
6477
/// @brief Get the traffic light's total cycle time
6578
/// @return Delay The traffic light's cycle time
6679
inline Delay cycleTime() const { return m_cycleTime; }

0 commit comments

Comments
 (0)