From c5369caa458fb048db4f362d47259db68a6b5b11 Mon Sep 17 00:00:00 2001 From: Nicolas Chappe <74881848+nchappe@users.noreply.github.com> Date: Sat, 13 Nov 2021 20:49:35 +0100 Subject: [PATCH] Fix: [Linkgraph] possible rounding errors for travel times of low-capacity links --- src/linkgraph/linkgraph.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/linkgraph/linkgraph.cpp b/src/linkgraph/linkgraph.cpp index 2efbe19d15..7478118650 100644 --- a/src/linkgraph/linkgraph.cpp +++ b/src/linkgraph/linkgraph.cpp @@ -72,12 +72,15 @@ void LinkGraph::Compress() for (NodeID node2 = 0; node2 < this->Size(); ++node2) { BaseEdge &edge = this->edges[node1][node2]; if (edge.capacity > 0) { - edge.capacity = std::max(1U, edge.capacity / 2); + uint new_capacity = std::max(1U, edge.capacity / 2); + if (edge.capacity < (1 << 16)) { + edge.travel_time_sum = edge.travel_time_sum * new_capacity / edge.capacity; + } else if (edge.travel_time_sum != 0) { + edge.travel_time_sum = std::max(1ULL, edge.travel_time_sum / 2); + } + edge.capacity = new_capacity; edge.usage /= 2; } - if (edge.travel_time_sum > 0) { - edge.travel_time_sum = std::max(1ULL, edge.travel_time_sum / 2); - } } } }