Skip to content
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

Merged
merged 6 commits into from
Nov 13, 2024
Merged

Conversation

Grufoony
Copy link
Collaborator

@Grufoony Grufoony commented Nov 12, 2024

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;

@@ -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

MISRA 14.4 rule
src/dsm/headers/Node.cpp Fixed Show fixed Hide fixed
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

MISRA 14.4 rule
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

MISRA 12.1 rule
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

MISRA 15.5 rule
src/dsm/headers/Node.hpp Fixed Show fixed Hide fixed
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

MISRA 12.1 rule
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

MISRA 15.5 rule
src/dsm/headers/Node.hpp Fixed Show fixed Hide fixed
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

MISRA 15.7 rule
Copy link

codecov bot commented Nov 12, 2024

Codecov Report

Attention: Patch coverage is 96.17834% with 6 lines in your changes missing coverage. Please review.

Project coverage is 93.93%. Comparing base (1264b84) to head (40bf3cd).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/dsm/headers/Node.hpp 80.00% 5 Missing ⚠️
src/dsm/headers/Dynamics.hpp 92.30% 1 Missing ⚠️
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     
Flag Coverage Δ
unittests 93.93% <96.17%> (+0.54%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

}
} 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

MISRA 15.5 rule
}
} 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

MISRA 12.1 rule
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

MISRA 12.1 rule
} 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

MISRA 12.1 rule
@@ -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

MISRA 12.3 rule
@@ -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

MISRA 12.3 rule
@@ -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

MISRA 12.3 rule
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

MISRA 12.1 rule
"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

MISRA 12.3 rule
"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

MISRA 12.3 rule
// 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

MISRA 12.3 rule
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

MISRA 12.3 rule
"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

MISRA 12.3 rule
"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

MISRA 12.3 rule
// 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

MISRA 12.3 rule
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

MISRA 12.3 rule
@Grufoony Grufoony marked this pull request as ready for review November 13, 2024 08:41
@Grufoony Grufoony requested a review from sbaldu November 13, 2024 08:41
@sbaldu sbaldu merged commit fc68ee9 into main Nov 13, 2024
26 checks passed
@Grufoony Grufoony deleted the feature_multi-lane-TrafficLights branch November 13, 2024 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants