-
Notifications
You must be signed in to change notification settings - Fork 3
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
Manage multi-lane Traffic Lights #211
Conversation
@@ -475,7 +475,20 @@ | |||
} | |||
if (destinationNode->isTrafficLight()) { | |||
auto& tl = dynamic_cast<TrafficLight<Delay>&>(*destinationNode); | |||
if (!tl.isGreen(streetId)) { | |||
if (tl.leftTurnRatio().has_value()) { |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 14.4 rule Note
bool const hasPriority{this->streetPriorities().contains(streetId)}; | ||
auto const pair{m_delay.value()}; | ||
if (angle > 0.) { | ||
if (hasPriority) { |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 14.4 rule Note
auto const pair{m_delay.value()}; | ||
if (angle > 0.) { | ||
if (hasPriority) { | ||
return m_counter > pair.first * (1. - m_leftTurnRatio.value().first) && |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 12.1 rule Note
auto const pair{m_delay.value()}; | ||
if (angle > 0.) { | ||
if (hasPriority) { | ||
return m_counter > pair.first * (1. - m_leftTurnRatio.value().first) && |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 15.5 rule Note
if (hasPriority) { | ||
return m_counter < pair.first * m_leftTurnRatio.value().first; | ||
} else { | ||
return m_counter > pair.first && |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 12.1 rule Note
if (hasPriority) { | ||
return m_counter < pair.first * m_leftTurnRatio.value().first; | ||
} else { | ||
return m_counter > pair.first && |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 15.5 rule Note
deltaAngle -= 2 * std::numbers::pi; | ||
} else if (deltaAngle < -std::numbers::pi) { | ||
deltaAngle += 2 * std::numbers::pi; | ||
} |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 15.7 rule Note
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #211 +/- ##
==========================================
+ Coverage 93.39% 93.93% +0.54%
==========================================
Files 21 21
Lines 3890 4040 +150
Branches 359 364 +5
==========================================
+ Hits 3633 3795 +162
+ Misses 257 245 -12
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
} | ||
} else { | ||
if (hasPriority) { | ||
return m_counter < pair.first * (1. - m_leftTurnRatio.value().first); |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 15.5 rule Note
} | ||
} else { | ||
if (hasPriority) { | ||
return m_counter < pair.first * (1. - m_leftTurnRatio.value().first); |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 12.1 rule Note
return m_counter < pair.first * (1. - m_leftTurnRatio.value().first); | ||
} else { | ||
return m_counter > pair.first && | ||
m_counter < |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 12.1 rule Note
} else { | ||
return m_counter > pair.first && | ||
m_counter < | ||
pair.first + pair.second * (1. - m_leftTurnRatio.value().second); |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 12.1 rule Note
@@ -164,6 +165,7 @@ | |||
requires(std::unsigned_integral<Delay>) | |||
class TrafficLight : public Intersection { | |||
private: | |||
std::optional<std::pair<double, double>> m_leftTurnRatio; |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 12.3 rule Note
@@ -213,10 +231,16 @@ | |||
/// @return std::optional<Delay> The node's delay | |||
std::optional<std::pair<Delay, Delay>> delay() const { return m_delay; } | |||
Delay counter() const { return m_counter; } | |||
/// @brief Get the node's left turn ratio | |||
/// @return std::optional<std::pair<double, double>> The node's left turn ratio | |||
inline std::optional<std::pair<double, double>> leftTurnRatio() const { |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 12.3 rule Note
@@ -282,6 +306,15 @@ | |||
m_phase = phase; | |||
} | |||
|
|||
template <typename Delay> | |||
requires(std::unsigned_integral<Delay>) | |||
void TrafficLight<Delay>::setLeftTurnRatio(std::pair<double, double> ratio) { |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 12.3 rule Note
requires(std::unsigned_integral<Delay>) | ||
void TrafficLight<Delay>::setLeftTurnRatio(std::pair<double, double> ratio) { | ||
assert((void("Left turn ratio components must be between 0 and 1."), | ||
ratio.first >= 0. && ratio.first <= 1. && ratio.second >= 0. && |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 12.1 rule Note
"A traffic light managing an intersection with 4 3-lanes streets and 4 1-lane " | ||
"streets") { | ||
// Streets | ||
Street s0_1{1, 1, 30., 15., std::make_pair(0, 1), 3}; |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 12.3 rule Note test
"streets") { | ||
// Streets | ||
Street s0_1{1, 1, 30., 15., std::make_pair(0, 1), 3}; | ||
Street s1_0{5, 1, 30., 15., std::make_pair(1, 0), 3}; |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 12.3 rule Note test
// Streets | ||
Street s0_1{1, 1, 30., 15., std::make_pair(0, 1), 3}; | ||
Street s1_0{5, 1, 30., 15., std::make_pair(1, 0), 3}; | ||
Street s1_2{7, 1, 30., 15., std::make_pair(1, 2), 3}; |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 12.3 rule Note test
Street s0_1{1, 1, 30., 15., std::make_pair(0, 1), 3}; | ||
Street s1_0{5, 1, 30., 15., std::make_pair(1, 0), 3}; | ||
Street s1_2{7, 1, 30., 15., std::make_pair(1, 2), 3}; | ||
Street s2_1{11, 1, 30., 15., std::make_pair(2, 1), 3}; |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 12.3 rule Note test
"A traffic light managing an intersection with 4 3-lanes streets and 4 1-lane " | ||
"streets") { | ||
// Streets | ||
Street s0_1{1, 1, 30., 15., std::make_pair(0, 1), 3}; |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 12.3 rule Note test
"streets") { | ||
// Streets | ||
Street s0_1{1, 1, 30., 15., std::make_pair(0, 1), 3}; | ||
Street s1_0{5, 1, 30., 15., std::make_pair(1, 0), 3}; |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 12.3 rule Note test
// Streets | ||
Street s0_1{1, 1, 30., 15., std::make_pair(0, 1), 3}; | ||
Street s1_0{5, 1, 30., 15., std::make_pair(1, 0), 3}; | ||
Street s1_2{7, 1, 30., 15., std::make_pair(1, 2), 3}; |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 12.3 rule Note test
Street s0_1{1, 1, 30., 15., std::make_pair(0, 1), 3}; | ||
Street s1_0{5, 1, 30., 15., std::make_pair(1, 0), 3}; | ||
Street s1_2{7, 1, 30., 15., std::make_pair(1, 2), 3}; | ||
Street s2_1{11, 1, 30., 15., std::make_pair(2, 1), 3}; |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 12.3 rule Note test
The base idea is adding a new
std::pair<double, double>
to Traffic Light class.In this way, we can have four different time intervals:
0
->delay.first * (1 - pair.first)
in which is green for right/straight turns;delay.first * (1 - pair.first)
->delay.first
in which is green for left turns;delay.first
->delay.first + delay.second * (1 - pair.second)
in which is red for right/straight turns;delay.first + delay.second * (1 - pair.second)
->delay.second
in which is red for left turns;