use incremental NN query for distance table generation
This commit is contained in:
parent
b74a573ec5
commit
4d7e0f6b79
@ -85,31 +85,37 @@ template <class DataFacadeT> class DistanceTablePlugin : public BasePlugin
|
|||||||
|
|
||||||
for (const FixedPointCoordinate &coordinate : route_parameters.coordinates)
|
for (const FixedPointCoordinate &coordinate : route_parameters.coordinates)
|
||||||
{
|
{
|
||||||
raw_route.raw_via_node_coordinates.emplace_back(coordinate);
|
raw_route.raw_via_node_coordinates.emplace_back(std::move(coordinate));
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool checksum_OK = (route_parameters.check_sum == raw_route.check_sum);
|
const bool checksum_OK = (route_parameters.check_sum == raw_route.check_sum);
|
||||||
unsigned max_locations = std::min(100u, static_cast<unsigned>(raw_route.raw_via_node_coordinates.size()));
|
unsigned max_locations =
|
||||||
std::vector<PhantomNode> phantom_node_vector(max_locations);
|
std::min(100u, static_cast<unsigned>(raw_route.raw_via_node_coordinates.size()));
|
||||||
|
PhantomNodeArray phantom_node_vector(max_locations);
|
||||||
for (unsigned i = 0; i < max_locations; ++i)
|
for (unsigned i = 0; i < max_locations; ++i)
|
||||||
{
|
{
|
||||||
if (checksum_OK && i < route_parameters.hints.size() &&
|
if (checksum_OK && i < route_parameters.hints.size() &&
|
||||||
!route_parameters.hints[i].empty())
|
!route_parameters.hints[i].empty())
|
||||||
{
|
{
|
||||||
DecodeObjectFromBase64(route_parameters.hints[i], phantom_node_vector[i]);
|
PhantomNode current_phantom_node;
|
||||||
if (phantom_node_vector[i].isValid(facade->GetNumberOfNodes()))
|
DecodeObjectFromBase64(route_parameters.hints[i], current_phantom_node);
|
||||||
|
if (current_phantom_node.isValid(facade->GetNumberOfNodes()))
|
||||||
{
|
{
|
||||||
|
phantom_node_vector[i].emplace_back(std::move(current_phantom_node));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
facade->FindPhantomNodeForCoordinate(raw_route.raw_via_node_coordinates[i],
|
facade->IncrementalFindPhantomNodeForCoordinate(raw_route.raw_via_node_coordinates[i],
|
||||||
phantom_node_vector[i],
|
phantom_node_vector[i],
|
||||||
route_parameters.zoom_level);
|
route_parameters.zoom_level,
|
||||||
BOOST_ASSERT(phantom_node_vector[i].isValid(facade->GetNumberOfNodes()));
|
1);
|
||||||
|
|
||||||
|
BOOST_ASSERT(phantom_node_vector[i].front().isValid(facade->GetNumberOfNodes()));
|
||||||
}
|
}
|
||||||
|
|
||||||
TIMER_START(distance_table);
|
TIMER_START(distance_table);
|
||||||
std::shared_ptr<std::vector<EdgeWeight>> result_table = search_engine_ptr->distance_table(phantom_node_vector);
|
std::shared_ptr<std::vector<EdgeWeight>> result_table =
|
||||||
|
search_engine_ptr->distance_table(phantom_node_vector);
|
||||||
TIMER_STOP(distance_table);
|
TIMER_STOP(distance_table);
|
||||||
|
|
||||||
if (!result_table)
|
if (!result_table)
|
||||||
@ -120,11 +126,11 @@ template <class DataFacadeT> class DistanceTablePlugin : public BasePlugin
|
|||||||
JSON::Object json_object;
|
JSON::Object json_object;
|
||||||
JSON::Array json_array;
|
JSON::Array json_array;
|
||||||
const unsigned number_of_locations = static_cast<unsigned>(phantom_node_vector.size());
|
const unsigned number_of_locations = static_cast<unsigned>(phantom_node_vector.size());
|
||||||
for(unsigned row = 0; row < number_of_locations; ++row)
|
for (unsigned row = 0; row < number_of_locations; ++row)
|
||||||
{
|
{
|
||||||
JSON::Array json_row;
|
JSON::Array json_row;
|
||||||
auto row_begin_iterator = result_table->begin() + (row*number_of_locations);
|
auto row_begin_iterator = result_table->begin() + (row * number_of_locations);
|
||||||
auto row_end_iterator = result_table->begin() + ((row+1)*number_of_locations);
|
auto row_end_iterator = result_table->begin() + ((row + 1) * number_of_locations);
|
||||||
json_row.values.insert(json_row.values.end(), row_begin_iterator, row_end_iterator);
|
json_row.values.insert(json_row.values.end(), row_begin_iterator, row_end_iterator);
|
||||||
json_array.values.push_back(json_row);
|
json_array.values.push_back(json_row);
|
||||||
}
|
}
|
||||||
|
@ -64,12 +64,13 @@ template <class DataFacadeT> class ManyToManyRouting : public BasicRoutingInterf
|
|||||||
|
|
||||||
~ManyToManyRouting() {}
|
~ManyToManyRouting() {}
|
||||||
|
|
||||||
std::shared_ptr<std::vector<EdgeWeight>>
|
std::shared_ptr<std::vector<EdgeWeight>> operator()(const PhantomNodeArray &phantom_nodes_array)
|
||||||
operator()(const std::vector<PhantomNode> &phantom_nodes_vector) const
|
const
|
||||||
{
|
{
|
||||||
const unsigned number_of_locations = static_cast<unsigned>(phantom_nodes_vector.size());
|
const unsigned number_of_locations = static_cast<unsigned>(phantom_nodes_array.size());
|
||||||
std::shared_ptr<std::vector<EdgeWeight>> result_table = std::make_shared<std::vector<EdgeWeight>>(
|
std::shared_ptr<std::vector<EdgeWeight>> result_table =
|
||||||
number_of_locations * number_of_locations, std::numeric_limits<EdgeWeight>::max());
|
std::make_shared<std::vector<EdgeWeight>>(number_of_locations * number_of_locations,
|
||||||
|
std::numeric_limits<EdgeWeight>::max());
|
||||||
|
|
||||||
engine_working_data.InitializeOrClearFirstThreadLocalStorage(
|
engine_working_data.InitializeOrClearFirstThreadLocalStorage(
|
||||||
super::facade->GetNumberOfNodes());
|
super::facade->GetNumberOfNodes());
|
||||||
@ -79,17 +80,27 @@ template <class DataFacadeT> class ManyToManyRouting : public BasicRoutingInterf
|
|||||||
SearchSpaceWithBuckets search_space_with_buckets;
|
SearchSpaceWithBuckets search_space_with_buckets;
|
||||||
|
|
||||||
unsigned target_id = 0;
|
unsigned target_id = 0;
|
||||||
for (const PhantomNode &phantom_node : phantom_nodes_vector)
|
for (const std::vector<PhantomNode> &phantom_node_vector : phantom_nodes_array)
|
||||||
{
|
{
|
||||||
query_heap.Clear();
|
query_heap.Clear();
|
||||||
// insert target(s) at distance 0
|
// insert target(s) at distance 0
|
||||||
|
|
||||||
|
for (const PhantomNode &phantom_node : phantom_node_vector)
|
||||||
|
{
|
||||||
if (SPECIAL_NODEID != phantom_node.forward_node_id)
|
if (SPECIAL_NODEID != phantom_node.forward_node_id)
|
||||||
{
|
{
|
||||||
query_heap.Insert(phantom_node.forward_node_id, phantom_node.GetForwardWeightPlusOffset(), phantom_node.forward_node_id);
|
query_heap.Insert(phantom_node.forward_node_id,
|
||||||
|
phantom_node.GetForwardWeightPlusOffset(),
|
||||||
|
phantom_node.forward_node_id);
|
||||||
|
SimpleLogger().Write(logDEBUG) << "[" << target_id << "] rev insert: " << phantom_node.forward_node_id;
|
||||||
}
|
}
|
||||||
if (SPECIAL_NODEID != phantom_node.reverse_node_id)
|
if (SPECIAL_NODEID != phantom_node.reverse_node_id)
|
||||||
{
|
{
|
||||||
query_heap.Insert(phantom_node.reverse_node_id, phantom_node.GetReverseWeightPlusOffset(), phantom_node.reverse_node_id);
|
query_heap.Insert(phantom_node.reverse_node_id,
|
||||||
|
phantom_node.GetReverseWeightPlusOffset(),
|
||||||
|
phantom_node.reverse_node_id);
|
||||||
|
SimpleLogger().Write(logDEBUG) << "[" << target_id << "] rev insert: " << phantom_node.reverse_node_id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// explore search space
|
// explore search space
|
||||||
@ -102,17 +113,26 @@ template <class DataFacadeT> class ManyToManyRouting : public BasicRoutingInterf
|
|||||||
|
|
||||||
// for each source do forward search
|
// for each source do forward search
|
||||||
unsigned source_id = 0;
|
unsigned source_id = 0;
|
||||||
for (const PhantomNode &phantom_node : phantom_nodes_vector)
|
for (const std::vector<PhantomNode> &phantom_node_vector : phantom_nodes_array)
|
||||||
{
|
{
|
||||||
query_heap.Clear();
|
query_heap.Clear();
|
||||||
|
for (const PhantomNode &phantom_node : phantom_node_vector)
|
||||||
|
{
|
||||||
// insert sources at distance 0
|
// insert sources at distance 0
|
||||||
if (SPECIAL_NODEID != phantom_node.forward_node_id)
|
if (SPECIAL_NODEID != phantom_node.forward_node_id)
|
||||||
{
|
{
|
||||||
query_heap.Insert(phantom_node.forward_node_id, -phantom_node.GetForwardWeightPlusOffset(), phantom_node.forward_node_id);
|
query_heap.Insert(phantom_node.forward_node_id,
|
||||||
|
-phantom_node.GetForwardWeightPlusOffset(),
|
||||||
|
phantom_node.forward_node_id);
|
||||||
|
SimpleLogger().Write(logDEBUG) << "[" << source_id << "] fwd insert: " << phantom_node.forward_node_id;
|
||||||
}
|
}
|
||||||
if (SPECIAL_NODEID != phantom_node.reverse_node_id)
|
if (SPECIAL_NODEID != phantom_node.reverse_node_id)
|
||||||
{
|
{
|
||||||
query_heap.Insert(phantom_node.reverse_node_id, -phantom_node.GetReverseWeightPlusOffset(), phantom_node.reverse_node_id);
|
query_heap.Insert(phantom_node.reverse_node_id,
|
||||||
|
-phantom_node.GetReverseWeightPlusOffset(),
|
||||||
|
phantom_node.reverse_node_id);
|
||||||
|
SimpleLogger().Write(logDEBUG) << "[" << source_id << "] fwd insert: " << phantom_node.reverse_node_id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// explore search space
|
// explore search space
|
||||||
@ -221,7 +241,8 @@ template <class DataFacadeT> class ManyToManyRouting : public BasicRoutingInterf
|
|||||||
|
|
||||||
// Stalling
|
// Stalling
|
||||||
template <bool forward_direction>
|
template <bool forward_direction>
|
||||||
inline bool StallAtNode(const NodeID node, const EdgeWeight distance, QueryHeap &query_heap) const
|
inline bool StallAtNode(const NodeID node, const EdgeWeight distance, QueryHeap &query_heap)
|
||||||
|
const
|
||||||
{
|
{
|
||||||
for (auto edge : super::facade->GetAdjacentEdgeRange(node))
|
for (auto edge : super::facade->GetAdjacentEdgeRange(node))
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user