From 3f485ac09bca7c42801af8bed0cf3599b05c4f33 Mon Sep 17 00:00:00 2001 From: Patrick Niklaus Date: Wed, 1 Mar 2017 20:17:34 +0000 Subject: [PATCH] Addressed PR comments by @daniel-j-h and @oxidase --- include/engine/algorithm.hpp | 4 ++++ include/engine/data_watchdog.hpp | 2 +- include/engine/engine.hpp | 11 ++++++++--- include/engine/routing_algorithms.hpp | 8 -------- .../routing_algorithms/alternative_path.hpp | 10 ---------- .../direct_shortest_path.hpp | 10 ---------- .../engine/routing_algorithms/many_to_many.hpp | 12 ------------ .../engine/routing_algorithms/map_matching.hpp | 18 +++--------------- .../engine/routing_algorithms/routing_base.hpp | 2 +- .../routing_algorithms/shortest_path.hpp | 11 ----------- .../engine/routing_algorithms/tile_turns.hpp | 10 ---------- include/util/binary_heap.hpp | 6 ++++++ src/engine/plugins/tile.cpp | 2 +- 13 files changed, 24 insertions(+), 82 deletions(-) diff --git a/include/engine/algorithm.hpp b/include/engine/algorithm.hpp index 43477f86a..0a710fa5b 100644 --- a/include/engine/algorithm.hpp +++ b/include/engine/algorithm.hpp @@ -18,6 +18,10 @@ struct CH final struct CoreCH final { }; + +template const char* name(); +template<> inline const char* name() { return "CH"; } +template<> inline const char* name() { return "CoreCH"; } } namespace algorithm_trais diff --git a/include/engine/data_watchdog.hpp b/include/engine/data_watchdog.hpp index bb29d0c04..59c2d3cd0 100644 --- a/include/engine/data_watchdog.hpp +++ b/include/engine/data_watchdog.hpp @@ -44,7 +44,7 @@ template class DataWatchdog final watcher = std::thread(&DataWatchdog::Run, this); } - virtual ~DataWatchdog() + ~DataWatchdog() { active = false; barrier.notify_all(); diff --git a/include/engine/engine.hpp b/include/engine/engine.hpp index 42608eb42..81f650043 100644 --- a/include/engine/engine.hpp +++ b/include/engine/engine.hpp @@ -35,7 +35,7 @@ namespace engine class EngineInterface { public: - virtual ~EngineInterface(){}; + virtual ~EngineInterface() = default; virtual Status Route(const api::RouteParameters ¶meters, util::json::Object &result) const = 0; virtual Status Table(const api::TableParameters ¶meters, @@ -63,10 +63,12 @@ template class Engine final : public EngineInterface { if (config.use_shared_memory) { + util::Log(logDEBUG) << "Using shared memory with algorithm " << algorithm::name(); facade_provider = std::make_unique>(); } else { + util::Log(logDEBUG) << "Using internal memory with algorithm " << algorithm::name(); facade_provider = std::make_unique>(config.storage_config); } @@ -77,7 +79,7 @@ template class Engine final : public EngineInterface Engine(const Engine &) = delete; Engine &operator=(const Engine &) = delete; - virtual ~Engine(){}; + virtual ~Engine() = default; Status Route(const api::RouteParameters ¶ms, util::json::Object &result) const override final @@ -155,6 +157,8 @@ template <> bool Engine::CheckCompability(const EngineConfig &con else { std::ifstream in(config.storage_config.hsgr_data_path.string().c_str()); + if (!in) return false; + in.seekg(0, std::ios::end); auto size = in.tellg(); return size > 0; @@ -176,12 +180,13 @@ template <> bool Engine::CheckCompability(const EngineConfig auto mem = storage::makeSharedMemory(barrier.data().region); auto layout = reinterpret_cast(mem->Ptr()); - std::cout << layout->GetBlockSize(storage::DataLayout::CH_CORE_MARKER) << std::endl; return layout->GetBlockSize(storage::DataLayout::CH_CORE_MARKER) > 4; } else { std::ifstream in(config.storage_config.core_data_path.string().c_str()); + if (!in) return false; + in.seekg(0, std::ios::end); std::size_t size = in.tellg(); // An empty core files is only the 4 byte size header. diff --git a/include/engine/routing_algorithms.hpp b/include/engine/routing_algorithms.hpp index 283e2f2c5..706d35326 100644 --- a/include/engine/routing_algorithms.hpp +++ b/include/engine/routing_algorithms.hpp @@ -52,14 +52,6 @@ class RoutingAlgorithmsInterface virtual bool HasGetTileTurns() const = 0; }; -namespace detail -{ - -struct NotImplementedException : public std::runtime_error -{ -}; -} - // Short-lived object passed to each plugin in request to wrap routing algorithms template class RoutingAlgorithms final : public RoutingAlgorithmsInterface { diff --git a/include/engine/routing_algorithms/alternative_path.hpp b/include/engine/routing_algorithms/alternative_path.hpp index 2a039910d..93b94e025 100644 --- a/include/engine/routing_algorithms/alternative_path.hpp +++ b/include/engine/routing_algorithms/alternative_path.hpp @@ -16,16 +16,6 @@ namespace engine namespace routing_algorithms { -template -InternalRouteResult -alternativePathSearch(SearchEngineData &, - const datafacade::ContiguousInternalMemoryDataFacade &, - const PhantomNodes &) -{ - throw util::exception(std::string("alternativePathSearch is not implemented for ") + - typeid(AlgorithmT).name()); -} - InternalRouteResult alternativePathSearch(SearchEngineData &search_engine_data, 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 391a451a7..5b1be5df7 100644 --- a/include/engine/routing_algorithms/direct_shortest_path.hpp +++ b/include/engine/routing_algorithms/direct_shortest_path.hpp @@ -15,16 +15,6 @@ namespace engine namespace routing_algorithms { -template -InternalRouteResult -directShortestPathSearch(SearchEngineData &, - const datafacade::ContiguousInternalMemoryDataFacade &, - const std::vector &) -{ - throw util::exception(std::string("directShortestPathSearch is not implemented for ") + - typeid(AlgorithmT).name()); -} - /// 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 /// necessary in case of vias, where the directions of the start node is constrainted diff --git a/include/engine/routing_algorithms/many_to_many.hpp b/include/engine/routing_algorithms/many_to_many.hpp index 9b5a7b073..c6c1dbced 100644 --- a/include/engine/routing_algorithms/many_to_many.hpp +++ b/include/engine/routing_algorithms/many_to_many.hpp @@ -17,18 +17,6 @@ namespace engine namespace routing_algorithms { -template -std::vector -manyToManySearch(SearchEngineData &, - const datafacade::ContiguousInternalMemoryDataFacade &, - const std::vector &, - const std::vector &, - const std::vector &) -{ - throw util::exception(std::string("manyToManySearch is not implemented for ") + - typeid(AlgorithmT).name()); -} - std::vector manyToManySearch(SearchEngineData &engine_working_data, const datafacade::ContiguousInternalMemoryDataFacade &facade, diff --git a/include/engine/routing_algorithms/map_matching.hpp b/include/engine/routing_algorithms/map_matching.hpp index 61add6525..275e6ddcf 100644 --- a/include/engine/routing_algorithms/map_matching.hpp +++ b/include/engine/routing_algorithms/map_matching.hpp @@ -15,23 +15,14 @@ namespace engine namespace routing_algorithms { + using CandidateList = std::vector; using CandidateLists = std::vector; using SubMatchingList = std::vector; static const constexpr double DEFAULT_GPS_PRECISION = 5; -template -SubMatchingList mapMatching(SearchEngineData &, - const datafacade::ContiguousInternalMemoryDataFacade &, - const CandidateLists &, - const std::vector &, - const std::vector &, - const std::vector> &) -{ - throw util::exception(std::string("mapMatching is not implemented for ") + - typeid(AlgorithmT).name()); -} - +//[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, @@ -51,7 +42,4 @@ mapMatching(SearchEngineData &engine_working_data, } } -//[1] "Hidden Markov Map Matching Through Noise and Sparseness"; P. Newson and J. Krumm; 2009; ACM -// GIS - #endif /* MAP_MATCHING_HPP */ diff --git a/include/engine/routing_algorithms/routing_base.hpp b/include/engine/routing_algorithms/routing_base.hpp index 67ef99867..e1b0a630e 100644 --- a/include/engine/routing_algorithms/routing_base.hpp +++ b/include/engine/routing_algorithms/routing_base.hpp @@ -41,7 +41,7 @@ template bool stallAtNode(const datafacade::ContiguousInternalMemoryDataFacade &facade, const NodeID node, const EdgeWeight weight, - HeapT &query_heap) + const HeapT &query_heap) { for (auto edge : facade.GetAdjacentEdgeRange(node)) { diff --git a/include/engine/routing_algorithms/shortest_path.hpp b/include/engine/routing_algorithms/shortest_path.hpp index bb6b67914..2b24282cb 100644 --- a/include/engine/routing_algorithms/shortest_path.hpp +++ b/include/engine/routing_algorithms/shortest_path.hpp @@ -13,17 +13,6 @@ namespace engine namespace routing_algorithms { -template -InternalRouteResult -shortestPathSearch(SearchEngineData &, - const datafacade::ContiguousInternalMemoryDataFacade &, - const std::vector &, - const boost::optional) -{ - throw util::exception(std::string("shortestPathSearch is not implemented for ") + - typeid(AlgorithmT).name()); -} - InternalRouteResult shortestPathSearch(SearchEngineData &engine_working_data, const datafacade::ContiguousInternalMemoryDataFacade &facade, diff --git a/include/engine/routing_algorithms/tile_turns.hpp b/include/engine/routing_algorithms/tile_turns.hpp index 1aa9d1618..6baa8ef0d 100644 --- a/include/engine/routing_algorithms/tile_turns.hpp +++ b/include/engine/routing_algorithms/tile_turns.hpp @@ -27,16 +27,6 @@ struct TurnData final using RTreeLeaf = datafacade::BaseDataFacade::RTreeLeaf; -template -std::vector -getTileTurns(const datafacade::ContiguousInternalMemoryDataFacade &, - const std::vector &, - const std::vector &) -{ - throw util::exception(std::string("getTileTurns is not implemented for ") + - typeid(AlgorithmT).name()); -} - std::vector getTileTurns(const datafacade::ContiguousInternalMemoryDataFacade &facade, const std::vector &edges, diff --git a/include/util/binary_heap.hpp b/include/util/binary_heap.hpp index 29ba58a50..4d711b47d 100644 --- a/include/util/binary_heap.hpp +++ b/include/util/binary_heap.hpp @@ -145,6 +145,12 @@ class BinaryHeap return inserted_nodes[index].weight; } + const Weight &GetKey(NodeID node) const + { + const Key index = node_index.peek_index(node); + return inserted_nodes[index].weight; + } + bool WasRemoved(const NodeID node) const { BOOST_ASSERT(WasInserted(node)); diff --git a/src/engine/plugins/tile.cpp b/src/engine/plugins/tile.cpp index d1fd3b35c..f99281ef3 100644 --- a/src/engine/plugins/tile.cpp +++ b/src/engine/plugins/tile.cpp @@ -259,7 +259,7 @@ std::vector getEdgeIndex(const std::vector &edges) // GetEdgesInBox is marked `const`, so we can't sort the array itself, // instead we create an array of indexes and sort that instead. std::vector sorted_edge_indexes(edges.size(), 0); - std::iota(sorted_edge_indexes.begin(), sorted_edge_indexes.end(), 0); // fill with 1,2,3,...N + std::iota(sorted_edge_indexes.begin(), sorted_edge_indexes.end(), 0); // fill with 0,1,2,3,...N-1 // Now, sort that array based on the edges list, using the u/v node IDs // as the sort condition