#ifndef OSRM_ENGINE_ROUTING_ALGORITHM_HPP #define OSRM_ENGINE_ROUTING_ALGORITHM_HPP #include "engine/algorithm.hpp" #include "engine/internal_route_result.hpp" #include "engine/phantom_node.hpp" #include "engine/routing_algorithms/alternative_path.hpp" #include "engine/routing_algorithms/direct_shortest_path.hpp" #include "engine/routing_algorithms/many_to_many.hpp" #include "engine/routing_algorithms/map_matching.hpp" #include "engine/routing_algorithms/shortest_path.hpp" #include "engine/routing_algorithms/tile_turns.hpp" namespace osrm { namespace engine { class RoutingAlgorithmsInterface { public: virtual InternalManyRoutesResult AlternativePathSearch(const PhantomNodes &phantom_node_pair, unsigned number_of_alternatives) const = 0; virtual InternalRouteResult ShortestPathSearch(const std::vector &phantom_node_pair, const boost::optional continue_straight_at_waypoint) const = 0; virtual InternalRouteResult DirectShortestPathSearch(const PhantomNodes &phantom_node_pair) const = 0; virtual std::pair, std::vector> ManyToManySearch(const std::vector &phantom_nodes, const std::vector &source_indices, const std::vector &target_indices, const bool calculate_distance) const = 0; virtual routing_algorithms::SubMatchingList MapMatching(const routing_algorithms::CandidateLists &candidates_list, const std::vector &trace_coordinates, const std::vector &trace_timestamps, const std::vector> &trace_gps_precision, const bool allow_splitting) const = 0; virtual std::vector GetTileTurns(const std::vector &edges, const std::vector &sorted_edge_indexes) const = 0; virtual const DataFacadeBase &GetFacade() 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 SupportsDistanceAnnotationType() const = 0; virtual bool HasGetTileTurns() const = 0; virtual bool HasExcludeFlags() const = 0; virtual bool IsValid() const = 0; }; // Short-lived object passed to each plugin in request to wrap routing algorithms template class RoutingAlgorithms final : public RoutingAlgorithmsInterface { public: RoutingAlgorithms(SearchEngineData &heaps, std::shared_ptr> facade) : heaps(heaps), facade(facade) { } virtual ~RoutingAlgorithms() = default; InternalManyRoutesResult AlternativePathSearch(const PhantomNodes &phantom_node_pair, unsigned number_of_alternatives) const final override; InternalRouteResult ShortestPathSearch( const std::vector &phantom_node_pair, const boost::optional continue_straight_at_waypoint) const final override; InternalRouteResult DirectShortestPathSearch(const PhantomNodes &phantom_nodes) const final override; virtual std::pair, std::vector> ManyToManySearch(const std::vector &phantom_nodes, const std::vector &source_indices, const std::vector &target_indices, const bool calculate_distance) const final override; routing_algorithms::SubMatchingList MapMatching(const routing_algorithms::CandidateLists &candidates_list, const std::vector &trace_coordinates, const std::vector &trace_timestamps, const std::vector> &trace_gps_precision, const bool allow_splitting) const final override; std::vector GetTileTurns(const std::vector &edges, const std::vector &sorted_edge_indexes) const final override; const DataFacadeBase &GetFacade() const final override { return *facade; } bool HasAlternativePathSearch() const final override { return routing_algorithms::HasAlternativePathSearch::value; } bool HasShortestPathSearch() const final override { return routing_algorithms::HasShortestPathSearch::value; } bool HasDirectShortestPathSearch() const final override { return routing_algorithms::HasDirectShortestPathSearch::value; } bool HasMapMatching() const final override { return routing_algorithms::HasMapMatching::value; } bool HasManyToManySearch() const final override { return routing_algorithms::HasManyToManySearch::value; } bool SupportsDistanceAnnotationType() const final override { return routing_algorithms::SupportsDistanceAnnotationType::value; } bool HasGetTileTurns() const final override { return routing_algorithms::HasGetTileTurns::value; } bool HasExcludeFlags() const final override { return routing_algorithms::HasExcludeFlags::value; } bool IsValid() const final override { return static_cast(facade); } private: SearchEngineData &heaps; std::shared_ptr> facade; }; template InternalManyRoutesResult RoutingAlgorithms::AlternativePathSearch(const PhantomNodes &phantom_node_pair, unsigned number_of_alternatives) const { return routing_algorithms::alternativePathSearch( heaps, *facade, phantom_node_pair, number_of_alternatives); } template InternalRouteResult RoutingAlgorithms::ShortestPathSearch( const std::vector &phantom_node_pair, const boost::optional continue_straight_at_waypoint) const { return routing_algorithms::shortestPathSearch( heaps, *facade, phantom_node_pair, continue_straight_at_waypoint); } template InternalRouteResult RoutingAlgorithms::DirectShortestPathSearch(const PhantomNodes &phantom_nodes) const { return routing_algorithms::directShortestPathSearch(heaps, *facade, phantom_nodes); } template inline routing_algorithms::SubMatchingList RoutingAlgorithms::MapMatching( const routing_algorithms::CandidateLists &candidates_list, const std::vector &trace_coordinates, const std::vector &trace_timestamps, 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); } template std::pair, std::vector> RoutingAlgorithms::ManyToManySearch(const std::vector &phantom_nodes, const std::vector &_source_indices, const std::vector &_target_indices, const bool calculate_distance) const { BOOST_ASSERT(!phantom_nodes.empty()); auto source_indices = _source_indices; auto target_indices = _target_indices; if (source_indices.empty()) { source_indices.resize(phantom_nodes.size()); std::iota(source_indices.begin(), source_indices.end(), 0); } if (target_indices.empty()) { target_indices.resize(phantom_nodes.size()); std::iota(target_indices.begin(), target_indices.end(), 0); } return routing_algorithms::manyToManySearch(heaps, *facade, phantom_nodes, std::move(source_indices), std::move(target_indices), calculate_distance); } template inline std::vector RoutingAlgorithms::GetTileTurns( const std::vector &edges, const std::vector &sorted_edge_indexes) const { return routing_algorithms::getTileTurns(*facade, edges, sorted_edge_indexes); } } // ns engine } // ns osrm #endif