Add type traits to disable plugins for specific algorithms
This commit is contained in:
committed by
Patrick Niklaus
parent
436b34ffea
commit
922e155763
@@ -1,6 +1,8 @@
|
||||
#ifndef OSRM_ENGINE_ALGORITHM_HPP
|
||||
#define OSRM_ENGINE_ALGORITHM_HPP
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace engine
|
||||
@@ -9,27 +11,29 @@ namespace algorithm
|
||||
{
|
||||
|
||||
// Contraction Hiearchy
|
||||
struct CH;
|
||||
struct CH final {};
|
||||
// Contraction Hiearchy with core
|
||||
struct CoreCH final {};
|
||||
|
||||
}
|
||||
|
||||
namespace algorithm_trais
|
||||
{
|
||||
template <typename AlgorithmT> struct HasAlternativeRouting final
|
||||
{
|
||||
template <template <typename A> class FacadeT> bool operator()(const FacadeT<AlgorithmT> &)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
template <> struct HasAlternativeRouting<algorithm::CH> final
|
||||
{
|
||||
template <template <typename A> class FacadeT>
|
||||
bool operator()(const FacadeT<algorithm::CH> &facade)
|
||||
{
|
||||
return facade.GetCoreSize() == 0;
|
||||
}
|
||||
};
|
||||
template <typename AlgorithmT> struct HasAlternativePathSearch final : std::false_type {};
|
||||
template <typename AlgorithmT> struct HasShortestPathSearch final : std::false_type {};
|
||||
template <typename AlgorithmT> struct HasDirectShortestPathSearch final : std::false_type {};
|
||||
template <typename AlgorithmT> struct HasMapMatching final : std::false_type {};
|
||||
template <typename AlgorithmT> struct HasManyToManySearch final : std::false_type {};
|
||||
template <typename AlgorithmT> struct HasGetTileTurns final : std::false_type {};
|
||||
|
||||
template <> struct HasAlternativePathSearch<algorithm::CH> final : std::true_type {};
|
||||
template <> struct HasShortestPathSearch<algorithm::CH> final : std::true_type {};
|
||||
template <> struct HasDirectShortestPathSearch<algorithm::CH> final : std::true_type {};
|
||||
template <> struct HasMapMatching<algorithm::CH> final : std::true_type {};
|
||||
template <> struct HasManyToManySearch<algorithm::CH> final : std::true_type {};
|
||||
template <> struct HasGetTileTurns<algorithm::CH> final : std::true_type {};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,17 +19,17 @@ namespace engine
|
||||
class RoutingAlgorithmsInterface
|
||||
{
|
||||
public:
|
||||
virtual InternalRouteResult AlternativeRouting(const PhantomNodes &phantom_node_pair) const = 0;
|
||||
virtual InternalRouteResult AlternativePathSearch(const PhantomNodes &phantom_node_pair) const = 0;
|
||||
|
||||
virtual InternalRouteResult
|
||||
ShortestRouting(const std::vector<PhantomNodes> &phantom_node_pair,
|
||||
ShortestPathSearch(const std::vector<PhantomNodes> &phantom_node_pair,
|
||||
const boost::optional<bool> continue_straight_at_waypoint) const = 0;
|
||||
|
||||
virtual InternalRouteResult
|
||||
DirectShortestPathRouting(const std::vector<PhantomNodes> &phantom_node_pair) const = 0;
|
||||
DirectShortestPathSearch(const std::vector<PhantomNodes> &phantom_node_pair) const = 0;
|
||||
|
||||
virtual std::vector<EdgeWeight>
|
||||
ManyToManyRouting(const std::vector<PhantomNode> &phantom_nodes,
|
||||
ManyToManySearch(const std::vector<PhantomNode> &phantom_nodes,
|
||||
const std::vector<std::size_t> &source_indices,
|
||||
const std::vector<std::size_t> &target_indices) const = 0;
|
||||
|
||||
@@ -40,12 +40,24 @@ class RoutingAlgorithmsInterface
|
||||
const std::vector<boost::optional<double>> &trace_gps_precision) const = 0;
|
||||
|
||||
virtual std::vector<routing_algorithms::TurnData>
|
||||
TileTurns(const std::vector<datafacade::BaseDataFacade::RTreeLeaf> &edges,
|
||||
GetTileTurns(const std::vector<datafacade::BaseDataFacade::RTreeLeaf> &edges,
|
||||
const std::vector<std::size_t> &sorted_edge_indexes) const = 0;
|
||||
|
||||
virtual bool HasAlternativeRouting() const = 0;
|
||||
virtual bool HasAlternativePathSearch() const = 0;
|
||||
virtual bool HasShortestPathSearch() const = 0;
|
||||
virtual bool HasDirectShortestPathSearch() const = 0;
|
||||
virtual bool HasMapMatching() const = 0;
|
||||
virtual bool HasManyToManySearch() 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
|
||||
template <typename AlgorithmT> class RoutingAlgorithms final : public RoutingAlgorithmsInterface
|
||||
{
|
||||
@@ -57,27 +69,27 @@ template <typename AlgorithmT> class RoutingAlgorithms final : public RoutingAlg
|
||||
}
|
||||
|
||||
InternalRouteResult
|
||||
AlternativeRouting(const PhantomNodes &phantom_node_pair) const final override
|
||||
AlternativePathSearch(const PhantomNodes &phantom_node_pair) const final override
|
||||
{
|
||||
return routing_algorithms::alternativePathSearch(heaps, facade, phantom_node_pair);
|
||||
}
|
||||
|
||||
InternalRouteResult
|
||||
ShortestRouting(const std::vector<PhantomNodes> &phantom_node_pair,
|
||||
ShortestPathSearch(const std::vector<PhantomNodes> &phantom_node_pair,
|
||||
const boost::optional<bool> continue_straight_at_waypoint) const final override
|
||||
{
|
||||
return routing_algorithms::shortestPathSearch(
|
||||
heaps, facade, phantom_node_pair, continue_straight_at_waypoint);
|
||||
}
|
||||
|
||||
InternalRouteResult DirectShortestPathRouting(
|
||||
InternalRouteResult DirectShortestPathSearch(
|
||||
const std::vector<PhantomNodes> &phantom_node_pair) const final override
|
||||
{
|
||||
return routing_algorithms::directShortestPathSearch(heaps, facade, phantom_node_pair);
|
||||
}
|
||||
|
||||
std::vector<EdgeWeight>
|
||||
ManyToManyRouting(const std::vector<PhantomNode> &phantom_nodes,
|
||||
ManyToManySearch(const std::vector<PhantomNode> &phantom_nodes,
|
||||
const std::vector<std::size_t> &source_indices,
|
||||
const std::vector<std::size_t> &target_indices) const final override
|
||||
{
|
||||
@@ -100,15 +112,40 @@ template <typename AlgorithmT> class RoutingAlgorithms final : public RoutingAlg
|
||||
}
|
||||
|
||||
std::vector<routing_algorithms::TurnData>
|
||||
TileTurns(const std::vector<datafacade::BaseDataFacade::RTreeLeaf> &edges,
|
||||
GetTileTurns(const std::vector<datafacade::BaseDataFacade::RTreeLeaf> &edges,
|
||||
const std::vector<std::size_t> &sorted_edge_indexes) const final override
|
||||
{
|
||||
return routing_algorithms::getTileTurns(facade, edges, sorted_edge_indexes);
|
||||
}
|
||||
|
||||
bool HasAlternativeRouting() const final override
|
||||
bool HasAlternativePathSearch() const final override
|
||||
{
|
||||
return algorithm_trais::HasAlternativeRouting<AlgorithmT>()(facade);
|
||||
return algorithm_trais::HasAlternativePathSearch<AlgorithmT>::value;
|
||||
}
|
||||
|
||||
bool HasShortestPathSearch() const final override
|
||||
{
|
||||
return algorithm_trais::HasShortestPathSearch<AlgorithmT>::value;
|
||||
}
|
||||
|
||||
bool HasDirectShortestPathSearch() const final override
|
||||
{
|
||||
return algorithm_trais::HasDirectShortestPathSearch<AlgorithmT>::value;
|
||||
}
|
||||
|
||||
bool HasMapMatching() const final override
|
||||
{
|
||||
return algorithm_trais::HasMapMatching<AlgorithmT>::value;
|
||||
}
|
||||
|
||||
bool HasManyToManySearch() const final override
|
||||
{
|
||||
return algorithm_trais::HasManyToManySearch<AlgorithmT>::value;
|
||||
}
|
||||
|
||||
bool HasGetTileTurns() const final override
|
||||
{
|
||||
return algorithm_trais::HasGetTileTurns<AlgorithmT>::value;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#include "engine/algorithm.hpp"
|
||||
#include "engine/search_engine_data.hpp"
|
||||
|
||||
#include "util/exception.hpp"
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace engine
|
||||
@@ -14,6 +16,16 @@ namespace engine
|
||||
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
|
||||
alternativePathSearch(SearchEngineData &search_engine_data,
|
||||
const datafacade::ContiguousInternalMemoryDataFacade<algorithm::CH> &facade,
|
||||
|
||||
@@ -15,6 +15,16 @@ namespace engine
|
||||
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.
|
||||
/// 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
|
||||
|
||||
@@ -17,6 +17,18 @@ namespace engine
|
||||
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>
|
||||
manyToManySearch(SearchEngineData &engine_working_data,
|
||||
const datafacade::ContiguousInternalMemoryDataFacade<algorithm::CH> &facade,
|
||||
|
||||
@@ -20,6 +20,18 @@ using CandidateLists = std::vector<CandidateList>;
|
||||
using SubMatchingList = std::vector<map_matching::SubMatching>;
|
||||
static const constexpr double DEFAULT_GPS_PRECISION = 5;
|
||||
|
||||
template <typename AlgorithmT>
|
||||
SubMatchingList mapMatching(SearchEngineData &,
|
||||
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
|
||||
mapMatching(SearchEngineData &engine_working_data,
|
||||
const datafacade::ContiguousInternalMemoryDataFacade<algorithm::CH> &facade,
|
||||
|
||||
@@ -13,6 +13,17 @@ namespace engine
|
||||
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
|
||||
shortestPathSearch(SearchEngineData &engine_working_data,
|
||||
const datafacade::ContiguousInternalMemoryDataFacade<algorithm::CH> &facade,
|
||||
|
||||
@@ -27,6 +27,16 @@ struct TurnData final
|
||||
|
||||
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>
|
||||
getTileTurns(const datafacade::ContiguousInternalMemoryDataFacade<algorithm::CH> &facade,
|
||||
const std::vector<RTreeLeaf> &edges,
|
||||
|
||||
Reference in New Issue
Block a user