From 8c64b01d67638a4db162e87aaa069afa3355afb4 Mon Sep 17 00:00:00 2001 From: Michael Krasnyk Date: Fri, 31 Mar 2017 12:52:04 +0200 Subject: [PATCH] itroduce ADL via algorithm specific ch, corech and mld namespaces --- include/engine/algorithm.hpp | 84 ++-- .../datafacade/algorithm_datafacade.hpp | 11 +- .../contiguous_internalmem_datafacade.hpp | 33 +- include/engine/engine.hpp | 12 +- include/engine/routing_algorithms.hpp | 59 +-- .../routing_algorithms/alternative_path.hpp | 7 +- .../routing_algorithms/many_to_many.hpp | 6 +- .../routing_algorithms/map_matching.hpp | 36 +- .../routing_algorithms/routing_base_ch.hpp | 96 ++-- .../routing_algorithms/routing_base_mld.hpp | 4 +- .../routing_algorithms/shortest_path.hpp | 4 +- .../engine/routing_algorithms/tile_turns.hpp | 2 +- .../routing_algorithms/alternative_path.cpp | 26 +- .../direct_shortest_path.cpp | 6 +- .../routing_algorithms/many_to_many.cpp | 19 +- .../routing_algorithms/map_matching.cpp | 36 +- .../routing_algorithms/routing_base_ch.cpp | 473 +++++++++--------- .../routing_algorithms/shortest_path.cpp | 6 +- src/engine/routing_algorithms/tile_turns.cpp | 2 +- src/osrm/osrm.cpp | 13 +- unit_tests/engine/base64.cpp | 4 +- unit_tests/mocks/mock_datafacade.hpp | 14 +- unit_tests/util/static_rtree.cpp | 12 +- 23 files changed, 501 insertions(+), 464 deletions(-) diff --git a/include/engine/algorithm.hpp b/include/engine/algorithm.hpp index d106d9b21..3cc0fce7d 100644 --- a/include/engine/algorithm.hpp +++ b/include/engine/algorithm.hpp @@ -7,30 +7,36 @@ namespace osrm { namespace engine { -namespace algorithm +namespace routing_algorithms { // Contraction Hiearchy -struct CH final +namespace ch +{ +struct Algorithm final { }; +} // Contraction Hiearchy with core -struct CoreCH final +namespace corech +{ +struct Algorithm final { }; +} // Multi-Level Dijkstra -struct MLD final +namespace mld +{ +struct Algorithm final { }; - -template const char *name(); -template <> inline const char *name() { return "CH"; } -template <> inline const char *name() { return "CoreCH"; } -template <> inline const char *name() { return "MLD"; } } -namespace algorithm_trais -{ +// Algorithm names +template const char *name(); +template <> inline const char *name() { return "CH"; } +template <> inline const char *name() { return "CoreCH"; } +template <> inline const char *name() { return "MLD"; } template struct HasAlternativePathSearch final : std::false_type { @@ -51,62 +57,64 @@ template struct HasGetTileTurns final : std::false_type { }; -template <> struct HasAlternativePathSearch final : std::true_type +// Algorithms supported by Contraction Hierarchies +template <> struct HasAlternativePathSearch final : std::true_type { }; -template <> struct HasShortestPathSearch final : std::true_type +template <> struct HasShortestPathSearch final : std::true_type { }; -template <> struct HasDirectShortestPathSearch final : std::true_type +template <> struct HasDirectShortestPathSearch final : std::true_type { }; -template <> struct HasMapMatching final : std::true_type +template <> struct HasMapMatching final : std::true_type { }; -template <> struct HasManyToManySearch final : std::true_type +template <> struct HasManyToManySearch final : std::true_type { }; -template <> struct HasGetTileTurns final : std::true_type +template <> struct HasGetTileTurns final : std::true_type { }; +// Algorithms supported by Contraction Hierarchies with core +template <> struct HasShortestPathSearch final : std::true_type +{ +}; +template <> struct HasDirectShortestPathSearch final : std::true_type +{ +}; +template <> struct HasMapMatching final : std::true_type +{ +}; +template <> struct HasGetTileTurns final : std::true_type +{ +}; // disbaled because of perfomance reasons -template <> struct HasAlternativePathSearch final : std::false_type +template <> struct HasAlternativePathSearch final : std::false_type { }; -template <> struct HasManyToManySearch final : std::false_type -{ -}; -template <> struct HasShortestPathSearch final : std::true_type -{ -}; -template <> struct HasDirectShortestPathSearch final : std::true_type -{ -}; -template <> struct HasMapMatching final : std::true_type -{ -}; -template <> struct HasGetTileTurns final : std::true_type +template <> struct HasManyToManySearch final : std::false_type { }; -// disbaled because of perfomance reasons -template <> struct HasAlternativePathSearch final : std::false_type +// Algorithms supported by Multi-Level Dijkstra +template <> struct HasDirectShortestPathSearch final : std::true_type { }; -template <> struct HasManyToManySearch final : std::false_type +template <> struct HasMapMatching final : std::false_type { }; -template <> struct HasShortestPathSearch final : std::false_type +template <> struct HasAlternativePathSearch final : std::false_type { }; -template <> struct HasDirectShortestPathSearch final : std::true_type +template <> struct HasManyToManySearch final : std::false_type { }; -template <> struct HasMapMatching final : std::false_type +template <> struct HasShortestPathSearch final : std::false_type { }; -template <> struct HasGetTileTurns final : std::false_type +template <> struct HasGetTileTurns final : std::false_type { }; } diff --git a/include/engine/datafacade/algorithm_datafacade.hpp b/include/engine/datafacade/algorithm_datafacade.hpp index eb3062228..19725bcc0 100644 --- a/include/engine/datafacade/algorithm_datafacade.hpp +++ b/include/engine/datafacade/algorithm_datafacade.hpp @@ -17,11 +17,16 @@ namespace engine namespace datafacade { +// Namespace local aliases for algorithms +using CH = routing_algorithms::ch::Algorithm; +using CoreCH = routing_algorithms::corech::Algorithm; +using MLD = routing_algorithms::mld::Algorithm; + using EdgeRange = util::range; template class AlgorithmDataFacade; -template <> class AlgorithmDataFacade +template <> class AlgorithmDataFacade { public: using EdgeData = contractor::QueryEdge::EdgeData; @@ -56,7 +61,7 @@ template <> class AlgorithmDataFacade const std::function filter) const = 0; }; -template <> class AlgorithmDataFacade +template <> class AlgorithmDataFacade { public: using EdgeData = contractor::QueryEdge::EdgeData; @@ -64,7 +69,7 @@ template <> class AlgorithmDataFacade virtual bool IsCoreNode(const NodeID id) const = 0; }; -template <> class AlgorithmDataFacade +template <> class AlgorithmDataFacade { public: using EdgeData = extractor::EdgeBasedEdge::EdgeData; diff --git a/include/engine/datafacade/contiguous_internalmem_datafacade.hpp b/include/engine/datafacade/contiguous_internalmem_datafacade.hpp index 4f3974fb4..0b9398a1e 100644 --- a/include/engine/datafacade/contiguous_internalmem_datafacade.hpp +++ b/include/engine/datafacade/contiguous_internalmem_datafacade.hpp @@ -58,8 +58,7 @@ namespace datafacade template class ContiguousInternalMemoryAlgorithmDataFacade; template <> -class ContiguousInternalMemoryAlgorithmDataFacade - : public datafacade::AlgorithmDataFacade +class ContiguousInternalMemoryAlgorithmDataFacade : public datafacade::AlgorithmDataFacade { private: using QueryGraph = util::StaticGraph; @@ -151,8 +150,8 @@ class ContiguousInternalMemoryAlgorithmDataFacade }; template <> -class ContiguousInternalMemoryAlgorithmDataFacade - : public datafacade::AlgorithmDataFacade +class ContiguousInternalMemoryAlgorithmDataFacade + : public datafacade::AlgorithmDataFacade { private: util::vector_view m_is_core_node; @@ -869,36 +868,34 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade template class ContiguousInternalMemoryDataFacade; template <> -class ContiguousInternalMemoryDataFacade +class ContiguousInternalMemoryDataFacade : public ContiguousInternalMemoryDataFacadeBase, - public ContiguousInternalMemoryAlgorithmDataFacade + public ContiguousInternalMemoryAlgorithmDataFacade { public: ContiguousInternalMemoryDataFacade(std::shared_ptr allocator) : ContiguousInternalMemoryDataFacadeBase(allocator), - ContiguousInternalMemoryAlgorithmDataFacade(allocator) + ContiguousInternalMemoryAlgorithmDataFacade(allocator) { } }; template <> -class ContiguousInternalMemoryDataFacade final - : public ContiguousInternalMemoryDataFacade, - public ContiguousInternalMemoryAlgorithmDataFacade +class ContiguousInternalMemoryDataFacade final + : public ContiguousInternalMemoryDataFacade, + public ContiguousInternalMemoryAlgorithmDataFacade { public: ContiguousInternalMemoryDataFacade(std::shared_ptr allocator) - : ContiguousInternalMemoryDataFacade(allocator), - ContiguousInternalMemoryAlgorithmDataFacade(allocator) + : ContiguousInternalMemoryDataFacade(allocator), + ContiguousInternalMemoryAlgorithmDataFacade(allocator) { } }; -template <> -class ContiguousInternalMemoryAlgorithmDataFacade - : public datafacade::AlgorithmDataFacade +template <> class ContiguousInternalMemoryAlgorithmDataFacade : public AlgorithmDataFacade { // MLD data partition::MultiLevelPartitionView mld_partition; @@ -1065,15 +1062,15 @@ class ContiguousInternalMemoryAlgorithmDataFacade }; template <> -class ContiguousInternalMemoryDataFacade final +class ContiguousInternalMemoryDataFacade final : public ContiguousInternalMemoryDataFacadeBase, - public ContiguousInternalMemoryAlgorithmDataFacade + public ContiguousInternalMemoryAlgorithmDataFacade { private: public: ContiguousInternalMemoryDataFacade(std::shared_ptr allocator) : ContiguousInternalMemoryDataFacadeBase(allocator), - ContiguousInternalMemoryAlgorithmDataFacade(allocator) + ContiguousInternalMemoryAlgorithmDataFacade(allocator) { } diff --git a/include/engine/engine.hpp b/include/engine/engine.hpp index 0d10dc8c4..90f79b67d 100644 --- a/include/engine/engine.hpp +++ b/include/engine/engine.hpp @@ -64,13 +64,13 @@ template class Engine final : public EngineInterface if (config.use_shared_memory) { util::Log(logDEBUG) << "Using shared memory with algorithm " - << algorithm::name(); + << routing_algorithms::name(); facade_provider = std::make_unique>(); } else { util::Log(logDEBUG) << "Using internal memory with algorithm " - << algorithm::name(); + << routing_algorithms::name(); facade_provider = std::make_unique>(config.storage_config); } @@ -143,7 +143,8 @@ template class Engine final : public EngineInterface const plugins::TilePlugin tile_plugin; }; -template <> bool Engine::CheckCompability(const EngineConfig &config) +template <> +bool Engine::CheckCompability(const EngineConfig &config) { if (config.use_shared_memory) { @@ -168,9 +169,10 @@ template <> bool Engine::CheckCompability(const EngineConfig &con } } -template <> bool Engine::CheckCompability(const EngineConfig &config) +template <> +bool Engine::CheckCompability(const EngineConfig &config) { - if (!Engine::CheckCompability(config)) + if (!Engine::CheckCompability(config)) { return false; } diff --git a/include/engine/routing_algorithms.hpp b/include/engine/routing_algorithms.hpp index 4096e3a8a..730f31b6a 100644 --- a/include/engine/routing_algorithms.hpp +++ b/include/engine/routing_algorithms.hpp @@ -93,32 +93,32 @@ template class RoutingAlgorithms final : public RoutingAlg bool HasAlternativePathSearch() const final override { - return algorithm_trais::HasAlternativePathSearch::value; + return routing_algorithms::HasAlternativePathSearch::value; } bool HasShortestPathSearch() const final override { - return algorithm_trais::HasShortestPathSearch::value; + return routing_algorithms::HasShortestPathSearch::value; } bool HasDirectShortestPathSearch() const final override { - return algorithm_trais::HasDirectShortestPathSearch::value; + return routing_algorithms::HasDirectShortestPathSearch::value; } bool HasMapMatching() const final override { - return algorithm_trais::HasMapMatching::value; + return routing_algorithms::HasMapMatching::value; } bool HasManyToManySearch() const final override { - return algorithm_trais::HasManyToManySearch::value; + return routing_algorithms::HasManyToManySearch::value; } bool HasGetTileTurns() const final override { - return algorithm_trais::HasGetTileTurns::value; + return routing_algorithms::HasGetTileTurns::value; } private: @@ -131,7 +131,7 @@ template InternalRouteResult RoutingAlgorithms::AlternativePathSearch(const PhantomNodes &phantom_node_pair) const { - return routing_algorithms::alternativePathSearch(heaps, facade, phantom_node_pair); + return routing_algorithms::ch::alternativePathSearch(heaps, facade, phantom_node_pair); } template @@ -156,7 +156,7 @@ std::vector RoutingAlgorithms::ManyToManySearch( const std::vector &source_indices, const std::vector &target_indices) const { - return routing_algorithms::manyToManySearch( + return routing_algorithms::ch::manyToManySearch( heaps, facade, phantom_nodes, source_indices, target_indices); } @@ -168,13 +168,13 @@ inline routing_algorithms::SubMatchingList RoutingAlgorithms::MapMat const std::vector> &trace_gps_precision, const bool allow_splitting) const { - return routing_algorithms::mapMatching(heaps, - facade, - candidates_list, - trace_coordinates, - trace_timestamps, - trace_gps_precision, - allow_splitting); + return routing_algorithms::ch::mapMatching(heaps, + facade, + candidates_list, + trace_coordinates, + trace_timestamps, + trace_gps_precision, + allow_splitting); } template @@ -187,42 +187,45 @@ inline std::vector RoutingAlgorithms:: // MLD overrides for not implemented template <> -InternalRouteResult inline RoutingAlgorithms::AlternativePathSearch( - const PhantomNodes &) const +InternalRouteResult inline RoutingAlgorithms< + routing_algorithms::mld::Algorithm>::AlternativePathSearch(const PhantomNodes &) const { throw util::exception("AlternativePathSearch is not implemented"); } template <> inline InternalRouteResult -RoutingAlgorithms::ShortestPathSearch(const std::vector &, - const boost::optional) const +RoutingAlgorithms::ShortestPathSearch( + const std::vector &, const boost::optional) const { throw util::exception("ShortestPathSearch is not implemented"); } template <> inline std::vector -RoutingAlgorithms::ManyToManySearch(const std::vector &, - const std::vector &, - const std::vector &) const +RoutingAlgorithms::ManyToManySearch( + const std::vector &, + const std::vector &, + const std::vector &) const { throw util::exception("ManyToManySearch is not implemented"); } template <> inline routing_algorithms::SubMatchingList -RoutingAlgorithms::MapMatching(const routing_algorithms::CandidateLists &, - const std::vector &, - const std::vector &, - const std::vector> &, - const bool) const +RoutingAlgorithms::MapMatching( + const routing_algorithms::CandidateLists &, + const std::vector &, + const std::vector &, + const std::vector> &, + const bool) const { throw util::exception("MapMatching is not implemented"); } template <> -inline std::vector RoutingAlgorithms::GetTileTurns( +inline std::vector +RoutingAlgorithms::GetTileTurns( const std::vector &, const std::vector &) const { diff --git a/include/engine/routing_algorithms/alternative_path.hpp b/include/engine/routing_algorithms/alternative_path.hpp index 93b94e025..12999784e 100644 --- a/include/engine/routing_algorithms/alternative_path.hpp +++ b/include/engine/routing_algorithms/alternative_path.hpp @@ -15,12 +15,13 @@ namespace engine { namespace routing_algorithms { - +namespace ch +{ InternalRouteResult alternativePathSearch(SearchEngineData &search_engine_data, - const datafacade::ContiguousInternalMemoryDataFacade &facade, + const datafacade::ContiguousInternalMemoryDataFacade &facade, const PhantomNodes &phantom_node_pair); - +} // namespace ch } // 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 c6c1dbced..06697e4c5 100644 --- a/include/engine/routing_algorithms/many_to_many.hpp +++ b/include/engine/routing_algorithms/many_to_many.hpp @@ -13,16 +13,18 @@ namespace osrm { namespace engine { - namespace routing_algorithms { +namespace ch +{ std::vector manyToManySearch(SearchEngineData &engine_working_data, - const datafacade::ContiguousInternalMemoryDataFacade &facade, + const datafacade::ContiguousInternalMemoryDataFacade &facade, const std::vector &phantom_nodes, const std::vector &source_indices, const std::vector &target_indices); +} // namespace ch } // namespace routing_algorithms } // namespace engine diff --git a/include/engine/routing_algorithms/map_matching.hpp b/include/engine/routing_algorithms/map_matching.hpp index 499ce1937..aed5427e1 100644 --- a/include/engine/routing_algorithms/map_matching.hpp +++ b/include/engine/routing_algorithms/map_matching.hpp @@ -22,23 +22,27 @@ 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 -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 ch +{ +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); +} -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_ch.hpp b/include/engine/routing_algorithms/routing_base_ch.hpp index e6bf5682c..52174e8b1 100644 --- a/include/engine/routing_algorithms/routing_base_ch.hpp +++ b/include/engine/routing_algorithms/routing_base_ch.hpp @@ -23,7 +23,7 @@ namespace ch // Stalling template -bool stallAtNode(const datafacade::ContiguousInternalMemoryDataFacade &facade, +bool stallAtNode(const datafacade::ContiguousInternalMemoryDataFacade &facade, const NodeID node, const EdgeWeight weight, const HeapT &query_heap) @@ -49,7 +49,7 @@ bool stallAtNode(const datafacade::ContiguousInternalMemoryDataFacade -void relaxOutgoingEdges(const datafacade::ContiguousInternalMemoryDataFacade &facade, +void relaxOutgoingEdges(const datafacade::ContiguousInternalMemoryDataFacade &facade, const NodeID node, const EdgeWeight weight, SearchEngineData::QueryHeap &heap) @@ -113,7 +113,7 @@ we need to add an offset to the termination criterion. static constexpr bool ENABLE_STALLING = true; static constexpr bool DISABLE_STALLING = false; template -void routingStep(const datafacade::ContiguousInternalMemoryDataFacade &facade, +void routingStep(const datafacade::ContiguousInternalMemoryDataFacade &facade, SearchEngineData::QueryHeap &forward_heap, SearchEngineData::QueryHeap &reverse_heap, NodeID &middle_node_id, @@ -186,9 +186,8 @@ void routingStep(const datafacade::ContiguousInternalMemoryDataFacade -EdgeWeight -getLoopWeight(const datafacade::ContiguousInternalMemoryDataFacade &facade, - NodeID node) +EdgeWeight getLoopWeight(const datafacade::ContiguousInternalMemoryDataFacade &facade, + NodeID node) { EdgeWeight loop_weight = UseDuration ? MAXIMAL_EDGE_DURATION : INVALID_EDGE_WEIGHT; for (auto edge : facade.GetAdjacentEdgeRange(node)) @@ -228,7 +227,7 @@ getLoopWeight(const datafacade::ContiguousInternalMemoryDataFacade -void unpackPath(const datafacade::ContiguousInternalMemoryDataFacade &facade, +void unpackPath(const datafacade::ContiguousInternalMemoryDataFacade &facade, BidirectionalIterator packed_path_begin, BidirectionalIterator packed_path_end, Callback &&callback) @@ -325,7 +324,7 @@ void unpackPath(const FacadeT &facade, * @param to the node the CH edge finishes at * @param unpacked_path the sequence of original NodeIDs that make up the expanded CH edge */ -void unpackEdge(const datafacade::ContiguousInternalMemoryDataFacade &facade, +void unpackEdge(const datafacade::ContiguousInternalMemoryDataFacade &facade, const NodeID from, const NodeID to, std::vector &unpacked_path); @@ -351,7 +350,7 @@ void retrievePackedPathFromSingleHeap(const SearchEngineData::QueryHeap &search_ // && source_phantom.GetForwardWeightPlusOffset() > target_phantom.GetForwardWeightPlusOffset()) // requires // a force loop, if the heaps have been initialized with positive offsets. -void search(const datafacade::ContiguousInternalMemoryDataFacade &facade, +void search(const datafacade::ContiguousInternalMemoryDataFacade &facade, SearchEngineData::QueryHeap &forward_heap, SearchEngineData::QueryHeap &reverse_heap, std::int32_t &weight, @@ -361,7 +360,7 @@ void search(const datafacade::ContiguousInternalMemoryDataFacade const int duration_upper_bound = INVALID_EDGE_WEIGHT); // Alias to be compatible with the overload for CoreCH that needs 4 heaps -inline void search(const datafacade::ContiguousInternalMemoryDataFacade &facade, +inline void search(const datafacade::ContiguousInternalMemoryDataFacade &facade, SearchEngineData::QueryHeap &forward_heap, SearchEngineData::QueryHeap &reverse_heap, SearchEngineData::QueryHeap &, @@ -382,31 +381,11 @@ inline void search(const datafacade::ContiguousInternalMemoryDataFacade target_phantom.GetForwardWeightPlusOffset()) -// 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, - int &weight, - std::vector &packed_leg, - const bool force_loop_forward, - const bool force_loop_reverse, - int duration_upper_bound = INVALID_EDGE_WEIGHT); - bool needsLoopForward(const PhantomNode &source_phantom, const PhantomNode &target_phantom); bool needsLoopBackwards(const PhantomNode &source_phantom, const PhantomNode &target_phantom); -double getPathDistance(const datafacade::ContiguousInternalMemoryDataFacade &facade, +double getPathDistance(const datafacade::ContiguousInternalMemoryDataFacade &facade, const std::vector &packed_path, const PhantomNode &source_phantom, const PhantomNode &target_phantom); @@ -415,20 +394,7 @@ double getPathDistance(const datafacade::ContiguousInternalMemoryDataFacade &facade, - 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); - -// 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(const datafacade::ContiguousInternalMemoryDataFacade &facade, +getNetworkDistance(const datafacade::ContiguousInternalMemoryDataFacade &facade, SearchEngineData::QueryHeap &forward_heap, SearchEngineData::QueryHeap &reverse_heap, const PhantomNode &source_phantom, @@ -437,7 +403,7 @@ getNetworkDistance(const datafacade::ContiguousInternalMemoryDataFacade &facade, +getNetworkDistance(const datafacade::ContiguousInternalMemoryDataFacade &facade, SearchEngineData::QueryHeap &forward_heap, SearchEngineData::QueryHeap &reverse_heap, SearchEngineData::QueryHeap &, @@ -449,8 +415,44 @@ getNetworkDistance(const datafacade::ContiguousInternalMemoryDataFacade target_phantom.GetForwardWeightPlusOffset()) +// 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, + int &weight, + std::vector &packed_leg, + const bool force_loop_forward, + const bool force_loop_reverse, + int duration_upper_bound = INVALID_EDGE_WEIGHT); + +// 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(const datafacade::ContiguousInternalMemoryDataFacade &facade, + 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); +} // namespace corech + } // namespace routing_algorithms } // namespace engine } // namespace osrm diff --git a/include/engine/routing_algorithms/routing_base_mld.hpp b/include/engine/routing_algorithms/routing_base_mld.hpp index e705f106d..9f839a84d 100644 --- a/include/engine/routing_algorithms/routing_base_mld.hpp +++ b/include/engine/routing_algorithms/routing_base_mld.hpp @@ -57,7 +57,7 @@ bool checkParentCellRestriction(CellID cell, LevelID, CellID parent) { return ce } template -void routingStep(const datafacade::ContiguousInternalMemoryDataFacade &facade, +void routingStep(const datafacade::ContiguousInternalMemoryDataFacade &facade, SearchEngineData::MultiLayerDijkstraHeap &forward_heap, SearchEngineData::MultiLayerDijkstraHeap &reverse_heap, NodeID &middle_node, @@ -171,7 +171,7 @@ void routingStep(const datafacade::ContiguousInternalMemoryDataFacade std::tuple> -search(const datafacade::ContiguousInternalMemoryDataFacade &facade, +search(const datafacade::ContiguousInternalMemoryDataFacade &facade, SearchEngineData::MultiLayerDijkstraHeap &forward_heap, SearchEngineData::MultiLayerDijkstraHeap &reverse_heap, Args... args) diff --git a/include/engine/routing_algorithms/shortest_path.hpp b/include/engine/routing_algorithms/shortest_path.hpp index 2b24282cb..aa9af81b8 100644 --- a/include/engine/routing_algorithms/shortest_path.hpp +++ b/include/engine/routing_algorithms/shortest_path.hpp @@ -15,13 +15,13 @@ namespace routing_algorithms InternalRouteResult shortestPathSearch(SearchEngineData &engine_working_data, - const datafacade::ContiguousInternalMemoryDataFacade &facade, + 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, + const datafacade::ContiguousInternalMemoryDataFacade &facade, const std::vector &phantom_nodes_vector, const boost::optional continue_straight_at_waypoint); diff --git a/include/engine/routing_algorithms/tile_turns.hpp b/include/engine/routing_algorithms/tile_turns.hpp index 957aea38f..39981839b 100644 --- a/include/engine/routing_algorithms/tile_turns.hpp +++ b/include/engine/routing_algorithms/tile_turns.hpp @@ -29,7 +29,7 @@ struct TurnData final using RTreeLeaf = datafacade::BaseDataFacade::RTreeLeaf; std::vector -getTileTurns(const datafacade::ContiguousInternalMemoryDataFacade &facade, +getTileTurns(const datafacade::ContiguousInternalMemoryDataFacade &facade, const std::vector &edges, const std::vector &sorted_edge_indexes); diff --git a/src/engine/routing_algorithms/alternative_path.cpp b/src/engine/routing_algorithms/alternative_path.cpp index bd7572190..fe84df78b 100644 --- a/src/engine/routing_algorithms/alternative_path.cpp +++ b/src/engine/routing_algorithms/alternative_path.cpp @@ -19,6 +19,8 @@ namespace engine { namespace routing_algorithms { +namespace ch +{ namespace { @@ -48,15 +50,14 @@ struct RankedCandidateNode // todo: reorder parameters template -void alternativeRoutingStep( - const datafacade::ContiguousInternalMemoryDataFacade &facade, - QueryHeap &heap1, - QueryHeap &heap2, - NodeID *middle_node, - EdgeWeight *upper_bound_to_shortest_path_weight, - std::vector &search_space_intersection, - std::vector &search_space, - const EdgeWeight min_edge_offset) +void alternativeRoutingStep(const datafacade::ContiguousInternalMemoryDataFacade &facade, + QueryHeap &heap1, + QueryHeap &heap2, + NodeID *middle_node, + EdgeWeight *upper_bound_to_shortest_path_weight, + std::vector &search_space_intersection, + std::vector &search_space, + const EdgeWeight min_edge_offset) { QueryHeap &forward_heap = DIRECTION == FORWARD_DIRECTION ? heap1 : heap2; QueryHeap &reverse_heap = DIRECTION == FORWARD_DIRECTION ? heap2 : heap1; @@ -154,7 +155,7 @@ void retrievePackedAlternatePath(const QueryHeap &forward_heap1, // done at this stage void computeLengthAndSharingOfViaPath( SearchEngineData &engine_working_data, - const datafacade::ContiguousInternalMemoryDataFacade &facade, + const datafacade::ContiguousInternalMemoryDataFacade &facade, const NodeID via_node, int *real_length_of_via_path, int *sharing_of_via_path, @@ -319,7 +320,7 @@ void computeLengthAndSharingOfViaPath( // conduct T-Test bool viaNodeCandidatePassesTTest( SearchEngineData &engine_working_data, - const datafacade::ContiguousInternalMemoryDataFacade &facade, + const datafacade::ContiguousInternalMemoryDataFacade &facade, QueryHeap &existing_forward_heap, QueryHeap &existing_reverse_heap, QueryHeap &new_forward_heap, @@ -563,7 +564,7 @@ bool viaNodeCandidatePassesTTest( InternalRouteResult alternativePathSearch(SearchEngineData &engine_working_data, - const datafacade::ContiguousInternalMemoryDataFacade &facade, + const datafacade::ContiguousInternalMemoryDataFacade &facade, const PhantomNodes &phantom_node_pair) { InternalRouteResult raw_route_data; @@ -846,6 +847,7 @@ alternativePathSearch(SearchEngineData &engine_working_data, return raw_route_data; } +} // namespace ch } // namespace routing_algorithms } // namespace engine } // namespace osrm} diff --git a/src/engine/routing_algorithms/direct_shortest_path.cpp b/src/engine/routing_algorithms/direct_shortest_path.cpp index a7af4a16c..ec45460a8 100644 --- a/src/engine/routing_algorithms/direct_shortest_path.cpp +++ b/src/engine/routing_algorithms/direct_shortest_path.cpp @@ -109,7 +109,7 @@ InternalRouteResult directShortestPathSearchImpl( template <> InternalRouteResult directShortestPathSearch( SearchEngineData &engine_working_data, - const datafacade::ContiguousInternalMemoryDataFacade &facade, + const datafacade::ContiguousInternalMemoryDataFacade &facade, const PhantomNodes &phantom_nodes) { return ch::directShortestPathSearchImpl(engine_working_data, facade, phantom_nodes); @@ -118,7 +118,7 @@ InternalRouteResult directShortestPathSearch( template <> InternalRouteResult directShortestPathSearch( SearchEngineData &engine_working_data, - const datafacade::ContiguousInternalMemoryDataFacade &facade, + const datafacade::ContiguousInternalMemoryDataFacade &facade, const PhantomNodes &phantom_nodes) { return ch::directShortestPathSearchImpl(engine_working_data, facade, phantom_nodes); @@ -127,7 +127,7 @@ InternalRouteResult directShortestPathSearch( template <> InternalRouteResult directShortestPathSearch( SearchEngineData &engine_working_data, - const datafacade::ContiguousInternalMemoryDataFacade &facade, + const datafacade::ContiguousInternalMemoryDataFacade &facade, const PhantomNodes &phantom_nodes) { engine_working_data.InitializeOrClearMultiLayerDijkstraThreadLocalStorage( diff --git a/src/engine/routing_algorithms/many_to_many.cpp b/src/engine/routing_algorithms/many_to_many.cpp index 64e30e9cb..71150ebb6 100644 --- a/src/engine/routing_algorithms/many_to_many.cpp +++ b/src/engine/routing_algorithms/many_to_many.cpp @@ -17,6 +17,9 @@ namespace routing_algorithms using ManyToManyQueryHeap = SearchEngineData::ManyToManyQueryHeap; +namespace ch +{ + namespace { struct NodeBucket @@ -34,7 +37,7 @@ struct NodeBucket using SearchSpaceWithBuckets = std::unordered_map>; template -void relaxOutgoingEdges(const datafacade::ContiguousInternalMemoryDataFacade &facade, +void relaxOutgoingEdges(const datafacade::ContiguousInternalMemoryDataFacade &facade, const NodeID node, const EdgeWeight weight, const EdgeWeight duration, @@ -69,7 +72,7 @@ void relaxOutgoingEdges(const datafacade::ContiguousInternalMemoryDataFacade &facade, +void forwardRoutingStep(const datafacade::ContiguousInternalMemoryDataFacade &facade, const unsigned row_idx, const unsigned number_of_targets, ManyToManyQueryHeap &query_heap, @@ -126,11 +129,10 @@ void forwardRoutingStep(const datafacade::ContiguousInternalMemoryDataFacade(facade, node, source_weight, source_duration, query_heap); } -void backwardRoutingStep( - const datafacade::ContiguousInternalMemoryDataFacade &facade, - const unsigned column_idx, - ManyToManyQueryHeap &query_heap, - SearchSpaceWithBuckets &search_space_with_buckets) +void backwardRoutingStep(const datafacade::ContiguousInternalMemoryDataFacade &facade, + const unsigned column_idx, + ManyToManyQueryHeap &query_heap, + SearchSpaceWithBuckets &search_space_with_buckets) { const NodeID node = query_heap.DeleteMin(); const EdgeWeight target_weight = query_heap.GetKey(node); @@ -150,7 +152,7 @@ void backwardRoutingStep( std::vector manyToManySearch(SearchEngineData &engine_working_data, - const datafacade::ContiguousInternalMemoryDataFacade &facade, + const datafacade::ContiguousInternalMemoryDataFacade &facade, const std::vector &phantom_nodes, const std::vector &source_indices, const std::vector &target_indices) @@ -240,6 +242,7 @@ manyToManySearch(SearchEngineData &engine_working_data, return durations_table; } +} // namespace ch } // namespace routing_algorithms } // namespace engine } // namespace osrm diff --git a/src/engine/routing_algorithms/map_matching.cpp b/src/engine/routing_algorithms/map_matching.cpp index 39dc0db9b..3240082cd 100644 --- a/src/engine/routing_algorithms/map_matching.cpp +++ b/src/engine/routing_algorithms/map_matching.cpp @@ -419,14 +419,15 @@ mapMatchingImpl(SearchEngineData &engine_working_data, return sub_matchings; } -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 use_tidying) +namespace ch +{ +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 use_tidying) { return mapMatchingImpl(engine_working_data, facade, @@ -436,15 +437,17 @@ mapMatching(SearchEngineData &engine_working_data, trace_gps_precision, use_tidying); } +} -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 use_tidying) +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 use_tidying) { return mapMatchingImpl(engine_working_data, @@ -455,6 +458,7 @@ 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 484e3b8e3..a070f5275 100644 --- a/src/engine/routing_algorithms/routing_base_ch.cpp +++ b/src/engine/routing_algorithms/routing_base_ch.cpp @@ -16,7 +16,7 @@ namespace ch * @param to the node the CH edge finishes at * @param unpacked_path the sequence of original NodeIDs that make up the expanded CH edge */ -void unpackEdge(const datafacade::ContiguousInternalMemoryDataFacade &facade, +void unpackEdge(const datafacade::ContiguousInternalMemoryDataFacade &facade, const NodeID from, const NodeID to, std::vector &unpacked_path) @@ -71,7 +71,7 @@ void retrievePackedPathFromSingleHeap(const SearchEngineData::QueryHeap &search_ // && source_phantom.GetForwardWeightPlusOffset() > target_phantom.GetForwardWeightPlusOffset()) // requires // a force loop, if the heaps have been initialized with positive offsets. -void search(const datafacade::ContiguousInternalMemoryDataFacade &facade, +void search(const datafacade::ContiguousInternalMemoryDataFacade &facade, SearchEngineData::QueryHeap &forward_heap, SearchEngineData::QueryHeap &reverse_heap, EdgeWeight &weight, @@ -139,190 +139,6 @@ void search(const datafacade::ContiguousInternalMemoryDataFacade } } -// assumes that heaps are already setup correctly. -// A forced loop might be necessary, if source and target are on the same segment. -// If this is the case and the offsets of the respective direction are larger for the source -// than the target -// then a force loop is required (e.g. source_phantom.forward_segment_id == -// target_phantom.forward_segment_id -// && source_phantom.GetForwardWeightPlusOffset() > target_phantom.GetForwardWeightPlusOffset()) -// 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, - EdgeWeight &weight, - std::vector &packed_leg, - const bool force_loop_forward, - const bool force_loop_reverse, - EdgeWeight weight_upper_bound) -{ - NodeID middle = SPECIAL_NODEID; - weight = weight_upper_bound; - - using CoreEntryPoint = std::tuple; - std::vector forward_entry_points; - std::vector reverse_entry_points; - - // get offset to account for offsets on phantom nodes on compressed edges - const auto min_edge_offset = std::min(0, forward_heap.MinKey()); - // we only every insert negative offsets for nodes in the forward heap - BOOST_ASSERT(reverse_heap.MinKey() >= 0); - - // run two-Target Dijkstra routing step. - while (0 < (forward_heap.Size() + reverse_heap.Size())) - { - if (!forward_heap.Empty()) - { - if (facade.IsCoreNode(forward_heap.Min())) - { - const NodeID node = forward_heap.DeleteMin(); - const EdgeWeight key = forward_heap.GetKey(node); - forward_entry_points.emplace_back(node, key, forward_heap.GetData(node).parent); - } - else - { - routingStep(facade, - forward_heap, - reverse_heap, - middle, - weight, - min_edge_offset, - force_loop_forward, - force_loop_reverse); - } - } - if (!reverse_heap.Empty()) - { - if (facade.IsCoreNode(reverse_heap.Min())) - { - const NodeID node = reverse_heap.DeleteMin(); - const EdgeWeight key = reverse_heap.GetKey(node); - reverse_entry_points.emplace_back(node, key, reverse_heap.GetData(node).parent); - } - else - { - routingStep(facade, - reverse_heap, - forward_heap, - middle, - weight, - min_edge_offset, - force_loop_reverse, - force_loop_forward); - } - } - } - - const auto insertInCoreHeap = [](const CoreEntryPoint &p, - SearchEngineData::QueryHeap &core_heap) { - NodeID id; - EdgeWeight weight; - NodeID parent; - // TODO this should use std::apply when we get c++17 support - std::tie(id, weight, parent) = p; - core_heap.Insert(id, weight, parent); - }; - - forward_core_heap.Clear(); - for (const auto &p : forward_entry_points) - { - insertInCoreHeap(p, forward_core_heap); - } - - reverse_core_heap.Clear(); - for (const auto &p : reverse_entry_points) - { - insertInCoreHeap(p, reverse_core_heap); - } - - // get offset to account for offsets on phantom nodes on compressed edges - EdgeWeight min_core_edge_offset = 0; - if (forward_core_heap.Size() > 0) - { - min_core_edge_offset = std::min(min_core_edge_offset, forward_core_heap.MinKey()); - } - if (reverse_core_heap.Size() > 0 && reverse_core_heap.MinKey() < 0) - { - min_core_edge_offset = std::min(min_core_edge_offset, reverse_core_heap.MinKey()); - } - BOOST_ASSERT(min_core_edge_offset <= 0); - - // run two-target Dijkstra routing step on core with termination criterion - while (0 < forward_core_heap.Size() && 0 < reverse_core_heap.Size() && - weight > (forward_core_heap.MinKey() + reverse_core_heap.MinKey())) - { - routingStep(facade, - forward_core_heap, - reverse_core_heap, - middle, - weight, - min_core_edge_offset, - force_loop_forward, - force_loop_reverse); - - routingStep(facade, - reverse_core_heap, - forward_core_heap, - middle, - weight, - min_core_edge_offset, - force_loop_reverse, - force_loop_forward); - } - - // No path found for both target nodes? - if (weight_upper_bound <= weight || SPECIAL_NODEID == middle) - { - weight = INVALID_EDGE_WEIGHT; - return; - } - - // Was a paths over one of the forward/reverse nodes not found? - BOOST_ASSERT_MSG((SPECIAL_NODEID != middle && INVALID_EDGE_WEIGHT != weight), "no path found"); - - // we need to unpack sub path from core heaps - if (facade.IsCoreNode(middle)) - { - if (weight != forward_core_heap.GetKey(middle) + reverse_core_heap.GetKey(middle)) - { - // self loop - BOOST_ASSERT(forward_core_heap.GetData(middle).parent == middle && - reverse_core_heap.GetData(middle).parent == middle); - packed_leg.push_back(middle); - packed_leg.push_back(middle); - } - else - { - std::vector packed_core_leg; - retrievePackedPathFromHeap( - forward_core_heap, reverse_core_heap, middle, packed_core_leg); - BOOST_ASSERT(packed_core_leg.size() > 0); - retrievePackedPathFromSingleHeap(forward_heap, packed_core_leg.front(), packed_leg); - std::reverse(packed_leg.begin(), packed_leg.end()); - packed_leg.insert(packed_leg.end(), packed_core_leg.begin(), packed_core_leg.end()); - retrievePackedPathFromSingleHeap(reverse_heap, packed_core_leg.back(), packed_leg); - } - } - else - { - if (weight != forward_heap.GetKey(middle) + reverse_heap.GetKey(middle)) - { - // self loop - BOOST_ASSERT(forward_heap.GetData(middle).parent == middle && - reverse_heap.GetData(middle).parent == middle); - packed_leg.push_back(middle); - packed_leg.push_back(middle); - } - else - { - retrievePackedPathFromHeap(forward_heap, reverse_heap, middle, packed_leg); - } - } -} - bool needsLoopForward(const PhantomNode &source_phantom, const PhantomNode &target_phantom) { return source_phantom.forward_segment_id.enabled && target_phantom.forward_segment_id.enabled && @@ -339,7 +155,7 @@ bool needsLoopBackwards(const PhantomNode &source_phantom, const PhantomNode &ta target_phantom.GetReverseWeightPlusOffset(); } -double getPathDistance(const datafacade::ContiguousInternalMemoryDataFacade &facade, +double getPathDistance(const datafacade::ContiguousInternalMemoryDataFacade &facade, const std::vector &packed_path, const PhantomNode &source_phantom, const PhantomNode &target_phantom) @@ -398,54 +214,12 @@ double getPathDistance(const datafacade::ContiguousInternalMemoryDataFacade &facade, - 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) -{ - forward_heap.Clear(); - reverse_heap.Clear(); - forward_core_heap.Clear(); - reverse_core_heap.Clear(); - - insertNodesInHeaps(forward_heap, reverse_heap, {source_phantom, target_phantom}); - - EdgeWeight weight = INVALID_EDGE_WEIGHT; - std::vector packed_path; - search(facade, - forward_heap, - reverse_heap, - forward_core_heap, - reverse_core_heap, - weight, - packed_path, - DO_NOT_FORCE_LOOPS, - DO_NOT_FORCE_LOOPS, - weight_upper_bound); - - double distance = std::numeric_limits::max(); - if (weight != INVALID_EDGE_WEIGHT) - { - return getPathDistance(facade, packed_path, source_phantom, target_phantom); - } - return distance; -} - -// 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(const datafacade::ContiguousInternalMemoryDataFacade &facade, - SearchEngineData::QueryHeap &forward_heap, - SearchEngineData::QueryHeap &reverse_heap, - const PhantomNode &source_phantom, - const PhantomNode &target_phantom, - EdgeWeight weight_upper_bound) +double getNetworkDistance(const datafacade::ContiguousInternalMemoryDataFacade &facade, + SearchEngineData::QueryHeap &forward_heap, + SearchEngineData::QueryHeap &reverse_heap, + const PhantomNode &source_phantom, + const PhantomNode &target_phantom, + EdgeWeight weight_upper_bound) { forward_heap.Clear(); reverse_heap.Clear(); @@ -494,8 +268,235 @@ getNetworkDistance(const datafacade::ContiguousInternalMemoryDataFacade target_phantom.GetForwardWeightPlusOffset()) +// 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, + EdgeWeight &weight, + std::vector &packed_leg, + const bool force_loop_forward, + const bool force_loop_reverse, + EdgeWeight weight_upper_bound) +{ + NodeID middle = SPECIAL_NODEID; + weight = weight_upper_bound; + + using CoreEntryPoint = std::tuple; + std::vector forward_entry_points; + std::vector reverse_entry_points; + + // get offset to account for offsets on phantom nodes on compressed edges + const auto min_edge_offset = std::min(0, forward_heap.MinKey()); + // we only every insert negative offsets for nodes in the forward heap + BOOST_ASSERT(reverse_heap.MinKey() >= 0); + + // run two-Target Dijkstra routing step. + while (0 < (forward_heap.Size() + reverse_heap.Size())) + { + if (!forward_heap.Empty()) + { + if (facade.IsCoreNode(forward_heap.Min())) + { + const NodeID node = forward_heap.DeleteMin(); + const EdgeWeight key = forward_heap.GetKey(node); + forward_entry_points.emplace_back(node, key, forward_heap.GetData(node).parent); + } + else + { + ch::routingStep(facade, + forward_heap, + reverse_heap, + middle, + weight, + min_edge_offset, + force_loop_forward, + force_loop_reverse); + } + } + if (!reverse_heap.Empty()) + { + if (facade.IsCoreNode(reverse_heap.Min())) + { + const NodeID node = reverse_heap.DeleteMin(); + const EdgeWeight key = reverse_heap.GetKey(node); + reverse_entry_points.emplace_back(node, key, reverse_heap.GetData(node).parent); + } + else + { + ch::routingStep(facade, + reverse_heap, + forward_heap, + middle, + weight, + min_edge_offset, + force_loop_reverse, + force_loop_forward); + } + } + } + + const auto insertInCoreHeap = [](const CoreEntryPoint &p, + SearchEngineData::QueryHeap &core_heap) { + NodeID id; + EdgeWeight weight; + NodeID parent; + // TODO this should use std::apply when we get c++17 support + std::tie(id, weight, parent) = p; + core_heap.Insert(id, weight, parent); + }; + + forward_core_heap.Clear(); + for (const auto &p : forward_entry_points) + { + insertInCoreHeap(p, forward_core_heap); + } + + reverse_core_heap.Clear(); + for (const auto &p : reverse_entry_points) + { + insertInCoreHeap(p, reverse_core_heap); + } + + // get offset to account for offsets on phantom nodes on compressed edges + EdgeWeight min_core_edge_offset = 0; + if (forward_core_heap.Size() > 0) + { + min_core_edge_offset = std::min(min_core_edge_offset, forward_core_heap.MinKey()); + } + if (reverse_core_heap.Size() > 0 && reverse_core_heap.MinKey() < 0) + { + min_core_edge_offset = std::min(min_core_edge_offset, reverse_core_heap.MinKey()); + } + BOOST_ASSERT(min_core_edge_offset <= 0); + + // run two-target Dijkstra routing step on core with termination criterion + while (0 < forward_core_heap.Size() && 0 < reverse_core_heap.Size() && + weight > (forward_core_heap.MinKey() + reverse_core_heap.MinKey())) + { + ch::routingStep(facade, + forward_core_heap, + reverse_core_heap, + middle, + weight, + min_core_edge_offset, + force_loop_forward, + force_loop_reverse); + + ch::routingStep(facade, + reverse_core_heap, + forward_core_heap, + middle, + weight, + min_core_edge_offset, + force_loop_reverse, + force_loop_forward); + } + + // No path found for both target nodes? + if (weight_upper_bound <= weight || SPECIAL_NODEID == middle) + { + weight = INVALID_EDGE_WEIGHT; + return; + } + + // Was a paths over one of the forward/reverse nodes not found? + BOOST_ASSERT_MSG((SPECIAL_NODEID != middle && INVALID_EDGE_WEIGHT != weight), "no path found"); + + // we need to unpack sub path from core heaps + if (facade.IsCoreNode(middle)) + { + if (weight != forward_core_heap.GetKey(middle) + reverse_core_heap.GetKey(middle)) + { + // self loop + BOOST_ASSERT(forward_core_heap.GetData(middle).parent == middle && + reverse_core_heap.GetData(middle).parent == middle); + packed_leg.push_back(middle); + packed_leg.push_back(middle); + } + else + { + std::vector packed_core_leg; + ch::retrievePackedPathFromHeap( + forward_core_heap, reverse_core_heap, middle, packed_core_leg); + BOOST_ASSERT(packed_core_leg.size() > 0); + ch::retrievePackedPathFromSingleHeap(forward_heap, packed_core_leg.front(), packed_leg); + std::reverse(packed_leg.begin(), packed_leg.end()); + packed_leg.insert(packed_leg.end(), packed_core_leg.begin(), packed_core_leg.end()); + ch::retrievePackedPathFromSingleHeap(reverse_heap, packed_core_leg.back(), packed_leg); + } + } + else + { + if (weight != forward_heap.GetKey(middle) + reverse_heap.GetKey(middle)) + { + // self loop + BOOST_ASSERT(forward_heap.GetData(middle).parent == middle && + reverse_heap.GetData(middle).parent == middle); + packed_leg.push_back(middle); + packed_leg.push_back(middle); + } + else + { + ch::retrievePackedPathFromHeap(forward_heap, reverse_heap, middle, packed_leg); + } + } +} + +// 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(const datafacade::ContiguousInternalMemoryDataFacade &facade, + 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) +{ + forward_heap.Clear(); + reverse_heap.Clear(); + forward_core_heap.Clear(); + reverse_core_heap.Clear(); + + insertNodesInHeaps(forward_heap, reverse_heap, {source_phantom, target_phantom}); + + EdgeWeight weight = INVALID_EDGE_WEIGHT; + std::vector packed_path; + search(facade, + forward_heap, + reverse_heap, + forward_core_heap, + reverse_core_heap, + weight, + packed_path, + DO_NOT_FORCE_LOOPS, + DO_NOT_FORCE_LOOPS, + weight_upper_bound); + + double distance = std::numeric_limits::max(); + if (weight != INVALID_EDGE_WEIGHT) + { + return ch::getPathDistance(facade, packed_path, source_phantom, target_phantom); + } + return distance; +} +} // namespace corech + } // namespace routing_algorithms } // namespace engine } // namespace osrm diff --git a/src/engine/routing_algorithms/shortest_path.cpp b/src/engine/routing_algorithms/shortest_path.cpp index fc640e7d4..4b2fcede3 100644 --- a/src/engine/routing_algorithms/shortest_path.cpp +++ b/src/engine/routing_algorithms/shortest_path.cpp @@ -198,7 +198,7 @@ void search(const datafacade::ContiguousInternalMemoryDataFacade &fa } } -void unpackLegs(const datafacade::ContiguousInternalMemoryDataFacade &facade, +void unpackLegs(const datafacade::ContiguousInternalMemoryDataFacade &facade, const std::vector &phantom_nodes_vector, const std::vector &total_packed_path, const std::vector &packed_leg_begin, @@ -486,7 +486,7 @@ shortestPathSearchImpl(SearchEngineData &engine_working_data, InternalRouteResult shortestPathSearch(SearchEngineData &engine_working_data, - const datafacade::ContiguousInternalMemoryDataFacade &facade, + const datafacade::ContiguousInternalMemoryDataFacade &facade, const std::vector &phantom_nodes_vector, const boost::optional continue_straight_at_waypoint) { @@ -496,7 +496,7 @@ shortestPathSearch(SearchEngineData &engine_working_data, InternalRouteResult shortestPathSearch(SearchEngineData &engine_working_data, - const datafacade::ContiguousInternalMemoryDataFacade &facade, + const datafacade::ContiguousInternalMemoryDataFacade &facade, const std::vector &phantom_nodes_vector, const boost::optional continue_straight_at_waypoint) { diff --git a/src/engine/routing_algorithms/tile_turns.cpp b/src/engine/routing_algorithms/tile_turns.cpp index 1dbbf5c72..8cac0d8f6 100644 --- a/src/engine/routing_algorithms/tile_turns.cpp +++ b/src/engine/routing_algorithms/tile_turns.cpp @@ -8,7 +8,7 @@ namespace routing_algorithms { std::vector -getTileTurns(const datafacade::ContiguousInternalMemoryDataFacade &facade, +getTileTurns(const datafacade::ContiguousInternalMemoryDataFacade &facade, const std::vector &edges, const std::vector &sorted_edge_indexes) { diff --git a/src/osrm/osrm.cpp b/src/osrm/osrm.cpp index 61b5644e9..261ec2c79 100644 --- a/src/osrm/osrm.cpp +++ b/src/osrm/osrm.cpp @@ -18,11 +18,14 @@ namespace osrm OSRM::OSRM(engine::EngineConfig &config) { + using CH = engine::routing_algorithms::ch::Algorithm; + using CoreCH = engine::routing_algorithms::corech::Algorithm; + using MLD = engine::routing_algorithms::mld::Algorithm; + if (config.algorithm == EngineConfig::Algorithm::CoreCH || config.algorithm == EngineConfig::Algorithm::CH) { - bool corech_compatible = - engine::Engine::CheckCompability(config); + bool corech_compatible = engine::Engine::CheckCompability(config); // Activate CoreCH if we can because it is faster if (config.algorithm == EngineConfig::Algorithm::CH && corech_compatible) @@ -40,13 +43,13 @@ OSRM::OSRM(engine::EngineConfig &config) switch (config.algorithm) { case EngineConfig::Algorithm::CH: - engine_ = std::make_unique>(config); + engine_ = std::make_unique>(config); break; case EngineConfig::Algorithm::CoreCH: - engine_ = std::make_unique>(config); + engine_ = std::make_unique>(config); break; case EngineConfig::Algorithm::MLD: - engine_ = std::make_unique>(config); + engine_ = std::make_unique>(config); break; default: util::exception("Algorithm not implemented!"); diff --git a/unit_tests/engine/base64.cpp b/unit_tests/engine/base64.cpp index c82ef36d7..dae855f92 100644 --- a/unit_tests/engine/base64.cpp +++ b/unit_tests/engine/base64.cpp @@ -43,7 +43,7 @@ BOOST_AUTO_TEST_CASE(hint_encoding_decoding_roundtrip) const Coordinate coordinate; const PhantomNode phantom; - const osrm::test::MockDataFacade facade{}; + const osrm::test::MockDataFacade facade{}; const Hint hint{phantom, facade.GetCheckSum()}; @@ -64,7 +64,7 @@ BOOST_AUTO_TEST_CASE(hint_encoding_decoding_roundtrip_bytewise) const Coordinate coordinate; const PhantomNode phantom; - const osrm::test::MockDataFacade facade{}; + const osrm::test::MockDataFacade facade{}; const Hint hint{phantom, facade.GetCheckSum()}; diff --git a/unit_tests/mocks/mock_datafacade.hpp b/unit_tests/mocks/mock_datafacade.hpp index 1d490b70e..d009ab61a 100644 --- a/unit_tests/mocks/mock_datafacade.hpp +++ b/unit_tests/mocks/mock_datafacade.hpp @@ -238,8 +238,8 @@ class MockBaseDataFacade : public engine::datafacade::BaseDataFacade template class MockAlgorithmDataFacade; template <> -class MockAlgorithmDataFacade - : public engine::datafacade::AlgorithmDataFacade +class MockAlgorithmDataFacade + : public engine::datafacade::AlgorithmDataFacade { private: EdgeData foo; @@ -281,8 +281,8 @@ class MockAlgorithmDataFacade }; template <> -class MockAlgorithmDataFacade - : public engine::datafacade::AlgorithmDataFacade +class MockAlgorithmDataFacade + : public engine::datafacade::AlgorithmDataFacade { private: EdgeData foo; @@ -297,10 +297,10 @@ class MockDataFacade final : public MockBaseDataFacade, public MockAlgorithmData }; template <> -class MockDataFacade final +class MockDataFacade final : public MockBaseDataFacade, - public MockAlgorithmDataFacade, - public MockAlgorithmDataFacade + public MockAlgorithmDataFacade, + public MockAlgorithmDataFacade { }; diff --git a/unit_tests/util/static_rtree.cpp b/unit_tests/util/static_rtree.cpp index ac9dff37e..8046a2e66 100644 --- a/unit_tests/util/static_rtree.cpp +++ b/unit_tests/util/static_rtree.cpp @@ -360,8 +360,8 @@ BOOST_AUTO_TEST_CASE(radius_regression_test) std::string nodes_path; build_rtree("test_angle", &fixture, leaves_path, nodes_path); MiniStaticRTree rtree(nodes_path, leaves_path, fixture.coords); - MockDataFacade mockfacade; - engine::GeospatialQuery> query( + MockDataFacade mockfacade; + engine::GeospatialQuery> query( rtree, fixture.coords, mockfacade); Coordinate input(FloatLongitude{5.2}, FloatLatitude{5.0}); @@ -387,8 +387,8 @@ BOOST_AUTO_TEST_CASE(bearing_tests) std::string nodes_path; build_rtree("test_bearing", &fixture, leaves_path, nodes_path); MiniStaticRTree rtree(nodes_path, leaves_path, fixture.coords); - MockDataFacade mockfacade; - engine::GeospatialQuery> query( + MockDataFacade mockfacade; + engine::GeospatialQuery> query( rtree, fixture.coords, mockfacade); Coordinate input(FloatLongitude{5.1}, FloatLatitude{5.0}); @@ -461,8 +461,8 @@ BOOST_AUTO_TEST_CASE(bbox_search_tests) std::string nodes_path; build_rtree("test_bbox", &fixture, leaves_path, nodes_path); MiniStaticRTree rtree(nodes_path, leaves_path, fixture.coords); - MockDataFacade mockfacade; - engine::GeospatialQuery> query( + MockDataFacade mockfacade; + engine::GeospatialQuery> query( rtree, fixture.coords, mockfacade); {