From 21ecb8c209e286f3f731a9a9f5e328b1ec4d9c54 Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Fri, 10 May 2024 20:30:14 +0200 Subject: [PATCH] Optimise path distance calculation in MLD map matching --- .../routing_algorithms/routing_base_mld.hpp | 32 +++++++++++++++++-- src/benchmarks/match.cpp | 2 ++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/include/engine/routing_algorithms/routing_base_mld.hpp b/include/engine/routing_algorithms/routing_base_mld.hpp index c577c3be3..b680867ee 100644 --- a/include/engine/routing_algorithms/routing_base_mld.hpp +++ b/include/engine/routing_algorithms/routing_base_mld.hpp @@ -650,11 +650,37 @@ double getNetworkDistance(SearchEngineData &engine_working_data, return std::numeric_limits::max(); } - std::vector unpacked_path; - annotatePath(facade, endpoints, unpacked_nodes, unpacked_edges, unpacked_path); - return getPathDistance(facade, unpacked_path, source_phantom, target_phantom); + EdgeDistance distance = {0.0}; + + if (source_phantom.forward_segment_id.id == unpacked_nodes[0]) + { + BOOST_ASSERT(source_phantom.forward_segment_id.enabled); + distance = EdgeDistance{0} - source_phantom.GetForwardDistance(); + } + else if (source_phantom.reverse_segment_id.id == unpacked_nodes[0]) + { + BOOST_ASSERT(source_phantom.reverse_segment_id.enabled); + distance = EdgeDistance{0} - source_phantom.GetReverseDistance(); + } + + for (size_t index = 0; index < unpacked_nodes.size() - 1; ++index) { + distance += facade.GetNodeDistance(unpacked_nodes[index]); + } + + if (target_phantom.forward_segment_id.id == unpacked_nodes.back()) + { + BOOST_ASSERT(target_phantom.forward_segment_id.enabled); + distance += target_phantom.GetForwardDistance(); + } + else if (target_phantom.reverse_segment_id.id == unpacked_nodes.back()) + { + BOOST_ASSERT(target_phantom.reverse_segment_id.enabled); + distance += target_phantom.GetReverseDistance(); + } + + return static_cast(static_cast(distance)); } } // namespace osrm::engine::routing_algorithms::mld diff --git a/src/benchmarks/match.cpp b/src/benchmarks/match.cpp index 932820e88..8bad6ea95 100644 --- a/src/benchmarks/match.cpp +++ b/src/benchmarks/match.cpp @@ -1,3 +1,4 @@ +#include "engine/engine_config.hpp" #include "util/timing_util.hpp" #include "osrm/match_parameters.hpp" @@ -32,6 +33,7 @@ try // Configure based on a .osrm base path, and no datasets in shared mem from osrm-datastore EngineConfig config; config.storage_config = {argv[1]}; + config.algorithm = (argc > 2 && std::string{argv[2]} == "mld") ? EngineConfig::Algorithm::MLD : EngineConfig::Algorithm::CH; config.use_shared_memory = false; // Routing machine with several services (such as Route, Table, Nearest, Trip, Match)