Addressed PR comments by @daniel-j-h and @oxidase

This commit is contained in:
Patrick Niklaus 2017-03-01 20:17:34 +00:00 committed by Patrick Niklaus
parent a901bda41e
commit 3f485ac09b
13 changed files with 24 additions and 82 deletions

View File

@ -18,6 +18,10 @@ struct CH final
struct CoreCH final struct CoreCH final
{ {
}; };
template<typename AlgorithmT> const char* name();
template<> inline const char* name<CH>() { return "CH"; }
template<> inline const char* name<CoreCH>() { return "CoreCH"; }
} }
namespace algorithm_trais namespace algorithm_trais

View File

@ -44,7 +44,7 @@ template <typename AlgorithmT> class DataWatchdog final
watcher = std::thread(&DataWatchdog::Run, this); watcher = std::thread(&DataWatchdog::Run, this);
} }
virtual ~DataWatchdog() ~DataWatchdog()
{ {
active = false; active = false;
barrier.notify_all(); barrier.notify_all();

View File

@ -35,7 +35,7 @@ namespace engine
class EngineInterface class EngineInterface
{ {
public: public:
virtual ~EngineInterface(){}; virtual ~EngineInterface() = default;
virtual Status Route(const api::RouteParameters &parameters, virtual Status Route(const api::RouteParameters &parameters,
util::json::Object &result) const = 0; util::json::Object &result) const = 0;
virtual Status Table(const api::TableParameters &parameters, virtual Status Table(const api::TableParameters &parameters,
@ -63,10 +63,12 @@ template <typename AlgorithmT> class Engine final : public EngineInterface
{ {
if (config.use_shared_memory) if (config.use_shared_memory)
{ {
util::Log(logDEBUG) << "Using shared memory with algorithm " << algorithm::name<AlgorithmT>();
facade_provider = std::make_unique<WatchingProvider<AlgorithmT>>(); facade_provider = std::make_unique<WatchingProvider<AlgorithmT>>();
} }
else else
{ {
util::Log(logDEBUG) << "Using internal memory with algorithm " << algorithm::name<AlgorithmT>();
facade_provider = facade_provider =
std::make_unique<ImmutableProvider<AlgorithmT>>(config.storage_config); std::make_unique<ImmutableProvider<AlgorithmT>>(config.storage_config);
} }
@ -77,7 +79,7 @@ template <typename AlgorithmT> class Engine final : public EngineInterface
Engine(const Engine &) = delete; Engine(const Engine &) = delete;
Engine &operator=(const Engine &) = delete; Engine &operator=(const Engine &) = delete;
virtual ~Engine(){}; virtual ~Engine() = default;
Status Route(const api::RouteParameters &params, Status Route(const api::RouteParameters &params,
util::json::Object &result) const override final util::json::Object &result) const override final
@ -155,6 +157,8 @@ template <> bool Engine<algorithm::CH>::CheckCompability(const EngineConfig &con
else else
{ {
std::ifstream in(config.storage_config.hsgr_data_path.string().c_str()); std::ifstream in(config.storage_config.hsgr_data_path.string().c_str());
if (!in) return false;
in.seekg(0, std::ios::end); in.seekg(0, std::ios::end);
auto size = in.tellg(); auto size = in.tellg();
return size > 0; return size > 0;
@ -176,12 +180,13 @@ template <> bool Engine<algorithm::CoreCH>::CheckCompability(const EngineConfig
auto mem = storage::makeSharedMemory(barrier.data().region); auto mem = storage::makeSharedMemory(barrier.data().region);
auto layout = reinterpret_cast<storage::DataLayout *>(mem->Ptr()); auto layout = reinterpret_cast<storage::DataLayout *>(mem->Ptr());
std::cout << layout->GetBlockSize(storage::DataLayout::CH_CORE_MARKER) << std::endl;
return layout->GetBlockSize(storage::DataLayout::CH_CORE_MARKER) > 4; return layout->GetBlockSize(storage::DataLayout::CH_CORE_MARKER) > 4;
} }
else else
{ {
std::ifstream in(config.storage_config.core_data_path.string().c_str()); std::ifstream in(config.storage_config.core_data_path.string().c_str());
if (!in) return false;
in.seekg(0, std::ios::end); in.seekg(0, std::ios::end);
std::size_t size = in.tellg(); std::size_t size = in.tellg();
// An empty core files is only the 4 byte size header. // An empty core files is only the 4 byte size header.

View File

@ -52,14 +52,6 @@ class RoutingAlgorithmsInterface
virtual bool HasGetTileTurns() const = 0; 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 // Short-lived object passed to each plugin in request to wrap routing algorithms
template <typename AlgorithmT> class RoutingAlgorithms final : public RoutingAlgorithmsInterface template <typename AlgorithmT> class RoutingAlgorithms final : public RoutingAlgorithmsInterface
{ {

View File

@ -16,16 +16,6 @@ namespace engine
namespace routing_algorithms namespace routing_algorithms
{ {
template <typename AlgorithmT>
InternalRouteResult
alternativePathSearch(SearchEngineData &,
const datafacade::ContiguousInternalMemoryDataFacade<AlgorithmT> &,
const PhantomNodes &)
{
throw util::exception(std::string("alternativePathSearch is not implemented for ") +
typeid(AlgorithmT).name());
}
InternalRouteResult InternalRouteResult
alternativePathSearch(SearchEngineData &search_engine_data, alternativePathSearch(SearchEngineData &search_engine_data,
const datafacade::ContiguousInternalMemoryDataFacade<algorithm::CH> &facade, const datafacade::ContiguousInternalMemoryDataFacade<algorithm::CH> &facade,

View File

@ -15,16 +15,6 @@ namespace engine
namespace routing_algorithms namespace routing_algorithms
{ {
template <typename AlgorithmT>
InternalRouteResult
directShortestPathSearch(SearchEngineData &,
const datafacade::ContiguousInternalMemoryDataFacade<AlgorithmT> &,
const std::vector<PhantomNodes> &)
{
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. /// 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 /// 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 /// necessary in case of vias, where the directions of the start node is constrainted

View File

@ -17,18 +17,6 @@ namespace engine
namespace routing_algorithms namespace routing_algorithms
{ {
template <typename AlgorithmT>
std::vector<EdgeWeight>
manyToManySearch(SearchEngineData &,
const datafacade::ContiguousInternalMemoryDataFacade<AlgorithmT> &,
const std::vector<PhantomNode> &,
const std::vector<std::size_t> &,
const std::vector<std::size_t> &)
{
throw util::exception(std::string("manyToManySearch is not implemented for ") +
typeid(AlgorithmT).name());
}
std::vector<EdgeWeight> std::vector<EdgeWeight>
manyToManySearch(SearchEngineData &engine_working_data, manyToManySearch(SearchEngineData &engine_working_data,
const datafacade::ContiguousInternalMemoryDataFacade<algorithm::CH> &facade, const datafacade::ContiguousInternalMemoryDataFacade<algorithm::CH> &facade,

View File

@ -15,23 +15,14 @@ namespace engine
namespace routing_algorithms namespace routing_algorithms
{ {
using CandidateList = std::vector<PhantomNodeWithDistance>; using CandidateList = std::vector<PhantomNodeWithDistance>;
using CandidateLists = std::vector<CandidateList>; using CandidateLists = std::vector<CandidateList>;
using SubMatchingList = std::vector<map_matching::SubMatching>; using SubMatchingList = std::vector<map_matching::SubMatching>;
static const constexpr double DEFAULT_GPS_PRECISION = 5; static const constexpr double DEFAULT_GPS_PRECISION = 5;
template <typename AlgorithmT> //[1] "Hidden Markov Map Matching Through Noise and Sparseness";
SubMatchingList mapMatching(SearchEngineData &, // P. Newson and J. Krumm; 2009; ACM GIS
const datafacade::ContiguousInternalMemoryDataFacade<AlgorithmT> &,
const CandidateLists &,
const std::vector<util::Coordinate> &,
const std::vector<unsigned> &,
const std::vector<boost::optional<double>> &)
{
throw util::exception(std::string("mapMatching is not implemented for ") +
typeid(AlgorithmT).name());
}
SubMatchingList SubMatchingList
mapMatching(SearchEngineData &engine_working_data, mapMatching(SearchEngineData &engine_working_data,
const datafacade::ContiguousInternalMemoryDataFacade<algorithm::CH> &facade, const datafacade::ContiguousInternalMemoryDataFacade<algorithm::CH> &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 */ #endif /* MAP_MATCHING_HPP */

View File

@ -41,7 +41,7 @@ template <bool DIRECTION, typename HeapT>
bool stallAtNode(const datafacade::ContiguousInternalMemoryDataFacade<algorithm::CH> &facade, bool stallAtNode(const datafacade::ContiguousInternalMemoryDataFacade<algorithm::CH> &facade,
const NodeID node, const NodeID node,
const EdgeWeight weight, const EdgeWeight weight,
HeapT &query_heap) const HeapT &query_heap)
{ {
for (auto edge : facade.GetAdjacentEdgeRange(node)) for (auto edge : facade.GetAdjacentEdgeRange(node))
{ {

View File

@ -13,17 +13,6 @@ namespace engine
namespace routing_algorithms namespace routing_algorithms
{ {
template <typename AlgorithmT>
InternalRouteResult
shortestPathSearch(SearchEngineData &,
const datafacade::ContiguousInternalMemoryDataFacade<AlgorithmT> &,
const std::vector<PhantomNodes> &,
const boost::optional<bool>)
{
throw util::exception(std::string("shortestPathSearch is not implemented for ") +
typeid(AlgorithmT).name());
}
InternalRouteResult InternalRouteResult
shortestPathSearch(SearchEngineData &engine_working_data, shortestPathSearch(SearchEngineData &engine_working_data,
const datafacade::ContiguousInternalMemoryDataFacade<algorithm::CH> &facade, const datafacade::ContiguousInternalMemoryDataFacade<algorithm::CH> &facade,

View File

@ -27,16 +27,6 @@ struct TurnData final
using RTreeLeaf = datafacade::BaseDataFacade::RTreeLeaf; using RTreeLeaf = datafacade::BaseDataFacade::RTreeLeaf;
template <typename AlgorithmT>
std::vector<TurnData>
getTileTurns(const datafacade::ContiguousInternalMemoryDataFacade<AlgorithmT> &,
const std::vector<RTreeLeaf> &,
const std::vector<std::size_t> &)
{
throw util::exception(std::string("getTileTurns is not implemented for ") +
typeid(AlgorithmT).name());
}
std::vector<TurnData> std::vector<TurnData>
getTileTurns(const datafacade::ContiguousInternalMemoryDataFacade<algorithm::CH> &facade, getTileTurns(const datafacade::ContiguousInternalMemoryDataFacade<algorithm::CH> &facade,
const std::vector<RTreeLeaf> &edges, const std::vector<RTreeLeaf> &edges,

View File

@ -145,6 +145,12 @@ class BinaryHeap
return inserted_nodes[index].weight; 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 bool WasRemoved(const NodeID node) const
{ {
BOOST_ASSERT(WasInserted(node)); BOOST_ASSERT(WasInserted(node));

View File

@ -259,7 +259,7 @@ std::vector<std::size_t> getEdgeIndex(const std::vector<RTreeLeaf> &edges)
// GetEdgesInBox is marked `const`, so we can't sort the array itself, // GetEdgesInBox is marked `const`, so we can't sort the array itself,
// instead we create an array of indexes and sort that instead. // instead we create an array of indexes and sort that instead.
std::vector<std::size_t> sorted_edge_indexes(edges.size(), 0); std::vector<std::size_t> 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 // Now, sort that array based on the edges list, using the u/v node IDs
// as the sort condition // as the sort condition