Make DataFacade local to every request

This is the first step to having fine grained locking on data updates,
see issue #2570.
This commit is contained in:
Patrick Niklaus 2016-10-06 01:05:03 +02:00 committed by Patrick Niklaus
parent 66f2cc5184
commit 1c2ead8fb8
21 changed files with 361 additions and 291 deletions

View File

@ -80,7 +80,7 @@ class Engine final
std::unique_ptr<plugins::MatchPlugin> match_plugin; std::unique_ptr<plugins::MatchPlugin> match_plugin;
std::unique_ptr<plugins::TilePlugin> tile_plugin; std::unique_ptr<plugins::TilePlugin> tile_plugin;
std::unique_ptr<datafacade::BaseDataFacade> query_data_facade; std::shared_ptr<datafacade::BaseDataFacade> query_data_facade;
}; };
} }
} }

View File

@ -27,13 +27,15 @@ class MatchPlugin : public BasePlugin
static const constexpr double DEFAULT_GPS_PRECISION = 5; static const constexpr double DEFAULT_GPS_PRECISION = 5;
static const constexpr double RADIUS_MULTIPLIER = 3; static const constexpr double RADIUS_MULTIPLIER = 3;
MatchPlugin(datafacade::BaseDataFacade &facade_, const int max_locations_map_matching) MatchPlugin(const int max_locations_map_matching)
: BasePlugin(facade_), map_matching(&facade_, heaps, DEFAULT_GPS_PRECISION), : map_matching(heaps, DEFAULT_GPS_PRECISION),
shortest_path(&facade_, heaps), max_locations_map_matching(max_locations_map_matching) shortest_path(heaps), max_locations_map_matching(max_locations_map_matching)
{ {
} }
Status HandleRequest(const api::MatchParameters &parameters, util::json::Object &json_result); Status HandleRequest(const std::shared_ptr<datafacade::BaseDataFacade> facade,
const api::MatchParameters &parameters,
util::json::Object &json_result);
private: private:
SearchEngineData heaps; SearchEngineData heaps;

View File

@ -15,9 +15,11 @@ namespace plugins
class NearestPlugin final : public BasePlugin class NearestPlugin final : public BasePlugin
{ {
public: public:
explicit NearestPlugin(datafacade::BaseDataFacade &facade, const int max_results); explicit NearestPlugin(const int max_results);
Status HandleRequest(const api::NearestParameters &params, util::json::Object &result); Status HandleRequest(const std::shared_ptr<datafacade::BaseDataFacade> facade,
const api::NearestParameters &params,
util::json::Object &result) const;
private: private:
const int max_results; const int max_results;

View File

@ -26,10 +26,7 @@ namespace plugins
class BasePlugin class BasePlugin
{ {
protected: protected:
datafacade::BaseDataFacade &facade; bool CheckAllCoordinates(const std::vector<util::Coordinate> &coordinates) const
BasePlugin(datafacade::BaseDataFacade &facade_) : facade(facade_) {}
bool CheckAllCoordinates(const std::vector<util::Coordinate> &coordinates)
{ {
return !std::any_of( return !std::any_of(
std::begin(coordinates), std::end(coordinates), [](const util::Coordinate coordinate) { std::begin(coordinates), std::end(coordinates), [](const util::Coordinate coordinate) {
@ -111,7 +108,8 @@ class BasePlugin
// Falls back to default_radius for non-set radii // Falls back to default_radius for non-set radii
std::vector<std::vector<PhantomNodeWithDistance>> std::vector<std::vector<PhantomNodeWithDistance>>
GetPhantomNodesInRange(const api::BaseParameters &parameters, GetPhantomNodesInRange(const datafacade::BaseDataFacade &facade,
const api::BaseParameters &parameters,
const std::vector<double> radiuses) const const std::vector<double> radiuses) const
{ {
std::vector<std::vector<PhantomNodeWithDistance>> phantom_nodes( std::vector<std::vector<PhantomNodeWithDistance>> phantom_nodes(
@ -152,7 +150,9 @@ class BasePlugin
} }
std::vector<std::vector<PhantomNodeWithDistance>> std::vector<std::vector<PhantomNodeWithDistance>>
GetPhantomNodes(const api::BaseParameters &parameters, unsigned number_of_results) GetPhantomNodes(const datafacade::BaseDataFacade &facade,
const api::BaseParameters &parameters,
unsigned number_of_results) const
{ {
std::vector<std::vector<PhantomNodeWithDistance>> phantom_nodes( std::vector<std::vector<PhantomNodeWithDistance>> phantom_nodes(
parameters.coordinates.size()); parameters.coordinates.size());
@ -216,7 +216,8 @@ class BasePlugin
return phantom_nodes; return phantom_nodes;
} }
std::vector<PhantomNodePair> GetPhantomNodes(const api::BaseParameters &parameters) std::vector<PhantomNodePair> GetPhantomNodes(const datafacade::BaseDataFacade &facade,
const api::BaseParameters &parameters) const
{ {
std::vector<PhantomNodePair> phantom_node_pairs(parameters.coordinates.size()); std::vector<PhantomNodePair> phantom_node_pairs(parameters.coordinates.size());

View File

@ -18,10 +18,11 @@ namespace plugins
class TablePlugin final : public BasePlugin class TablePlugin final : public BasePlugin
{ {
public: public:
explicit TablePlugin(datafacade::BaseDataFacade &facade, explicit TablePlugin(const int max_locations_distance_table);
const int max_locations_distance_table);
Status HandleRequest(const api::TableParameters &params, util::json::Object &result); Status HandleRequest(const std::shared_ptr<datafacade::BaseDataFacade> facade,
const api::TableParameters &params,
util::json::Object &result);
private: private:
SearchEngineData heaps; SearchEngineData heaps;

View File

@ -26,9 +26,7 @@ namespace plugins
class TilePlugin final : public BasePlugin class TilePlugin final : public BasePlugin
{ {
public: public:
TilePlugin(datafacade::BaseDataFacade &facade) : BasePlugin(facade) {} Status HandleRequest(const std::shared_ptr<datafacade::BaseDataFacade> facade, const api::TileParameters &parameters, std::string &pbf_buffer) const;
Status HandleRequest(const api::TileParameters &parameters, std::string &pbf_buffer);
}; };
} }
} }

View File

@ -34,17 +34,20 @@ class TripPlugin final : public BasePlugin
routing_algorithms::ManyToManyRouting<datafacade::BaseDataFacade> duration_table; routing_algorithms::ManyToManyRouting<datafacade::BaseDataFacade> duration_table;
int max_locations_trip; int max_locations_trip;
InternalRouteResult ComputeRoute(const std::vector<PhantomNode> &phantom_node_list, InternalRouteResult ComputeRoute(const datafacade::BaseDataFacade &facade,
const std::vector<PhantomNode> &phantom_node_list,
const std::vector<NodeID> &trip); const std::vector<NodeID> &trip);
public: public:
explicit TripPlugin(datafacade::BaseDataFacade &facade_, const int max_locations_trip_) explicit TripPlugin(const int max_locations_trip_)
: BasePlugin(facade_), shortest_path(&facade_, heaps), duration_table(&facade_, heaps), : shortest_path(heaps), duration_table(heaps),
max_locations_trip(max_locations_trip_) max_locations_trip(max_locations_trip_)
{ {
} }
Status HandleRequest(const api::TripParameters &parameters, util::json::Object &json_result); Status HandleRequest(const std::shared_ptr<datafacade::BaseDataFacade> facade,
const api::TripParameters &parameters,
util::json::Object &json_result);
}; };
} }
} }

View File

@ -35,9 +35,10 @@ class ViaRoutePlugin final : public BasePlugin
int max_locations_viaroute; int max_locations_viaroute;
public: public:
explicit ViaRoutePlugin(datafacade::BaseDataFacade &facade, int max_locations_viaroute); explicit ViaRoutePlugin(int max_locations_viaroute);
Status HandleRequest(const api::RouteParameters &route_parameters, Status HandleRequest(const std::shared_ptr<datafacade::BaseDataFacade> facade,
const api::RouteParameters &route_parameters,
util::json::Object &json_result); util::json::Object &json_result);
}; };
} }

View File

@ -50,18 +50,19 @@ class AlternativeRouting final
return (2 * length + sharing) < (2 * other.length + other.sharing); return (2 * length + sharing) < (2 * other.length + other.sharing);
} }
}; };
DataFacadeT *facade;
SearchEngineData &engine_working_data; SearchEngineData &engine_working_data;
public: public:
AlternativeRouting(DataFacadeT *facade, SearchEngineData &engine_working_data) AlternativeRouting(SearchEngineData &engine_working_data)
: super(facade), facade(facade), engine_working_data(engine_working_data) : engine_working_data(engine_working_data)
{ {
} }
virtual ~AlternativeRouting() {} virtual ~AlternativeRouting() {}
void operator()(const PhantomNodes &phantom_node_pair, InternalRouteResult &raw_route_data) void operator()(const DataFacadeT &facade,
const PhantomNodes &phantom_node_pair,
InternalRouteResult &raw_route_data)
{ {
std::vector<NodeID> alternative_path; std::vector<NodeID> alternative_path;
std::vector<NodeID> via_node_candidate_list; std::vector<NodeID> via_node_candidate_list;
@ -70,11 +71,11 @@ class AlternativeRouting final
// Init queues, semi-expensive because access to TSS invokes a sys-call // Init queues, semi-expensive because access to TSS invokes a sys-call
engine_working_data.InitializeOrClearFirstThreadLocalStorage( engine_working_data.InitializeOrClearFirstThreadLocalStorage(
super::facade->GetNumberOfNodes()); facade.GetNumberOfNodes());
engine_working_data.InitializeOrClearSecondThreadLocalStorage( engine_working_data.InitializeOrClearSecondThreadLocalStorage(
super::facade->GetNumberOfNodes()); facade.GetNumberOfNodes());
engine_working_data.InitializeOrClearThirdThreadLocalStorage( engine_working_data.InitializeOrClearThirdThreadLocalStorage(
super::facade->GetNumberOfNodes()); facade.GetNumberOfNodes());
QueryHeap &forward_heap1 = *(engine_working_data.forward_heap_1); QueryHeap &forward_heap1 = *(engine_working_data.forward_heap_1);
QueryHeap &reverse_heap1 = *(engine_working_data.reverse_heap_1); QueryHeap &reverse_heap1 = *(engine_working_data.reverse_heap_1);
@ -130,7 +131,8 @@ class AlternativeRouting final
{ {
if (0 < forward_heap1.Size()) if (0 < forward_heap1.Size())
{ {
AlternativeRoutingStep<true>(forward_heap1, AlternativeRoutingStep<true>(facade,
forward_heap1,
reverse_heap1, reverse_heap1,
&middle_node, &middle_node,
&upper_bound_to_shortest_path_distance, &upper_bound_to_shortest_path_distance,
@ -140,7 +142,8 @@ class AlternativeRouting final
} }
if (0 < reverse_heap1.Size()) if (0 < reverse_heap1.Size())
{ {
AlternativeRoutingStep<false>(forward_heap1, AlternativeRoutingStep<false>(facade,
forward_heap1,
reverse_heap1, reverse_heap1,
&middle_node, &middle_node,
&upper_bound_to_shortest_path_distance, &upper_bound_to_shortest_path_distance,
@ -286,7 +289,8 @@ class AlternativeRouting final
for (const NodeID node : preselected_node_list) for (const NodeID node : preselected_node_list)
{ {
int length_of_via_path = 0, sharing_of_via_path = 0; int length_of_via_path = 0, sharing_of_via_path = 0;
ComputeLengthAndSharingOfViaPath(node, ComputeLengthAndSharingOfViaPath(facade,
node,
&length_of_via_path, &length_of_via_path,
&sharing_of_via_path, &sharing_of_via_path,
packed_shortest_path, packed_shortest_path,
@ -306,7 +310,8 @@ class AlternativeRouting final
NodeID s_v_middle = SPECIAL_NODEID, v_t_middle = SPECIAL_NODEID; NodeID s_v_middle = SPECIAL_NODEID, v_t_middle = SPECIAL_NODEID;
for (const RankedCandidateNode &candidate : ranked_candidates_list) for (const RankedCandidateNode &candidate : ranked_candidates_list)
{ {
if (ViaNodeCandidatePassesTTest(forward_heap1, if (ViaNodeCandidatePassesTTest(facade,
forward_heap1,
reverse_heap1, reverse_heap1,
forward_heap2, forward_heap2,
reverse_heap2, reverse_heap2,
@ -336,6 +341,7 @@ class AlternativeRouting final
phantom_node_pair.target_phantom.forward_segment_id.id)); phantom_node_pair.target_phantom.forward_segment_id.id));
super::UnpackPath( super::UnpackPath(
facade,
// -- packed input // -- packed input
packed_shortest_path.begin(), packed_shortest_path.begin(),
packed_shortest_path.end(), packed_shortest_path.end(),
@ -366,7 +372,8 @@ class AlternativeRouting final
phantom_node_pair.target_phantom.forward_segment_id.id)); phantom_node_pair.target_phantom.forward_segment_id.id));
// unpack the alternate path // unpack the alternate path
super::UnpackPath(packed_alternate_path.begin(), super::UnpackPath(facade,
packed_alternate_path.begin(),
packed_alternate_path.end(), packed_alternate_path.end(),
phantom_node_pair, phantom_node_pair,
raw_route_data.unpacked_alternative); raw_route_data.unpacked_alternative);
@ -405,14 +412,15 @@ class AlternativeRouting final
// compute and unpack <s,..,v> and <v,..,t> by exploring search spaces // compute and unpack <s,..,v> and <v,..,t> by exploring search spaces
// from v and intersecting against queues. only half-searches have to be // from v and intersecting against queues. only half-searches have to be
// done at this stage // done at this stage
void ComputeLengthAndSharingOfViaPath(const NodeID via_node, void ComputeLengthAndSharingOfViaPath(const DataFacadeT& facade,
const NodeID via_node,
int *real_length_of_via_path, int *real_length_of_via_path,
int *sharing_of_via_path, int *sharing_of_via_path,
const std::vector<NodeID> &packed_shortest_path, const std::vector<NodeID> &packed_shortest_path,
const EdgeWeight min_edge_offset) const EdgeWeight min_edge_offset)
{ {
engine_working_data.InitializeOrClearSecondThreadLocalStorage( engine_working_data.InitializeOrClearSecondThreadLocalStorage(
super::facade->GetNumberOfNodes()); facade.GetNumberOfNodes());
QueryHeap &existing_forward_heap = *engine_working_data.forward_heap_1; QueryHeap &existing_forward_heap = *engine_working_data.forward_heap_1;
QueryHeap &existing_reverse_heap = *engine_working_data.reverse_heap_1; QueryHeap &existing_reverse_heap = *engine_working_data.reverse_heap_1;
@ -433,7 +441,8 @@ class AlternativeRouting final
const bool constexpr DO_NOT_FORCE_LOOPS = false; const bool constexpr DO_NOT_FORCE_LOOPS = false;
while (!new_reverse_heap.Empty()) while (!new_reverse_heap.Empty())
{ {
super::RoutingStep(new_reverse_heap, super::RoutingStep(facade,
new_reverse_heap,
existing_forward_heap, existing_forward_heap,
s_v_middle, s_v_middle,
upper_bound_s_v_path_length, upper_bound_s_v_path_length,
@ -449,7 +458,8 @@ class AlternativeRouting final
new_forward_heap.Insert(via_node, 0, via_node); new_forward_heap.Insert(via_node, 0, via_node);
while (!new_forward_heap.Empty()) while (!new_forward_heap.Empty())
{ {
super::RoutingStep(new_forward_heap, super::RoutingStep(facade,
new_forward_heap,
existing_reverse_heap, existing_reverse_heap,
v_t_middle, v_t_middle,
upper_bound_of_v_t_path_length, upper_bound_of_v_t_path_length,
@ -481,18 +491,20 @@ class AlternativeRouting final
if (packed_s_v_path[current_node] == packed_shortest_path[current_node] && if (packed_s_v_path[current_node] == packed_shortest_path[current_node] &&
packed_s_v_path[current_node + 1] == packed_shortest_path[current_node + 1]) packed_s_v_path[current_node + 1] == packed_shortest_path[current_node + 1])
{ {
EdgeID edgeID = facade->FindEdgeInEitherDirection( EdgeID edgeID = facade.FindEdgeInEitherDirection(
packed_s_v_path[current_node], packed_s_v_path[current_node + 1]); packed_s_v_path[current_node], packed_s_v_path[current_node + 1]);
*sharing_of_via_path += facade->GetEdgeData(edgeID).distance; *sharing_of_via_path += facade.GetEdgeData(edgeID).distance;
} }
else else
{ {
if (packed_s_v_path[current_node] == packed_shortest_path[current_node]) if (packed_s_v_path[current_node] == packed_shortest_path[current_node])
{ {
super::UnpackEdge(packed_s_v_path[current_node], super::UnpackEdge(facade,
packed_s_v_path[current_node],
packed_s_v_path[current_node + 1], packed_s_v_path[current_node + 1],
partially_unpacked_via_path); partially_unpacked_via_path);
super::UnpackEdge(packed_shortest_path[current_node], super::UnpackEdge(facade,
packed_shortest_path[current_node],
packed_shortest_path[current_node + 1], packed_shortest_path[current_node + 1],
partially_unpacked_shortest_path); partially_unpacked_shortest_path);
break; break;
@ -512,9 +524,9 @@ class AlternativeRouting final
++current_node) ++current_node)
{ {
EdgeID selected_edge = EdgeID selected_edge =
facade->FindEdgeInEitherDirection(partially_unpacked_via_path[current_node], facade.FindEdgeInEitherDirection(partially_unpacked_via_path[current_node],
partially_unpacked_via_path[current_node + 1]); partially_unpacked_via_path[current_node + 1]);
*sharing_of_via_path += facade->GetEdgeData(selected_edge).distance; *sharing_of_via_path += facade.GetEdgeData(selected_edge).distance;
} }
// Second, partially unpack v-->t in reverse order until paths deviate and note lengths // Second, partially unpack v-->t in reverse order until paths deviate and note lengths
@ -527,18 +539,20 @@ class AlternativeRouting final
packed_shortest_path[shortest_path_index - 1] && packed_shortest_path[shortest_path_index - 1] &&
packed_v_t_path[via_path_index] == packed_shortest_path[shortest_path_index]) packed_v_t_path[via_path_index] == packed_shortest_path[shortest_path_index])
{ {
EdgeID edgeID = facade->FindEdgeInEitherDirection( EdgeID edgeID = facade.FindEdgeInEitherDirection(
packed_v_t_path[via_path_index - 1], packed_v_t_path[via_path_index]); packed_v_t_path[via_path_index - 1], packed_v_t_path[via_path_index]);
*sharing_of_via_path += facade->GetEdgeData(edgeID).distance; *sharing_of_via_path += facade.GetEdgeData(edgeID).distance;
} }
else else
{ {
if (packed_v_t_path[via_path_index] == packed_shortest_path[shortest_path_index]) if (packed_v_t_path[via_path_index] == packed_shortest_path[shortest_path_index])
{ {
super::UnpackEdge(packed_v_t_path[via_path_index - 1], super::UnpackEdge(facade,
packed_v_t_path[via_path_index - 1],
packed_v_t_path[via_path_index], packed_v_t_path[via_path_index],
partially_unpacked_via_path); partially_unpacked_via_path);
super::UnpackEdge(packed_shortest_path[shortest_path_index - 1], super::UnpackEdge(facade,
packed_shortest_path[shortest_path_index - 1],
packed_shortest_path[shortest_path_index], packed_shortest_path[shortest_path_index],
partially_unpacked_shortest_path); partially_unpacked_shortest_path);
break; break;
@ -556,10 +570,10 @@ class AlternativeRouting final
partially_unpacked_via_path[via_path_index] == partially_unpacked_via_path[via_path_index] ==
partially_unpacked_shortest_path[shortest_path_index]) partially_unpacked_shortest_path[shortest_path_index])
{ {
EdgeID edgeID = facade->FindEdgeInEitherDirection( EdgeID edgeID = facade.FindEdgeInEitherDirection(
partially_unpacked_via_path[via_path_index - 1], partially_unpacked_via_path[via_path_index - 1],
partially_unpacked_via_path[via_path_index]); partially_unpacked_via_path[via_path_index]);
*sharing_of_via_path += facade->GetEdgeData(edgeID).distance; *sharing_of_via_path += facade.GetEdgeData(edgeID).distance;
} }
else else
{ {
@ -617,7 +631,8 @@ class AlternativeRouting final
// todo: reorder parameters // todo: reorder parameters
template <bool is_forward_directed> template <bool is_forward_directed>
void AlternativeRoutingStep(QueryHeap &heap1, void AlternativeRoutingStep(const DataFacadeT &facade,
QueryHeap &heap1,
QueryHeap &heap2, QueryHeap &heap2,
NodeID *middle_node, NodeID *middle_node,
int *upper_bound_to_shortest_path_distance, int *upper_bound_to_shortest_path_distance,
@ -667,7 +682,7 @@ class AlternativeRouting final
else else
{ {
// check whether there is a loop present at the node // check whether there is a loop present at the node
const auto loop_distance = super::GetLoopWeight(node); const auto loop_distance = super::GetLoopWeight(facade, node);
const int new_distance_with_loop = new_distance + loop_distance; const int new_distance_with_loop = new_distance + loop_distance;
if (loop_distance != INVALID_EDGE_WEIGHT && if (loop_distance != INVALID_EDGE_WEIGHT &&
new_distance_with_loop <= *upper_bound_to_shortest_path_distance) new_distance_with_loop <= *upper_bound_to_shortest_path_distance)
@ -679,15 +694,15 @@ class AlternativeRouting final
} }
} }
for (auto edge : facade->GetAdjacentEdgeRange(node)) for (auto edge : facade.GetAdjacentEdgeRange(node))
{ {
const EdgeData &data = facade->GetEdgeData(edge); const EdgeData &data = facade.GetEdgeData(edge);
const bool edge_is_forward_directed = const bool edge_is_forward_directed =
(is_forward_directed ? data.forward : data.backward); (is_forward_directed ? data.forward : data.backward);
if (edge_is_forward_directed) if (edge_is_forward_directed)
{ {
const NodeID to = facade->GetTarget(edge); const NodeID to = facade.GetTarget(edge);
const int edge_weight = data.distance; const int edge_weight = data.distance;
BOOST_ASSERT(edge_weight > 0); BOOST_ASSERT(edge_weight > 0);
@ -711,7 +726,8 @@ class AlternativeRouting final
} }
// conduct T-Test // conduct T-Test
bool ViaNodeCandidatePassesTTest(QueryHeap &existing_forward_heap, bool ViaNodeCandidatePassesTTest(const DataFacadeT &facade,
QueryHeap &existing_forward_heap,
QueryHeap &existing_reverse_heap, QueryHeap &existing_reverse_heap,
QueryHeap &new_forward_heap, QueryHeap &new_forward_heap,
QueryHeap &new_reverse_heap, QueryHeap &new_reverse_heap,
@ -735,7 +751,8 @@ class AlternativeRouting final
const bool constexpr DO_NOT_FORCE_LOOPS = false; const bool constexpr DO_NOT_FORCE_LOOPS = false;
while (new_reverse_heap.Size() > 0) while (new_reverse_heap.Size() > 0)
{ {
super::RoutingStep(new_reverse_heap, super::RoutingStep(facade,
new_reverse_heap,
existing_forward_heap, existing_forward_heap,
*s_v_middle, *s_v_middle,
upper_bound_s_v_path_length, upper_bound_s_v_path_length,
@ -757,7 +774,8 @@ class AlternativeRouting final
new_forward_heap.Insert(candidate.node, 0, candidate.node); new_forward_heap.Insert(candidate.node, 0, candidate.node);
while (new_forward_heap.Size() > 0) while (new_forward_heap.Size() > 0)
{ {
super::RoutingStep(new_forward_heap, super::RoutingStep(facade,
new_forward_heap,
existing_reverse_heap, existing_reverse_heap,
*v_t_middle, *v_t_middle,
upper_bound_of_v_t_path_length, upper_bound_of_v_t_path_length,
@ -800,8 +818,8 @@ class AlternativeRouting final
for (std::size_t i = packed_s_v_path.size() - 1; (i > 0) && unpack_stack.empty(); --i) for (std::size_t i = packed_s_v_path.size() - 1; (i > 0) && unpack_stack.empty(); --i)
{ {
const EdgeID current_edge_id = const EdgeID current_edge_id =
facade->FindEdgeInEitherDirection(packed_s_v_path[i - 1], packed_s_v_path[i]); facade.FindEdgeInEitherDirection(packed_s_v_path[i - 1], packed_s_v_path[i]);
const int length_of_current_edge = facade->GetEdgeData(current_edge_id).distance; const int length_of_current_edge = facade.GetEdgeData(current_edge_id).distance;
if ((length_of_current_edge + unpacked_until_distance) >= T_threshold) if ((length_of_current_edge + unpacked_until_distance) >= T_threshold)
{ {
unpack_stack.emplace(packed_s_v_path[i - 1], packed_s_v_path[i]); unpack_stack.emplace(packed_s_v_path[i - 1], packed_s_v_path[i]);
@ -818,22 +836,22 @@ class AlternativeRouting final
const SearchSpaceEdge via_path_edge = unpack_stack.top(); const SearchSpaceEdge via_path_edge = unpack_stack.top();
unpack_stack.pop(); unpack_stack.pop();
EdgeID edge_in_via_path_id = EdgeID edge_in_via_path_id =
facade->FindEdgeInEitherDirection(via_path_edge.first, via_path_edge.second); facade.FindEdgeInEitherDirection(via_path_edge.first, via_path_edge.second);
if (SPECIAL_EDGEID == edge_in_via_path_id) if (SPECIAL_EDGEID == edge_in_via_path_id)
{ {
return false; return false;
} }
const EdgeData &current_edge_data = facade->GetEdgeData(edge_in_via_path_id); const EdgeData &current_edge_data = facade.GetEdgeData(edge_in_via_path_id);
const bool current_edge_is_shortcut = current_edge_data.shortcut; const bool current_edge_is_shortcut = current_edge_data.shortcut;
if (current_edge_is_shortcut) if (current_edge_is_shortcut)
{ {
const NodeID via_path_middle_node_id = current_edge_data.id; const NodeID via_path_middle_node_id = current_edge_data.id;
const EdgeID second_segment_edge_id = facade->FindEdgeInEitherDirection( const EdgeID second_segment_edge_id = facade.FindEdgeInEitherDirection(
via_path_middle_node_id, via_path_edge.second); via_path_middle_node_id, via_path_edge.second);
const int second_segment_length = const int second_segment_length =
facade->GetEdgeData(second_segment_edge_id).distance; facade.GetEdgeData(second_segment_edge_id).distance;
// attention: !unpacking in reverse! // attention: !unpacking in reverse!
// Check if second segment is the one to go over treshold? if yes add second segment // Check if second segment is the one to go over treshold? if yes add second segment
// to stack, else push first segment to stack and add distance of second one. // to stack, else push first segment to stack and add distance of second one.
@ -864,8 +882,8 @@ class AlternativeRouting final
++i) ++i)
{ {
const EdgeID edgeID = const EdgeID edgeID =
facade->FindEdgeInEitherDirection(packed_v_t_path[i], packed_v_t_path[i + 1]); facade.FindEdgeInEitherDirection(packed_v_t_path[i], packed_v_t_path[i + 1]);
int length_of_current_edge = facade->GetEdgeData(edgeID).distance; int length_of_current_edge = facade.GetEdgeData(edgeID).distance;
if (length_of_current_edge + unpacked_until_distance >= T_threshold) if (length_of_current_edge + unpacked_until_distance >= T_threshold)
{ {
unpack_stack.emplace(packed_v_t_path[i], packed_v_t_path[i + 1]); unpack_stack.emplace(packed_v_t_path[i], packed_v_t_path[i + 1]);
@ -882,20 +900,20 @@ class AlternativeRouting final
const SearchSpaceEdge via_path_edge = unpack_stack.top(); const SearchSpaceEdge via_path_edge = unpack_stack.top();
unpack_stack.pop(); unpack_stack.pop();
EdgeID edge_in_via_path_id = EdgeID edge_in_via_path_id =
facade->FindEdgeInEitherDirection(via_path_edge.first, via_path_edge.second); facade.FindEdgeInEitherDirection(via_path_edge.first, via_path_edge.second);
if (SPECIAL_EDGEID == edge_in_via_path_id) if (SPECIAL_EDGEID == edge_in_via_path_id)
{ {
return false; return false;
} }
const EdgeData &current_edge_data = facade->GetEdgeData(edge_in_via_path_id); const EdgeData &current_edge_data = facade.GetEdgeData(edge_in_via_path_id);
const bool IsViaEdgeShortCut = current_edge_data.shortcut; const bool IsViaEdgeShortCut = current_edge_data.shortcut;
if (IsViaEdgeShortCut) if (IsViaEdgeShortCut)
{ {
const NodeID middleOfViaPath = current_edge_data.id; const NodeID middleOfViaPath = current_edge_data.id;
EdgeID edgeIDOfFirstSegment = EdgeID edgeIDOfFirstSegment =
facade->FindEdgeInEitherDirection(via_path_edge.first, middleOfViaPath); facade.FindEdgeInEitherDirection(via_path_edge.first, middleOfViaPath);
int lengthOfFirstSegment = facade->GetEdgeData(edgeIDOfFirstSegment).distance; int lengthOfFirstSegment = facade.GetEdgeData(edgeIDOfFirstSegment).distance;
// Check if first segment is the one to go over treshold? if yes first segment to // Check if first segment is the one to go over treshold? if yes first segment to
// stack, else push second segment to stack and add distance of first one. // stack, else push second segment to stack and add distance of first one.
if (unpacked_until_distance + lengthOfFirstSegment >= T_threshold) if (unpacked_until_distance + lengthOfFirstSegment >= T_threshold)
@ -919,7 +937,7 @@ class AlternativeRouting final
t_test_path_length += unpacked_until_distance; t_test_path_length += unpacked_until_distance;
// Run actual T-Test query and compare if distances equal. // Run actual T-Test query and compare if distances equal.
engine_working_data.InitializeOrClearThirdThreadLocalStorage( engine_working_data.InitializeOrClearThirdThreadLocalStorage(
super::facade->GetNumberOfNodes()); facade.GetNumberOfNodes());
QueryHeap &forward_heap3 = *engine_working_data.forward_heap_3; QueryHeap &forward_heap3 = *engine_working_data.forward_heap_3;
QueryHeap &reverse_heap3 = *engine_working_data.reverse_heap_3; QueryHeap &reverse_heap3 = *engine_working_data.reverse_heap_3;
@ -933,7 +951,8 @@ class AlternativeRouting final
{ {
if (!forward_heap3.Empty()) if (!forward_heap3.Empty())
{ {
super::RoutingStep(forward_heap3, super::RoutingStep(facade,
forward_heap3,
reverse_heap3, reverse_heap3,
middle, middle,
upper_bound, upper_bound,
@ -945,7 +964,8 @@ class AlternativeRouting final
} }
if (!reverse_heap3.Empty()) if (!reverse_heap3.Empty())
{ {
super::RoutingStep(reverse_heap3, super::RoutingStep(facade,
reverse_heap3,
forward_heap3, forward_heap3,
middle, middle,
upper_bound, upper_bound,

View File

@ -32,14 +32,15 @@ class DirectShortestPathRouting final
SearchEngineData &engine_working_data; SearchEngineData &engine_working_data;
public: public:
DirectShortestPathRouting(DataFacadeT *facade, SearchEngineData &engine_working_data) DirectShortestPathRouting(SearchEngineData &engine_working_data)
: super(facade), engine_working_data(engine_working_data) : engine_working_data(engine_working_data)
{ {
} }
~DirectShortestPathRouting() {} ~DirectShortestPathRouting() {}
void operator()(const std::vector<PhantomNodes> &phantom_nodes_vector, void operator()(const DataFacadeT& facade,
const std::vector<PhantomNodes> &phantom_nodes_vector,
InternalRouteResult &raw_route_data) const InternalRouteResult &raw_route_data) const
{ {
// Get distance to next pair of target nodes. // Get distance to next pair of target nodes.
@ -51,7 +52,7 @@ class DirectShortestPathRouting final
const auto &target_phantom = phantom_node_pair.target_phantom; const auto &target_phantom = phantom_node_pair.target_phantom;
engine_working_data.InitializeOrClearFirstThreadLocalStorage( engine_working_data.InitializeOrClearFirstThreadLocalStorage(
super::facade->GetNumberOfNodes()); facade.GetNumberOfNodes());
QueryHeap &forward_heap = *(engine_working_data.forward_heap_1); QueryHeap &forward_heap = *(engine_working_data.forward_heap_1);
QueryHeap &reverse_heap = *(engine_working_data.reverse_heap_1); QueryHeap &reverse_heap = *(engine_working_data.reverse_heap_1);
forward_heap.Clear(); forward_heap.Clear();
@ -93,16 +94,17 @@ class DirectShortestPathRouting final
const bool constexpr DO_NOT_FORCE_LOOPS = const bool constexpr DO_NOT_FORCE_LOOPS =
false; // prevents forcing of loops, since offsets are set correctly false; // prevents forcing of loops, since offsets are set correctly
if (super::facade->GetCoreSize() > 0) if (facade.GetCoreSize() > 0)
{ {
engine_working_data.InitializeOrClearSecondThreadLocalStorage( engine_working_data.InitializeOrClearSecondThreadLocalStorage(
super::facade->GetNumberOfNodes()); facade.GetNumberOfNodes());
QueryHeap &forward_core_heap = *(engine_working_data.forward_heap_2); QueryHeap &forward_core_heap = *(engine_working_data.forward_heap_2);
QueryHeap &reverse_core_heap = *(engine_working_data.reverse_heap_2); QueryHeap &reverse_core_heap = *(engine_working_data.reverse_heap_2);
forward_core_heap.Clear(); forward_core_heap.Clear();
reverse_core_heap.Clear(); reverse_core_heap.Clear();
super::SearchWithCore(forward_heap, super::SearchWithCore(facade,
forward_heap,
reverse_heap, reverse_heap,
forward_core_heap, forward_core_heap,
reverse_core_heap, reverse_core_heap,
@ -113,7 +115,8 @@ class DirectShortestPathRouting final
} }
else else
{ {
super::Search(forward_heap, super::Search(facade,
forward_heap,
reverse_heap, reverse_heap,
distance, distance,
packed_leg, packed_leg,
@ -138,7 +141,8 @@ class DirectShortestPathRouting final
raw_route_data.target_traversed_in_reverse.push_back( raw_route_data.target_traversed_in_reverse.push_back(
(packed_leg.back() != phantom_node_pair.target_phantom.forward_segment_id.id)); (packed_leg.back() != phantom_node_pair.target_phantom.forward_segment_id.id));
super::UnpackPath(packed_leg.begin(), super::UnpackPath(facade,
packed_leg.begin(),
packed_leg.end(), packed_leg.end(),
phantom_node_pair, phantom_node_pair,
raw_route_data.unpacked_path_segments.front()); raw_route_data.unpacked_path_segments.front());

View File

@ -41,12 +41,13 @@ class ManyToManyRouting final
using SearchSpaceWithBuckets = std::unordered_map<NodeID, std::vector<NodeBucket>>; using SearchSpaceWithBuckets = std::unordered_map<NodeID, std::vector<NodeBucket>>;
public: public:
ManyToManyRouting(DataFacadeT *facade, SearchEngineData &engine_working_data) ManyToManyRouting(SearchEngineData &engine_working_data)
: super(facade), engine_working_data(engine_working_data) : engine_working_data(engine_working_data)
{ {
} }
std::vector<EdgeWeight> operator()(const std::vector<PhantomNode> &phantom_nodes, std::vector<EdgeWeight> operator()(const DataFacadeT& facade,
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
{ {
@ -59,7 +60,7 @@ class ManyToManyRouting final
std::numeric_limits<EdgeWeight>::max()); std::numeric_limits<EdgeWeight>::max());
engine_working_data.InitializeOrClearFirstThreadLocalStorage( engine_working_data.InitializeOrClearFirstThreadLocalStorage(
super::facade->GetNumberOfNodes()); facade.GetNumberOfNodes());
QueryHeap &query_heap = *(engine_working_data.forward_heap_1); QueryHeap &query_heap = *(engine_working_data.forward_heap_1);
@ -86,7 +87,7 @@ class ManyToManyRouting final
// explore search space // explore search space
while (!query_heap.Empty()) while (!query_heap.Empty())
{ {
BackwardRoutingStep(column_idx, query_heap, search_space_with_buckets); BackwardRoutingStep(facade, column_idx, query_heap, search_space_with_buckets);
} }
++column_idx; ++column_idx;
}; };
@ -113,7 +114,8 @@ class ManyToManyRouting final
// explore search space // explore search space
while (!query_heap.Empty()) while (!query_heap.Empty())
{ {
ForwardRoutingStep(row_idx, ForwardRoutingStep(facade,
row_idx,
number_of_targets, number_of_targets,
query_heap, query_heap,
search_space_with_buckets, search_space_with_buckets,
@ -157,7 +159,8 @@ class ManyToManyRouting final
return result_table; return result_table;
} }
void ForwardRoutingStep(const unsigned row_idx, void ForwardRoutingStep(const DataFacadeT &facade,
const unsigned row_idx,
const unsigned number_of_targets, const unsigned number_of_targets,
QueryHeap &query_heap, QueryHeap &query_heap,
const SearchSpaceWithBuckets &search_space_with_buckets, const SearchSpaceWithBuckets &search_space_with_buckets,
@ -182,7 +185,7 @@ class ManyToManyRouting final
const EdgeWeight new_distance = source_distance + target_distance; const EdgeWeight new_distance = source_distance + target_distance;
if (new_distance < 0) if (new_distance < 0)
{ {
const EdgeWeight loop_weight = super::GetLoopWeight(node); const EdgeWeight loop_weight = super::GetLoopWeight(facade, node);
const int new_distance_with_loop = new_distance + loop_weight; const int new_distance_with_loop = new_distance + loop_weight;
if (loop_weight != INVALID_EDGE_WEIGHT && new_distance_with_loop >= 0) if (loop_weight != INVALID_EDGE_WEIGHT && new_distance_with_loop >= 0)
{ {
@ -195,14 +198,15 @@ class ManyToManyRouting final
} }
} }
} }
if (StallAtNode<true>(node, source_distance, query_heap)) if (StallAtNode<true>(facade, node, source_distance, query_heap))
{ {
return; return;
} }
RelaxOutgoingEdges<true>(node, source_distance, query_heap); RelaxOutgoingEdges<true>(facade, node, source_distance, query_heap);
} }
void BackwardRoutingStep(const unsigned column_idx, void BackwardRoutingStep(const DataFacadeT &facade,
const unsigned column_idx,
QueryHeap &query_heap, QueryHeap &query_heap,
SearchSpaceWithBuckets &search_space_with_buckets) const SearchSpaceWithBuckets &search_space_with_buckets) const
{ {
@ -212,25 +216,27 @@ class ManyToManyRouting final
// store settled nodes in search space bucket // store settled nodes in search space bucket
search_space_with_buckets[node].emplace_back(column_idx, target_distance); search_space_with_buckets[node].emplace_back(column_idx, target_distance);
if (StallAtNode<false>(node, target_distance, query_heap)) if (StallAtNode<false>(facade, node, target_distance, query_heap))
{ {
return; return;
} }
RelaxOutgoingEdges<false>(node, target_distance, query_heap); RelaxOutgoingEdges<false>(facade, node, target_distance, query_heap);
} }
template <bool forward_direction> template <bool forward_direction>
inline void inline void RelaxOutgoingEdges(const DataFacadeT &facade,
RelaxOutgoingEdges(const NodeID node, const EdgeWeight distance, QueryHeap &query_heap) const const NodeID node,
const EdgeWeight distance,
QueryHeap &query_heap) const
{ {
for (auto edge : super::facade->GetAdjacentEdgeRange(node)) for (auto edge : facade.GetAdjacentEdgeRange(node))
{ {
const auto &data = super::facade->GetEdgeData(edge); const auto &data = facade.GetEdgeData(edge);
const bool direction_flag = (forward_direction ? data.forward : data.backward); const bool direction_flag = (forward_direction ? data.forward : data.backward);
if (direction_flag) if (direction_flag)
{ {
const NodeID to = super::facade->GetTarget(edge); const NodeID to = facade.GetTarget(edge);
const int edge_weight = data.distance; const int edge_weight = data.distance;
BOOST_ASSERT_MSG(edge_weight > 0, "edge_weight invalid"); BOOST_ASSERT_MSG(edge_weight > 0, "edge_weight invalid");
@ -254,16 +260,18 @@ class ManyToManyRouting final
// Stalling // Stalling
template <bool forward_direction> template <bool forward_direction>
inline bool inline bool StallAtNode(const DataFacadeT &facade,
StallAtNode(const NodeID node, const EdgeWeight distance, QueryHeap &query_heap) const const NodeID node,
const EdgeWeight distance,
QueryHeap &query_heap) const
{ {
for (auto edge : super::facade->GetAdjacentEdgeRange(node)) for (auto edge : facade.GetAdjacentEdgeRange(node))
{ {
const auto &data = super::facade->GetEdgeData(edge); const auto &data = facade.GetEdgeData(edge);
const bool reverse_flag = ((!forward_direction) ? data.forward : data.backward); const bool reverse_flag = ((!forward_direction) ? data.forward : data.backward);
if (reverse_flag) if (reverse_flag)
{ {
const NodeID to = super::facade->GetTarget(edge); const NodeID to = facade.GetTarget(edge);
const int edge_weight = data.distance; const int edge_weight = data.distance;
BOOST_ASSERT_MSG(edge_weight > 0, "edge_weight invalid"); BOOST_ASSERT_MSG(edge_weight > 0, "edge_weight invalid");
if (query_heap.WasInserted(to)) if (query_heap.WasInserted(to))

View File

@ -63,17 +63,17 @@ class MapMatching final : public BasicRoutingInterface<DataFacadeT, MapMatching<
} }
public: public:
MapMatching(DataFacadeT *facade, MapMatching(SearchEngineData &engine_working_data,
SearchEngineData &engine_working_data,
const double default_gps_precision) const double default_gps_precision)
: super(facade), engine_working_data(engine_working_data), : engine_working_data(engine_working_data),
default_emission_log_probability(default_gps_precision), default_emission_log_probability(default_gps_precision),
transition_log_probability(MATCHING_BETA) transition_log_probability(MATCHING_BETA)
{ {
} }
SubMatchingList SubMatchingList
operator()(const CandidateLists &candidates_list, operator()(const DataFacadeT &facade,
const CandidateLists &candidates_list,
const std::vector<util::Coordinate> &trace_coordinates, const std::vector<util::Coordinate> &trace_coordinates,
const std::vector<unsigned> &trace_timestamps, const std::vector<unsigned> &trace_timestamps,
const std::vector<boost::optional<double>> &trace_gps_precision) const const std::vector<boost::optional<double>> &trace_gps_precision) const
@ -159,9 +159,9 @@ class MapMatching final : public BasicRoutingInterface<DataFacadeT, MapMatching<
} }
engine_working_data.InitializeOrClearFirstThreadLocalStorage( engine_working_data.InitializeOrClearFirstThreadLocalStorage(
super::facade->GetNumberOfNodes()); facade.GetNumberOfNodes());
engine_working_data.InitializeOrClearSecondThreadLocalStorage( engine_working_data.InitializeOrClearSecondThreadLocalStorage(
super::facade->GetNumberOfNodes()); facade.GetNumberOfNodes());
QueryHeap &forward_heap = *(engine_working_data.forward_heap_1); QueryHeap &forward_heap = *(engine_working_data.forward_heap_1);
QueryHeap &reverse_heap = *(engine_working_data.reverse_heap_1); QueryHeap &reverse_heap = *(engine_working_data.reverse_heap_1);
@ -261,11 +261,12 @@ class MapMatching final : public BasicRoutingInterface<DataFacadeT, MapMatching<
reverse_heap.Clear(); reverse_heap.Clear();
double network_distance; double network_distance;
if (super::facade->GetCoreSize() > 0) if (facade.GetCoreSize() > 0)
{ {
forward_core_heap.Clear(); forward_core_heap.Clear();
reverse_core_heap.Clear(); reverse_core_heap.Clear();
network_distance = super::GetNetworkDistanceWithCore( network_distance = super::GetNetworkDistanceWithCore(
facade,
forward_heap, forward_heap,
reverse_heap, reverse_heap,
forward_core_heap, forward_core_heap,
@ -277,6 +278,7 @@ class MapMatching final : public BasicRoutingInterface<DataFacadeT, MapMatching<
else else
{ {
network_distance = super::GetNetworkDistance( network_distance = super::GetNetworkDistance(
facade,
forward_heap, forward_heap,
reverse_heap, reverse_heap,
prev_unbroken_timestamps_list[s].phantom_node, prev_unbroken_timestamps_list[s].phantom_node,

View File

@ -2,9 +2,9 @@
#define ROUTING_BASE_HPP #define ROUTING_BASE_HPP
#include "extractor/guidance/turn_instruction.hpp" #include "extractor/guidance/turn_instruction.hpp"
#include "engine/edge_unpacker.hpp"
#include "engine/internal_route_result.hpp" #include "engine/internal_route_result.hpp"
#include "engine/search_engine_data.hpp" #include "engine/search_engine_data.hpp"
#include "engine/edge_unpacker.hpp"
#include "util/coordinate_calculation.hpp" #include "util/coordinate_calculation.hpp"
#include "util/typedefs.hpp" #include "util/typedefs.hpp"
@ -33,16 +33,7 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
private: private:
using EdgeData = typename DataFacadeT::EdgeData; using EdgeData = typename DataFacadeT::EdgeData;
protected:
DataFacadeT *facade;
public: public:
explicit BasicRoutingInterface(DataFacadeT *facade) : facade(facade) {}
~BasicRoutingInterface() {}
BasicRoutingInterface(const BasicRoutingInterface &) = delete;
BasicRoutingInterface &operator=(const BasicRoutingInterface &) = delete;
/* /*
min_edge_offset is needed in case we use multiple min_edge_offset is needed in case we use multiple
nodes as start/target nodes with different (even negative) offsets. nodes as start/target nodes with different (even negative) offsets.
@ -72,7 +63,8 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
Since we are dealing with a graph that contains _negative_ edges, Since we are dealing with a graph that contains _negative_ edges,
we need to add an offset to the termination criterion. we need to add an offset to the termination criterion.
*/ */
void RoutingStep(SearchEngineData::QueryHeap &forward_heap, void RoutingStep(const DataFacadeT &facade,
SearchEngineData::QueryHeap &forward_heap,
SearchEngineData::QueryHeap &reverse_heap, SearchEngineData::QueryHeap &reverse_heap,
NodeID &middle_node_id, NodeID &middle_node_id,
std::int32_t &upper_bound, std::int32_t &upper_bound,
@ -98,14 +90,14 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
new_distance < 0) new_distance < 0)
{ {
// check whether there is a loop present at the node // check whether there is a loop present at the node
for (const auto edge : facade->GetAdjacentEdgeRange(node)) for (const auto edge : facade.GetAdjacentEdgeRange(node))
{ {
const EdgeData &data = facade->GetEdgeData(edge); const EdgeData &data = facade.GetEdgeData(edge);
bool forward_directionFlag = bool forward_directionFlag =
(forward_direction ? data.forward : data.backward); (forward_direction ? data.forward : data.backward);
if (forward_directionFlag) if (forward_directionFlag)
{ {
const NodeID to = facade->GetTarget(edge); const NodeID to = facade.GetTarget(edge);
if (to == node) if (to == node)
{ {
const EdgeWeight edge_weight = data.distance; const EdgeWeight edge_weight = data.distance;
@ -141,13 +133,13 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
// Stalling // Stalling
if (stalling) if (stalling)
{ {
for (const auto edge : facade->GetAdjacentEdgeRange(node)) for (const auto edge : facade.GetAdjacentEdgeRange(node))
{ {
const EdgeData &data = facade->GetEdgeData(edge); const EdgeData &data = facade.GetEdgeData(edge);
const bool reverse_flag = ((!forward_direction) ? data.forward : data.backward); const bool reverse_flag = ((!forward_direction) ? data.forward : data.backward);
if (reverse_flag) if (reverse_flag)
{ {
const NodeID to = facade->GetTarget(edge); const NodeID to = facade.GetTarget(edge);
const EdgeWeight edge_weight = data.distance; const EdgeWeight edge_weight = data.distance;
BOOST_ASSERT_MSG(edge_weight > 0, "edge_weight invalid"); BOOST_ASSERT_MSG(edge_weight > 0, "edge_weight invalid");
@ -163,14 +155,14 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
} }
} }
for (const auto edge : facade->GetAdjacentEdgeRange(node)) for (const auto edge : facade.GetAdjacentEdgeRange(node))
{ {
const EdgeData &data = facade->GetEdgeData(edge); const EdgeData &data = facade.GetEdgeData(edge);
bool forward_directionFlag = (forward_direction ? data.forward : data.backward); bool forward_directionFlag = (forward_direction ? data.forward : data.backward);
if (forward_directionFlag) if (forward_directionFlag)
{ {
const NodeID to = facade->GetTarget(edge); const NodeID to = facade.GetTarget(edge);
const EdgeWeight edge_weight = data.distance; const EdgeWeight edge_weight = data.distance;
BOOST_ASSERT_MSG(edge_weight > 0, "edge_weight invalid"); BOOST_ASSERT_MSG(edge_weight > 0, "edge_weight invalid");
@ -192,15 +184,15 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
} }
} }
inline EdgeWeight GetLoopWeight(NodeID node) const inline EdgeWeight GetLoopWeight(const DataFacadeT &facade, NodeID node) const
{ {
EdgeWeight loop_weight = INVALID_EDGE_WEIGHT; EdgeWeight loop_weight = INVALID_EDGE_WEIGHT;
for (auto edge : facade->GetAdjacentEdgeRange(node)) for (auto edge : facade.GetAdjacentEdgeRange(node))
{ {
const auto &data = facade->GetEdgeData(edge); const auto &data = facade.GetEdgeData(edge);
if (data.forward) if (data.forward)
{ {
const NodeID to = facade->GetTarget(edge); const NodeID to = facade.GetTarget(edge);
if (to == node) if (to == node)
{ {
loop_weight = std::min(loop_weight, data.distance); loop_weight = std::min(loop_weight, data.distance);
@ -211,7 +203,8 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
} }
template <typename RandomIter> template <typename RandomIter>
void UnpackPath(RandomIter packed_path_begin, void UnpackPath(const DataFacadeT &facade,
RandomIter packed_path_begin,
RandomIter packed_path_end, RandomIter packed_path_end,
const PhantomNodes &phantom_node_pair, const PhantomNodes &phantom_node_pair,
std::vector<PathData> &unpacked_path) const std::vector<PathData> &unpacked_path) const
@ -230,10 +223,11 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
*std::prev(packed_path_end) == phantom_node_pair.target_phantom.reverse_segment_id.id); *std::prev(packed_path_end) == phantom_node_pair.target_phantom.reverse_segment_id.id);
UnpackCHPath( UnpackCHPath(
*facade, facade,
packed_path_begin, packed_path_begin,
packed_path_end, packed_path_end,
[this, [this,
&facade,
&unpacked_path, &unpacked_path,
&phantom_node_pair, &phantom_node_pair,
&start_traversed_in_reverse, &start_traversed_in_reverse,
@ -241,26 +235,27 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
const EdgeData &edge_data) { const EdgeData &edge_data) {
BOOST_ASSERT_MSG(!edge_data.shortcut, "original edge flagged as shortcut"); BOOST_ASSERT_MSG(!edge_data.shortcut, "original edge flagged as shortcut");
const auto name_index = facade->GetNameIndexFromEdgeID(edge_data.id); const auto name_index = facade.GetNameIndexFromEdgeID(edge_data.id);
const auto turn_instruction = facade->GetTurnInstructionForEdgeID(edge_data.id); const auto turn_instruction = facade.GetTurnInstructionForEdgeID(edge_data.id);
const extractor::TravelMode travel_mode = const extractor::TravelMode travel_mode =
(unpacked_path.empty() && start_traversed_in_reverse) (unpacked_path.empty() && start_traversed_in_reverse)
? phantom_node_pair.source_phantom.backward_travel_mode ? phantom_node_pair.source_phantom.backward_travel_mode
: facade->GetTravelModeForEdgeID(edge_data.id); : facade.GetTravelModeForEdgeID(edge_data.id);
const auto geometry_index = facade->GetGeometryIndexForEdgeID(edge_data.id); const auto geometry_index = facade.GetGeometryIndexForEdgeID(edge_data.id);
std::vector<NodeID> id_vector; std::vector<NodeID> id_vector;
facade->GetUncompressedGeometry(geometry_index, id_vector); facade.GetUncompressedGeometry(geometry_index, id_vector);
BOOST_ASSERT(id_vector.size() > 0); BOOST_ASSERT(id_vector.size() > 0);
std::vector<EdgeWeight> weight_vector; std::vector<EdgeWeight> weight_vector;
facade->GetUncompressedWeights(geometry_index, weight_vector); facade.GetUncompressedWeights(geometry_index, weight_vector);
BOOST_ASSERT(weight_vector.size() > 0); BOOST_ASSERT(weight_vector.size() > 0);
std::vector<DatasourceID> datasource_vector; std::vector<DatasourceID> datasource_vector;
facade->GetUncompressedDatasources(geometry_index, datasource_vector); facade.GetUncompressedDatasources(geometry_index, datasource_vector);
const auto total_weight = std::accumulate(weight_vector.begin(), weight_vector.end(), 0); const auto total_weight =
std::accumulate(weight_vector.begin(), weight_vector.end(), 0);
BOOST_ASSERT(weight_vector.size() == id_vector.size()); BOOST_ASSERT(weight_vector.size() == id_vector.size());
const bool is_first_segment = unpacked_path.empty(); const bool is_first_segment = unpacked_path.empty();
@ -289,10 +284,10 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
datasource_vector[i]}); datasource_vector[i]});
} }
BOOST_ASSERT(unpacked_path.size() > 0); BOOST_ASSERT(unpacked_path.size() > 0);
if (facade->hasLaneData(edge_data.id)) if (facade.hasLaneData(edge_data.id))
unpacked_path.back().lane_data = facade->GetLaneData(edge_data.id); unpacked_path.back().lane_data = facade.GetLaneData(edge_data.id);
unpacked_path.back().entry_classid = facade->GetEntryClassID(edge_data.id); unpacked_path.back().entry_classid = facade.GetEntryClassID(edge_data.id);
unpacked_path.back().turn_instruction = turn_instruction; unpacked_path.back().turn_instruction = turn_instruction;
unpacked_path.back().duration_until_turn += (edge_data.distance - total_weight); unpacked_path.back().duration_until_turn += (edge_data.distance - total_weight);
}); });
@ -307,13 +302,13 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
if (target_traversed_in_reverse) if (target_traversed_in_reverse)
{ {
facade->GetUncompressedGeometry( facade.GetUncompressedGeometry(
phantom_node_pair.target_phantom.reverse_packed_geometry_id, id_vector); phantom_node_pair.target_phantom.reverse_packed_geometry_id, id_vector);
facade->GetUncompressedWeights( facade.GetUncompressedWeights(
phantom_node_pair.target_phantom.reverse_packed_geometry_id, weight_vector); phantom_node_pair.target_phantom.reverse_packed_geometry_id, weight_vector);
facade->GetUncompressedDatasources( facade.GetUncompressedDatasources(
phantom_node_pair.target_phantom.reverse_packed_geometry_id, datasource_vector); phantom_node_pair.target_phantom.reverse_packed_geometry_id, datasource_vector);
if (is_local_path) if (is_local_path)
@ -331,13 +326,13 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
start_index = phantom_node_pair.source_phantom.fwd_segment_position; start_index = phantom_node_pair.source_phantom.fwd_segment_position;
} }
end_index = phantom_node_pair.target_phantom.fwd_segment_position; end_index = phantom_node_pair.target_phantom.fwd_segment_position;
facade->GetUncompressedGeometry( facade.GetUncompressedGeometry(
phantom_node_pair.target_phantom.forward_packed_geometry_id, id_vector); phantom_node_pair.target_phantom.forward_packed_geometry_id, id_vector);
facade->GetUncompressedWeights( facade.GetUncompressedWeights(
phantom_node_pair.target_phantom.forward_packed_geometry_id, weight_vector); phantom_node_pair.target_phantom.forward_packed_geometry_id, weight_vector);
facade->GetUncompressedDatasources( facade.GetUncompressedDatasources(
phantom_node_pair.target_phantom.forward_packed_geometry_id, datasource_vector); phantom_node_pair.target_phantom.forward_packed_geometry_id, datasource_vector);
} }
@ -412,11 +407,14 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
* @param to the node the CH edge finishes at * @param to the node the CH edge finishes at
* @param unpacked_path the sequence of original NodeIDs that make up the expanded CH edge * @param unpacked_path the sequence of original NodeIDs that make up the expanded CH edge
*/ */
void UnpackEdge(const NodeID from, const NodeID to, std::vector<NodeID> &unpacked_path) const void UnpackEdge(const DataFacadeT &facade,
const NodeID from,
const NodeID to,
std::vector<NodeID> &unpacked_path) const
{ {
std::array<NodeID, 2> path{{from, to}}; std::array<NodeID, 2> path{{from, to}};
UnpackCHPath( UnpackCHPath(
*facade, facade,
path.begin(), path.begin(),
path.end(), path.end(),
[&unpacked_path](const std::pair<NodeID, NodeID> &edge, const EdgeData & /* data */) { [&unpacked_path](const std::pair<NodeID, NodeID> &edge, const EdgeData & /* data */) {
@ -465,7 +463,8 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
// && source_phantom.GetForwardWeightPlusOffset() > target_phantom.GetForwardWeightPlusOffset()) // && source_phantom.GetForwardWeightPlusOffset() > target_phantom.GetForwardWeightPlusOffset())
// requires // requires
// a force loop, if the heaps have been initialized with positive offsets. // a force loop, if the heaps have been initialized with positive offsets.
void Search(SearchEngineData::QueryHeap &forward_heap, void Search(const DataFacadeT &facade,
SearchEngineData::QueryHeap &forward_heap,
SearchEngineData::QueryHeap &reverse_heap, SearchEngineData::QueryHeap &reverse_heap,
std::int32_t &distance, std::int32_t &distance,
std::vector<NodeID> &packed_leg, std::vector<NodeID> &packed_leg,
@ -488,7 +487,8 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
{ {
if (!forward_heap.Empty()) if (!forward_heap.Empty())
{ {
RoutingStep(forward_heap, RoutingStep(facade,
forward_heap,
reverse_heap, reverse_heap,
middle, middle,
distance, distance,
@ -500,7 +500,8 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
} }
if (!reverse_heap.Empty()) if (!reverse_heap.Empty())
{ {
RoutingStep(reverse_heap, RoutingStep(facade,
reverse_heap,
forward_heap, forward_heap,
middle, middle,
distance, distance,
@ -545,7 +546,8 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
// && source_phantom.GetForwardWeightPlusOffset() > target_phantom.GetForwardWeightPlusOffset()) // && source_phantom.GetForwardWeightPlusOffset() > target_phantom.GetForwardWeightPlusOffset())
// requires // requires
// a force loop, if the heaps have been initialized with positive offsets. // a force loop, if the heaps have been initialized with positive offsets.
void SearchWithCore(SearchEngineData::QueryHeap &forward_heap, void SearchWithCore(const DataFacadeT &facade,
SearchEngineData::QueryHeap &forward_heap,
SearchEngineData::QueryHeap &reverse_heap, SearchEngineData::QueryHeap &reverse_heap,
SearchEngineData::QueryHeap &forward_core_heap, SearchEngineData::QueryHeap &forward_core_heap,
SearchEngineData::QueryHeap &reverse_core_heap, SearchEngineData::QueryHeap &reverse_core_heap,
@ -573,7 +575,7 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
{ {
if (!forward_heap.Empty()) if (!forward_heap.Empty())
{ {
if (facade->IsCoreNode(forward_heap.Min())) if (facade.IsCoreNode(forward_heap.Min()))
{ {
const NodeID node = forward_heap.DeleteMin(); const NodeID node = forward_heap.DeleteMin();
const int key = forward_heap.GetKey(node); const int key = forward_heap.GetKey(node);
@ -581,7 +583,8 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
} }
else else
{ {
RoutingStep(forward_heap, RoutingStep(facade,
forward_heap,
reverse_heap, reverse_heap,
middle, middle,
distance, distance,
@ -594,7 +597,7 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
} }
if (!reverse_heap.Empty()) if (!reverse_heap.Empty())
{ {
if (facade->IsCoreNode(reverse_heap.Min())) if (facade.IsCoreNode(reverse_heap.Min()))
{ {
const NodeID node = reverse_heap.DeleteMin(); const NodeID node = reverse_heap.DeleteMin();
const int key = reverse_heap.GetKey(node); const int key = reverse_heap.GetKey(node);
@ -602,7 +605,8 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
} }
else else
{ {
RoutingStep(reverse_heap, RoutingStep(facade,
reverse_heap,
forward_heap, forward_heap,
middle, middle,
distance, distance,
@ -654,7 +658,8 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
while (0 < forward_core_heap.Size() && 0 < reverse_core_heap.Size() && while (0 < forward_core_heap.Size() && 0 < reverse_core_heap.Size() &&
distance > (forward_core_heap.MinKey() + reverse_core_heap.MinKey())) distance > (forward_core_heap.MinKey() + reverse_core_heap.MinKey()))
{ {
RoutingStep(forward_core_heap, RoutingStep(facade,
forward_core_heap,
reverse_core_heap, reverse_core_heap,
middle, middle,
distance, distance,
@ -664,7 +669,8 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
force_loop_forward, force_loop_forward,
force_loop_reverse); force_loop_reverse);
RoutingStep(reverse_core_heap, RoutingStep(facade,
reverse_core_heap,
forward_core_heap, forward_core_heap,
middle, middle,
distance, distance,
@ -687,7 +693,7 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
"no path found"); "no path found");
// we need to unpack sub path from core heaps // we need to unpack sub path from core heaps
if (facade->IsCoreNode(middle)) if (facade.IsCoreNode(middle))
{ {
if (distance != forward_core_heap.GetKey(middle) + reverse_core_heap.GetKey(middle)) if (distance != forward_core_heap.GetKey(middle) + reverse_core_heap.GetKey(middle))
{ {
@ -746,7 +752,8 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
target_phantom.GetReverseWeightPlusOffset(); target_phantom.GetReverseWeightPlusOffset();
} }
double GetPathDistance(const std::vector<NodeID> &packed_path, double GetPathDistance(const DataFacadeT &facade,
const std::vector<NodeID> &packed_path,
const PhantomNode &source_phantom, const PhantomNode &source_phantom,
const PhantomNode &target_phantom) const const PhantomNode &target_phantom) const
{ {
@ -754,7 +761,7 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
PhantomNodes nodes; PhantomNodes nodes;
nodes.source_phantom = source_phantom; nodes.source_phantom = source_phantom;
nodes.target_phantom = target_phantom; nodes.target_phantom = target_phantom;
UnpackPath(packed_path.begin(), packed_path.end(), nodes, unpacked_path); UnpackPath(facade, packed_path.begin(), packed_path.end(), nodes, unpacked_path);
using util::coordinate_calculation::detail::DEGREE_TO_RAD; using util::coordinate_calculation::detail::DEGREE_TO_RAD;
using util::coordinate_calculation::detail::EARTH_RADIUS; using util::coordinate_calculation::detail::EARTH_RADIUS;
@ -767,7 +774,7 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
double prev_cos = std::cos(prev_lat); double prev_cos = std::cos(prev_lat);
for (const auto &p : unpacked_path) for (const auto &p : unpacked_path)
{ {
const auto current_coordinate = facade->GetCoordinateOfNode(p.turn_via_node); const auto current_coordinate = facade.GetCoordinateOfNode(p.turn_via_node);
const double current_lat = const double current_lat =
static_cast<double>(toFloating(current_coordinate.lat)) * DEGREE_TO_RAD; static_cast<double>(toFloating(current_coordinate.lat)) * DEGREE_TO_RAD;
@ -806,7 +813,8 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
// Requires the heaps for be empty // Requires the heaps for be empty
// If heaps should be adjusted to be initialized outside of this function, // If heaps should be adjusted to be initialized outside of this function,
// the addition of force_loop parameters might be required // the addition of force_loop parameters might be required
double GetNetworkDistanceWithCore(SearchEngineData::QueryHeap &forward_heap, double GetNetworkDistanceWithCore(const DataFacadeT &facade,
SearchEngineData::QueryHeap &forward_heap,
SearchEngineData::QueryHeap &reverse_heap, SearchEngineData::QueryHeap &reverse_heap,
SearchEngineData::QueryHeap &forward_core_heap, SearchEngineData::QueryHeap &forward_core_heap,
SearchEngineData::QueryHeap &reverse_core_heap, SearchEngineData::QueryHeap &reverse_core_heap,
@ -848,7 +856,8 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
int duration = INVALID_EDGE_WEIGHT; int duration = INVALID_EDGE_WEIGHT;
std::vector<NodeID> packed_path; std::vector<NodeID> packed_path;
SearchWithCore(forward_heap, SearchWithCore(facade,
forward_heap,
reverse_heap, reverse_heap,
forward_core_heap, forward_core_heap,
reverse_core_heap, reverse_core_heap,
@ -861,7 +870,7 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
double distance = std::numeric_limits<double>::max(); double distance = std::numeric_limits<double>::max();
if (duration != INVALID_EDGE_WEIGHT) if (duration != INVALID_EDGE_WEIGHT)
{ {
return GetPathDistance(packed_path, source_phantom, target_phantom); return GetPathDistance(facade, packed_path, source_phantom, target_phantom);
} }
return distance; return distance;
} }
@ -869,7 +878,8 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
// Requires the heaps for be empty // Requires the heaps for be empty
// If heaps should be adjusted to be initialized outside of this function, // If heaps should be adjusted to be initialized outside of this function,
// the addition of force_loop parameters might be required // the addition of force_loop parameters might be required
double GetNetworkDistance(SearchEngineData::QueryHeap &forward_heap, double GetNetworkDistance(const DataFacadeT &facade,
SearchEngineData::QueryHeap &forward_heap,
SearchEngineData::QueryHeap &reverse_heap, SearchEngineData::QueryHeap &reverse_heap,
const PhantomNode &source_phantom, const PhantomNode &source_phantom,
const PhantomNode &target_phantom, const PhantomNode &target_phantom,
@ -909,7 +919,8 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
int duration = INVALID_EDGE_WEIGHT; int duration = INVALID_EDGE_WEIGHT;
std::vector<NodeID> packed_path; std::vector<NodeID> packed_path;
Search(forward_heap, Search(facade,
forward_heap,
reverse_heap, reverse_heap,
duration, duration,
packed_path, packed_path,
@ -922,7 +933,7 @@ template <class DataFacadeT, class Derived> class BasicRoutingInterface
return std::numeric_limits<double>::max(); return std::numeric_limits<double>::max();
} }
return GetPathDistance(packed_path, source_phantom, target_phantom); return GetPathDistance(facade, packed_path, source_phantom, target_phantom);
} }
}; };
} }

View File

@ -28,8 +28,8 @@ class ShortestPathRouting final
const static constexpr bool DO_NOT_FORCE_LOOP = false; const static constexpr bool DO_NOT_FORCE_LOOP = false;
public: public:
ShortestPathRouting(DataFacadeT *facade, SearchEngineData &engine_working_data) ShortestPathRouting(SearchEngineData &engine_working_data)
: super(facade), engine_working_data(engine_working_data) : engine_working_data(engine_working_data)
{ {
} }
@ -37,7 +37,8 @@ class ShortestPathRouting final
// allows a uturn at the target_phantom // allows a uturn at the target_phantom
// searches source forward/reverse -> target forward/reverse // searches source forward/reverse -> target forward/reverse
void SearchWithUTurn(QueryHeap &forward_heap, void SearchWithUTurn(const DataFacadeT &facade,
QueryHeap &forward_heap,
QueryHeap &reverse_heap, QueryHeap &reverse_heap,
QueryHeap &forward_core_heap, QueryHeap &forward_core_heap,
QueryHeap &reverse_core_heap, QueryHeap &reverse_core_heap,
@ -90,13 +91,14 @@ class ShortestPathRouting final
is_oneway_source && super::NeedsLoopForward(source_phantom, target_phantom); is_oneway_source && super::NeedsLoopForward(source_phantom, target_phantom);
auto needs_loop_backwards = auto needs_loop_backwards =
is_oneway_target && super::NeedsLoopBackwards(source_phantom, target_phantom); is_oneway_target && super::NeedsLoopBackwards(source_phantom, target_phantom);
if (super::facade->GetCoreSize() > 0) if (facade.GetCoreSize() > 0)
{ {
forward_core_heap.Clear(); forward_core_heap.Clear();
reverse_core_heap.Clear(); reverse_core_heap.Clear();
BOOST_ASSERT(forward_core_heap.Size() == 0); BOOST_ASSERT(forward_core_heap.Size() == 0);
BOOST_ASSERT(reverse_core_heap.Size() == 0); BOOST_ASSERT(reverse_core_heap.Size() == 0);
super::SearchWithCore(forward_heap, super::SearchWithCore(facade,
forward_heap,
reverse_heap, reverse_heap,
forward_core_heap, forward_core_heap,
reverse_core_heap, reverse_core_heap,
@ -107,7 +109,8 @@ class ShortestPathRouting final
} }
else else
{ {
super::Search(forward_heap, super::Search(facade,
forward_heap,
reverse_heap, reverse_heap,
new_total_distance, new_total_distance,
leg_packed_path, leg_packed_path,
@ -124,7 +127,8 @@ class ShortestPathRouting final
// searches shortest path between: // searches shortest path between:
// source forward/reverse -> target forward // source forward/reverse -> target forward
// source forward/reverse -> target reverse // source forward/reverse -> target reverse
void Search(QueryHeap &forward_heap, void Search(const DataFacadeT &facade,
QueryHeap &forward_heap,
QueryHeap &reverse_heap, QueryHeap &reverse_heap,
QueryHeap &forward_core_heap, QueryHeap &forward_core_heap,
QueryHeap &reverse_core_heap, QueryHeap &reverse_core_heap,
@ -166,13 +170,14 @@ class ShortestPathRouting final
BOOST_ASSERT(forward_heap.Size() > 0); BOOST_ASSERT(forward_heap.Size() > 0);
BOOST_ASSERT(reverse_heap.Size() > 0); BOOST_ASSERT(reverse_heap.Size() > 0);
if (super::facade->GetCoreSize() > 0) if (facade.GetCoreSize() > 0)
{ {
forward_core_heap.Clear(); forward_core_heap.Clear();
reverse_core_heap.Clear(); reverse_core_heap.Clear();
BOOST_ASSERT(forward_core_heap.Size() == 0); BOOST_ASSERT(forward_core_heap.Size() == 0);
BOOST_ASSERT(reverse_core_heap.Size() == 0); BOOST_ASSERT(reverse_core_heap.Size() == 0);
super::SearchWithCore(forward_heap, super::SearchWithCore(facade,
forward_heap,
reverse_heap, reverse_heap,
forward_core_heap, forward_core_heap,
reverse_core_heap, reverse_core_heap,
@ -183,7 +188,8 @@ class ShortestPathRouting final
} }
else else
{ {
super::Search(forward_heap, super::Search(facade,
forward_heap,
reverse_heap, reverse_heap,
new_total_distance_to_forward, new_total_distance_to_forward,
leg_packed_path_forward, leg_packed_path_forward,
@ -215,13 +221,14 @@ class ShortestPathRouting final
} }
BOOST_ASSERT(forward_heap.Size() > 0); BOOST_ASSERT(forward_heap.Size() > 0);
BOOST_ASSERT(reverse_heap.Size() > 0); BOOST_ASSERT(reverse_heap.Size() > 0);
if (super::facade->GetCoreSize() > 0) if (facade.GetCoreSize() > 0)
{ {
forward_core_heap.Clear(); forward_core_heap.Clear();
reverse_core_heap.Clear(); reverse_core_heap.Clear();
BOOST_ASSERT(forward_core_heap.Size() == 0); BOOST_ASSERT(forward_core_heap.Size() == 0);
BOOST_ASSERT(reverse_core_heap.Size() == 0); BOOST_ASSERT(reverse_core_heap.Size() == 0);
super::SearchWithCore(forward_heap, super::SearchWithCore(facade,
forward_heap,
reverse_heap, reverse_heap,
forward_core_heap, forward_core_heap,
reverse_core_heap, reverse_core_heap,
@ -232,7 +239,8 @@ class ShortestPathRouting final
} }
else else
{ {
super::Search(forward_heap, super::Search(facade,
forward_heap,
reverse_heap, reverse_heap,
new_total_distance_to_reverse, new_total_distance_to_reverse,
leg_packed_path_reverse, leg_packed_path_reverse,
@ -242,7 +250,8 @@ class ShortestPathRouting final
} }
} }
void UnpackLegs(const std::vector<PhantomNodes> &phantom_nodes_vector, void UnpackLegs(const DataFacadeT &facade,
const std::vector<PhantomNodes> &phantom_nodes_vector,
const std::vector<NodeID> &total_packed_path, const std::vector<NodeID> &total_packed_path,
const std::vector<std::size_t> &packed_leg_begin, const std::vector<std::size_t> &packed_leg_begin,
const int shortest_path_length, const int shortest_path_length,
@ -257,7 +266,8 @@ class ShortestPathRouting final
auto leg_begin = total_packed_path.begin() + packed_leg_begin[current_leg]; auto leg_begin = total_packed_path.begin() + packed_leg_begin[current_leg];
auto leg_end = total_packed_path.begin() + packed_leg_begin[current_leg + 1]; auto leg_end = total_packed_path.begin() + packed_leg_begin[current_leg + 1];
const auto &unpack_phantom_node_pair = phantom_nodes_vector[current_leg]; const auto &unpack_phantom_node_pair = phantom_nodes_vector[current_leg];
super::UnpackPath(leg_begin, super::UnpackPath(facade,
leg_begin,
leg_end, leg_end,
unpack_phantom_node_pair, unpack_phantom_node_pair,
raw_route_data.unpacked_path_segments[current_leg]); raw_route_data.unpacked_path_segments[current_leg]);
@ -271,18 +281,19 @@ class ShortestPathRouting final
} }
} }
void operator()(const std::vector<PhantomNodes> &phantom_nodes_vector, void operator()(const DataFacadeT &facade,
const std::vector<PhantomNodes> &phantom_nodes_vector,
const boost::optional<bool> continue_straight_at_waypoint, const boost::optional<bool> continue_straight_at_waypoint,
InternalRouteResult &raw_route_data) const InternalRouteResult &raw_route_data) const
{ {
const bool allow_uturn_at_waypoint = const bool allow_uturn_at_waypoint =
!(continue_straight_at_waypoint ? *continue_straight_at_waypoint !(continue_straight_at_waypoint ? *continue_straight_at_waypoint
: super::facade->GetContinueStraightDefault()); : facade.GetContinueStraightDefault());
engine_working_data.InitializeOrClearFirstThreadLocalStorage( engine_working_data.InitializeOrClearFirstThreadLocalStorage(
super::facade->GetNumberOfNodes()); facade.GetNumberOfNodes());
engine_working_data.InitializeOrClearSecondThreadLocalStorage( engine_working_data.InitializeOrClearSecondThreadLocalStorage(
super::facade->GetNumberOfNodes()); facade.GetNumberOfNodes());
QueryHeap &forward_heap = *(engine_working_data.forward_heap_1); QueryHeap &forward_heap = *(engine_working_data.forward_heap_1);
QueryHeap &reverse_heap = *(engine_working_data.reverse_heap_1); QueryHeap &reverse_heap = *(engine_working_data.reverse_heap_1);
@ -330,7 +341,8 @@ class ShortestPathRouting final
{ {
if (allow_uturn_at_waypoint) if (allow_uturn_at_waypoint)
{ {
SearchWithUTurn(forward_heap, SearchWithUTurn(facade,
forward_heap,
reverse_heap, reverse_heap,
forward_core_heap, forward_core_heap,
reverse_core_heap, reverse_core_heap,
@ -361,7 +373,8 @@ class ShortestPathRouting final
} }
else else
{ {
Search(forward_heap, Search(facade,
forward_heap,
reverse_heap, reverse_heap,
forward_core_heap, forward_core_heap,
reverse_core_heap, reverse_core_heap,
@ -489,7 +502,8 @@ class ShortestPathRouting final
packed_leg_to_reverse_begin.push_back(total_packed_path_to_reverse.size()); packed_leg_to_reverse_begin.push_back(total_packed_path_to_reverse.size());
BOOST_ASSERT(packed_leg_to_reverse_begin.size() == phantom_nodes_vector.size() + 1); BOOST_ASSERT(packed_leg_to_reverse_begin.size() == phantom_nodes_vector.size() + 1);
UnpackLegs(phantom_nodes_vector, UnpackLegs(facade,
phantom_nodes_vector,
total_packed_path_to_reverse, total_packed_path_to_reverse,
packed_leg_to_reverse_begin, packed_leg_to_reverse_begin,
total_distance_to_reverse, total_distance_to_reverse,
@ -501,7 +515,8 @@ class ShortestPathRouting final
packed_leg_to_forward_begin.push_back(total_packed_path_to_forward.size()); packed_leg_to_forward_begin.push_back(total_packed_path_to_forward.size());
BOOST_ASSERT(packed_leg_to_forward_begin.size() == phantom_nodes_vector.size() + 1); BOOST_ASSERT(packed_leg_to_forward_begin.size() == phantom_nodes_vector.size() + 1);
UnpackLegs(phantom_nodes_vector, UnpackLegs(facade,
phantom_nodes_vector,
total_packed_path_to_forward, total_packed_path_to_forward,
packed_leg_to_forward_begin, packed_leg_to_forward_begin,
total_distance_to_forward, total_distance_to_forward,

View File

@ -15,7 +15,6 @@
#include "engine/datafacade/shared_datafacade.hpp" #include "engine/datafacade/shared_datafacade.hpp"
#include "storage/shared_barriers.hpp" #include "storage/shared_barriers.hpp"
#include "util/make_unique.hpp"
#include "util/simple_logger.hpp" #include "util/simple_logger.hpp"
#include <boost/assert.hpp> #include <boost/assert.hpp>
@ -86,37 +85,31 @@ namespace
// Works the same for every plugin. // Works the same for every plugin.
template <typename ParameterT, typename PluginT, typename ResultT> template <typename ParameterT, typename PluginT, typename ResultT>
osrm::engine::Status RunQuery(const std::unique_ptr<osrm::engine::Engine::EngineLock> &lock, osrm::engine::Status RunQuery(const std::unique_ptr<osrm::engine::Engine::EngineLock> &lock,
osrm::engine::datafacade::BaseDataFacade &facade, const std::shared_ptr<osrm::engine::datafacade::BaseDataFacade> &facade,
const ParameterT &parameters, const ParameterT &parameters,
PluginT &plugin, PluginT &plugin,
ResultT &result) ResultT &result)
{ {
if (!lock) if (!lock)
{ {
return plugin.HandleRequest(parameters, result); return plugin.HandleRequest(facade, parameters, result);
} }
BOOST_ASSERT(lock); BOOST_ASSERT(lock);
lock->IncreaseQueryCount(); lock->IncreaseQueryCount();
auto &shared_facade = static_cast<osrm::engine::datafacade::SharedDataFacade &>(facade); auto &shared_facade = static_cast<osrm::engine::datafacade::SharedDataFacade &>(*facade);
shared_facade.CheckAndReloadFacade(); shared_facade.CheckAndReloadFacade();
// Get a shared data lock so that other threads won't update // Get a shared data lock so that other threads won't update
// things while the query is running // things while the query is running
boost::shared_lock<boost::shared_mutex> data_lock{shared_facade.data_mutex}; boost::shared_lock<boost::shared_mutex> data_lock{shared_facade.data_mutex};
osrm::engine::Status status = plugin.HandleRequest(parameters, result); osrm::engine::Status status = plugin.HandleRequest(facade, parameters, result);
lock->DecreaseQueryCount(); lock->DecreaseQueryCount();
return status; return status;
} }
template <typename Plugin, typename Facade, typename... Args>
std::unique_ptr<Plugin> create(Facade &facade, Args... args)
{
return osrm::util::make_unique<Plugin>(facade, std::forward<Args>(args)...);
}
} // anon. ns } // anon. ns
namespace osrm namespace osrm
@ -128,8 +121,8 @@ Engine::Engine(const EngineConfig &config)
{ {
if (config.use_shared_memory) if (config.use_shared_memory)
{ {
lock = util::make_unique<EngineLock>(); lock = std::make_unique<EngineLock>();
query_data_facade = util::make_unique<datafacade::SharedDataFacade>(); query_data_facade = std::make_shared<datafacade::SharedDataFacade>();
} }
else else
{ {
@ -138,18 +131,18 @@ Engine::Engine(const EngineConfig &config)
throw util::exception("Invalid file paths given!"); throw util::exception("Invalid file paths given!");
} }
query_data_facade = query_data_facade =
util::make_unique<datafacade::InternalDataFacade>(config.storage_config); std::make_shared<datafacade::InternalDataFacade>(config.storage_config);
} }
// Register plugins // Register plugins
using namespace plugins; using namespace plugins;
route_plugin = create<ViaRoutePlugin>(*query_data_facade, config.max_locations_viaroute); route_plugin = std::make_unique<ViaRoutePlugin>(config.max_locations_viaroute);
table_plugin = create<TablePlugin>(*query_data_facade, config.max_locations_distance_table); table_plugin = std::make_unique<TablePlugin>(config.max_locations_distance_table);
nearest_plugin = create<NearestPlugin>(*query_data_facade, config.max_results_nearest); nearest_plugin = std::make_unique<NearestPlugin>(config.max_results_nearest);
trip_plugin = create<TripPlugin>(*query_data_facade, config.max_locations_trip); trip_plugin = std::make_unique<TripPlugin>(config.max_locations_trip);
match_plugin = create<MatchPlugin>(*query_data_facade, config.max_locations_map_matching); match_plugin = std::make_unique<MatchPlugin>(config.max_locations_map_matching);
tile_plugin = create<TilePlugin>(*query_data_facade); tile_plugin = std::make_unique<TilePlugin>();
} }
// make sure we deallocate the unique ptr at a position where we know the size of the plugins // make sure we deallocate the unique ptr at a position where we know the size of the plugins
@ -159,32 +152,32 @@ Engine &Engine::operator=(Engine &&) noexcept = default;
Status Engine::Route(const api::RouteParameters &params, util::json::Object &result) const Status Engine::Route(const api::RouteParameters &params, util::json::Object &result) const
{ {
return RunQuery(lock, *query_data_facade, params, *route_plugin, result); return RunQuery(lock, query_data_facade, params, *route_plugin, result);
} }
Status Engine::Table(const api::TableParameters &params, util::json::Object &result) const Status Engine::Table(const api::TableParameters &params, util::json::Object &result) const
{ {
return RunQuery(lock, *query_data_facade, params, *table_plugin, result); return RunQuery(lock, query_data_facade, params, *table_plugin, result);
} }
Status Engine::Nearest(const api::NearestParameters &params, util::json::Object &result) const Status Engine::Nearest(const api::NearestParameters &params, util::json::Object &result) const
{ {
return RunQuery(lock, *query_data_facade, params, *nearest_plugin, result); return RunQuery(lock, query_data_facade, params, *nearest_plugin, result);
} }
Status Engine::Trip(const api::TripParameters &params, util::json::Object &result) const Status Engine::Trip(const api::TripParameters &params, util::json::Object &result) const
{ {
return RunQuery(lock, *query_data_facade, params, *trip_plugin, result); return RunQuery(lock, query_data_facade, params, *trip_plugin, result);
} }
Status Engine::Match(const api::MatchParameters &params, util::json::Object &result) const Status Engine::Match(const api::MatchParameters &params, util::json::Object &result) const
{ {
return RunQuery(lock, *query_data_facade, params, *match_plugin, result); return RunQuery(lock, query_data_facade, params, *match_plugin, result);
} }
Status Engine::Tile(const api::TileParameters &params, std::string &result) const Status Engine::Tile(const api::TileParameters &params, std::string &result) const
{ {
return RunQuery(lock, *query_data_facade, params, *tile_plugin, result); return RunQuery(lock, query_data_facade, params, *tile_plugin, result);
} }
} // engine ns } // engine ns

View File

@ -105,7 +105,8 @@ void filterCandidates(const std::vector<util::Coordinate> &coordinates,
} }
} }
Status MatchPlugin::HandleRequest(const api::MatchParameters &parameters, Status MatchPlugin::HandleRequest(const std::shared_ptr<datafacade::BaseDataFacade> facade,
const api::MatchParameters &parameters,
util::json::Object &json_result) util::json::Object &json_result)
{ {
BOOST_ASSERT(parameters.IsValid()); BOOST_ASSERT(parameters.IsValid());
@ -150,7 +151,7 @@ Status MatchPlugin::HandleRequest(const api::MatchParameters &parameters,
}); });
} }
auto candidates_lists = GetPhantomNodesInRange(parameters, search_radiuses); auto candidates_lists = GetPhantomNodesInRange(*facade, parameters, search_radiuses);
filterCandidates(parameters.coordinates, candidates_lists); filterCandidates(parameters.coordinates, candidates_lists);
if (std::all_of(candidates_lists.begin(), if (std::all_of(candidates_lists.begin(),
@ -165,7 +166,7 @@ Status MatchPlugin::HandleRequest(const api::MatchParameters &parameters,
} }
// call the actual map matching // call the actual map matching
SubMatchingList sub_matchings = map_matching( SubMatchingList sub_matchings = map_matching(*facade,
candidates_lists, parameters.coordinates, parameters.timestamps, parameters.radiuses); candidates_lists, parameters.coordinates, parameters.timestamps, parameters.radiuses);
if (sub_matchings.size() == 0) if (sub_matchings.size() == 0)
@ -192,11 +193,11 @@ Status MatchPlugin::HandleRequest(const api::MatchParameters &parameters,
// force uturns to be on, since we split the phantom nodes anyway and only have // force uturns to be on, since we split the phantom nodes anyway and only have
// bi-directional // bi-directional
// phantom nodes for possible uturns // phantom nodes for possible uturns
shortest_path(sub_routes[index].segment_end_coordinates, {false}, sub_routes[index]); shortest_path(*facade, sub_routes[index].segment_end_coordinates, {false}, sub_routes[index]);
BOOST_ASSERT(sub_routes[index].shortest_path_length != INVALID_EDGE_WEIGHT); BOOST_ASSERT(sub_routes[index].shortest_path_length != INVALID_EDGE_WEIGHT);
} }
api::MatchAPI match_api{BasePlugin::facade, parameters}; api::MatchAPI match_api{*facade, parameters};
match_api.MakeResponse(sub_matchings, sub_routes, json_result); match_api.MakeResponse(sub_matchings, sub_routes, json_result);
return Status::Ok; return Status::Ok;

View File

@ -17,13 +17,14 @@ namespace engine
namespace plugins namespace plugins
{ {
NearestPlugin::NearestPlugin(datafacade::BaseDataFacade &facade, const int max_results_) NearestPlugin::NearestPlugin(const int max_results_)
: BasePlugin{facade}, max_results{max_results_} : max_results{max_results_}
{ {
} }
Status NearestPlugin::HandleRequest(const api::NearestParameters &params, Status NearestPlugin::HandleRequest(const std::shared_ptr<datafacade::BaseDataFacade> facade,
util::json::Object &json_result) const api::NearestParameters &params,
util::json::Object &json_result) const
{ {
BOOST_ASSERT(params.IsValid()); BOOST_ASSERT(params.IsValid());
@ -44,7 +45,7 @@ Status NearestPlugin::HandleRequest(const api::NearestParameters &params,
return Error("InvalidOptions", "Only one input coordinate is supported", json_result); return Error("InvalidOptions", "Only one input coordinate is supported", json_result);
} }
auto phantom_nodes = GetPhantomNodes(params, params.number_of_results); auto phantom_nodes = GetPhantomNodes(*facade, params, params.number_of_results);
if (phantom_nodes.front().size() == 0) if (phantom_nodes.front().size() == 0)
{ {
@ -52,7 +53,7 @@ Status NearestPlugin::HandleRequest(const api::NearestParameters &params,
} }
BOOST_ASSERT(phantom_nodes.front().size() > 0); BOOST_ASSERT(phantom_nodes.front().size() > 0);
api::NearestAPI nearest_api(facade, params); api::NearestAPI nearest_api(*facade, params);
nearest_api.MakeResponse(phantom_nodes, json_result); nearest_api.MakeResponse(phantom_nodes, json_result);
return Status::Ok; return Status::Ok;

View File

@ -23,13 +23,15 @@ namespace engine
namespace plugins namespace plugins
{ {
TablePlugin::TablePlugin(datafacade::BaseDataFacade &facade, const int max_locations_distance_table) TablePlugin::TablePlugin(const int max_locations_distance_table)
: BasePlugin{facade}, distance_table(&facade, heaps), : distance_table(heaps),
max_locations_distance_table(max_locations_distance_table) max_locations_distance_table(max_locations_distance_table)
{ {
} }
Status TablePlugin::HandleRequest(const api::TableParameters &params, util::json::Object &result) Status TablePlugin::HandleRequest(const std::shared_ptr<datafacade::BaseDataFacade> facade,
const api::TableParameters &params,
util::json::Object &result)
{ {
BOOST_ASSERT(params.IsValid()); BOOST_ASSERT(params.IsValid());
@ -58,15 +60,15 @@ Status TablePlugin::HandleRequest(const api::TableParameters &params, util::json
return Error("TooBig", "Too many table coordinates", result); return Error("TooBig", "Too many table coordinates", result);
} }
auto snapped_phantoms = SnapPhantomNodes(GetPhantomNodes(params)); auto snapped_phantoms = SnapPhantomNodes(GetPhantomNodes(*facade, params));
auto result_table = distance_table(snapped_phantoms, params.sources, params.destinations); auto result_table = distance_table(*facade, snapped_phantoms, params.sources, params.destinations);
if (result_table.empty()) if (result_table.empty())
{ {
return Error("NoTable", "No table found", result); return Error("NoTable", "No table found", result);
} }
api::TableAPI table_api{facade, params}; api::TableAPI table_api{*facade, params};
table_api.MakeResponse(result_table, snapped_phantoms, result); table_api.MakeResponse(result_table, snapped_phantoms, result);
return Status::Ok; return Status::Ok;

View File

@ -269,7 +269,9 @@ void UnpackEdgeToEdges(const datafacade::BaseDataFacade &facade,
} }
} // namespace } // namespace
Status TilePlugin::HandleRequest(const api::TileParameters &parameters, std::string &pbf_buffer) Status TilePlugin::HandleRequest(const std::shared_ptr<datafacade::BaseDataFacade> facade,
const api::TileParameters &parameters,
std::string &pbf_buffer) const
{ {
BOOST_ASSERT(parameters.IsValid()); BOOST_ASSERT(parameters.IsValid());
@ -284,7 +286,7 @@ Status TilePlugin::HandleRequest(const api::TileParameters &parameters, std::str
// Fetch all the segments that are in our bounding box. // Fetch all the segments that are in our bounding box.
// This hits the OSRM StaticRTree // This hits the OSRM StaticRTree
const auto edges = facade.GetEdgesInBox(southwest, northeast); const auto edges = facade->GetEdgesInBox(southwest, northeast);
// Vector tiles encode properties as references to a common lookup table. // Vector tiles encode properties as references to a common lookup table.
// When we add a property to a "feature", we actually attach the index of the value // When we add a property to a "feature", we actually attach the index of the value
@ -467,7 +469,7 @@ Status TilePlugin::HandleRequest(const api::TileParameters &parameters, std::str
{ {
// Grab a copy of the geometry leading up to the intersection. // Grab a copy of the geometry leading up to the intersection.
first_geometry.clear(); first_geometry.clear();
facade.GetUncompressedGeometry(source_ebn.second.packed_geometry_id, first_geometry); facade->GetUncompressedGeometry(source_ebn.second.packed_geometry_id, first_geometry);
// We earlier saved the source and target intersection nodes for every road section. // We earlier saved the source and target intersection nodes for every road section.
// We can use the target node to find all road sections that lead away from // We can use the target node to find all road sections that lead away from
@ -481,7 +483,7 @@ Status TilePlugin::HandleRequest(const api::TileParameters &parameters, std::str
continue; continue;
// Find the connection between our source road and the target node // Find the connection between our source road and the target node
EdgeID smaller_edge_id = facade.FindSmallestEdge( EdgeID smaller_edge_id = facade->FindSmallestEdge(
source_ebn.first, target_ebn, [](const contractor::QueryEdge::EdgeData &data) { source_ebn.first, target_ebn, [](const contractor::QueryEdge::EdgeData &data) {
return data.forward; return data.forward;
}); });
@ -493,7 +495,7 @@ Status TilePlugin::HandleRequest(const api::TileParameters &parameters, std::str
// If we didn't find a forward edge, try for a backward one // If we didn't find a forward edge, try for a backward one
if (SPECIAL_EDGEID == smaller_edge_id) if (SPECIAL_EDGEID == smaller_edge_id)
{ {
smaller_edge_id = facade.FindSmallestEdge( smaller_edge_id = facade->FindSmallestEdge(
target_ebn, target_ebn,
source_ebn.first, source_ebn.first,
[](const contractor::QueryEdge::EdgeData &data) { return data.backward; }); [](const contractor::QueryEdge::EdgeData &data) { return data.backward; });
@ -510,13 +512,13 @@ Status TilePlugin::HandleRequest(const api::TileParameters &parameters, std::str
// out of it, which should represent the first hop, which is the one // out of it, which should represent the first hop, which is the one
// we want to find the turn. // we want to find the turn.
const auto &data = const auto &data =
[this, smaller_edge_id, source_ebn, target_ebn, &unpacked_shortcut]() { [this, &facade, smaller_edge_id, source_ebn, target_ebn, &unpacked_shortcut]() {
const auto inner_data = facade.GetEdgeData(smaller_edge_id); const auto inner_data = facade->GetEdgeData(smaller_edge_id);
if (inner_data.shortcut) if (inner_data.shortcut)
{ {
unpacked_shortcut.clear(); unpacked_shortcut.clear();
UnpackEdgeToEdges( UnpackEdgeToEdges(
facade, source_ebn.first, target_ebn, unpacked_shortcut); *facade, source_ebn.first, target_ebn, unpacked_shortcut);
return unpacked_shortcut.front(); return unpacked_shortcut.front();
} }
else else
@ -527,12 +529,12 @@ Status TilePlugin::HandleRequest(const api::TileParameters &parameters, std::str
// This is the geometry leading away from the intersection // This is the geometry leading away from the intersection
// (i.e. the geometry of the target edge-based-node) // (i.e. the geometry of the target edge-based-node)
second_geometry.clear(); second_geometry.clear();
facade.GetUncompressedGeometry( facade->GetUncompressedGeometry(
edge_based_node_info.at(target_ebn).packed_geometry_id, second_geometry); edge_based_node_info.at(target_ebn).packed_geometry_id, second_geometry);
// Now, calculate the sum of the weight of all the segments. // Now, calculate the sum of the weight of all the segments.
forward_weight_vector.clear(); forward_weight_vector.clear();
facade.GetUncompressedWeights(source_ebn.second.packed_geometry_id, facade->GetUncompressedWeights(source_ebn.second.packed_geometry_id,
forward_weight_vector); forward_weight_vector);
const auto sum_node_weight = std::accumulate( const auto sum_node_weight = std::accumulate(
forward_weight_vector.begin(), forward_weight_vector.end(), EdgeWeight{0}); forward_weight_vector.begin(), forward_weight_vector.end(), EdgeWeight{0});
@ -552,9 +554,9 @@ Status TilePlugin::HandleRequest(const api::TileParameters &parameters, std::str
const auto node_via = source_ebn.second.target_intersection; const auto node_via = source_ebn.second.target_intersection;
const auto node_to = second_geometry.front(); const auto node_to = second_geometry.front();
const auto coord_from = facade.GetCoordinateOfNode(node_from); const auto coord_from = facade->GetCoordinateOfNode(node_from);
const auto coord_via = facade.GetCoordinateOfNode(node_via); const auto coord_via = facade->GetCoordinateOfNode(node_via);
const auto coord_to = facade.GetCoordinateOfNode(node_to); const auto coord_to = facade->GetCoordinateOfNode(node_to);
// Calculate the bearing that we approach the intersection at // Calculate the bearing that we approach the intersection at
const auto angle_in = static_cast<int>( const auto angle_in = static_cast<int>(
@ -613,11 +615,11 @@ Status TilePlugin::HandleRequest(const api::TileParameters &parameters, std::str
if (edge.forward_packed_geometry_id != SPECIAL_EDGEID) if (edge.forward_packed_geometry_id != SPECIAL_EDGEID)
{ {
forward_weight_vector.clear(); forward_weight_vector.clear();
facade.GetUncompressedWeights(edge.forward_packed_geometry_id, forward_weight_vector); facade->GetUncompressedWeights(edge.forward_packed_geometry_id, forward_weight_vector);
forward_weight = forward_weight_vector[edge.fwd_segment_position]; forward_weight = forward_weight_vector[edge.fwd_segment_position];
forward_datasource_vector.clear(); forward_datasource_vector.clear();
facade.GetUncompressedDatasources(edge.forward_packed_geometry_id, facade->GetUncompressedDatasources(edge.forward_packed_geometry_id,
forward_datasource_vector); forward_datasource_vector);
forward_datasource = forward_datasource_vector[edge.fwd_segment_position]; forward_datasource = forward_datasource_vector[edge.fwd_segment_position];
@ -627,7 +629,7 @@ Status TilePlugin::HandleRequest(const api::TileParameters &parameters, std::str
if (edge.reverse_packed_geometry_id != SPECIAL_EDGEID) if (edge.reverse_packed_geometry_id != SPECIAL_EDGEID)
{ {
reverse_weight_vector.clear(); reverse_weight_vector.clear();
facade.GetUncompressedWeights(edge.reverse_packed_geometry_id, reverse_weight_vector); facade->GetUncompressedWeights(edge.reverse_packed_geometry_id, reverse_weight_vector);
BOOST_ASSERT(edge.fwd_segment_position < reverse_weight_vector.size()); BOOST_ASSERT(edge.fwd_segment_position < reverse_weight_vector.size());
@ -635,7 +637,7 @@ Status TilePlugin::HandleRequest(const api::TileParameters &parameters, std::str
reverse_weight_vector[reverse_weight_vector.size() - edge.fwd_segment_position - 1]; reverse_weight_vector[reverse_weight_vector.size() - edge.fwd_segment_position - 1];
reverse_datasource_vector.clear(); reverse_datasource_vector.clear();
facade.GetUncompressedDatasources(edge.reverse_packed_geometry_id, facade->GetUncompressedDatasources(edge.reverse_packed_geometry_id,
reverse_datasource_vector); reverse_datasource_vector);
reverse_datasource = reverse_datasource_vector[reverse_datasource_vector.size() - reverse_datasource = reverse_datasource_vector[reverse_datasource_vector.size() -
edge.fwd_segment_position - 1]; edge.fwd_segment_position - 1];
@ -647,7 +649,7 @@ Status TilePlugin::HandleRequest(const api::TileParameters &parameters, std::str
max_datasource_id = std::max(max_datasource_id, forward_datasource); max_datasource_id = std::max(max_datasource_id, forward_datasource);
max_datasource_id = std::max(max_datasource_id, reverse_datasource); max_datasource_id = std::max(max_datasource_id, reverse_datasource);
std::string name = facade.GetNameForID(edge.name_id); std::string name = facade->GetNameForID(edge.name_id);
if (name_offsets.find(name) == name_offsets.end()) if (name_offsets.find(name) == name_offsets.end())
{ {
names.push_back(name); names.push_back(name);
@ -687,8 +689,8 @@ Status TilePlugin::HandleRequest(const api::TileParameters &parameters, std::str
for (const auto &edge : edges) for (const auto &edge : edges)
{ {
// Get coordinates for start/end nodes of segment (NodeIDs u and v) // Get coordinates for start/end nodes of segment (NodeIDs u and v)
const auto a = facade.GetCoordinateOfNode(edge.u); const auto a = facade->GetCoordinateOfNode(edge.u);
const auto b = facade.GetCoordinateOfNode(edge.v); const auto b = facade->GetCoordinateOfNode(edge.v);
// Calculate the length in meters // Calculate the length in meters
const double length = const double length =
osrm::util::coordinate_calculation::haversineDistance(a, b); osrm::util::coordinate_calculation::haversineDistance(a, b);
@ -699,17 +701,17 @@ Status TilePlugin::HandleRequest(const api::TileParameters &parameters, std::str
std::uint8_t forward_datasource = 0; std::uint8_t forward_datasource = 0;
std::uint8_t reverse_datasource = 0; std::uint8_t reverse_datasource = 0;
std::string name = facade.GetNameForID(edge.name_id); std::string name = facade->GetNameForID(edge.name_id);
if (edge.forward_packed_geometry_id != SPECIAL_EDGEID) if (edge.forward_packed_geometry_id != SPECIAL_EDGEID)
{ {
forward_weight_vector.clear(); forward_weight_vector.clear();
facade.GetUncompressedWeights(edge.forward_packed_geometry_id, facade->GetUncompressedWeights(edge.forward_packed_geometry_id,
forward_weight_vector); forward_weight_vector);
forward_weight = forward_weight_vector[edge.fwd_segment_position]; forward_weight = forward_weight_vector[edge.fwd_segment_position];
forward_datasource_vector.clear(); forward_datasource_vector.clear();
facade.GetUncompressedDatasources(edge.forward_packed_geometry_id, facade->GetUncompressedDatasources(edge.forward_packed_geometry_id,
forward_datasource_vector); forward_datasource_vector);
forward_datasource = forward_datasource_vector[edge.fwd_segment_position]; forward_datasource = forward_datasource_vector[edge.fwd_segment_position];
} }
@ -717,7 +719,7 @@ Status TilePlugin::HandleRequest(const api::TileParameters &parameters, std::str
if (edge.reverse_packed_geometry_id != SPECIAL_EDGEID) if (edge.reverse_packed_geometry_id != SPECIAL_EDGEID)
{ {
reverse_weight_vector.clear(); reverse_weight_vector.clear();
facade.GetUncompressedWeights(edge.reverse_packed_geometry_id, facade->GetUncompressedWeights(edge.reverse_packed_geometry_id,
reverse_weight_vector); reverse_weight_vector);
BOOST_ASSERT(edge.fwd_segment_position < reverse_weight_vector.size()); BOOST_ASSERT(edge.fwd_segment_position < reverse_weight_vector.size());
@ -726,7 +728,7 @@ Status TilePlugin::HandleRequest(const api::TileParameters &parameters, std::str
edge.fwd_segment_position - 1]; edge.fwd_segment_position - 1];
reverse_datasource_vector.clear(); reverse_datasource_vector.clear();
facade.GetUncompressedDatasources(edge.reverse_packed_geometry_id, facade->GetUncompressedDatasources(edge.reverse_packed_geometry_id,
reverse_datasource_vector); reverse_datasource_vector);
reverse_datasource = reverse_datasource =
reverse_datasource_vector[reverse_datasource_vector.size() - reverse_datasource_vector[reverse_datasource_vector.size() -
@ -884,7 +886,7 @@ Status TilePlugin::HandleRequest(const api::TileParameters &parameters, std::str
util::vector_tile::VARIANT_TAG); util::vector_tile::VARIANT_TAG);
// Attribute value 1 == string type // Attribute value 1 == string type
values_writer.add_string(util::vector_tile::VARIANT_TYPE_STRING, values_writer.add_string(util::vector_tile::VARIANT_TYPE_STRING,
facade.GetDatasourceName(i)); facade->GetDatasourceName(i));
} }
for (auto value : used_line_ints) for (auto value : used_line_ints)
{ {

View File

@ -114,7 +114,8 @@ SCC_Component SplitUnaccessibleLocations(const std::size_t number_of_locations,
return SCC_Component(std::move(components), std::move(range)); return SCC_Component(std::move(components), std::move(range));
} }
InternalRouteResult TripPlugin::ComputeRoute(const std::vector<PhantomNode> &snapped_phantoms, InternalRouteResult TripPlugin::ComputeRoute(const datafacade::BaseDataFacade& facade,
const std::vector<PhantomNode> &snapped_phantoms,
const std::vector<NodeID> &trip) const std::vector<NodeID> &trip)
{ {
InternalRouteResult min_route; InternalRouteResult min_route;
@ -134,13 +135,14 @@ InternalRouteResult TripPlugin::ComputeRoute(const std::vector<PhantomNode> &sna
} }
BOOST_ASSERT(min_route.segment_end_coordinates.size() == trip.size()); BOOST_ASSERT(min_route.segment_end_coordinates.size() == trip.size());
shortest_path(min_route.segment_end_coordinates, {false}, min_route); shortest_path(facade, min_route.segment_end_coordinates, {false}, min_route);
BOOST_ASSERT_MSG(min_route.shortest_path_length < INVALID_EDGE_WEIGHT, "unroutable route"); BOOST_ASSERT_MSG(min_route.shortest_path_length < INVALID_EDGE_WEIGHT, "unroutable route");
return min_route; return min_route;
} }
Status TripPlugin::HandleRequest(const api::TripParameters &parameters, Status TripPlugin::HandleRequest(const std::shared_ptr<datafacade::BaseDataFacade> facade,
const api::TripParameters &parameters,
util::json::Object &json_result) util::json::Object &json_result)
{ {
BOOST_ASSERT(parameters.IsValid()); BOOST_ASSERT(parameters.IsValid());
@ -157,7 +159,7 @@ Status TripPlugin::HandleRequest(const api::TripParameters &parameters,
return Error("InvalidValue", "Invalid coordinate value.", json_result); return Error("InvalidValue", "Invalid coordinate value.", json_result);
} }
auto phantom_node_pairs = GetPhantomNodes(parameters); auto phantom_node_pairs = GetPhantomNodes(*facade, parameters);
if (phantom_node_pairs.size() != parameters.coordinates.size()) if (phantom_node_pairs.size() != parameters.coordinates.size())
{ {
return Error("NoSegment", return Error("NoSegment",
@ -173,7 +175,7 @@ Status TripPlugin::HandleRequest(const api::TripParameters &parameters,
// 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(*facade, snapped_phantoms, {}, {}), number_of_locations);
if (result_table.size() == 0) if (result_table.size() == 0)
{ {
@ -231,10 +233,10 @@ Status TripPlugin::HandleRequest(const api::TripParameters &parameters,
routes.reserve(trips.size()); routes.reserve(trips.size());
for (const auto &trip : trips) for (const auto &trip : trips)
{ {
routes.push_back(ComputeRoute(snapped_phantoms, trip)); routes.push_back(ComputeRoute(*facade, snapped_phantoms, trip));
} }
api::TripAPI trip_api{BasePlugin::facade, parameters}; api::TripAPI trip_api{*facade, parameters};
trip_api.MakeResponse(trips, routes, snapped_phantoms, json_result); trip_api.MakeResponse(trips, routes, snapped_phantoms, json_result);
return Status::Ok; return Status::Ok;

View File

@ -21,13 +21,14 @@ namespace engine
namespace plugins namespace plugins
{ {
ViaRoutePlugin::ViaRoutePlugin(datafacade::BaseDataFacade &facade_, int max_locations_viaroute) ViaRoutePlugin::ViaRoutePlugin(int max_locations_viaroute)
: BasePlugin(facade_), shortest_path(&facade_, heaps), alternative_path(&facade_, heaps), : shortest_path(heaps), alternative_path(heaps), direct_shortest_path(heaps),
direct_shortest_path(&facade_, heaps), max_locations_viaroute(max_locations_viaroute) max_locations_viaroute(max_locations_viaroute)
{ {
} }
Status ViaRoutePlugin::HandleRequest(const api::RouteParameters &route_parameters, Status ViaRoutePlugin::HandleRequest(const std::shared_ptr<datafacade::BaseDataFacade> facade,
const api::RouteParameters &route_parameters,
util::json::Object &json_result) util::json::Object &json_result)
{ {
BOOST_ASSERT(route_parameters.IsValid()); BOOST_ASSERT(route_parameters.IsValid());
@ -47,7 +48,7 @@ Status ViaRoutePlugin::HandleRequest(const api::RouteParameters &route_parameter
return Error("InvalidValue", "Invalid coordinate value.", json_result); return Error("InvalidValue", "Invalid coordinate value.", json_result);
} }
auto phantom_node_pairs = GetPhantomNodes(route_parameters); auto phantom_node_pairs = GetPhantomNodes(*facade, route_parameters);
if (phantom_node_pairs.size() != route_parameters.coordinates.size()) if (phantom_node_pairs.size() != route_parameters.coordinates.size())
{ {
return Error("NoSegment", return Error("NoSegment",
@ -61,7 +62,7 @@ Status ViaRoutePlugin::HandleRequest(const api::RouteParameters &route_parameter
const bool continue_straight_at_waypoint = route_parameters.continue_straight const bool continue_straight_at_waypoint = route_parameters.continue_straight
? *route_parameters.continue_straight ? *route_parameters.continue_straight
: facade.GetContinueStraightDefault(); : facade->GetContinueStraightDefault();
InternalRouteResult raw_route; InternalRouteResult raw_route;
auto build_phantom_pairs = [&raw_route, continue_straight_at_waypoint]( auto build_phantom_pairs = [&raw_route, continue_straight_at_waypoint](
@ -85,18 +86,18 @@ Status ViaRoutePlugin::HandleRequest(const api::RouteParameters &route_parameter
if (1 == raw_route.segment_end_coordinates.size()) if (1 == raw_route.segment_end_coordinates.size())
{ {
if (route_parameters.alternatives && facade.GetCoreSize() == 0) if (route_parameters.alternatives && facade->GetCoreSize() == 0)
{ {
alternative_path(raw_route.segment_end_coordinates.front(), raw_route); alternative_path(*facade, raw_route.segment_end_coordinates.front(), raw_route);
} }
else else
{ {
direct_shortest_path(raw_route.segment_end_coordinates, raw_route); direct_shortest_path(*facade, raw_route.segment_end_coordinates, raw_route);
} }
} }
else else
{ {
shortest_path( shortest_path(*facade,
raw_route.segment_end_coordinates, route_parameters.continue_straight, raw_route); raw_route.segment_end_coordinates, route_parameters.continue_straight, raw_route);
} }
@ -104,7 +105,7 @@ Status ViaRoutePlugin::HandleRequest(const api::RouteParameters &route_parameter
// allow for connection in one direction. // allow for connection in one direction.
if (raw_route.is_valid()) if (raw_route.is_valid())
{ {
api::RouteAPI route_api{BasePlugin::facade, route_parameters}; api::RouteAPI route_api{*facade, route_parameters};
route_api.MakeResponse(raw_route, json_result); route_api.MakeResponse(raw_route, json_result);
} }
else else