Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/dsm/dsm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

static constexpr uint8_t DSM_VERSION_MAJOR = 2;
static constexpr uint8_t DSM_VERSION_MINOR = 6;
static constexpr uint8_t DSM_VERSION_PATCH = 11;
static constexpr uint8_t DSM_VERSION_PATCH = 12;

static auto const DSM_VERSION =
std::format("{}.{}.{}", DSM_VERSION_MAJOR, DSM_VERSION_MINOR, DSM_VERSION_PATCH);
Expand Down
6 changes: 3 additions & 3 deletions src/dsm/headers/RoadDynamics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,8 @@
pair.second->deltaAngle(this->graph().edge(previousStreetId)->angle())};
if (std::abs(delta) < std::numbers::pi) {
if (delta < 0.) {
m_turnMapping[pair.first][dsm::Direction::RIGHT] = previousStreetId;
; // right
m_turnMapping[pair.first][dsm::Direction::RIGHT] =
previousStreetId; // right
} else if (delta > 0.) {
m_turnMapping[pair.first][dsm::Direction::LEFT] =
previousStreetId; // left
Expand Down Expand Up @@ -1049,7 +1049,7 @@
auto const deltaAngle{pNextStreet->deltaAngle(pStreet->angle())};
if (std::abs(deltaAngle) < std::numbers::pi) {
// Lanes are counted as 0 is the far right lane
if (std::abs(deltaAngle) < std::numbers::pi / 4) {
if (std::abs(deltaAngle) < std::numbers::pi / 8) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.1 rule Note

MISRA 12.1 rule
std::vector<double> weights;
for (auto const& queue : pStreet->exitQueues()) {
weights.push_back(1. / (queue.size() + 1));
Expand Down
119 changes: 82 additions & 37 deletions src/dsm/sources/RoadNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,8 @@
auto const& pInStreet{m_edges.at(inNodeId * m_nodes.size() + pair.first)};
auto const nLanes{pInStreet->nLanes()};
if (nLanes == 1) {
return;

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 15.5 rule Note

MISRA 15.5 rule
}
// auto const& laneMapping{pInStreet->laneMapping()};
std::multiset<Direction> allowedTurns;
std::for_each(
outNeighbours.cbegin(),
Expand All @@ -281,9 +280,11 @@
}
auto const deltaAngle{pOutStreet->deltaAngle(pInStreet->angle())};
auto const& outOppositeStreet{this->street(pair.first, outNodeId)};
if (!outOppositeStreet) {
return;

Check warning on line 284 in src/dsm/sources/RoadNetwork.cpp

View check run for this annotation

Codecov / codecov/patch

src/dsm/sources/RoadNetwork.cpp#L284

Added line #L284 was not covered by tests
}
// Actually going straight means remain on the same road, thus...
if (outOppositeStreet &&
((pInStreet->priority() == maxPriority) ==
if (((pInStreet->priority() == maxPriority) ==
(outOppositeStreet->get()->priority() == maxPriority)) &&
!allowedTurns.contains(Direction::STRAIGHT)) {
Logger::debug(
Expand All @@ -298,44 +299,30 @@
// allowedTurns.emplace(Direction::STRAIGHT);
// return;
// }
} else if (std::abs(deltaAngle) < 5 * std::numbers::pi / 6) {
} else if (std::abs(deltaAngle) < std::numbers::pi) {
// Logger::debug(std::format("Angle in {} - angle out {}",
// pInStreet->angle(),
// pOutStreet->angle()));
// Logger::debug(std::format("Delta: {}", deltaAngle));
if (deltaAngle < -std::numbers::pi / 6.) {
Logger::debug(
std::format("Street {} can turn RIGHT", pInStreet->id()));
if (std::abs(deltaAngle) < std::numbers::pi / 8) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.1 rule Note

MISRA 12.1 rule
Logger::debug(std::format("Street {} -> {} can turn STRAIGHT",

Check warning on line 308 in src/dsm/sources/RoadNetwork.cpp

View check run for this annotation

Codecov / codecov/patch

src/dsm/sources/RoadNetwork.cpp#L308

Added line #L308 was not covered by tests
pInStreet->source(),
pInStreet->target()));
allowedTurns.emplace(Direction::STRAIGHT);

Check warning on line 311 in src/dsm/sources/RoadNetwork.cpp

View check run for this annotation

Codecov / codecov/patch

src/dsm/sources/RoadNetwork.cpp#L311

Added line #L311 was not covered by tests
} else if (deltaAngle < 0.) {
Logger::debug(std::format("Street {} -> {} can turn RIGHT",

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 17.7 rule Note

MISRA 17.7 rule
pInStreet->source(),
pInStreet->target()));
allowedTurns.emplace(Direction::RIGHT);
} else if (deltaAngle > std::numbers::pi / 6.) {
Logger::debug(
std::format("Street {} can turn LEFT", pInStreet->id()));
} else if (deltaAngle > 0.) {
Logger::debug(std::format("Street {} -> {} can turn LEFT",

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 17.7 rule Note

MISRA 17.7 rule
pInStreet->source(),
pInStreet->target()));
allowedTurns.emplace(Direction::LEFT);
} else {
Logger::debug(
std::format("Street {} can go STRAIGHT", pInStreet->id()));
if (!allowedTurns.contains(Direction::STRAIGHT)) {
allowedTurns.emplace(Direction::STRAIGHT);
} else if (deltaAngle > 0.) {
allowedTurns.emplace(Direction::LEFT);
} else {
allowedTurns.emplace(Direction::RIGHT);
}
}
}
});
// if (!allowedTurns.contains(Direction::RIGHT)) {
// std::multiset<Direction> updatedTurns;
// for (auto turn : allowedTurns) {
// if (turn > Direction::RIGHT && turn <= Direction::UTURN) {
// updatedTurns.insert(static_cast<Direction>(turn - 1));
// } else {
// updatedTurns.insert(turn);
// }
// }
// allowedTurns = std::move(updatedTurns); // Replace with the updated set
// }
while (allowedTurns.size() < static_cast<size_t>(nLanes)) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 15.7 rule Note

MISRA 15.7 rule
if (allowedTurns.contains(Direction::STRAIGHT)) {
allowedTurns.emplace(Direction::STRAIGHT);
} else if (allowedTurns.contains(Direction::RIGHT)) {
Expand All @@ -347,11 +334,36 @@
}
}
// If allowedTurns contains all RIGHT, STRAIGHT and LEFT, transform RIGHT into RIGHTANDSTRAIGHT
if (allowedTurns.contains(Direction::STRAIGHT) &&
allowedTurns.contains(Direction::RIGHT) &&
allowedTurns.contains(Direction::LEFT)) {
allowedTurns.erase(Direction::RIGHT);
allowedTurns.emplace(Direction::RIGHTANDSTRAIGHT);
if (allowedTurns.size() > static_cast<size_t>(nLanes)) {
if (pair.second->isTrafficLight()) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 14.4 rule Note

MISRA 14.4 rule
auto& tl = dynamic_cast<TrafficLight&>(*pair.second);
auto const& cycles{tl.cycles()};

Check warning on line 340 in src/dsm/sources/RoadNetwork.cpp

View check run for this annotation

Codecov / codecov/patch

src/dsm/sources/RoadNetwork.cpp#L339-L340

Added lines #L339 - L340 were not covered by tests
if (cycles.contains(pInStreet->id())) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 14.4 rule Note

MISRA 14.4 rule
if (cycles.size() == static_cast<size_t>(nLanes)) {
// Replace with the traffic light cycles
Logger::debug(
std::format("Using traffic light {} cycles for street {} -> {}",
tl.id(),
pInStreet->source(),
pInStreet->target()));
auto const& cycle{cycles.at(pInStreet->id())};
allowedTurns.clear();

Check warning on line 350 in src/dsm/sources/RoadNetwork.cpp

View check run for this annotation

Codecov / codecov/patch

src/dsm/sources/RoadNetwork.cpp#L344-L350

Added lines #L344 - L350 were not covered by tests
for (auto const& [direction, cycle] : cycle) {
allowedTurns.emplace(direction);

Check warning on line 352 in src/dsm/sources/RoadNetwork.cpp

View check run for this annotation

Codecov / codecov/patch

src/dsm/sources/RoadNetwork.cpp#L352

Added line #L352 was not covered by tests
}
} else if (cycles.at(pInStreet->id())

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 14.4 rule Note

MISRA 14.4 rule
.contains(Direction::LEFTANDSTRAIGHT)) {
allowedTurns.erase(Direction::LEFT);
allowedTurns.erase(Direction::STRAIGHT);
allowedTurns.emplace(Direction::LEFTANDSTRAIGHT);

Check warning on line 358 in src/dsm/sources/RoadNetwork.cpp

View check run for this annotation

Codecov / codecov/patch

src/dsm/sources/RoadNetwork.cpp#L355-L358

Added lines #L355 - L358 were not covered by tests

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 17.7 rule Note

MISRA 17.7 rule
} else if (cycles.at(pInStreet->id())

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 14.4 rule Note

MISRA 14.4 rule
.contains(Direction::RIGHTANDSTRAIGHT)) {
allowedTurns.erase(Direction::RIGHT);
allowedTurns.erase(Direction::STRAIGHT);
allowedTurns.emplace(Direction::RIGHTANDSTRAIGHT);

Check warning on line 363 in src/dsm/sources/RoadNetwork.cpp

View check run for this annotation

Codecov / codecov/patch

src/dsm/sources/RoadNetwork.cpp#L360-L363

Added lines #L360 - L363 were not covered by tests
}

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 15.7 rule Note

MISRA 15.7 rule
}
}
}
switch (nLanes) {
case 1:
Expand All @@ -361,11 +373,44 @@
if (allowedTurns.contains(Direction::STRAIGHT) &&
allowedTurns.contains(Direction::RIGHT) &&
allowedTurns.contains(Direction::LEFT)) {
break;
if (pair.second->isTrafficLight()) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 14.4 rule Note

MISRA 14.4 rule
auto& tl = dynamic_cast<TrafficLight&>(*pair.second);
auto const& cycles{tl.cycles()};

Check warning on line 378 in src/dsm/sources/RoadNetwork.cpp

View check run for this annotation

Codecov / codecov/patch

src/dsm/sources/RoadNetwork.cpp#L377-L378

Added lines #L377 - L378 were not covered by tests

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 17.7 rule Note

MISRA 17.7 rule
if (cycles.contains(pInStreet->id())) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 14.4 rule Note

MISRA 14.4 rule
auto const& cycle{cycles.at(pInStreet->id())};

Check warning on line 380 in src/dsm/sources/RoadNetwork.cpp

View check run for this annotation

Codecov / codecov/patch

src/dsm/sources/RoadNetwork.cpp#L380

Added line #L380 was not covered by tests
if (cycle.contains(Direction::LEFTANDSTRAIGHT) &&
cycle.contains(Direction::RIGHT)) {
allowedTurns.erase(Direction::LEFT);
allowedTurns.erase(Direction::STRAIGHT);
allowedTurns.emplace(Direction::LEFTANDSTRAIGHT);

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 17.7 rule Note

MISRA 17.7 rule
break;

Check warning on line 386 in src/dsm/sources/RoadNetwork.cpp

View check run for this annotation

Codecov / codecov/patch

src/dsm/sources/RoadNetwork.cpp#L382-L386

Added lines #L382 - L386 were not covered by tests
}
}
}
allowedTurns.clear();
allowedTurns.emplace(Direction::RIGHTANDSTRAIGHT);

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 17.7 rule Note

MISRA 17.7 rule
allowedTurns.emplace(Direction::LEFT);

Check warning on line 392 in src/dsm/sources/RoadNetwork.cpp

View check run for this annotation

Codecov / codecov/patch

src/dsm/sources/RoadNetwork.cpp#L390-L392

Added lines #L390 - L392 were not covered by tests
}
if (allowedTurns.size() > 2) {
// Remove duplicates
std::set<Direction> uniqueDirections;
std::copy(allowedTurns.begin(),

Check warning on line 397 in src/dsm/sources/RoadNetwork.cpp

View check run for this annotation

Codecov / codecov/patch

src/dsm/sources/RoadNetwork.cpp#L396-L397

Added lines #L396 - L397 were not covered by tests
allowedTurns.end(),
std::inserter(uniqueDirections, uniqueDirections.begin()));
allowedTurns.clear();
std::copy(uniqueDirections.begin(),

Check warning on line 401 in src/dsm/sources/RoadNetwork.cpp

View check run for this annotation

Codecov / codecov/patch

src/dsm/sources/RoadNetwork.cpp#L400-L401

Added lines #L400 - L401 were not covered by tests
uniqueDirections.end(),
std::inserter(allowedTurns, allowedTurns.begin()));
}
[[fallthrough]];
default:
assert(allowedTurns.size() == static_cast<size_t>(nLanes));
// Logger::info(
// std::format("Street {}->{} with {} lanes and {} allowed turns",

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 15.5 rule Note

MISRA 15.5 rule
// pInStreet->source(),
// pInStreet->target(),
// nLanes,
// allowedTurns.size()));
std::vector<Direction> newMapping(nLanes);
auto it{allowedTurns.cbegin()};
for (size_t i{0}; i < allowedTurns.size(); ++i, ++it) {
Expand Down
Loading