From c1647c99c84c483872f530d4b52e43a24e29ec7e Mon Sep 17 00:00:00 2001 From: Patrick Niklaus Date: Thu, 25 Feb 2016 00:27:14 +0100 Subject: [PATCH] Fix behaviour of table if sources/destinations arrays are empty --- .../routing_algorithms/many_to_many.hpp | 112 ++++++------------ src/engine/plugins/table.cpp | 14 +-- src/engine/plugins/trip.cpp | 2 +- 3 files changed, 37 insertions(+), 91 deletions(-) diff --git a/include/engine/routing_algorithms/many_to_many.hpp b/include/engine/routing_algorithms/many_to_many.hpp index 676ddcf8c..38abefbe2 100644 --- a/include/engine/routing_algorithms/many_to_many.hpp +++ b/include/engine/routing_algorithms/many_to_many.hpp @@ -46,78 +46,6 @@ class ManyToManyRouting final { } - // semmetric version - std::vector operator()(const std::vector &phantom_nodes) const - { - const auto number_of_sources = phantom_nodes.size(); - const auto number_of_targets = phantom_nodes.size(); - const auto number_of_entries = number_of_sources * number_of_targets; - std::vector result_table(number_of_entries, - std::numeric_limits::max()); - - engine_working_data.InitializeOrClearFirstThreadLocalStorage( - super::facade->GetNumberOfNodes()); - - QueryHeap &query_heap = *(engine_working_data.forward_heap_1); - - SearchSpaceWithBuckets search_space_with_buckets; - - unsigned column_idx = 0; - for (const auto &phantom : phantom_nodes) - { - query_heap.Clear(); - // insert target(s) at distance 0 - - if (SPECIAL_NODEID != phantom.forward_node_id) - { - query_heap.Insert(phantom.forward_node_id, phantom.GetForwardWeightPlusOffset(), - phantom.forward_node_id); - } - if (SPECIAL_NODEID != phantom.reverse_node_id) - { - query_heap.Insert(phantom.reverse_node_id, phantom.GetReverseWeightPlusOffset(), - phantom.reverse_node_id); - } - - // explore search space - while (!query_heap.Empty()) - { - BackwardRoutingStep(column_idx, query_heap, search_space_with_buckets); - } - ++column_idx; - } - - // for each source do forward search - unsigned row_idx = 0; - for (const auto &phantom : phantom_nodes) - { - query_heap.Clear(); - // insert target(s) at distance 0 - - if (SPECIAL_NODEID != phantom.forward_node_id) - { - query_heap.Insert(phantom.forward_node_id, -phantom.GetForwardWeightPlusOffset(), - phantom.forward_node_id); - } - if (SPECIAL_NODEID != phantom.reverse_node_id) - { - query_heap.Insert(phantom.reverse_node_id, -phantom.GetReverseWeightPlusOffset(), - phantom.reverse_node_id); - } - - // explore search space - while (!query_heap.Empty()) - { - ForwardRoutingStep(row_idx, number_of_targets, query_heap, - search_space_with_buckets, result_table); - } - ++row_idx; - } - - return result_table; - } - - // asymmetric version std::vector operator()(const std::vector &phantom_nodes, const std::vector &source_indices, const std::vector &target_indices) const @@ -136,9 +64,8 @@ class ManyToManyRouting final SearchSpaceWithBuckets search_space_with_buckets; unsigned column_idx = 0; - for (const auto index : target_indices) + const auto search_target_phantom = [&](const PhantomNode &phantom) { - const auto &phantom = phantom_nodes[index]; query_heap.Clear(); // insert target(s) at distance 0 @@ -159,13 +86,12 @@ class ManyToManyRouting final BackwardRoutingStep(column_idx, query_heap, search_space_with_buckets); } ++column_idx; - } + }; // for each source do forward search unsigned row_idx = 0; - for (const auto index : source_indices) + const auto search_source_phantom = [&](const PhantomNode& phantom) { - const auto &phantom = phantom_nodes[index]; query_heap.Clear(); // insert target(s) at distance 0 @@ -187,6 +113,38 @@ class ManyToManyRouting final search_space_with_buckets, result_table); } ++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 result_table; diff --git a/src/engine/plugins/table.cpp b/src/engine/plugins/table.cpp index 6cfef8dea..f6fd6a034 100644 --- a/src/engine/plugins/table.cpp +++ b/src/engine/plugins/table.cpp @@ -59,19 +59,7 @@ Status TablePlugin::HandleRequest(const api::TableParameters ¶ms, util::json } auto snapped_phantoms = SnapPhantomNodes(GetPhantomNodes(params)); - - const auto result_table = [&] - { - if (params.sources.empty()) - { - BOOST_ASSERT(params.destinations.empty()); - return distance_table(snapped_phantoms); - } - else - { - return distance_table(snapped_phantoms, params.sources, params.destinations); - } - }(); + auto result_table = distance_table(snapped_phantoms, params.sources, params.destinations); if (result_table.empty()) { diff --git a/src/engine/plugins/trip.cpp b/src/engine/plugins/trip.cpp index e648fdf72..fecab3461 100644 --- a/src/engine/plugins/trip.cpp +++ b/src/engine/plugins/trip.cpp @@ -186,7 +186,7 @@ Status TripPlugin::HandleRequest(const api::TripParameters ¶meters, // compute the duration table of all phantom nodes const auto result_table = util::DistTableWrapper( - duration_table(snapped_phantoms), number_of_locations); + duration_table(snapped_phantoms, {}, {}), number_of_locations); if (result_table.size() == 0) {