Skip to content

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;

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

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.

3 participants