Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions include/engine/concepts.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#ifndef OSRM_ENGINE_CONCEPTS_HPP
#define OSRM_ENGINE_CONCEPTS_HPP

#include "engine/algorithm.hpp"
#include <concepts>
#include <type_traits>

namespace osrm::engine::routing_algorithms
{

/*
* RoutingAlgorithm concept
* ------------------------
* This concept documents and checks the compile-time interface expected
* from the routing algorithm marker types used throughout the engine
* (e.g., routing_algorithms::ch::Algorithm and routing_algorithms::mld::Algorithm).
*
* Required compile-time/public interface (checked by this concept):
* - routing_algorithms::name<Algorithm>() -> const char*
* - routing_algorithms::identifier<Algorithm>() -> const char*
* - trait templates (instantiable):
* HasAlternativePathSearch<Algorithm>
* HasShortestPathSearch<Algorithm>
* HasDirectShortestPathSearch<Algorithm>
* HasMapMatching<Algorithm>
* HasManyToManySearch<Algorithm>
* SupportsDistanceAnnotationType<Algorithm>
* HasGetTileTurns<Algorithm>
* HasExcludeFlags<Algorithm>
* - the above trait specializations must expose a compile-time ::value convertible to bool
*/
template <typename T>
concept RoutingAlgorithm = requires {
/* name() and identifier() are callable and return C strings */
{ name<T>() } -> std::convertible_to<const char *>;
{ identifier<T>() } -> std::convertible_to<const char *>;

Comment on lines +32 to +37
/* trait templates are instantiable */
typename HasAlternativePathSearch<T>;
typename HasShortestPathSearch<T>;
typename HasDirectShortestPathSearch<T>;
typename HasMapMatching<T>;
typename HasManyToManySearch<T>;
typename SupportsDistanceAnnotationType<T>;
typename HasGetTileTurns<T>;
typename HasExcludeFlags<T>;

/* trait values are usable as compile-time booleans */
{ HasAlternativePathSearch<T>::value } -> std::convertible_to<bool>;
{ HasShortestPathSearch<T>::value } -> std::convertible_to<bool>;
{ HasDirectShortestPathSearch<T>::value } -> std::convertible_to<bool>;
{ HasMapMatching<T>::value } -> std::convertible_to<bool>;
{ HasManyToManySearch<T>::value } -> std::convertible_to<bool>;
{ SupportsDistanceAnnotationType<T>::value } -> std::convertible_to<bool>;
{ HasGetTileTurns<T>::value } -> std::convertible_to<bool>;
{ HasExcludeFlags<T>::value } -> std::convertible_to<bool>;
};

} // namespace osrm::engine::routing_algorithms

#endif // OSRM_ENGINE_CONCEPTS_HPP
3 changes: 2 additions & 1 deletion include/engine/engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class EngineInterface
virtual Status Tile(const api::TileParameters &parameters, api::ResultT &result) const = 0;
};

template <typename Algorithm> class Engine final : public EngineInterface
template <routing_algorithms::RoutingAlgorithm Algorithm>
class Engine final : public EngineInterface
Comment on lines 40 to +42
{
public:
explicit Engine(const EngineConfig &config)
Expand Down
16 changes: 9 additions & 7 deletions include/engine/routing_algorithms.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define OSRM_ENGINE_ROUTING_ALGORITHM_HPP

#include "engine/algorithm.hpp"
#include "engine/concepts.hpp"
#include "engine/internal_route_result.hpp"
#include "engine/phantom_node.hpp"
#include "engine/routing_algorithms/alternative_path.hpp"
Expand Down Expand Up @@ -61,7 +62,8 @@ class RoutingAlgorithmsInterface
};

// Short-lived object passed to each plugin in request to wrap routing algorithms
template <typename Algorithm> class RoutingAlgorithms final : public RoutingAlgorithmsInterface
template <routing_algorithms::RoutingAlgorithm Algorithm>
class RoutingAlgorithms final : public RoutingAlgorithmsInterface
{
public:
RoutingAlgorithms(SearchEngineData<Algorithm> &heaps,
Expand Down Expand Up @@ -149,15 +151,15 @@ template <typename Algorithm> class RoutingAlgorithms final : public RoutingAlgo
std::shared_ptr<const DataFacade<Algorithm>> facade;
};

template <typename Algorithm>
template <routing_algorithms::RoutingAlgorithm Algorithm>
InternalManyRoutesResult RoutingAlgorithms<Algorithm>::AlternativePathSearch(
const PhantomEndpointCandidates &endpoint_candidates, unsigned number_of_alternatives) const
{
return routing_algorithms::alternativePathSearch(
heaps, *facade, endpoint_candidates, number_of_alternatives);
}

template <typename Algorithm>
template <routing_algorithms::RoutingAlgorithm Algorithm>
InternalRouteResult RoutingAlgorithms<Algorithm>::ShortestPathSearch(
const std::vector<PhantomNodeCandidates> &waypoint_candidates,
const std::optional<bool> continue_straight_at_waypoint) const
Expand All @@ -166,14 +168,14 @@ InternalRouteResult RoutingAlgorithms<Algorithm>::ShortestPathSearch(
heaps, *facade, waypoint_candidates, continue_straight_at_waypoint);
}

template <typename Algorithm>
template <routing_algorithms::RoutingAlgorithm Algorithm>
InternalRouteResult RoutingAlgorithms<Algorithm>::DirectShortestPathSearch(
const PhantomEndpointCandidates &endpoint_candidates) const
{
return routing_algorithms::directShortestPathSearch(heaps, *facade, endpoint_candidates);
}

template <typename Algorithm>
template <routing_algorithms::RoutingAlgorithm Algorithm>
inline routing_algorithms::SubMatchingList RoutingAlgorithms<Algorithm>::MapMatching(
const routing_algorithms::CandidateLists &candidates_list,
const std::vector<util::Coordinate> &trace_coordinates,
Expand All @@ -190,7 +192,7 @@ inline routing_algorithms::SubMatchingList RoutingAlgorithms<Algorithm>::MapMatc
allow_splitting);
}

template <typename Algorithm>
template <routing_algorithms::RoutingAlgorithm Algorithm>
std::pair<std::vector<EdgeDuration>, std::vector<EdgeDistance>>
RoutingAlgorithms<Algorithm>::ManyToManySearch(
const std::vector<PhantomNodeCandidates> &candidates_list,
Expand Down Expand Up @@ -222,7 +224,7 @@ RoutingAlgorithms<Algorithm>::ManyToManySearch(
calculate_distance);
}

template <typename Algorithm>
template <routing_algorithms::RoutingAlgorithm Algorithm>
inline std::vector<routing_algorithms::TurnData> RoutingAlgorithms<Algorithm>::GetTileTurns(
const std::vector<datafacade::BaseDataFacade::RTreeLeaf> &edges,
const std::vector<std::size_t> &sorted_edge_indexes) const
Expand Down
3 changes: 2 additions & 1 deletion include/engine/search_engine_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define SEARCH_ENGINE_DATA_HPP

#include "engine/algorithm.hpp"
#include "engine/concepts.hpp"
#include "util/query_heap.hpp"
#include "util/typedefs.hpp"

Expand All @@ -14,7 +15,7 @@ namespace osrm::engine
// - CH algorithms use CH heaps
// - MLD algorithms use MLD heaps

template <typename Algorithm> struct SearchEngineData
template <routing_algorithms::RoutingAlgorithm Algorithm> struct SearchEngineData
{
};

Expand Down
Loading