diff --git a/include/engine/routing_algorithms/many_to_many.hpp b/include/engine/routing_algorithms/many_to_many.hpp index abaddce19..f1a24826d 100644 --- a/include/engine/routing_algorithms/many_to_many.hpp +++ b/include/engine/routing_algorithms/many_to_many.hpp @@ -20,8 +20,8 @@ template std::vector manyToManySearch(SearchEngineData &engine_working_data, const DataFacade &facade, const std::vector &phantom_nodes, - const std::vector &source_indices, - const std::vector &target_indices); + std::vector source_indices, + std::vector target_indices); } // namespace routing_algorithms } // namespace engine diff --git a/src/engine/routing_algorithms/many_to_many.cpp b/src/engine/routing_algorithms/many_to_many.cpp index c69a0cb04..3ee633052 100644 --- a/src/engine/routing_algorithms/many_to_many.cpp +++ b/src/engine/routing_algorithms/many_to_many.cpp @@ -301,27 +301,38 @@ template std::vector manyToManySearch(SearchEngineData &engine_working_data, const DataFacade &facade, const std::vector &phantom_nodes, - const std::vector &source_indices, - const std::vector &target_indices) + std::vector source_indices, + std::vector target_indices) { - const auto number_of_sources = - source_indices.empty() ? phantom_nodes.size() : source_indices.size(); - const auto number_of_targets = - target_indices.empty() ? phantom_nodes.size() : target_indices.size(); + 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; std::vector weights_table(number_of_entries, INVALID_EDGE_WEIGHT); std::vector durations_table(number_of_entries, MAXIMAL_EDGE_DURATION); - engine_working_data.InitializeOrClearManyToManyThreadLocalStorage(facade.GetNumberOfNodes()); - - auto &query_heap = *(engine_working_data.many_to_many_heap); - SearchSpaceWithBuckets search_space_with_buckets; - unsigned column_idx = 0; - const auto search_target_phantom = [&](const PhantomNode &phantom) { - // clear heap and insert target nodes + engine_working_data.InitializeOrClearManyToManyThreadLocalStorage(facade.GetNumberOfNodes()); + auto &query_heap = *(engine_working_data.many_to_many_heap); + + // Backward search for target phantoms + for (const auto column_idx : util::irange(0u, target_indices.size())) + { + const auto index = target_indices[column_idx]; + const auto &phantom = phantom_nodes[index]; + query_heap.Clear(); insertTargetInHeap(query_heap, phantom); @@ -330,12 +341,14 @@ std::vector manyToManySearch(SearchEngineData &engine_wor { backwardRoutingStep(facade, column_idx, query_heap, search_space_with_buckets, phantom); } - ++column_idx; - }; + } + + // For each source do forward search + for (const auto row_idx : util::irange(0, source_indices.size())) + { + const auto index = source_indices[row_idx]; + const auto &phantom = phantom_nodes[index]; - // for each source do forward search - unsigned row_idx = 0; - const auto search_source_phantom = [&](const PhantomNode &phantom) { // clear heap and insert source nodes query_heap.Clear(); insertSourceInHeap(query_heap, phantom); @@ -352,39 +365,6 @@ std::vector manyToManySearch(SearchEngineData &engine_wor durations_table, phantom); } - ++row_idx; - }; - - if (target_indices.empty()) - { - for (const auto &phantom : phantom_nodes) - { - search_target_phantom(phantom); - } - } - else - { - for (const auto index : target_indices) - { - const auto &phantom = phantom_nodes[index]; - search_target_phantom(phantom); - } - } - - if (source_indices.empty()) - { - for (const auto &phantom : phantom_nodes) - { - search_source_phantom(phantom); - } - } - else - { - for (const auto index : source_indices) - { - const auto &phantom = phantom_nodes[index]; - search_source_phantom(phantom); - } } return durations_table; @@ -394,15 +374,15 @@ template std::vector manyToManySearch(SearchEngineData &engine_working_data, const DataFacade &facade, const std::vector &phantom_nodes, - const std::vector &source_indices, - const std::vector &target_indices); + std::vector source_indices, + std::vector target_indices); template std::vector manyToManySearch(SearchEngineData &engine_working_data, const DataFacade &facade, const std::vector &phantom_nodes, - const std::vector &source_indices, - const std::vector &target_indices); + std::vector source_indices, + std::vector target_indices); } // namespace routing_algorithms } // namespace engine