Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 = 2;
static constexpr uint8_t DSM_VERSION_PATCH = 3;

static auto const DSM_VERSION =
std::format("{}.{}.{}", DSM_VERSION_MAJOR, DSM_VERSION_MINOR, DSM_VERSION_PATCH);
Expand Down
2 changes: 1 addition & 1 deletion src/dsm/headers/RoadDynamics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1556,7 +1556,7 @@ namespace dsm {
continue;
}
auto& spire = dynamic_cast<SpireStreet&>(*pStreet);
file << separator << spire.code();
file << separator << streetId;
}
file << std::endl;
}
Expand Down
3 changes: 3 additions & 0 deletions src/dsm/headers/RoadNetwork.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ namespace dsm {
/// Street priorities are assigned considering the number of lanes and the speed limit.
/// Traffic Lights with an input degree lower than 3 are converted to standard intersections.
void initTrafficLights();
/// @brief Automatically re-maps street lanes basing on network's topology
/// @details For example, if one street has the right turn forbidden, then the right lane becomes a straight one
void autoMapStreetLanes();

/// @brief Import the graph's adjacency matrix from a file.
/// If the file is not of a supported format, it will read the file as a matrix with the first two elements being
Expand Down
71 changes: 71 additions & 0 deletions src/dsm/sources/RoadNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
}
}
// continue;
}

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 15.7 rule Note

MISRA 15.7 rule
// Set first two elements of capacities to street priorities
// auto it{capacities.begin()};
// tl.addStreetPriority(it->first);
Expand Down Expand Up @@ -239,6 +239,77 @@
});
}
}
void RoadNetwork::autoMapStreetLanes() {
std::for_each(m_nodes.cbegin(), m_nodes.cend(), [this](auto const& pair) {
auto const& inNeighbours{m_adjacencyMatrix.getCol(pair.first)};
auto const& outNeighbours{m_adjacencyMatrix.getRow(pair.first)};
std::for_each(

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

View check run for this annotation

Codecov / codecov/patch

src/dsm/sources/RoadNetwork.cpp#L242-L246

Added lines #L242 - L246 were not covered by tests
inNeighbours.cbegin(),
inNeighbours.cend(),
[this, &pair, &outNeighbours](auto const& inNodeId) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
auto const& pInStreet{m_edges.at(inNodeId * m_nodes.size() + pair.first)};
auto const& laneMapping{pInStreet->laneMapping()};
auto const angle{pInStreet->angle()};
std::set<Direction> allowedTurns;
std::for_each(outNeighbours.cbegin(),

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

View check run for this annotation

Codecov / codecov/patch

src/dsm/sources/RoadNetwork.cpp#L249-L254

Added lines #L249 - L254 were not covered by tests
outNeighbours.cend(),
[this, &pair, &angle, &allowedTurns](auto const& outNodeId) {
auto const& pOutStreet{
m_edges.at(pair.first * m_nodes.size() + outNodeId)};
auto const deltaAngle{pOutStreet->deltaAngle(angle)};

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

View check run for this annotation

Codecov / codecov/patch

src/dsm/sources/RoadNetwork.cpp#L256-L259

Added lines #L256 - L259 were not covered by tests
// Logger::debug(std::format("Angle in {} - angle out {}", angle, pOutStreet->angle()));
if (std::abs(deltaAngle) < 5 * std::numbers::pi / 6) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.1 rule Note

MISRA 12.1 rule
// Logger::debug(std::format("Delta: {}", deltaAngle));
if (deltaAngle < -std::numbers::pi / 6.) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.1 rule Note

MISRA 12.1 rule
allowedTurns.emplace(Direction::RIGHT);

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

View check run for this annotation

Codecov / codecov/patch

src/dsm/sources/RoadNetwork.cpp#L264

Added line #L264 was not covered by tests
} else if (deltaAngle > std::numbers::pi / 6.) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.1 rule Note

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

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

View check run for this annotation

Codecov / codecov/patch

src/dsm/sources/RoadNetwork.cpp#L266

Added line #L266 was not covered by tests
}
}
});
auto const nLanes{pInStreet->nLanes()};
std::vector<Direction> newMapping(nLanes, Direction::STRAIGHT);
switch (nLanes) {
case 1:

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

View check run for this annotation

Codecov / codecov/patch

src/dsm/sources/RoadNetwork.cpp#L270-L273

Added lines #L270 - L273 were not covered by tests
// if (!allowedTurns.contains(Direction::RIGHT) &&
// !allowedTurns.contains(Direction::LEFT)) {
// pInStreet->setLaneMapping(std::vector<Direction>{Direction::STRAIGHT});
// } else if (!allowedTurns.contains(Direction::RIGHT)) {
// pInStreet->setLaneMapping(
// std::vector<Direction>{Direction::LEFTANDSTRAIGHT});
// } else if (!allowedTurns.contains(Direction::LEFT)) {
// pInStreet->setLaneMapping(
// std::vector<Direction>{Direction::RIGHTANDSTRAIGHT});
// }
break;
case 2:

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

View check run for this annotation

Codecov / codecov/patch

src/dsm/sources/RoadNetwork.cpp#L284-L285

Added lines #L284 - L285 were not covered by tests
if (!allowedTurns.contains(Direction::RIGHT) &&
!allowedTurns.contains(Direction::LEFT)) {
pInStreet->setLaneMapping(newMapping);

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

View check run for this annotation

Codecov / codecov/patch

src/dsm/sources/RoadNetwork.cpp#L287-L288

Added lines #L287 - L288 were not covered by tests
} else if (!allowedTurns.contains(Direction::RIGHT)) {
newMapping[0] = Direction::STRAIGHT;
pInStreet->setLaneMapping(newMapping);

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

View check run for this annotation

Codecov / codecov/patch

src/dsm/sources/RoadNetwork.cpp#L290-L291

Added lines #L290 - L291 were not covered by tests
} else if (!allowedTurns.contains(Direction::LEFT)) {
newMapping = {Direction::RIGHT, Direction::STRAIGHT};
pInStreet->setLaneMapping(newMapping);

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

View check run for this annotation

Codecov / codecov/patch

src/dsm/sources/RoadNetwork.cpp#L293-L294

Added lines #L293 - L294 were not covered by tests
}
break;
default:

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

View check run for this annotation

Codecov / codecov/patch

src/dsm/sources/RoadNetwork.cpp#L296-L297

Added lines #L296 - L297 were not covered by tests
if (!allowedTurns.contains(Direction::RIGHT) &&
!allowedTurns.contains(Direction::LEFT)) {
pInStreet->setLaneMapping(newMapping);

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

View check run for this annotation

Codecov / codecov/patch

src/dsm/sources/RoadNetwork.cpp#L299-L300

Added lines #L299 - L300 were not covered by tests
} else if (!allowedTurns.contains(Direction::RIGHT)) {
newMapping[0] = Direction::STRAIGHT;
pInStreet->setLaneMapping(newMapping);

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

View check run for this annotation

Codecov / codecov/patch

src/dsm/sources/RoadNetwork.cpp#L302-L303

Added lines #L302 - L303 were not covered by tests
} else if (!allowedTurns.contains(Direction::LEFT)) {
newMapping[0] = Direction::RIGHT;
newMapping[nLanes - 1] = Direction::STRAIGHT;
pInStreet->setLaneMapping(newMapping);

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

View check run for this annotation

Codecov / codecov/patch

src/dsm/sources/RoadNetwork.cpp#L305-L307

Added lines #L305 - L307 were not covered by tests
}
}

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 16.3 rule Note

MISRA 16.3 rule
});
});
}

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

View check run for this annotation

Codecov / codecov/patch

src/dsm/sources/RoadNetwork.cpp#L310-L312

Added lines #L310 - L312 were not covered by tests

void RoadNetwork::buildAdj() {
// find max values in streets node pairs
Expand Down
7 changes: 7 additions & 0 deletions src/dsm/sources/Street.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@
void Street::setLaneMapping(std::vector<Direction> const& laneMapping) {
assert(laneMapping.size() == static_cast<size_t>(m_nLanes));
m_laneMapping = laneMapping;
std::string strLaneMapping;
std::for_each(
laneMapping.cbegin(), laneMapping.cend(), [&strLaneMapping](auto const item) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 13.1 rule Note

MISRA 13.1 rule
strLaneMapping += std::format("{} - ", static_cast<int>(item));
});
Logger::debug(
std::format("New lane mapping for street {} is: {}", m_id, strLaneMapping));
}
void Street::setQueue(dsm::queue<std::unique_ptr<Agent>> queue, size_t index) {
assert(index < m_exitQueues.size());
Expand Down
Loading