From 59b70c4d1113956f9351c344ad616cd71be9c930 Mon Sep 17 00:00:00 2001 From: Michael Krasnyk Date: Wed, 12 Apr 2017 08:22:28 +0200 Subject: [PATCH] Make CoreCH SearchEngineData inherited from CH one this allows to keep a single Algorithm template parameter in internal interfaces as template search(SearchEngineData &, const datafacade::ContiguousInternalMemoryDataFacade &, ...) --- include/engine/engine.hpp | 2 +- include/engine/routing_algorithms.hpp | 13 ++--------- .../direct_shortest_path.hpp | 2 +- .../routing_algorithms/map_matching.hpp | 4 ++-- .../routing_algorithms/shortest_path.hpp | 4 ++-- include/engine/search_engine_data.hpp | 12 ++++++++++ .../direct_shortest_path.cpp | 6 ++--- .../routing_algorithms/map_matching.cpp | 6 ++--- .../routing_algorithms/routing_base_ch.cpp | 12 +++++----- .../routing_algorithms/shortest_path.cpp | 22 +++++++++---------- 10 files changed, 43 insertions(+), 40 deletions(-) diff --git a/include/engine/engine.hpp b/include/engine/engine.hpp index 038dc4132..978d750bc 100644 --- a/include/engine/engine.hpp +++ b/include/engine/engine.hpp @@ -132,7 +132,7 @@ template class Engine final : public EngineInterface private: std::unique_ptr> facade_provider; - mutable SearchEngineData::HeapAlgorithm> heaps; + 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 d6c73c457..7a19e2b41 100644 --- a/include/engine/routing_algorithms.hpp +++ b/include/engine/routing_algorithms.hpp @@ -57,16 +57,7 @@ class RoutingAlgorithmsInterface template class RoutingAlgorithms final : public RoutingAlgorithmsInterface { public: - // HeapAlgorithm is an explicit heap algorithm type to be used with Algorithm - // - CH algorithms use CH heap - // - CoreCH algorithms use CH heap - // - MLD algorithms use MLD heap - using HeapAlgorithm = typename std::conditional< - std::is_same::value, - routing_algorithms::ch::Algorithm, - Algorithm>::type; - - RoutingAlgorithms(SearchEngineData &heaps, + RoutingAlgorithms(SearchEngineData &heaps, const datafacade::ContiguousInternalMemoryDataFacade &facade) : heaps(heaps), facade(facade) { @@ -131,7 +122,7 @@ template class RoutingAlgorithms final : public RoutingAlgo } private: - SearchEngineData &heaps; + SearchEngineData &heaps; // Owned by shared-ptr passed to the query const datafacade::ContiguousInternalMemoryDataFacade &facade; diff --git a/include/engine/routing_algorithms/direct_shortest_path.hpp b/include/engine/routing_algorithms/direct_shortest_path.hpp index 873c5a561..055b6ab13 100644 --- a/include/engine/routing_algorithms/direct_shortest_path.hpp +++ b/include/engine/routing_algorithms/direct_shortest_path.hpp @@ -27,7 +27,7 @@ InternalRouteResult directShortestPathSearch( const PhantomNodes &phantom_nodes); InternalRouteResult directShortestPathSearch( - SearchEngineData &engine_working_data, + SearchEngineData &engine_working_data, const datafacade::ContiguousInternalMemoryDataFacade &facade, const PhantomNodes &phantom_nodes); diff --git a/include/engine/routing_algorithms/map_matching.hpp b/include/engine/routing_algorithms/map_matching.hpp index 9922f2095..98946337d 100644 --- a/include/engine/routing_algorithms/map_matching.hpp +++ b/include/engine/routing_algorithms/map_matching.hpp @@ -22,8 +22,8 @@ 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 -template -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, diff --git a/include/engine/routing_algorithms/shortest_path.hpp b/include/engine/routing_algorithms/shortest_path.hpp index 472692f82..ca0c6d21d 100644 --- a/include/engine/routing_algorithms/shortest_path.hpp +++ b/include/engine/routing_algorithms/shortest_path.hpp @@ -13,9 +13,9 @@ namespace engine namespace routing_algorithms { -template +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/include/engine/search_engine_data.hpp b/include/engine/search_engine_data.hpp index 8b59c77c9..34f7e06e9 100644 --- a/include/engine/search_engine_data.hpp +++ b/include/engine/search_engine_data.hpp @@ -12,6 +12,12 @@ namespace osrm namespace engine { +// Algorithm-dependent heaps +// - CH algorithms use CH heaps +// - CoreCH algorithms use CoreCH heaps that can be upcasted to CH heaps when CH algorithms reused +// by CoreCH at calling ch::routingStep, ch::retrievePackedPathFromSingleHeap and ch::unpackPath +// - MLD algorithms use MLD heaps + template struct SearchEngineData { }; @@ -59,6 +65,12 @@ template <> struct SearchEngineData void InitializeOrClearManyToManyThreadLocalStorage(unsigned number_of_nodes); }; +template <> +struct SearchEngineData + : public SearchEngineData +{ +}; + struct MultiLayerDijkstraHeapData { NodeID parent; diff --git a/src/engine/routing_algorithms/direct_shortest_path.cpp b/src/engine/routing_algorithms/direct_shortest_path.cpp index 9cb0fdcf4..588ad7d2f 100644 --- a/src/engine/routing_algorithms/direct_shortest_path.cpp +++ b/src/engine/routing_algorithms/direct_shortest_path.cpp @@ -55,9 +55,9 @@ namespace detail /// by the previous route. /// This variation is only an optimazation for graphs with slow queries, for example /// not fully contracted graphs. -template +template InternalRouteResult directShortestPathSearchImpl( - SearchEngineData &engine_working_data, + SearchEngineData &engine_working_data, const datafacade::ContiguousInternalMemoryDataFacade &facade, const PhantomNodes &phantom_nodes) { @@ -102,7 +102,7 @@ InternalRouteResult directShortestPathSearchImpl( } // namespace ch InternalRouteResult directShortestPathSearch( - SearchEngineData &engine_working_data, + SearchEngineData &engine_working_data, const datafacade::ContiguousInternalMemoryDataFacade &facade, const PhantomNodes &phantom_nodes) { diff --git a/src/engine/routing_algorithms/map_matching.cpp b/src/engine/routing_algorithms/map_matching.cpp index 907baeafe..1c3975d1c 100644 --- a/src/engine/routing_algorithms/map_matching.cpp +++ b/src/engine/routing_algorithms/map_matching.cpp @@ -48,8 +48,8 @@ unsigned getMedianSampleTime(const std::vector ×tamps) } } -template -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, @@ -426,7 +426,7 @@ mapMatching(SearchEngineData &engine_working_data, const bool allow_splitting); template SubMatchingList -mapMatching(SearchEngineData &engine_working_data, +mapMatching(SearchEngineData &engine_working_data, const datafacade::ContiguousInternalMemoryDataFacade &facade, const CandidateLists &candidates_list, const std::vector &trace_coordinates, diff --git a/src/engine/routing_algorithms/routing_base_ch.cpp b/src/engine/routing_algorithms/routing_base_ch.cpp index c941e1f4d..e581eef70 100644 --- a/src/engine/routing_algorithms/routing_base_ch.cpp +++ b/src/engine/routing_algorithms/routing_base_ch.cpp @@ -221,10 +221,10 @@ namespace corech // && source_phantom.GetForwardWeightPlusOffset() > target_phantom.GetForwardWeightPlusOffset()) // requires // a force loop, if the heaps have been initialized with positive offsets. -void search(SearchEngineData &engine_working_data, +void search(SearchEngineData &engine_working_data, 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, @@ -401,10 +401,10 @@ void search(SearchEngineData &engine_working_data, // Requires the heaps for be empty // If heaps should be adjusted to be initialized outside of this function, // the addition of force_loop parameters might be required -double getNetworkDistance(SearchEngineData &engine_working_data, +double getNetworkDistance(SearchEngineData &engine_working_data, 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) diff --git a/src/engine/routing_algorithms/shortest_path.cpp b/src/engine/routing_algorithms/shortest_path.cpp index 5d37cf919..8c11b772a 100644 --- a/src/engine/routing_algorithms/shortest_path.cpp +++ b/src/engine/routing_algorithms/shortest_path.cpp @@ -20,11 +20,11 @@ const static constexpr bool DO_NOT_FORCE_LOOP = false; // allows a uturn at the target_phantom // searches source forward/reverse -> target forward/reverse -template -void searchWithUTurn(SearchEngineData &engine_working_data, +template +void searchWithUTurn(SearchEngineData &engine_working_data, const datafacade::ContiguousInternalMemoryDataFacade &facade, - typename SearchEngineData::QueryHeap &forward_heap, - typename SearchEngineData::QueryHeap &reverse_heap, + typename SearchEngineData::QueryHeap &forward_heap, + typename SearchEngineData::QueryHeap &reverse_heap, const bool search_from_forward_node, const bool search_from_reverse_node, const bool search_to_forward_node, @@ -94,11 +94,11 @@ void searchWithUTurn(SearchEngineData &engine_working_data, // searches shortest path between: // source forward/reverse -> target forward // source forward/reverse -> target reverse -template -void search(SearchEngineData &engine_working_data, +template +void search(SearchEngineData &engine_working_data, const datafacade::ContiguousInternalMemoryDataFacade &facade, - typename SearchEngineData::QueryHeap &forward_heap, - typename SearchEngineData::QueryHeap &reverse_heap, + typename SearchEngineData::QueryHeap &forward_heap, + typename SearchEngineData::QueryHeap &reverse_heap, const bool search_from_forward_node, const bool search_from_reverse_node, const bool search_to_forward_node, @@ -215,9 +215,9 @@ void unpackLegs(const datafacade::ContiguousInternalMemoryDataFacade } } -template +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) @@ -474,7 +474,7 @@ shortestPathSearch(SearchEngineData &engine_working_data, const boost::optional 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);