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

static auto const DSM_VERSION =
std::format("{}.{}.{}", DSM_VERSION_MAJOR, DSM_VERSION_MINOR, DSM_VERSION_PATCH);
Expand Down
73 changes: 44 additions & 29 deletions src/dsm/headers/Dynamics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,27 +98,45 @@
return;
}
}
Size const dimension = m_graph.adjMatrix().getRowDim();

auto const dimension = static_cast<Size>(m_graph.nNodes());
auto const destinationID = pItinerary->destination();
std::vector<double> shortestDistances(m_graph.nNodes());
std::for_each(
m_graph.nodeSet().begin(),
m_graph.nodeSet().end(),
[this, &shortestDistances, &destinationID](auto const& it) -> void {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
auto const nodeId{it.first};
if (nodeId == destinationID) {
shortestDistances[nodeId] = -1.;
} else {
auto result = m_graph.shortestPath(nodeId, destinationID);
if (result.has_value()) {
shortestDistances[nodeId] = result.value().distance();
} else {
Logger::warning(std::format(
"No path found from node {} to node {}", nodeId, destinationID));
shortestDistances[nodeId] = -1.;
}
}
});
SparseMatrix<bool> path{dimension, dimension};
// cycle over the nodes
for (const auto& [nodeId, node] : m_graph.nodeSet()) {
if (nodeId == destinationID) {
continue;
}
auto result{m_graph.shortestPath(nodeId, destinationID)};
if (!result.has_value()) {
// save the minimum distance between i and the destination

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 14.4 rule Note

MISRA 14.4 rule
const auto minDistance{shortestDistances[nodeId]};
if (minDistance < 0.) {
continue;
}
// save the minimum distance between i and the destination
const auto minDistance{result.value().distance()};
auto const& row{m_graph.adjMatrix().getRow(nodeId)};
for (const auto [nextNodeId, _] : row) {
bool const bIsMinDistance{
std::abs(m_graph.street(nodeId * dimension + nextNodeId)->length() -
minDistance) < 1.}; // 1 meter tolerance between shortest paths
if (nextNodeId == destinationID) {
if (bIsMinDistance) {
if (std::abs(m_graph.street(nodeId * dimension + nextNodeId)->length() -

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.1 rule Note

MISRA 12.1 rule

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.1 rule Note

MISRA 12.1 rule
minDistance) < 1.) // 1 meter tolerance between shortest paths
{
path.insert(nodeId, nextNodeId, true);
} else {
Logger::debug(
Expand All @@ -130,26 +148,23 @@
}
continue;
}
result = m_graph.shortestPath(nextNodeId, destinationID);

if (result.has_value()) {
bool const bIsMinDistance{
std::abs(m_graph.street(nodeId * dimension + nextNodeId)->length() +
result.value().distance() - minDistance) <
1.}; // 1 meter tolerance between shortest paths
if (bIsMinDistance) {
path.insert(nodeId, nextNodeId, true);
} else {
Logger::debug(
std::format("Found a path from {} to {} which differs for more than {} "
"meter(s) from the shortest one.",
nodeId,
destinationID,
1.));
}
} else if ((nextNodeId != destinationID)) {
Logger::warning(std::format(
"No path found from node {} to node {}", nextNodeId, destinationID));
auto const distance{shortestDistances[nextNodeId]};

Check warning

Code scanning / Cppcheck (reported by Codacy)

Local variable 'distance' shadows outer function Warning

Local variable 'distance' shadows outer function
if (distance < 0.) {
continue;
}
bool const bIsMinDistance{
std::abs(m_graph.street(nodeId * dimension + nextNodeId)->length() +
distance - minDistance) <
1.}; // 1 meter tolerance between shortest paths
if (bIsMinDistance) {
path.insert(nodeId, nextNodeId, true);
} else {
Logger::debug(
std::format("Found a path from {} to {} which differs for more than {} "
"meter(s) from the shortest one.",
nodeId,
destinationID,
1.));
}
}
}
Expand Down
Loading