Fix behaviour of table if sources/destinations arrays are empty
This commit is contained in:
parent
25f86b68dc
commit
e4ed2f6a2f
@ -46,78 +46,6 @@ class ManyToManyRouting final
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// semmetric version
|
|
||||||
std::vector<EdgeWeight> operator()(const std::vector<PhantomNode> &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<EdgeWeight> result_table(number_of_entries,
|
|
||||||
std::numeric_limits<EdgeWeight>::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<EdgeWeight> operator()(const std::vector<PhantomNode> &phantom_nodes,
|
std::vector<EdgeWeight> operator()(const std::vector<PhantomNode> &phantom_nodes,
|
||||||
const std::vector<std::size_t> &source_indices,
|
const std::vector<std::size_t> &source_indices,
|
||||||
const std::vector<std::size_t> &target_indices) const
|
const std::vector<std::size_t> &target_indices) const
|
||||||
@ -136,9 +64,8 @@ class ManyToManyRouting final
|
|||||||
SearchSpaceWithBuckets search_space_with_buckets;
|
SearchSpaceWithBuckets search_space_with_buckets;
|
||||||
|
|
||||||
unsigned column_idx = 0;
|
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();
|
query_heap.Clear();
|
||||||
// insert target(s) at distance 0
|
// insert target(s) at distance 0
|
||||||
|
|
||||||
@ -159,13 +86,12 @@ class ManyToManyRouting final
|
|||||||
BackwardRoutingStep(column_idx, query_heap, search_space_with_buckets);
|
BackwardRoutingStep(column_idx, query_heap, search_space_with_buckets);
|
||||||
}
|
}
|
||||||
++column_idx;
|
++column_idx;
|
||||||
}
|
};
|
||||||
|
|
||||||
// for each source do forward search
|
// for each source do forward search
|
||||||
unsigned row_idx = 0;
|
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();
|
query_heap.Clear();
|
||||||
// insert target(s) at distance 0
|
// insert target(s) at distance 0
|
||||||
|
|
||||||
@ -187,6 +113,38 @@ class ManyToManyRouting final
|
|||||||
search_space_with_buckets, result_table);
|
search_space_with_buckets, result_table);
|
||||||
}
|
}
|
||||||
++row_idx;
|
++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;
|
return result_table;
|
||||||
|
@ -59,19 +59,7 @@ Status TablePlugin::HandleRequest(const api::TableParameters ¶ms, util::json
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto snapped_phantoms = SnapPhantomNodes(GetPhantomNodes(params));
|
auto snapped_phantoms = SnapPhantomNodes(GetPhantomNodes(params));
|
||||||
|
auto result_table = distance_table(snapped_phantoms, params.sources, params.destinations);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}();
|
|
||||||
|
|
||||||
if (result_table.empty())
|
if (result_table.empty())
|
||||||
{
|
{
|
||||||
|
@ -186,7 +186,7 @@ Status TripPlugin::HandleRequest(const api::TripParameters ¶meters,
|
|||||||
|
|
||||||
// compute the duration table of all phantom nodes
|
// compute the duration table of all phantom nodes
|
||||||
const auto result_table = util::DistTableWrapper<EdgeWeight>(
|
const auto result_table = util::DistTableWrapper<EdgeWeight>(
|
||||||
duration_table(snapped_phantoms), number_of_locations);
|
duration_table(snapped_phantoms, {}, {}), number_of_locations);
|
||||||
|
|
||||||
if (result_table.size() == 0)
|
if (result_table.size() == 0)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user