From 905ca69301c4929ae40b5c7aede05bbc6590d0e6 Mon Sep 17 00:00:00 2001 From: Michael Krasnyk Date: Mon, 3 Apr 2017 19:15:58 +0200 Subject: [PATCH] add Algorithm parameter to SearchEngineData --- include/engine/engine.hpp | 27 ++-- include/engine/routing_algorithms.hpp | 83 ++++++----- .../routing_algorithms/alternative_path.hpp | 4 +- .../direct_shortest_path.hpp | 11 +- .../routing_algorithms/many_to_many.hpp | 2 +- .../routing_algorithms/map_matching.hpp | 16 +-- .../routing_algorithms/routing_base.hpp | 3 +- .../routing_algorithms/routing_base_ch.hpp | 52 +++---- .../routing_algorithms/routing_base_mld.hpp | 8 +- .../routing_algorithms/shortest_path.hpp | 11 +- include/engine/search_engine_data.hpp | 68 ++++----- .../routing_algorithms/alternative_path.cpp | 27 ++-- .../direct_shortest_path.cpp | 37 +++-- .../routing_algorithms/many_to_many.cpp | 6 +- .../routing_algorithms/map_matching.cpp | 28 ++-- .../routing_algorithms/routing_base_ch.cpp | 32 ++--- .../routing_algorithms/shortest_path.cpp | 21 +-- src/engine/search_engine_data.cpp | 132 ++++++++++++------ 18 files changed, 294 insertions(+), 274 deletions(-) diff --git a/include/engine/engine.hpp b/include/engine/engine.hpp index 90f79b67d..978d750bc 100644 --- a/include/engine/engine.hpp +++ b/include/engine/engine.hpp @@ -49,7 +49,7 @@ class EngineInterface virtual Status Tile(const api::TileParameters ¶meters, std::string &result) const = 0; }; -template class Engine final : public EngineInterface +template class Engine final : public EngineInterface { public: explicit Engine(const EngineConfig &config) @@ -64,15 +64,14 @@ template class Engine final : public EngineInterface if (config.use_shared_memory) { util::Log(logDEBUG) << "Using shared memory with algorithm " - << routing_algorithms::name(); - facade_provider = std::make_unique>(); + << routing_algorithms::name(); + facade_provider = std::make_unique>(); } else { util::Log(logDEBUG) << "Using internal memory with algorithm " - << routing_algorithms::name(); - facade_provider = - std::make_unique>(config.storage_config); + << routing_algorithms::name(); + facade_provider = std::make_unique>(config.storage_config); } } @@ -87,7 +86,7 @@ template class Engine final : public EngineInterface util::json::Object &result) const override final { auto facade = facade_provider->Get(); - auto algorithms = RoutingAlgorithms{heaps, *facade}; + auto algorithms = RoutingAlgorithms{heaps, *facade}; return route_plugin.HandleRequest(*facade, algorithms, params, result); } @@ -95,7 +94,7 @@ template class Engine final : public EngineInterface util::json::Object &result) const override final { auto facade = facade_provider->Get(); - auto algorithms = RoutingAlgorithms{heaps, *facade}; + auto algorithms = RoutingAlgorithms{heaps, *facade}; return table_plugin.HandleRequest(*facade, algorithms, params, result); } @@ -103,14 +102,14 @@ template class Engine final : public EngineInterface util::json::Object &result) const override final { auto facade = facade_provider->Get(); - auto algorithms = RoutingAlgorithms{heaps, *facade}; + auto algorithms = RoutingAlgorithms{heaps, *facade}; return nearest_plugin.HandleRequest(*facade, algorithms, params, result); } Status Trip(const api::TripParameters ¶ms, util::json::Object &result) const override final { auto facade = facade_provider->Get(); - auto algorithms = RoutingAlgorithms{heaps, *facade}; + auto algorithms = RoutingAlgorithms{heaps, *facade}; return trip_plugin.HandleRequest(*facade, algorithms, params, result); } @@ -118,22 +117,22 @@ template class Engine final : public EngineInterface util::json::Object &result) const override final { auto facade = facade_provider->Get(); - auto algorithms = RoutingAlgorithms{heaps, *facade}; + auto algorithms = RoutingAlgorithms{heaps, *facade}; return match_plugin.HandleRequest(*facade, algorithms, params, result); } Status Tile(const api::TileParameters ¶ms, std::string &result) const override final { auto facade = facade_provider->Get(); - auto algorithms = RoutingAlgorithms{heaps, *facade}; + auto algorithms = RoutingAlgorithms{heaps, *facade}; return tile_plugin.HandleRequest(*facade, algorithms, params, result); } static bool CheckCompability(const EngineConfig &config); private: - std::unique_ptr> facade_provider; - mutable SearchEngineData heaps; + std::unique_ptr> facade_provider; + mutable SearchEngineData heaps; const plugins::ViaRoutePlugin route_plugin; const plugins::TablePlugin table_plugin; diff --git a/include/engine/routing_algorithms.hpp b/include/engine/routing_algorithms.hpp index 730f31b6a..bd8af9f8c 100644 --- a/include/engine/routing_algorithms.hpp +++ b/include/engine/routing_algorithms.hpp @@ -54,11 +54,11 @@ class RoutingAlgorithmsInterface }; // Short-lived object passed to each plugin in request to wrap routing algorithms -template class RoutingAlgorithms final : public RoutingAlgorithmsInterface +template class RoutingAlgorithms final : public RoutingAlgorithmsInterface { public: - RoutingAlgorithms(SearchEngineData &heaps, - const datafacade::ContiguousInternalMemoryDataFacade &facade) + RoutingAlgorithms(SearchEngineData &heaps, + const datafacade::ContiguousInternalMemoryDataFacade &facade) : heaps(heaps), facade(facade) { } @@ -93,49 +93,49 @@ template class RoutingAlgorithms final : public RoutingAlg bool HasAlternativePathSearch() const final override { - return routing_algorithms::HasAlternativePathSearch::value; + return routing_algorithms::HasAlternativePathSearch::value; } bool HasShortestPathSearch() const final override { - return routing_algorithms::HasShortestPathSearch::value; + return routing_algorithms::HasShortestPathSearch::value; } bool HasDirectShortestPathSearch() const final override { - return routing_algorithms::HasDirectShortestPathSearch::value; + return routing_algorithms::HasDirectShortestPathSearch::value; } bool HasMapMatching() const final override { - return routing_algorithms::HasMapMatching::value; + return routing_algorithms::HasMapMatching::value; } bool HasManyToManySearch() const final override { - return routing_algorithms::HasManyToManySearch::value; + return routing_algorithms::HasManyToManySearch::value; } bool HasGetTileTurns() const final override { - return routing_algorithms::HasGetTileTurns::value; + return routing_algorithms::HasGetTileTurns::value; } private: - SearchEngineData &heaps; + SearchEngineData &heaps; // Owned by shared-ptr passed to the query - const datafacade::ContiguousInternalMemoryDataFacade &facade; + const datafacade::ContiguousInternalMemoryDataFacade &facade; }; -template +template InternalRouteResult -RoutingAlgorithms::AlternativePathSearch(const PhantomNodes &phantom_node_pair) const +RoutingAlgorithms::AlternativePathSearch(const PhantomNodes &phantom_node_pair) const { return routing_algorithms::ch::alternativePathSearch(heaps, facade, phantom_node_pair); } -template -InternalRouteResult RoutingAlgorithms::ShortestPathSearch( +template +InternalRouteResult RoutingAlgorithms::ShortestPathSearch( const std::vector &phantom_node_pair, const boost::optional continue_straight_at_waypoint) const { @@ -143,48 +143,65 @@ InternalRouteResult RoutingAlgorithms::ShortestPathSearch( heaps, facade, phantom_node_pair, continue_straight_at_waypoint); } -template +template InternalRouteResult -RoutingAlgorithms::DirectShortestPathSearch(const PhantomNodes &phantom_nodes) const +RoutingAlgorithms::DirectShortestPathSearch(const PhantomNodes &phantom_nodes) const { return routing_algorithms::directShortestPathSearch(heaps, facade, phantom_nodes); } -template -std::vector RoutingAlgorithms::ManyToManySearch( - const std::vector &phantom_nodes, - const std::vector &source_indices, - const std::vector &target_indices) const +template +std::vector +RoutingAlgorithms::ManyToManySearch(const std::vector &phantom_nodes, + const std::vector &source_indices, + const std::vector &target_indices) const { return routing_algorithms::ch::manyToManySearch( heaps, facade, phantom_nodes, source_indices, target_indices); } -template -inline routing_algorithms::SubMatchingList RoutingAlgorithms::MapMatching( +template +inline routing_algorithms::SubMatchingList RoutingAlgorithms::MapMatching( const routing_algorithms::CandidateLists &candidates_list, const std::vector &trace_coordinates, const std::vector &trace_timestamps, const std::vector> &trace_gps_precision, const bool allow_splitting) const { - return routing_algorithms::ch::mapMatching(heaps, - facade, - candidates_list, - trace_coordinates, - trace_timestamps, - trace_gps_precision, - allow_splitting); + return routing_algorithms::mapMatching(heaps, + facade, + candidates_list, + trace_coordinates, + trace_timestamps, + trace_gps_precision, + allow_splitting); } -template -inline std::vector RoutingAlgorithms::GetTileTurns( +template +inline std::vector RoutingAlgorithms::GetTileTurns( const std::vector &edges, const std::vector &sorted_edge_indexes) const { return routing_algorithms::getTileTurns(facade, edges, sorted_edge_indexes); } +// CoreCH overrides +template <> +InternalRouteResult inline RoutingAlgorithms::AlternativePathSearch(const PhantomNodes &) const +{ + throw util::exception("AlternativePathSearch is disabled due to performance reasons"); +} + +template <> +inline std::vector +RoutingAlgorithms::ManyToManySearch( + const std::vector &, + const std::vector &, + const std::vector &) const +{ + throw util::exception("ManyToManySearch is disabled due to performance reasons"); +} + // MLD overrides for not implemented template <> InternalRouteResult inline RoutingAlgorithms< diff --git a/include/engine/routing_algorithms/alternative_path.hpp b/include/engine/routing_algorithms/alternative_path.hpp index 12999784e..0bd418275 100644 --- a/include/engine/routing_algorithms/alternative_path.hpp +++ b/include/engine/routing_algorithms/alternative_path.hpp @@ -18,8 +18,8 @@ namespace routing_algorithms namespace ch { InternalRouteResult -alternativePathSearch(SearchEngineData &search_engine_data, - const datafacade::ContiguousInternalMemoryDataFacade &facade, +alternativePathSearch(SearchEngineData &search_engine_data, + const datafacade::ContiguousInternalMemoryDataFacade &facade, const PhantomNodes &phantom_node_pair); } // namespace ch } // namespace routing_algorithms diff --git a/include/engine/routing_algorithms/direct_shortest_path.hpp b/include/engine/routing_algorithms/direct_shortest_path.hpp index 3a9472314..849e75d62 100644 --- a/include/engine/routing_algorithms/direct_shortest_path.hpp +++ b/include/engine/routing_algorithms/direct_shortest_path.hpp @@ -21,12 +21,17 @@ namespace routing_algorithms /// by the previous route. /// This variation is only an optimazation for graphs with slow queries, for example /// not fully contracted graphs. -template +template InternalRouteResult -directShortestPathSearch(SearchEngineData &engine_working_data, - const datafacade::ContiguousInternalMemoryDataFacade &facade, +directShortestPathSearch(SearchEngineData &engine_working_data, + const datafacade::ContiguousInternalMemoryDataFacade &facade, const PhantomNodes &phantom_nodes); +InternalRouteResult directShortestPathSearch( + SearchEngineData &engine_working_data, + const datafacade::ContiguousInternalMemoryDataFacade &facade, + const PhantomNodes &phantom_nodes); + } // namespace routing_algorithms } // namespace engine } // namespace osrm diff --git a/include/engine/routing_algorithms/many_to_many.hpp b/include/engine/routing_algorithms/many_to_many.hpp index 06697e4c5..338cf4a88 100644 --- a/include/engine/routing_algorithms/many_to_many.hpp +++ b/include/engine/routing_algorithms/many_to_many.hpp @@ -19,7 +19,7 @@ namespace routing_algorithms namespace ch { std::vector -manyToManySearch(SearchEngineData &engine_working_data, +manyToManySearch(SearchEngineData &engine_working_data, const datafacade::ContiguousInternalMemoryDataFacade &facade, const std::vector &phantom_nodes, const std::vector &source_indices, diff --git a/include/engine/routing_algorithms/map_matching.hpp b/include/engine/routing_algorithms/map_matching.hpp index aed5427e1..00984dc8a 100644 --- a/include/engine/routing_algorithms/map_matching.hpp +++ b/include/engine/routing_algorithms/map_matching.hpp @@ -22,27 +22,15 @@ static const constexpr double DEFAULT_GPS_PRECISION = 5; //[1] "Hidden Markov Map Matching Through Noise and Sparseness"; // P. Newson and J. Krumm; 2009; ACM GIS -namespace ch -{ -SubMatchingList mapMatching(SearchEngineData &engine_working_data, +template +SubMatchingList mapMatching(SearchEngineData &engine_working_data, const datafacade::ContiguousInternalMemoryDataFacade &facade, const CandidateLists &candidates_list, const std::vector &trace_coordinates, const std::vector &trace_timestamps, const std::vector> &trace_gps_precision, const bool allow_splitting); -} -namespace corech -{ -SubMatchingList mapMatching(SearchEngineData &engine_working_data, - const datafacade::ContiguousInternalMemoryDataFacade &facade, - const CandidateLists &candidates_list, - const std::vector &trace_coordinates, - const std::vector &trace_timestamps, - const std::vector> &trace_gps_precision, - const bool allow_splitting); -} } } } diff --git a/include/engine/routing_algorithms/routing_base.hpp b/include/engine/routing_algorithms/routing_base.hpp index def1960e6..c1952b1ed 100644 --- a/include/engine/routing_algorithms/routing_base.hpp +++ b/include/engine/routing_algorithms/routing_base.hpp @@ -58,7 +58,8 @@ void insertNodesInHeap(Heap &heap, const PhantomNode &phantom_node) } template -void insertNodesInHeap(SearchEngineData::ManyToManyQueryHeap &heap, const PhantomNode &phantom_node) +void insertNodesInHeap(SearchEngineData::ManyToManyQueryHeap &heap, + const PhantomNode &phantom_node) { BOOST_ASSERT(phantom_node.IsValid()); diff --git a/include/engine/routing_algorithms/routing_base_ch.hpp b/include/engine/routing_algorithms/routing_base_ch.hpp index 52174e8b1..0f89e512c 100644 --- a/include/engine/routing_algorithms/routing_base_ch.hpp +++ b/include/engine/routing_algorithms/routing_base_ch.hpp @@ -52,7 +52,7 @@ template void relaxOutgoingEdges(const datafacade::ContiguousInternalMemoryDataFacade &facade, const NodeID node, const EdgeWeight weight, - SearchEngineData::QueryHeap &heap) + SearchEngineData::QueryHeap &heap) { for (const auto edge : facade.GetAdjacentEdgeRange(node)) { @@ -114,8 +114,8 @@ static constexpr bool ENABLE_STALLING = true; static constexpr bool DISABLE_STALLING = false; template void routingStep(const datafacade::ContiguousInternalMemoryDataFacade &facade, - SearchEngineData::QueryHeap &forward_heap, - SearchEngineData::QueryHeap &reverse_heap, + SearchEngineData::QueryHeap &forward_heap, + SearchEngineData::QueryHeap &reverse_heap, NodeID &middle_node_id, EdgeWeight &upper_bound, EdgeWeight min_edge_offset, @@ -329,12 +329,12 @@ void unpackEdge(const datafacade::ContiguousInternalMemoryDataFacade const NodeID to, std::vector &unpacked_path); -void retrievePackedPathFromHeap(const SearchEngineData::QueryHeap &forward_heap, - const SearchEngineData::QueryHeap &reverse_heap, +void retrievePackedPathFromHeap(const SearchEngineData::QueryHeap &forward_heap, + const SearchEngineData::QueryHeap &reverse_heap, const NodeID middle_node_id, std::vector &packed_path); -void retrievePackedPathFromSingleHeap(const SearchEngineData::QueryHeap &search_heap, +void retrievePackedPathFromSingleHeap(const SearchEngineData::QueryHeap &search_heap, const NodeID middle_node_id, std::vector &packed_path); @@ -351,8 +351,8 @@ void retrievePackedPathFromSingleHeap(const SearchEngineData::QueryHeap &search_ // requires // a force loop, if the heaps have been initialized with positive offsets. void search(const datafacade::ContiguousInternalMemoryDataFacade &facade, - SearchEngineData::QueryHeap &forward_heap, - SearchEngineData::QueryHeap &reverse_heap, + SearchEngineData::QueryHeap &forward_heap, + SearchEngineData::QueryHeap &reverse_heap, std::int32_t &weight, std::vector &packed_leg, const bool force_loop_forward, @@ -361,10 +361,10 @@ void search(const datafacade::ContiguousInternalMemoryDataFacade &fac // Alias to be compatible with the overload for CoreCH that needs 4 heaps inline void search(const datafacade::ContiguousInternalMemoryDataFacade &facade, - SearchEngineData::QueryHeap &forward_heap, - SearchEngineData::QueryHeap &reverse_heap, - SearchEngineData::QueryHeap &, - SearchEngineData::QueryHeap &, + SearchEngineData::QueryHeap &forward_heap, + SearchEngineData::QueryHeap &reverse_heap, + SearchEngineData::QueryHeap &, + SearchEngineData::QueryHeap &, std::int32_t &weight, std::vector &packed_leg, const bool force_loop_forward, @@ -395,8 +395,8 @@ double getPathDistance(const datafacade::ContiguousInternalMemoryDataFacade &facade, - SearchEngineData::QueryHeap &forward_heap, - SearchEngineData::QueryHeap &reverse_heap, + SearchEngineData::QueryHeap &forward_heap, + SearchEngineData::QueryHeap &reverse_heap, const PhantomNode &source_phantom, const PhantomNode &target_phantom, int duration_upper_bound = INVALID_EDGE_WEIGHT); @@ -404,10 +404,10 @@ getNetworkDistance(const datafacade::ContiguousInternalMemoryDataFacade &facade, - SearchEngineData::QueryHeap &forward_heap, - SearchEngineData::QueryHeap &reverse_heap, - SearchEngineData::QueryHeap &, - SearchEngineData::QueryHeap &, + SearchEngineData::QueryHeap &forward_heap, + SearchEngineData::QueryHeap &reverse_heap, + SearchEngineData::QueryHeap &, + SearchEngineData::QueryHeap &, const PhantomNode &source_phantom, const PhantomNode &target_phantom, int duration_upper_bound = INVALID_EDGE_WEIGHT) @@ -429,10 +429,10 @@ namespace corech // requires // a force loop, if the heaps have been initialized with positive offsets. void search(const datafacade::ContiguousInternalMemoryDataFacade &facade, - SearchEngineData::QueryHeap &forward_heap, - SearchEngineData::QueryHeap &reverse_heap, - SearchEngineData::QueryHeap &forward_core_heap, - SearchEngineData::QueryHeap &reverse_core_heap, + SearchEngineData::QueryHeap &forward_heap, + SearchEngineData::QueryHeap &reverse_heap, + SearchEngineData::QueryHeap &forward_core_heap, + SearchEngineData::QueryHeap &reverse_core_heap, int &weight, std::vector &packed_leg, const bool force_loop_forward, @@ -444,10 +444,10 @@ void search(const datafacade::ContiguousInternalMemoryDataFacade &facade, - SearchEngineData::QueryHeap &forward_heap, - SearchEngineData::QueryHeap &reverse_heap, - SearchEngineData::QueryHeap &forward_core_heap, - SearchEngineData::QueryHeap &reverse_core_heap, + SearchEngineData::QueryHeap &forward_heap, + SearchEngineData::QueryHeap &reverse_heap, + SearchEngineData::QueryHeap &forward_core_heap, + SearchEngineData::QueryHeap &reverse_core_heap, const PhantomNode &source_phantom, const PhantomNode &target_phantom, int duration_upper_bound = INVALID_EDGE_WEIGHT); diff --git a/include/engine/routing_algorithms/routing_base_mld.hpp b/include/engine/routing_algorithms/routing_base_mld.hpp index 9f839a84d..dcf5b21e0 100644 --- a/include/engine/routing_algorithms/routing_base_mld.hpp +++ b/include/engine/routing_algorithms/routing_base_mld.hpp @@ -58,8 +58,8 @@ bool checkParentCellRestriction(CellID cell, LevelID, CellID parent) { return ce template void routingStep(const datafacade::ContiguousInternalMemoryDataFacade &facade, - SearchEngineData::MultiLayerDijkstraHeap &forward_heap, - SearchEngineData::MultiLayerDijkstraHeap &reverse_heap, + SearchEngineData::QueryHeap &forward_heap, + SearchEngineData::QueryHeap &reverse_heap, NodeID &middle_node, EdgeWeight &path_upper_bound, Args... args) @@ -172,8 +172,8 @@ void routingStep(const datafacade::ContiguousInternalMemoryDataFacade template std::tuple> search(const datafacade::ContiguousInternalMemoryDataFacade &facade, - SearchEngineData::MultiLayerDijkstraHeap &forward_heap, - SearchEngineData::MultiLayerDijkstraHeap &reverse_heap, + SearchEngineData::QueryHeap &forward_heap, + SearchEngineData::QueryHeap &reverse_heap, Args... args) { diff --git a/include/engine/routing_algorithms/shortest_path.hpp b/include/engine/routing_algorithms/shortest_path.hpp index aa9af81b8..2273192fb 100644 --- a/include/engine/routing_algorithms/shortest_path.hpp +++ b/include/engine/routing_algorithms/shortest_path.hpp @@ -13,15 +13,10 @@ namespace engine namespace routing_algorithms { +template InternalRouteResult -shortestPathSearch(SearchEngineData &engine_working_data, - const datafacade::ContiguousInternalMemoryDataFacade &facade, - const std::vector &phantom_nodes_vector, - const boost::optional continue_straight_at_waypoint); - -InternalRouteResult -shortestPathSearch(SearchEngineData &engine_working_data, - const datafacade::ContiguousInternalMemoryDataFacade &facade, +shortestPathSearch(SearchEngineData &engine_working_data, + const datafacade::ContiguousInternalMemoryDataFacade &facade, const std::vector &phantom_nodes_vector, const boost::optional continue_straight_at_waypoint); diff --git a/include/engine/search_engine_data.hpp b/include/engine/search_engine_data.hpp index 18f616ae1..ed3fac0ce 100644 --- a/include/engine/search_engine_data.hpp +++ b/include/engine/search_engine_data.hpp @@ -24,14 +24,7 @@ struct ManyToManyHeapData : HeapData ManyToManyHeapData(NodeID p, EdgeWeight duration) : HeapData(p), duration(duration) {} }; -struct MultiLayerDijkstraHeapData : HeapData -{ - bool from_clique_arc; - MultiLayerDijkstraHeapData(NodeID p) : HeapData(p), from_clique_arc(false) {} - MultiLayerDijkstraHeapData(NodeID p, bool from) : HeapData(p), from_clique_arc(from) {} -}; - -struct SearchEngineData +template struct SearchEngineData { using QueryHeap = util:: BinaryHeap>; @@ -45,58 +38,45 @@ struct SearchEngineData using ManyToManyHeapPtr = boost::thread_specific_ptr; - using MultiLayerDijkstraHeap = util::BinaryHeap>; - - using MultiLayerDijkstraHeapPtr = boost::thread_specific_ptr; - -private: static SearchEngineHeapPtr forward_heap_1; static SearchEngineHeapPtr reverse_heap_1; - static MultiLayerDijkstraHeapPtr mld_forward_heap; - static MultiLayerDijkstraHeapPtr mld_reverse_heap; - -public: static SearchEngineHeapPtr forward_heap_2; static SearchEngineHeapPtr reverse_heap_2; static SearchEngineHeapPtr forward_heap_3; static SearchEngineHeapPtr reverse_heap_3; static ManyToManyHeapPtr many_to_many_heap; - template - void InitializeOrClearFirstThreadLocalStorage(Algorithm, const unsigned number_of_nodes); + void InitializeOrClearFirstThreadLocalStorage(unsigned number_of_nodes); - template auto GetForwardHeapPtr(Algorithm) const - { - return forward_heap_1.get(); - } + void InitializeOrClearSecondThreadLocalStorage(unsigned number_of_nodes); - template auto GetReverseHeapPtr(Algorithm) const - { - return reverse_heap_1.get(); - } + void InitializeOrClearThirdThreadLocalStorage(unsigned number_of_nodes); - void InitializeOrClearFirstThreadLocalStorage(routing_algorithms::mld::Algorithm, - const unsigned number_of_nodes); + void InitializeOrClearManyToManyThreadLocalStorage(unsigned number_of_nodes); +}; - auto GetForwardHeapPtr(routing_algorithms::mld::Algorithm) const - { - return mld_forward_heap.get(); - } +struct MultiLayerDijkstraHeapData +{ + NodeID parent; + bool from_clique_arc; + MultiLayerDijkstraHeapData(NodeID p) : parent(p), from_clique_arc(false) {} + MultiLayerDijkstraHeapData(NodeID p, bool from) : parent(p), from_clique_arc(from) {} +}; - auto GetReverseHeapPtr(routing_algorithms::mld::Algorithm) const - { - return mld_reverse_heap.get(); - } +template <> struct SearchEngineData +{ + using QueryHeap = util::BinaryHeap>; - void InitializeOrClearSecondThreadLocalStorage(const unsigned number_of_nodes); + using SearchEngineHeapPtr = boost::thread_specific_ptr; - void InitializeOrClearThirdThreadLocalStorage(const unsigned number_of_nodes); + static SearchEngineHeapPtr forward_heap_1; + static SearchEngineHeapPtr reverse_heap_1; - void InitializeOrClearManyToManyThreadLocalStorage(const unsigned number_of_nodes); + void InitializeOrClearFirstThreadLocalStorage(unsigned number_of_nodes); }; } } diff --git a/src/engine/routing_algorithms/alternative_path.cpp b/src/engine/routing_algorithms/alternative_path.cpp index 0d58e373a..01739ead6 100644 --- a/src/engine/routing_algorithms/alternative_path.cpp +++ b/src/engine/routing_algorithms/alternative_path.cpp @@ -28,7 +28,7 @@ const double constexpr VIAPATH_ALPHA = 0.10; const double constexpr VIAPATH_EPSILON = 0.15; // alternative at most 15% longer const double constexpr VIAPATH_GAMMA = 0.75; // alternative shares at most 75% with the shortest. -using QueryHeap = SearchEngineData::QueryHeap; +using QueryHeap = SearchEngineData::QueryHeap; using SearchSpaceEdge = std::pair; struct RankedCandidateNode @@ -154,7 +154,7 @@ void retrievePackedAlternatePath(const QueryHeap &forward_heap1, // from v and intersecting against queues. only half-searches have to be // done at this stage void computeLengthAndSharingOfViaPath( - SearchEngineData &engine_working_data, + SearchEngineData &engine_working_data, const datafacade::ContiguousInternalMemoryDataFacade &facade, const NodeID via_node, int *real_length_of_via_path, @@ -164,10 +164,10 @@ void computeLengthAndSharingOfViaPath( { engine_working_data.InitializeOrClearSecondThreadLocalStorage(facade.GetNumberOfNodes()); - auto &existing_forward_heap = *engine_working_data.GetForwardHeapPtr(Algorithm{}); - auto &existing_reverse_heap = *engine_working_data.GetReverseHeapPtr(Algorithm{}); - QueryHeap &new_forward_heap = *engine_working_data.forward_heap_2; - QueryHeap &new_reverse_heap = *engine_working_data.reverse_heap_2; + auto &existing_forward_heap = *engine_working_data.forward_heap_1; + auto &existing_reverse_heap = *engine_working_data.reverse_heap_1; + auto &new_forward_heap = *engine_working_data.forward_heap_2; + auto &new_reverse_heap = *engine_working_data.reverse_heap_2; std::vector packed_s_v_path; std::vector packed_v_t_path; @@ -319,7 +319,7 @@ void computeLengthAndSharingOfViaPath( // conduct T-Test bool viaNodeCandidatePassesTTest( - SearchEngineData &engine_working_data, + SearchEngineData &engine_working_data, const datafacade::ContiguousInternalMemoryDataFacade &facade, QueryHeap &existing_forward_heap, QueryHeap &existing_reverse_heap, @@ -563,7 +563,7 @@ bool viaNodeCandidatePassesTTest( } InternalRouteResult -alternativePathSearch(SearchEngineData &engine_working_data, +alternativePathSearch(SearchEngineData &engine_working_data, const datafacade::ContiguousInternalMemoryDataFacade &facade, const PhantomNodes &phantom_node_pair) { @@ -575,15 +575,14 @@ alternativePathSearch(SearchEngineData &engine_working_data, std::vector reverse_search_space; // Init queues, semi-expensive because access to TSS invokes a sys-call - engine_working_data.InitializeOrClearFirstThreadLocalStorage(Algorithm{}, - facade.GetNumberOfNodes()); + engine_working_data.InitializeOrClearFirstThreadLocalStorage(facade.GetNumberOfNodes()); engine_working_data.InitializeOrClearSecondThreadLocalStorage(facade.GetNumberOfNodes()); engine_working_data.InitializeOrClearThirdThreadLocalStorage(facade.GetNumberOfNodes()); - auto &forward_heap1 = *engine_working_data.GetForwardHeapPtr(Algorithm{}); - auto &reverse_heap1 = *engine_working_data.GetReverseHeapPtr(Algorithm{}); - QueryHeap &forward_heap2 = *(engine_working_data.forward_heap_2); - QueryHeap &reverse_heap2 = *(engine_working_data.reverse_heap_2); + auto &forward_heap1 = *engine_working_data.forward_heap_1; + auto &reverse_heap1 = *engine_working_data.reverse_heap_1; + auto &forward_heap2 = *engine_working_data.forward_heap_2; + auto &reverse_heap2 = *engine_working_data.reverse_heap_2; EdgeWeight upper_bound_to_shortest_path_weight = INVALID_EDGE_WEIGHT; NodeID middle_node = SPECIAL_NODEID; diff --git a/src/engine/routing_algorithms/direct_shortest_path.cpp b/src/engine/routing_algorithms/direct_shortest_path.cpp index 657d91e8a..916db8532 100644 --- a/src/engine/routing_algorithms/direct_shortest_path.cpp +++ b/src/engine/routing_algorithms/direct_shortest_path.cpp @@ -47,7 +47,7 @@ extractRoute(const datafacade::ContiguousInternalMemoryDataFacade &f return raw_route_data; } -namespace ch +namespace detail { /// This is a striped down version of the general shortest path algorithm. /// The general algorithm always computes two queries for each leg. This is only @@ -57,17 +57,16 @@ namespace ch /// not fully contracted graphs. template InternalRouteResult directShortestPathSearchImpl( - SearchEngineData &engine_working_data, + SearchEngineData &engine_working_data, const datafacade::ContiguousInternalMemoryDataFacade &facade, const PhantomNodes &phantom_nodes) { - engine_working_data.InitializeOrClearFirstThreadLocalStorage(Algorithm{}, - facade.GetNumberOfNodes()); + engine_working_data.InitializeOrClearFirstThreadLocalStorage(facade.GetNumberOfNodes()); engine_working_data.InitializeOrClearSecondThreadLocalStorage(facade.GetNumberOfNodes()); - auto &forward_heap = *engine_working_data.GetForwardHeapPtr(Algorithm{}); - auto &reverse_heap = *engine_working_data.GetReverseHeapPtr(Algorithm{}); - auto &forward_core_heap = *(engine_working_data.forward_heap_2); - auto &reverse_core_heap = *(engine_working_data.reverse_heap_2); + auto &forward_heap = *engine_working_data.forward_heap_1; + auto &reverse_heap = *engine_working_data.reverse_heap_1; + auto &forward_core_heap = *engine_working_data.forward_heap_2; + auto &reverse_core_heap = *engine_working_data.reverse_heap_2; forward_heap.Clear(); reverse_heap.Clear(); forward_core_heap.Clear(); @@ -94,7 +93,7 @@ InternalRouteResult directShortestPathSearchImpl( source_node = packed_leg.front(); target_node = packed_leg.back(); unpacked_edges.reserve(packed_leg.size()); - unpackPath( + ch::unpackPath( facade, packed_leg.begin(), packed_leg.end(), @@ -109,34 +108,30 @@ InternalRouteResult directShortestPathSearchImpl( template <> InternalRouteResult directShortestPathSearch( - SearchEngineData &engine_working_data, + SearchEngineData &engine_working_data, const datafacade::ContiguousInternalMemoryDataFacade &facade, const PhantomNodes &phantom_nodes) { - return ch::directShortestPathSearchImpl(engine_working_data, facade, phantom_nodes); + return detail::directShortestPathSearchImpl(engine_working_data, facade, phantom_nodes); } template <> InternalRouteResult directShortestPathSearch( - SearchEngineData &engine_working_data, + SearchEngineData &engine_working_data, const datafacade::ContiguousInternalMemoryDataFacade &facade, const PhantomNodes &phantom_nodes) { - return ch::directShortestPathSearchImpl(engine_working_data, facade, phantom_nodes); + return detail::directShortestPathSearchImpl(engine_working_data, facade, phantom_nodes); } -template <> InternalRouteResult directShortestPathSearch( - SearchEngineData &engine_working_data, + SearchEngineData &engine_working_data, const datafacade::ContiguousInternalMemoryDataFacade &facade, const PhantomNodes &phantom_nodes) { - engine_working_data.InitializeOrClearFirstThreadLocalStorage(mld::Algorithm{}, - facade.GetNumberOfNodes()); - auto &forward_heap = *engine_working_data.GetForwardHeapPtr(mld::Algorithm{}); - auto &reverse_heap = *engine_working_data.GetReverseHeapPtr(mld::Algorithm{}); - forward_heap.Clear(); - reverse_heap.Clear(); + engine_working_data.InitializeOrClearFirstThreadLocalStorage(facade.GetNumberOfNodes()); + auto &forward_heap = *engine_working_data.forward_heap_1; + auto &reverse_heap = *engine_working_data.reverse_heap_1; insertNodesInHeaps(forward_heap, reverse_heap, phantom_nodes); // TODO: when structured bindings will be allowed change to diff --git a/src/engine/routing_algorithms/many_to_many.cpp b/src/engine/routing_algorithms/many_to_many.cpp index 71150ebb6..d9f21994b 100644 --- a/src/engine/routing_algorithms/many_to_many.cpp +++ b/src/engine/routing_algorithms/many_to_many.cpp @@ -15,11 +15,11 @@ namespace engine namespace routing_algorithms { -using ManyToManyQueryHeap = SearchEngineData::ManyToManyQueryHeap; - namespace ch { +using ManyToManyQueryHeap = SearchEngineData::ManyToManyQueryHeap; + namespace { struct NodeBucket @@ -151,7 +151,7 @@ void backwardRoutingStep(const datafacade::ContiguousInternalMemoryDataFacade -manyToManySearch(SearchEngineData &engine_working_data, +manyToManySearch(SearchEngineData &engine_working_data, const datafacade::ContiguousInternalMemoryDataFacade &facade, const std::vector &phantom_nodes, const std::vector &source_indices, diff --git a/src/engine/routing_algorithms/map_matching.cpp b/src/engine/routing_algorithms/map_matching.cpp index d83cded1e..18c7a6b3b 100644 --- a/src/engine/routing_algorithms/map_matching.cpp +++ b/src/engine/routing_algorithms/map_matching.cpp @@ -49,7 +49,7 @@ unsigned getMedianSampleTime(const std::vector ×tamps) template SubMatchingList -mapMatchingImpl(SearchEngineData &engine_working_data, +mapMatchingImpl(SearchEngineData &engine_working_data, const datafacade::ContiguousInternalMemoryDataFacade &facade, const CandidateLists &candidates_list, const std::vector &trace_coordinates, @@ -142,13 +142,13 @@ mapMatchingImpl(SearchEngineData &engine_working_data, } const auto nodes_number = facade.GetNumberOfNodes(); - engine_working_data.InitializeOrClearFirstThreadLocalStorage(Algorithm{}, nodes_number); + engine_working_data.InitializeOrClearFirstThreadLocalStorage(nodes_number); engine_working_data.InitializeOrClearSecondThreadLocalStorage(nodes_number); - auto &forward_heap = *engine_working_data.GetForwardHeapPtr(Algorithm{}); - auto &reverse_heap = *engine_working_data.GetReverseHeapPtr(Algorithm{}); - auto &forward_core_heap = *(engine_working_data.forward_heap_2); - auto &reverse_core_heap = *(engine_working_data.reverse_heap_2); + auto &forward_heap = *engine_working_data.forward_heap_1; + auto &reverse_heap = *engine_working_data.reverse_heap_1; + auto &forward_core_heap = *engine_working_data.forward_heap_2; + auto &reverse_core_heap = *engine_working_data.reverse_heap_2; std::size_t breakage_begin = map_matching::INVALID_STATE; std::vector split_points; @@ -420,10 +420,9 @@ mapMatchingImpl(SearchEngineData &engine_working_data, return sub_matchings; } -namespace ch -{ -SubMatchingList mapMatching(SearchEngineData &engine_working_data, - const datafacade::ContiguousInternalMemoryDataFacade &facade, +template<> +SubMatchingList mapMatching(SearchEngineData &engine_working_data, + const datafacade::ContiguousInternalMemoryDataFacade &facade, const CandidateLists &candidates_list, const std::vector &trace_coordinates, const std::vector &trace_timestamps, @@ -438,12 +437,10 @@ SubMatchingList mapMatching(SearchEngineData &engine_working_data, trace_gps_precision, use_tidying); } -} -namespace corech -{ -SubMatchingList mapMatching(SearchEngineData &engine_working_data, - const datafacade::ContiguousInternalMemoryDataFacade &facade, +template<> +SubMatchingList mapMatching(SearchEngineData &engine_working_data, + const datafacade::ContiguousInternalMemoryDataFacade &facade, const CandidateLists &candidates_list, const std::vector &trace_coordinates, const std::vector &trace_timestamps, @@ -459,7 +456,6 @@ SubMatchingList mapMatching(SearchEngineData &engine_working_data, trace_gps_precision, use_tidying); } -} } // namespace routing_algorithms } // namespace engine diff --git a/src/engine/routing_algorithms/routing_base_ch.cpp b/src/engine/routing_algorithms/routing_base_ch.cpp index a070f5275..b2d593031 100644 --- a/src/engine/routing_algorithms/routing_base_ch.cpp +++ b/src/engine/routing_algorithms/routing_base_ch.cpp @@ -31,8 +31,8 @@ void unpackEdge(const datafacade::ContiguousInternalMemoryDataFacade unpacked_path.emplace_back(to); } -void retrievePackedPathFromHeap(const SearchEngineData::QueryHeap &forward_heap, - const SearchEngineData::QueryHeap &reverse_heap, +void retrievePackedPathFromHeap(const SearchEngineData::QueryHeap &forward_heap, + const SearchEngineData::QueryHeap &reverse_heap, const NodeID middle_node_id, std::vector &packed_path) { @@ -42,7 +42,7 @@ void retrievePackedPathFromHeap(const SearchEngineData::QueryHeap &forward_heap, retrievePackedPathFromSingleHeap(reverse_heap, middle_node_id, packed_path); } -void retrievePackedPathFromSingleHeap(const SearchEngineData::QueryHeap &search_heap, +void retrievePackedPathFromSingleHeap(const SearchEngineData::QueryHeap &search_heap, const NodeID middle_node_id, std::vector &packed_path) { @@ -72,8 +72,8 @@ void retrievePackedPathFromSingleHeap(const SearchEngineData::QueryHeap &search_ // requires // a force loop, if the heaps have been initialized with positive offsets. void search(const datafacade::ContiguousInternalMemoryDataFacade &facade, - SearchEngineData::QueryHeap &forward_heap, - SearchEngineData::QueryHeap &reverse_heap, + SearchEngineData::QueryHeap &forward_heap, + SearchEngineData::QueryHeap &reverse_heap, EdgeWeight &weight, std::vector &packed_leg, const bool force_loop_forward, @@ -215,8 +215,8 @@ double getPathDistance(const datafacade::ContiguousInternalMemoryDataFacade &facade, - SearchEngineData::QueryHeap &forward_heap, - SearchEngineData::QueryHeap &reverse_heap, + SearchEngineData::QueryHeap &forward_heap, + SearchEngineData::QueryHeap &reverse_heap, const PhantomNode &source_phantom, const PhantomNode &target_phantom, EdgeWeight weight_upper_bound) @@ -282,10 +282,10 @@ namespace corech // requires // a force loop, if the heaps have been initialized with positive offsets. void search(const datafacade::ContiguousInternalMemoryDataFacade &facade, - SearchEngineData::QueryHeap &forward_heap, - SearchEngineData::QueryHeap &reverse_heap, - SearchEngineData::QueryHeap &forward_core_heap, - SearchEngineData::QueryHeap &reverse_core_heap, + SearchEngineData::QueryHeap &forward_heap, + SearchEngineData::QueryHeap &reverse_heap, + SearchEngineData::QueryHeap &forward_core_heap, + SearchEngineData::QueryHeap &reverse_core_heap, EdgeWeight &weight, std::vector &packed_leg, const bool force_loop_forward, @@ -350,7 +350,7 @@ void search(const datafacade::ContiguousInternalMemoryDataFacade &fac } const auto insertInCoreHeap = [](const CoreEntryPoint &p, - SearchEngineData::QueryHeap &core_heap) { + SearchEngineData::QueryHeap &core_heap) { NodeID id; EdgeWeight weight; NodeID parent; @@ -460,10 +460,10 @@ void search(const datafacade::ContiguousInternalMemoryDataFacade &fac // If heaps should be adjusted to be initialized outside of this function, // the addition of force_loop parameters might be required double getNetworkDistance(const datafacade::ContiguousInternalMemoryDataFacade &facade, - SearchEngineData::QueryHeap &forward_heap, - SearchEngineData::QueryHeap &reverse_heap, - SearchEngineData::QueryHeap &forward_core_heap, - SearchEngineData::QueryHeap &reverse_core_heap, + SearchEngineData::QueryHeap &forward_heap, + SearchEngineData::QueryHeap &reverse_heap, + SearchEngineData::QueryHeap &forward_core_heap, + SearchEngineData::QueryHeap &reverse_core_heap, const PhantomNode &source_phantom, const PhantomNode &target_phantom, EdgeWeight weight_upper_bound) diff --git a/src/engine/routing_algorithms/shortest_path.cpp b/src/engine/routing_algorithms/shortest_path.cpp index 158c5bc40..373777ee7 100644 --- a/src/engine/routing_algorithms/shortest_path.cpp +++ b/src/engine/routing_algorithms/shortest_path.cpp @@ -16,7 +16,7 @@ namespace { const static constexpr bool DO_NOT_FORCE_LOOP = false; -using QueryHeap = SearchEngineData::QueryHeap; +using QueryHeap = SearchEngineData::QueryHeap; // allows a uturn at the target_phantom // searches source forward/reverse -> target forward/reverse @@ -230,7 +230,7 @@ void unpackLegs(const datafacade::ContiguousInternalMemoryDataFacade InternalRouteResult -shortestPathSearchImpl(SearchEngineData &engine_working_data, +shortestPathSearchImpl(SearchEngineData &engine_working_data, const datafacade::ContiguousInternalMemoryDataFacade &facade, const std::vector &phantom_nodes_vector, const boost::optional continue_straight_at_waypoint) @@ -241,14 +241,13 @@ shortestPathSearchImpl(SearchEngineData &engine_working_data, !(continue_straight_at_waypoint ? *continue_straight_at_waypoint : facade.GetContinueStraightDefault()); - engine_working_data.InitializeOrClearFirstThreadLocalStorage(Algorithm{}, - facade.GetNumberOfNodes()); + engine_working_data.InitializeOrClearFirstThreadLocalStorage(facade.GetNumberOfNodes()); engine_working_data.InitializeOrClearSecondThreadLocalStorage(facade.GetNumberOfNodes()); - auto &forward_heap = *engine_working_data.GetForwardHeapPtr(Algorithm{}); - auto &reverse_heap = *engine_working_data.GetReverseHeapPtr(Algorithm{}); - QueryHeap &forward_core_heap = *(engine_working_data.forward_heap_2); - QueryHeap &reverse_core_heap = *(engine_working_data.reverse_heap_2); + auto &forward_heap = *engine_working_data.forward_heap_1; + auto &reverse_heap = *engine_working_data.reverse_heap_1; + auto &forward_core_heap = *engine_working_data.forward_heap_2; + auto &reverse_core_heap = *engine_working_data.reverse_heap_2; int total_weight_to_forward = 0; int total_weight_to_reverse = 0; @@ -485,8 +484,9 @@ shortestPathSearchImpl(SearchEngineData &engine_working_data, } } +template<> InternalRouteResult -shortestPathSearch(SearchEngineData &engine_working_data, +shortestPathSearch(SearchEngineData &engine_working_data, const datafacade::ContiguousInternalMemoryDataFacade &facade, const std::vector &phantom_nodes_vector, const boost::optional continue_straight_at_waypoint) @@ -495,8 +495,9 @@ shortestPathSearch(SearchEngineData &engine_working_data, engine_working_data, facade, phantom_nodes_vector, continue_straight_at_waypoint); } +template<> InternalRouteResult -shortestPathSearch(SearchEngineData &engine_working_data, +shortestPathSearch(SearchEngineData &engine_working_data, const datafacade::ContiguousInternalMemoryDataFacade &facade, const std::vector &phantom_nodes_vector, const boost::optional continue_straight_at_waypoint) diff --git a/src/engine/search_engine_data.cpp b/src/engine/search_engine_data.cpp index a1f6cf9e9..d6877cbda 100644 --- a/src/engine/search_engine_data.cpp +++ b/src/engine/search_engine_data.cpp @@ -7,20 +7,16 @@ namespace osrm namespace engine { -SearchEngineData::SearchEngineHeapPtr SearchEngineData::forward_heap_1; -SearchEngineData::SearchEngineHeapPtr SearchEngineData::reverse_heap_1; -SearchEngineData::SearchEngineHeapPtr SearchEngineData::forward_heap_2; -SearchEngineData::SearchEngineHeapPtr SearchEngineData::reverse_heap_2; -SearchEngineData::SearchEngineHeapPtr SearchEngineData::forward_heap_3; -SearchEngineData::SearchEngineHeapPtr SearchEngineData::reverse_heap_3; -SearchEngineData::ManyToManyHeapPtr SearchEngineData::many_to_many_heap; - -SearchEngineData::MultiLayerDijkstraHeapPtr SearchEngineData::mld_forward_heap; -SearchEngineData::MultiLayerDijkstraHeapPtr SearchEngineData::mld_reverse_heap; +template typename SearchEngineData::SearchEngineHeapPtr SearchEngineData::forward_heap_1; +template typename SearchEngineData::SearchEngineHeapPtr SearchEngineData::reverse_heap_1; +template typename SearchEngineData::SearchEngineHeapPtr SearchEngineData::forward_heap_2; +template typename SearchEngineData::SearchEngineHeapPtr SearchEngineData::reverse_heap_2; +template typename SearchEngineData::SearchEngineHeapPtr SearchEngineData::forward_heap_3; +template typename SearchEngineData::SearchEngineHeapPtr SearchEngineData::reverse_heap_3; +template typename SearchEngineData::ManyToManyHeapPtr SearchEngineData::many_to_many_heap; template -void SearchEngineData::InitializeOrClearFirstThreadLocalStorage(Algorithm, - const unsigned number_of_nodes) +void SearchEngineData::InitializeOrClearFirstThreadLocalStorage(unsigned number_of_nodes) { if (forward_heap_1.get()) { @@ -41,36 +37,9 @@ void SearchEngineData::InitializeOrClearFirstThreadLocalStorage(Algorithm, } } -template void -SearchEngineData::InitializeOrClearFirstThreadLocalStorage(routing_algorithms::ch::Algorithm, - const unsigned number_of_nodes); -template void -SearchEngineData::InitializeOrClearFirstThreadLocalStorage(routing_algorithms::corech::Algorithm, - const unsigned number_of_nodes); - -void SearchEngineData::InitializeOrClearFirstThreadLocalStorage(routing_algorithms::mld::Algorithm, - const unsigned number_of_nodes) -{ - if (mld_forward_heap.get()) - { - mld_forward_heap->Clear(); - } - else - { - mld_forward_heap.reset(new MultiLayerDijkstraHeap(number_of_nodes)); - } - - if (mld_reverse_heap.get()) - { - mld_reverse_heap->Clear(); - } - else - { - mld_reverse_heap.reset(new MultiLayerDijkstraHeap(number_of_nodes)); - } -} - -void SearchEngineData::InitializeOrClearSecondThreadLocalStorage(const unsigned number_of_nodes) +template +void SearchEngineData::InitializeOrClearSecondThreadLocalStorage( + unsigned number_of_nodes) { if (forward_heap_2.get()) { @@ -91,7 +60,8 @@ void SearchEngineData::InitializeOrClearSecondThreadLocalStorage(const unsigned } } -void SearchEngineData::InitializeOrClearThirdThreadLocalStorage(const unsigned number_of_nodes) +template +void SearchEngineData::InitializeOrClearThirdThreadLocalStorage(unsigned number_of_nodes) { if (forward_heap_3.get()) { @@ -112,7 +82,9 @@ void SearchEngineData::InitializeOrClearThirdThreadLocalStorage(const unsigned n } } -void SearchEngineData::InitializeOrClearManyToManyThreadLocalStorage(const unsigned number_of_nodes) +template +void SearchEngineData::InitializeOrClearManyToManyThreadLocalStorage( + unsigned number_of_nodes) { if (many_to_many_heap.get()) { @@ -123,5 +95,77 @@ void SearchEngineData::InitializeOrClearManyToManyThreadLocalStorage(const unsig many_to_many_heap.reset(new ManyToManyQueryHeap(number_of_nodes)); } } + +// CH +using CH = routing_algorithms::ch::Algorithm; +template SearchEngineData::SearchEngineHeapPtr SearchEngineData::forward_heap_1; +template SearchEngineData::SearchEngineHeapPtr SearchEngineData::reverse_heap_1; +template SearchEngineData::SearchEngineHeapPtr SearchEngineData::forward_heap_2; +template SearchEngineData::SearchEngineHeapPtr SearchEngineData::reverse_heap_2; +template SearchEngineData::SearchEngineHeapPtr SearchEngineData::forward_heap_3; +template SearchEngineData::SearchEngineHeapPtr SearchEngineData::reverse_heap_3; +template SearchEngineData::ManyToManyHeapPtr SearchEngineData::many_to_many_heap; + +template +void SearchEngineData::InitializeOrClearFirstThreadLocalStorage(unsigned number_of_nodes); + +template +void SearchEngineData::InitializeOrClearSecondThreadLocalStorage(unsigned number_of_nodes); + +template +void SearchEngineData::InitializeOrClearThirdThreadLocalStorage(unsigned number_of_nodes); + +template +void SearchEngineData::InitializeOrClearManyToManyThreadLocalStorage(unsigned number_of_nodes); + +// CoreCH +using CoreCH = routing_algorithms::corech::Algorithm; +template SearchEngineData::SearchEngineHeapPtr SearchEngineData::forward_heap_1; +template SearchEngineData::SearchEngineHeapPtr SearchEngineData::reverse_heap_1; +template SearchEngineData::SearchEngineHeapPtr SearchEngineData::forward_heap_2; +template SearchEngineData::SearchEngineHeapPtr SearchEngineData::reverse_heap_2; +template SearchEngineData::SearchEngineHeapPtr SearchEngineData::forward_heap_3; +template SearchEngineData::SearchEngineHeapPtr SearchEngineData::reverse_heap_3; +template SearchEngineData::ManyToManyHeapPtr SearchEngineData::many_to_many_heap; + +template +void SearchEngineData::InitializeOrClearFirstThreadLocalStorage(unsigned number_of_nodes); + +template +void SearchEngineData::InitializeOrClearSecondThreadLocalStorage(unsigned number_of_nodes); + +template +void SearchEngineData::InitializeOrClearThirdThreadLocalStorage(unsigned number_of_nodes); + +template +void SearchEngineData::InitializeOrClearManyToManyThreadLocalStorage( + unsigned number_of_nodes); + +// MLD +using MLD = routing_algorithms::mld::Algorithm; +SearchEngineData::SearchEngineHeapPtr SearchEngineData::forward_heap_1; +SearchEngineData::SearchEngineHeapPtr SearchEngineData::reverse_heap_1; + +void SearchEngineData::InitializeOrClearFirstThreadLocalStorage(unsigned number_of_nodes) +{ + if (forward_heap_1.get()) + { + forward_heap_1->Clear(); + } + else + { + forward_heap_1.reset(new QueryHeap(number_of_nodes)); + } + + if (reverse_heap_1.get()) + { + reverse_heap_1->Clear(); + } + else + { + reverse_heap_1.reset(new QueryHeap(number_of_nodes)); + } +} + } }