From 45f64e672f87417ab3b611d134548c45dcd59d1b Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Tue, 21 May 2024 20:41:25 +0200 Subject: [PATCH] Draft: re-use forward heap in map matching --- .../routing_algorithms/routing_base_mld.hpp | 32 ++++++++++--------- .../routing_algorithms/map_matching.cpp | 4 +++ 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/include/engine/routing_algorithms/routing_base_mld.hpp b/include/engine/routing_algorithms/routing_base_mld.hpp index d4e3e9f21..e1ede1ef0 100644 --- a/include/engine/routing_algorithms/routing_base_mld.hpp +++ b/include/engine/routing_algorithms/routing_base_mld.hpp @@ -701,25 +701,27 @@ double getNetworkDistance(SearchEngineData &engine_working_data, const PhantomNode &target_phantom, EdgeWeight weight_upper_bound = INVALID_EDGE_WEIGHT) { - forward_heap.Clear(); reverse_heap.Clear(); - if (source_phantom.IsValidForwardSource()) + if (forward_heap.Empty()) { - forward_heap.Insert(source_phantom.forward_segment_id.id, - EdgeWeight{0} - source_phantom.GetForwardWeightPlusOffset(), - {source_phantom.forward_segment_id.id, - false, - EdgeDistance{0} - source_phantom.GetForwardDistance()}); - } + if (source_phantom.IsValidForwardSource()) + { + forward_heap.Insert(source_phantom.forward_segment_id.id, + EdgeWeight{0} - source_phantom.GetForwardWeightPlusOffset(), + {source_phantom.forward_segment_id.id, + false, + EdgeDistance{0} - source_phantom.GetForwardDistance()}); + } - if (source_phantom.IsValidReverseSource()) - { - forward_heap.Insert(source_phantom.reverse_segment_id.id, - EdgeWeight{0} - source_phantom.GetReverseWeightPlusOffset(), - {source_phantom.reverse_segment_id.id, - false, - EdgeDistance{0} - source_phantom.GetReverseDistance()}); + if (source_phantom.IsValidReverseSource()) + { + forward_heap.Insert(source_phantom.reverse_segment_id.id, + EdgeWeight{0} - source_phantom.GetReverseWeightPlusOffset(), + {source_phantom.reverse_segment_id.id, + false, + EdgeDistance{0} - source_phantom.GetReverseDistance()}); + } } if (target_phantom.IsValidForwardTarget()) diff --git a/src/engine/routing_algorithms/map_matching.cpp b/src/engine/routing_algorithms/map_matching.cpp index 9f8a1d2a5..12c6ac4d3 100644 --- a/src/engine/routing_algorithms/map_matching.cpp +++ b/src/engine/routing_algorithms/map_matching.cpp @@ -225,6 +225,8 @@ SubMatchingList mapMatching(SearchEngineData &engine_working_data, continue; } + forward_heap.Clear(); + for (const auto s_prime : util::irange(0UL, current_viterbi.size())) { const double emission_pr = emission_log_probabilities[t][s_prime]; @@ -264,6 +266,8 @@ SubMatchingList mapMatching(SearchEngineData &engine_working_data, model.breakage[t] = false; } } + + forward_heap.Clear(); } if (model.breakage[t])