Skip to content

Commit d7a7c40

Browse files
committed
Add an indicator for traffic light modification
1 parent 335af08 commit d7a7c40

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

src/dsm/dsm.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
static constexpr uint8_t DSM_VERSION_MAJOR = 2;
88
static constexpr uint8_t DSM_VERSION_MINOR = 2;
9-
static constexpr uint8_t DSM_VERSION_PATCH = 11;
9+
static constexpr uint8_t DSM_VERSION_PATCH = 12;
1010

1111
static auto const DSM_VERSION =
1212
std::format("{}.{}.{}", DSM_VERSION_MAJOR, DSM_VERSION_MINOR, DSM_VERSION_PATCH);

src/dsm/headers/TrafficLight.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,20 @@ namespace dsm {
198198
return m_cycles.at(streetId)[direction].isGreen(m_cycleTime, m_counter);
199199
}
200200

201+
bool TrafficLight::isFavouringDirection(bool const priority) const {
202+
for (auto const& [streetId, cycles] : m_cycles) {
203+
if ((priority && m_streetPriorities.contains(streetId) ||
204+
(!priority && !m_streetPriorities.contains(streetId)))) {
205+
for (auto const& cycle : cycles) {
206+
if (!cycle.isGreenTimeIncreased()) {
207+
return false;
208+
}
209+
}
210+
}
211+
}
212+
return true;
213+
}
214+
201215
void TrafficLight::resetCycles() {
202216
for (auto& [streetId, cycles] : m_cycles) {
203217
for (auto& cycle : cycles) {

src/dsm/headers/TrafficLight.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ namespace dsm {
3333
inline bool isDefault() const {
3434
return m_greenTime == m_defaultValues.first && m_phase == m_defaultValues.second;
3535
}
36+
/// @brief Returns true if the current green time is greater than the default one
37+
inline bool isGreenTimeIncreased() const {
38+
return m_greenTime > m_defaultValues.first;
39+
}
40+
/// @brief Returns true if the current green time is smaller than the default one
41+
inline bool isRedTimeIncreased() const { return m_greenTime < m_defaultValues.first; }
3642
/// @brief Returns true if the traffic light is green
3743
/// @param cycleTime Delay, the total time of a red-green cycle
3844
/// @param counter Delay, the current counter
@@ -131,6 +137,10 @@ namespace dsm {
131137
/// @param direction Direction, the direction
132138
/// @return true if the traffic light is green for the street and direction
133139
bool isGreen(Id const streetId, Direction direction) const;
140+
/// @brief Returns true if the traffic light has green increased for all the cycles with priority
141+
/// @param priority bool, if true, only the priority streets are considered; else, only the non-priority streets are considered
142+
/// @return true if the traffic light has green increased for all the cycles with priority
143+
bool isFavouringDirection(bool const priority) const;
134144
/// @brief Resets all traffic light cycles
135145
/// @details For more info, see @ref TrafficLightCycle::reset()
136146
void resetCycles();

0 commit comments

Comments
 (0)