From 8300a6c57e721c7c71b53925702d13d5a47381e7 Mon Sep 17 00:00:00 2001 From: Michael Krasnyk Date: Tue, 10 Oct 2017 12:14:27 +0200 Subject: [PATCH] Prepare phantom nodes indices in ManyToManySearch search --- include/engine/routing_algorithms.hpp | 26 ++++++++++++++---- .../routing_algorithms/many_to_many.hpp | 4 +-- .../routing_algorithms/many_to_many_ch.cpp | 15 ++--------- .../routing_algorithms/many_to_many_mld.cpp | 27 ++++--------------- 4 files changed, 30 insertions(+), 42 deletions(-) diff --git a/include/engine/routing_algorithms.hpp b/include/engine/routing_algorithms.hpp index c9eab5a14..c73e4c224 100644 --- a/include/engine/routing_algorithms.hpp +++ b/include/engine/routing_algorithms.hpp @@ -184,13 +184,29 @@ inline routing_algorithms::SubMatchingList RoutingAlgorithms::MapMatc } template -std::vector -RoutingAlgorithms::ManyToManySearch(const std::vector &phantom_nodes, - const std::vector &source_indices, - const std::vector &target_indices) const +std::vector RoutingAlgorithms::ManyToManySearch( + const std::vector &phantom_nodes, + const std::vector &_source_indices, + const std::vector &_target_indices) const { + BOOST_ASSERT(!phantom_nodes.empty()); + + auto source_indices = _source_indices; + auto target_indices = _target_indices; + + if (source_indices.empty()) + { + source_indices.resize(phantom_nodes.size()); + std::iota(source_indices.begin(), source_indices.end(), 0); + } + if (target_indices.empty()) + { + target_indices.resize(phantom_nodes.size()); + std::iota(target_indices.begin(), target_indices.end(), 0); + } + return routing_algorithms::manyToManySearch( - heaps, *facade, phantom_nodes, source_indices, target_indices); + heaps, *facade, phantom_nodes, std::move(source_indices), std::move(target_indices)); } template diff --git a/include/engine/routing_algorithms/many_to_many.hpp b/include/engine/routing_algorithms/many_to_many.hpp index d9e18cef0..f4d218846 100644 --- a/include/engine/routing_algorithms/many_to_many.hpp +++ b/include/engine/routing_algorithms/many_to_many.hpp @@ -53,8 +53,8 @@ template std::vector manyToManySearch(SearchEngineData &engine_working_data, const DataFacade &facade, const std::vector &phantom_nodes, - std::vector source_indices, - std::vector target_indices); + const std::vector &source_indices, + const std::vector &target_indices); } // namespace routing_algorithms } // namespace engine diff --git a/src/engine/routing_algorithms/many_to_many_ch.cpp b/src/engine/routing_algorithms/many_to_many_ch.cpp index 2eab19ddc..807406281 100644 --- a/src/engine/routing_algorithms/many_to_many_ch.cpp +++ b/src/engine/routing_algorithms/many_to_many_ch.cpp @@ -158,20 +158,9 @@ template <> std::vector manyToManySearch(SearchEngineData &engine_working_data, const DataFacade &facade, const std::vector &phantom_nodes, - std::vector source_indices, - std::vector target_indices) + const std::vector &source_indices, + const std::vector &target_indices) { - if (source_indices.empty()) - { - source_indices.resize(phantom_nodes.size()); - std::iota(source_indices.begin(), source_indices.end(), 0); - } - if (target_indices.empty()) - { - target_indices.resize(phantom_nodes.size()); - std::iota(target_indices.begin(), target_indices.end(), 0); - } - const auto number_of_sources = source_indices.size(); const auto number_of_targets = target_indices.size(); const auto number_of_entries = number_of_sources * number_of_targets; diff --git a/src/engine/routing_algorithms/many_to_many_mld.cpp b/src/engine/routing_algorithms/many_to_many_mld.cpp index 42cee4983..417ec21da 100644 --- a/src/engine/routing_algorithms/many_to_many_mld.cpp +++ b/src/engine/routing_algorithms/many_to_many_mld.cpp @@ -251,14 +251,8 @@ std::vector oneToManySearch(SearchEngineData &engine_wo const DataFacade &facade, const std::vector &phantom_nodes, std::size_t phantom_index, - std::vector phantom_indices) + const std::vector &phantom_indices) { - if (phantom_indices.empty()) - { - phantom_indices.resize(phantom_nodes.size()); - std::iota(phantom_indices.begin(), phantom_indices.end(), 0); - } - std::vector weights(phantom_indices.size(), INVALID_EDGE_WEIGHT); std::vector durations(phantom_indices.size(), MAXIMAL_EDGE_DURATION); @@ -415,20 +409,9 @@ std::vector oneToManySearch(SearchEngineData &engine_wo std::vector manyToManySearch(SearchEngineData &engine_working_data, const DataFacade &facade, const std::vector &phantom_nodes, - std::vector source_indices, - std::vector target_indices) + const std::vector &source_indices, + const std::vector &target_indices) { - if (source_indices.empty()) - { - source_indices.resize(phantom_nodes.size()); - std::iota(source_indices.begin(), source_indices.end(), 0); - } - if (target_indices.empty()) - { - target_indices.resize(phantom_nodes.size()); - std::iota(target_indices.begin(), target_indices.end(), 0); - } - const auto number_of_sources = source_indices.size(); const auto number_of_targets = target_indices.size(); const auto number_of_entries = number_of_sources * number_of_targets; @@ -502,8 +485,8 @@ template <> std::vector manyToManySearch(SearchEngineData &engine_working_data, const DataFacade &facade, const std::vector &phantom_nodes, - std::vector source_indices, - std::vector target_indices) + const std::vector &source_indices, + const std::vector &target_indices) { if (source_indices.size() == 1) { // TODO: check if target_indices.size() == 1 and do a bi-directional search