From 4ab3e4782f80a32a1d676987cf445f91aac4fb68 Mon Sep 17 00:00:00 2001 From: Romain BERNARD <romain.bernard@uca.fr> Date: Thu, 19 Sep 2024 17:13:40 +0200 Subject: [PATCH] limit risks of overflow --- .../ShortestPath/Vehicle/VehicleShortestPathCalculation.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/algorithm/ShortestPath/Vehicle/VehicleShortestPathCalculation.cpp b/src/algorithm/ShortestPath/Vehicle/VehicleShortestPathCalculation.cpp index d7507cb..159d27c 100644 --- a/src/algorithm/ShortestPath/Vehicle/VehicleShortestPathCalculation.cpp +++ b/src/algorithm/ShortestPath/Vehicle/VehicleShortestPathCalculation.cpp @@ -10,7 +10,7 @@ std::vector<uint> VehicleShortestPathCalculation::computeShortestPathsFromNode(Graph &graph, size_t startingNodeIdx, bool useEdges) { std::vector<uint> results; - results.resize(graph.getNbNodes(), UINT32_MAX); + results.resize(graph.getNbNodes(), INT16_MAX); if(!useEdges) { results = graph.getShortestSaevPaths()[startingNodeIdx]; @@ -92,7 +92,7 @@ VehicleShortestPathCalculation::getClosestPTNodesFromX(const Graph &graph, size_ void VehicleShortestPathCalculation::expandStatesViaMatrix(const VehiclePathState& currentState, std::vector<uint> &results, std::priority_queue<VehiclePathState, std::vector<VehiclePathState>, std::greater<>> &stateQueue, const Graph& graph) { - uint newDistance = INT32_MAX; + uint newDistance = INT16_MAX; for(size_t i = 0; i < results.capacity(); ++i) { newDistance = currentState.getInstant() + graph.getShortestSAEVPath(currentState.getNodeIndex(), i); if(newDistance < results[i]) { @@ -105,7 +105,7 @@ void VehicleShortestPathCalculation::expandStatesViaMatrix(const VehiclePathStat void VehicleShortestPathCalculation::expandStatesViaEdges(const VehiclePathState ¤tState, std::vector<uint> &results, std::priority_queue<VehiclePathState, std::vector<VehiclePathState>, std::greater<>> &stateQueue, const Graph& graph) { - uint newDistance = INT32_MAX; + uint newDistance = INT16_MAX; for(const auto& edgeIndex : graph.getNode(currentState.getNodeIndex()).getOutgoingEdges()) { const Edge& edge = graph.getEdge(edgeIndex); newDistance = currentState.getInstant() + edge.getLength(); -- GitLab