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)
|
||||
{
|
||||
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);
|
||||
unsigned max_locations = std::min(100u, static_cast<unsigned>(raw_route.raw_via_node_coordinates.size()));
|
||||
std::vector<PhantomNode> phantom_node_vector(max_locations);
|
||||
unsigned 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)
|
||||
{
|
||||
if (checksum_OK && i < route_parameters.hints.size() &&
|
||||
!route_parameters.hints[i].empty())
|
||||
{
|
||||
DecodeObjectFromBase64(route_parameters.hints[i], phantom_node_vector[i]);
|
||||
if (phantom_node_vector[i].isValid(facade->GetNumberOfNodes()))
|
||||
PhantomNode current_phantom_node;
|
||||
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;
|
||||
}
|
||||
}
|
||||
facade->FindPhantomNodeForCoordinate(raw_route.raw_via_node_coordinates[i],
|
||||
phantom_node_vector[i],
|
||||
route_parameters.zoom_level);
|
||||
BOOST_ASSERT(phantom_node_vector[i].isValid(facade->GetNumberOfNodes()));
|
||||
facade->IncrementalFindPhantomNodeForCoordinate(raw_route.raw_via_node_coordinates[i],
|
||||
phantom_node_vector[i],
|
||||
route_parameters.zoom_level,
|
||||
1);
|
||||
|
||||
BOOST_ASSERT(phantom_node_vector[i].front().isValid(facade->GetNumberOfNodes()));
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
if (!result_table)
|
||||
@ -120,11 +126,11 @@ template <class DataFacadeT> class DistanceTablePlugin : public BasePlugin
|
||||
JSON::Object json_object;
|
||||
JSON::Array json_array;
|
||||
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;
|
||||
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_begin_iterator = result_table->begin() + (row * 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_array.values.push_back(json_row);
|
||||
}
|
||||
|
@ -64,12 +64,13 @@ template <class DataFacadeT> class ManyToManyRouting : public BasicRoutingInterf
|
||||
|
||||
~ManyToManyRouting() {}
|
||||
|
||||
std::shared_ptr<std::vector<EdgeWeight>>
|
||||
operator()(const std::vector<PhantomNode> &phantom_nodes_vector) const
|
||||
std::shared_ptr<std::vector<EdgeWeight>> operator()(const PhantomNodeArray &phantom_nodes_array)
|
||||
const
|
||||
{
|
||||
const unsigned number_of_locations = static_cast<unsigned>(phantom_nodes_vector.size());
|
||||
std::shared_ptr<std::vector<EdgeWeight>> result_table = std::make_shared<std::vector<EdgeWeight>>(
|
||||
number_of_locations * number_of_locations, std::numeric_limits<EdgeWeight>::max());
|
||||
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>>(number_of_locations * number_of_locations,
|
||||
std::numeric_limits<EdgeWeight>::max());
|
||||
|
||||
engine_working_data.InitializeOrClearFirstThreadLocalStorage(
|
||||
super::facade->GetNumberOfNodes());
|
||||
@ -79,17 +80,27 @@ template <class DataFacadeT> class ManyToManyRouting : public BasicRoutingInterf
|
||||
SearchSpaceWithBuckets search_space_with_buckets;
|
||||
|
||||
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();
|
||||
// insert target(s) at distance 0
|
||||
if (SPECIAL_NODEID != phantom_node.forward_node_id)
|
||||
|
||||
for (const PhantomNode &phantom_node : phantom_node_vector)
|
||||
{
|
||||
query_heap.Insert(phantom_node.forward_node_id, phantom_node.GetForwardWeightPlusOffset(), phantom_node.forward_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);
|
||||
if (SPECIAL_NODEID != 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)
|
||||
{
|
||||
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
|
||||
@ -102,17 +113,26 @@ template <class DataFacadeT> class ManyToManyRouting : public BasicRoutingInterf
|
||||
|
||||
// for each source do forward search
|
||||
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();
|
||||
// insert sources at distance 0
|
||||
if (SPECIAL_NODEID != phantom_node.forward_node_id)
|
||||
for (const PhantomNode &phantom_node : phantom_node_vector)
|
||||
{
|
||||
query_heap.Insert(phantom_node.forward_node_id, -phantom_node.GetForwardWeightPlusOffset(), phantom_node.forward_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);
|
||||
// insert sources at distance 0
|
||||
if (SPECIAL_NODEID != 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)
|
||||
{
|
||||
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
|
||||
@ -221,7 +241,8 @@ template <class DataFacadeT> class ManyToManyRouting : public BasicRoutingInterf
|
||||
|
||||
// Stalling
|
||||
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))
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user