osrm-backend/include/engine/routing_algorithms.hpp

229 lines
8.5 KiB
C++
Raw Normal View History

#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
2017-04-06 08:28:43 -04:00
AlternativePathSearch(const PhantomNodes &phantom_node_pair,
unsigned number_of_alternatives) const = 0;
virtual InternalRouteResult
ShortestPathSearch(const std::vector<PhantomNodes> &phantom_node_pair,
2017-02-25 00:13:38 -05:00
const boost::optional<bool> continue_straight_at_waypoint) const = 0;
virtual InternalRouteResult
2017-02-25 00:13:38 -05:00
DirectShortestPathSearch(const PhantomNodes &phantom_node_pair) const = 0;
virtual std::vector<EdgeWeight>
ManyToManySearch(const std::vector<PhantomNode> &phantom_nodes,
2017-02-25 00:13:38 -05:00
const std::vector<std::size_t> &source_indices,
const std::vector<std::size_t> &target_indices) const = 0;
virtual routing_algorithms::SubMatchingList
MapMatching(const routing_algorithms::CandidateLists &candidates_list,
const std::vector<util::Coordinate> &trace_coordinates,
const std::vector<unsigned> &trace_timestamps,
const std::vector<boost::optional<double>> &trace_gps_precision,
2017-03-20 06:30:24 -04:00
const bool allow_splitting) const = 0;
virtual std::vector<routing_algorithms::TurnData>
GetTileTurns(const std::vector<datafacade::BaseDataFacade::RTreeLeaf> &edges,
2017-02-25 00:13:38 -05:00
const std::vector<std::size_t> &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 HasGetTileTurns() const = 0;
virtual bool HasAvoidFlags() const = 0;
virtual bool IsValid() const = 0;
};
// Short-lived object passed to each plugin in request to wrap routing algorithms
template <typename Algorithm> class RoutingAlgorithms final : public RoutingAlgorithmsInterface
{
public:
RoutingAlgorithms(SearchEngineData<Algorithm> &heaps,
std::shared_ptr<const DataFacade<Algorithm>> facade)
: heaps(heaps), facade(facade)
{
}
2017-02-28 18:43:11 -05:00
virtual ~RoutingAlgorithms() = default;
InternalManyRoutesResult
2017-04-06 08:28:43 -04:00
AlternativePathSearch(const PhantomNodes &phantom_node_pair,
unsigned number_of_alternatives) const final override;
2017-02-25 00:13:38 -05:00
InternalRouteResult ShortestPathSearch(
const std::vector<PhantomNodes> &phantom_node_pair,
2017-03-01 17:55:18 -05:00
const boost::optional<bool> continue_straight_at_waypoint) const final override;
2017-02-25 00:13:38 -05:00
InternalRouteResult
2017-03-01 17:55:18 -05:00
DirectShortestPathSearch(const PhantomNodes &phantom_nodes) const final override;
std::vector<EdgeWeight>
ManyToManySearch(const std::vector<PhantomNode> &phantom_nodes,
2017-02-25 00:13:38 -05:00
const std::vector<std::size_t> &source_indices,
2017-03-01 17:55:18 -05:00
const std::vector<std::size_t> &target_indices) const final override;
2017-03-14 07:35:56 -04:00
routing_algorithms::SubMatchingList
MapMatching(const routing_algorithms::CandidateLists &candidates_list,
const std::vector<util::Coordinate> &trace_coordinates,
const std::vector<unsigned> &trace_timestamps,
const std::vector<boost::optional<double>> &trace_gps_precision,
2017-03-20 06:30:24 -04:00
const bool allow_splitting) const final override;
std::vector<routing_algorithms::TurnData>
GetTileTurns(const std::vector<datafacade::BaseDataFacade::RTreeLeaf> &edges,
2017-03-01 17:55:18 -05:00
const std::vector<std::size_t> &sorted_edge_indexes) const final override;
const DataFacadeBase &GetFacade() const final override { return *facade; }
bool HasAlternativePathSearch() const final override
{
return routing_algorithms::HasAlternativePathSearch<Algorithm>::value;
}
bool HasShortestPathSearch() const final override
{
return routing_algorithms::HasShortestPathSearch<Algorithm>::value;
}
bool HasDirectShortestPathSearch() const final override
{
return routing_algorithms::HasDirectShortestPathSearch<Algorithm>::value;
}
bool HasMapMatching() const final override
{
return routing_algorithms::HasMapMatching<Algorithm>::value;
}
bool HasManyToManySearch() const final override
{
return routing_algorithms::HasManyToManySearch<Algorithm>::value;
}
bool HasGetTileTurns() const final override
{
return routing_algorithms::HasGetTileTurns<Algorithm>::value;
}
bool HasAvoidFlags() const final override
{
return routing_algorithms::HasAvoidFlags<Algorithm>::value;
}
bool IsValid() const final override
{
return static_cast<bool>(facade);
}
private:
SearchEngineData<Algorithm> &heaps;
std::shared_ptr<const DataFacade<Algorithm>> facade;
};
2017-03-01 17:55:18 -05:00
template <typename Algorithm>
InternalManyRoutesResult
2017-04-06 08:28:43 -04:00
RoutingAlgorithms<Algorithm>::AlternativePathSearch(const PhantomNodes &phantom_node_pair,
unsigned number_of_alternatives) const
2017-03-01 17:55:18 -05:00
{
2017-04-06 08:28:43 -04:00
return routing_algorithms::alternativePathSearch(
heaps, *facade, phantom_node_pair, number_of_alternatives);
2017-03-01 17:55:18 -05:00
}
template <typename Algorithm>
InternalRouteResult RoutingAlgorithms<Algorithm>::ShortestPathSearch(
2017-03-01 17:55:18 -05:00
const std::vector<PhantomNodes> &phantom_node_pair,
const boost::optional<bool> continue_straight_at_waypoint) const
{
return routing_algorithms::shortestPathSearch(
heaps, *facade, phantom_node_pair, continue_straight_at_waypoint);
2017-03-01 17:55:18 -05:00
}
template <typename Algorithm>
2017-03-01 17:55:18 -05:00
InternalRouteResult
RoutingAlgorithms<Algorithm>::DirectShortestPathSearch(const PhantomNodes &phantom_nodes) const
2017-03-01 17:55:18 -05:00
{
return routing_algorithms::directShortestPathSearch(heaps, *facade, phantom_nodes);
2017-03-01 17:55:18 -05:00
}
template <typename Algorithm>
std::vector<EdgeWeight>
RoutingAlgorithms<Algorithm>::ManyToManySearch(const std::vector<PhantomNode> &phantom_nodes,
const std::vector<std::size_t> &source_indices,
const std::vector<std::size_t> &target_indices) const
2017-03-01 17:55:18 -05:00
{
return routing_algorithms::manyToManySearch(
heaps, *facade, phantom_nodes, source_indices, target_indices);
2017-03-01 17:55:18 -05:00
}
template <typename Algorithm>
inline routing_algorithms::SubMatchingList RoutingAlgorithms<Algorithm>::MapMatching(
2017-03-01 17:55:18 -05:00
const routing_algorithms::CandidateLists &candidates_list,
const std::vector<util::Coordinate> &trace_coordinates,
const std::vector<unsigned> &trace_timestamps,
const std::vector<boost::optional<double>> &trace_gps_precision,
2017-03-20 06:30:24 -04:00
const bool allow_splitting) const
2017-03-01 17:55:18 -05:00
{
return routing_algorithms::mapMatching(heaps,
*facade,
candidates_list,
trace_coordinates,
trace_timestamps,
trace_gps_precision,
allow_splitting);
2017-03-01 17:55:18 -05:00
}
template <typename Algorithm>
inline std::vector<routing_algorithms::TurnData> RoutingAlgorithms<Algorithm>::GetTileTurns(
2017-03-01 17:55:18 -05:00
const std::vector<datafacade::BaseDataFacade::RTreeLeaf> &edges,
const std::vector<std::size_t> &sorted_edge_indexes) const
{
return routing_algorithms::getTileTurns(*facade, edges, sorted_edge_indexes);
2017-03-01 17:55:18 -05:00
}
// CoreCH overrides
template <>
InternalManyRoutesResult inline RoutingAlgorithms<
2017-04-06 08:28:43 -04:00
routing_algorithms::corech::Algorithm>::AlternativePathSearch(const PhantomNodes &,
unsigned) const
{
throw util::exception("AlternativePathSearch is disabled due to performance reasons");
}
template <>
inline std::vector<EdgeWeight>
RoutingAlgorithms<routing_algorithms::corech::Algorithm>::ManyToManySearch(
const std::vector<PhantomNode> &,
const std::vector<std::size_t> &,
const std::vector<std::size_t> &) const
{
throw util::exception("ManyToManySearch is disabled due to performance reasons");
}
2017-04-06 08:28:43 -04:00
} // ns engine
} // ns osrm
#endif