add Algorithm parameter to SearchEngineData

This commit is contained in:
Michael Krasnyk 2017-04-03 19:15:58 +02:00
parent d66cc125aa
commit 905ca69301
18 changed files with 294 additions and 274 deletions

View File

@ -49,7 +49,7 @@ class EngineInterface
virtual Status Tile(const api::TileParameters &parameters, std::string &result) const = 0; virtual Status Tile(const api::TileParameters &parameters, std::string &result) const = 0;
}; };
template <typename AlgorithmT> class Engine final : public EngineInterface template <typename Algorithm> class Engine final : public EngineInterface
{ {
public: public:
explicit Engine(const EngineConfig &config) explicit Engine(const EngineConfig &config)
@ -64,15 +64,14 @@ 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 " util::Log(logDEBUG) << "Using shared memory with algorithm "
<< routing_algorithms::name<AlgorithmT>(); << routing_algorithms::name<Algorithm>();
facade_provider = std::make_unique<WatchingProvider<AlgorithmT>>(); facade_provider = std::make_unique<WatchingProvider<Algorithm>>();
} }
else else
{ {
util::Log(logDEBUG) << "Using internal memory with algorithm " util::Log(logDEBUG) << "Using internal memory with algorithm "
<< routing_algorithms::name<AlgorithmT>(); << routing_algorithms::name<Algorithm>();
facade_provider = facade_provider = std::make_unique<ImmutableProvider<Algorithm>>(config.storage_config);
std::make_unique<ImmutableProvider<AlgorithmT>>(config.storage_config);
} }
} }
@ -87,7 +86,7 @@ template <typename AlgorithmT> class Engine final : public EngineInterface
util::json::Object &result) const override final util::json::Object &result) const override final
{ {
auto facade = facade_provider->Get(); auto facade = facade_provider->Get();
auto algorithms = RoutingAlgorithms<AlgorithmT>{heaps, *facade}; auto algorithms = RoutingAlgorithms<Algorithm>{heaps, *facade};
return route_plugin.HandleRequest(*facade, algorithms, params, result); return route_plugin.HandleRequest(*facade, algorithms, params, result);
} }
@ -95,7 +94,7 @@ template <typename AlgorithmT> class Engine final : public EngineInterface
util::json::Object &result) const override final util::json::Object &result) const override final
{ {
auto facade = facade_provider->Get(); auto facade = facade_provider->Get();
auto algorithms = RoutingAlgorithms<AlgorithmT>{heaps, *facade}; auto algorithms = RoutingAlgorithms<Algorithm>{heaps, *facade};
return table_plugin.HandleRequest(*facade, algorithms, params, result); return table_plugin.HandleRequest(*facade, algorithms, params, result);
} }
@ -103,14 +102,14 @@ template <typename AlgorithmT> class Engine final : public EngineInterface
util::json::Object &result) const override final util::json::Object &result) const override final
{ {
auto facade = facade_provider->Get(); auto facade = facade_provider->Get();
auto algorithms = RoutingAlgorithms<AlgorithmT>{heaps, *facade}; auto algorithms = RoutingAlgorithms<Algorithm>{heaps, *facade};
return nearest_plugin.HandleRequest(*facade, algorithms, params, result); return nearest_plugin.HandleRequest(*facade, algorithms, params, result);
} }
Status Trip(const api::TripParameters &params, util::json::Object &result) const override final Status Trip(const api::TripParameters &params, util::json::Object &result) const override final
{ {
auto facade = facade_provider->Get(); auto facade = facade_provider->Get();
auto algorithms = RoutingAlgorithms<AlgorithmT>{heaps, *facade}; auto algorithms = RoutingAlgorithms<Algorithm>{heaps, *facade};
return trip_plugin.HandleRequest(*facade, algorithms, params, result); return trip_plugin.HandleRequest(*facade, algorithms, params, result);
} }
@ -118,22 +117,22 @@ template <typename AlgorithmT> class Engine final : public EngineInterface
util::json::Object &result) const override final util::json::Object &result) const override final
{ {
auto facade = facade_provider->Get(); auto facade = facade_provider->Get();
auto algorithms = RoutingAlgorithms<AlgorithmT>{heaps, *facade}; auto algorithms = RoutingAlgorithms<Algorithm>{heaps, *facade};
return match_plugin.HandleRequest(*facade, algorithms, params, result); return match_plugin.HandleRequest(*facade, algorithms, params, result);
} }
Status Tile(const api::TileParameters &params, std::string &result) const override final Status Tile(const api::TileParameters &params, std::string &result) const override final
{ {
auto facade = facade_provider->Get(); auto facade = facade_provider->Get();
auto algorithms = RoutingAlgorithms<AlgorithmT>{heaps, *facade}; auto algorithms = RoutingAlgorithms<Algorithm>{heaps, *facade};
return tile_plugin.HandleRequest(*facade, algorithms, params, result); return tile_plugin.HandleRequest(*facade, algorithms, params, result);
} }
static bool CheckCompability(const EngineConfig &config); static bool CheckCompability(const EngineConfig &config);
private: private:
std::unique_ptr<DataFacadeProvider<AlgorithmT>> facade_provider; std::unique_ptr<DataFacadeProvider<Algorithm>> facade_provider;
mutable SearchEngineData heaps; mutable SearchEngineData<Algorithm> heaps;
const plugins::ViaRoutePlugin route_plugin; const plugins::ViaRoutePlugin route_plugin;
const plugins::TablePlugin table_plugin; const plugins::TablePlugin table_plugin;

View File

@ -54,11 +54,11 @@ class RoutingAlgorithmsInterface
}; };
// 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 Algorithm> class RoutingAlgorithms final : public RoutingAlgorithmsInterface
{ {
public: public:
RoutingAlgorithms(SearchEngineData &heaps, RoutingAlgorithms(SearchEngineData<Algorithm> &heaps,
const datafacade::ContiguousInternalMemoryDataFacade<AlgorithmT> &facade) const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade)
: heaps(heaps), facade(facade) : heaps(heaps), facade(facade)
{ {
} }
@ -93,49 +93,49 @@ template <typename AlgorithmT> class RoutingAlgorithms final : public RoutingAlg
bool HasAlternativePathSearch() const final override bool HasAlternativePathSearch() const final override
{ {
return routing_algorithms::HasAlternativePathSearch<AlgorithmT>::value; return routing_algorithms::HasAlternativePathSearch<Algorithm>::value;
} }
bool HasShortestPathSearch() const final override bool HasShortestPathSearch() const final override
{ {
return routing_algorithms::HasShortestPathSearch<AlgorithmT>::value; return routing_algorithms::HasShortestPathSearch<Algorithm>::value;
} }
bool HasDirectShortestPathSearch() const final override bool HasDirectShortestPathSearch() const final override
{ {
return routing_algorithms::HasDirectShortestPathSearch<AlgorithmT>::value; return routing_algorithms::HasDirectShortestPathSearch<Algorithm>::value;
} }
bool HasMapMatching() const final override bool HasMapMatching() const final override
{ {
return routing_algorithms::HasMapMatching<AlgorithmT>::value; return routing_algorithms::HasMapMatching<Algorithm>::value;
} }
bool HasManyToManySearch() const final override bool HasManyToManySearch() const final override
{ {
return routing_algorithms::HasManyToManySearch<AlgorithmT>::value; return routing_algorithms::HasManyToManySearch<Algorithm>::value;
} }
bool HasGetTileTurns() const final override bool HasGetTileTurns() const final override
{ {
return routing_algorithms::HasGetTileTurns<AlgorithmT>::value; return routing_algorithms::HasGetTileTurns<Algorithm>::value;
} }
private: private:
SearchEngineData &heaps; SearchEngineData<Algorithm> &heaps;
// Owned by shared-ptr passed to the query // Owned by shared-ptr passed to the query
const datafacade::ContiguousInternalMemoryDataFacade<AlgorithmT> &facade; const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade;
}; };
template <typename AlgorithmT> template <typename Algorithm>
InternalRouteResult InternalRouteResult
RoutingAlgorithms<AlgorithmT>::AlternativePathSearch(const PhantomNodes &phantom_node_pair) const RoutingAlgorithms<Algorithm>::AlternativePathSearch(const PhantomNodes &phantom_node_pair) const
{ {
return routing_algorithms::ch::alternativePathSearch(heaps, facade, phantom_node_pair); return routing_algorithms::ch::alternativePathSearch(heaps, facade, phantom_node_pair);
} }
template <typename AlgorithmT> template <typename Algorithm>
InternalRouteResult RoutingAlgorithms<AlgorithmT>::ShortestPathSearch( InternalRouteResult RoutingAlgorithms<Algorithm>::ShortestPathSearch(
const std::vector<PhantomNodes> &phantom_node_pair, const std::vector<PhantomNodes> &phantom_node_pair,
const boost::optional<bool> continue_straight_at_waypoint) const const boost::optional<bool> continue_straight_at_waypoint) const
{ {
@ -143,16 +143,16 @@ InternalRouteResult RoutingAlgorithms<AlgorithmT>::ShortestPathSearch(
heaps, facade, phantom_node_pair, continue_straight_at_waypoint); heaps, facade, phantom_node_pair, continue_straight_at_waypoint);
} }
template <typename AlgorithmT> template <typename Algorithm>
InternalRouteResult InternalRouteResult
RoutingAlgorithms<AlgorithmT>::DirectShortestPathSearch(const PhantomNodes &phantom_nodes) const RoutingAlgorithms<Algorithm>::DirectShortestPathSearch(const PhantomNodes &phantom_nodes) const
{ {
return routing_algorithms::directShortestPathSearch(heaps, facade, phantom_nodes); return routing_algorithms::directShortestPathSearch(heaps, facade, phantom_nodes);
} }
template <typename AlgorithmT> template <typename Algorithm>
std::vector<EdgeWeight> RoutingAlgorithms<AlgorithmT>::ManyToManySearch( std::vector<EdgeWeight>
const std::vector<PhantomNode> &phantom_nodes, RoutingAlgorithms<Algorithm>::ManyToManySearch(const std::vector<PhantomNode> &phantom_nodes,
const std::vector<std::size_t> &source_indices, const std::vector<std::size_t> &source_indices,
const std::vector<std::size_t> &target_indices) const const std::vector<std::size_t> &target_indices) const
{ {
@ -160,15 +160,15 @@ std::vector<EdgeWeight> RoutingAlgorithms<AlgorithmT>::ManyToManySearch(
heaps, facade, phantom_nodes, source_indices, target_indices); heaps, facade, phantom_nodes, source_indices, target_indices);
} }
template <typename AlgorithmT> template <typename Algorithm>
inline routing_algorithms::SubMatchingList RoutingAlgorithms<AlgorithmT>::MapMatching( inline routing_algorithms::SubMatchingList RoutingAlgorithms<Algorithm>::MapMatching(
const routing_algorithms::CandidateLists &candidates_list, const routing_algorithms::CandidateLists &candidates_list,
const std::vector<util::Coordinate> &trace_coordinates, const std::vector<util::Coordinate> &trace_coordinates,
const std::vector<unsigned> &trace_timestamps, const std::vector<unsigned> &trace_timestamps,
const std::vector<boost::optional<double>> &trace_gps_precision, const std::vector<boost::optional<double>> &trace_gps_precision,
const bool allow_splitting) const const bool allow_splitting) const
{ {
return routing_algorithms::ch::mapMatching(heaps, return routing_algorithms::mapMatching(heaps,
facade, facade,
candidates_list, candidates_list,
trace_coordinates, trace_coordinates,
@ -177,14 +177,31 @@ inline routing_algorithms::SubMatchingList RoutingAlgorithms<AlgorithmT>::MapMat
allow_splitting); allow_splitting);
} }
template <typename AlgorithmT> template <typename Algorithm>
inline std::vector<routing_algorithms::TurnData> RoutingAlgorithms<AlgorithmT>::GetTileTurns( inline std::vector<routing_algorithms::TurnData> RoutingAlgorithms<Algorithm>::GetTileTurns(
const std::vector<datafacade::BaseDataFacade::RTreeLeaf> &edges, const std::vector<datafacade::BaseDataFacade::RTreeLeaf> &edges,
const std::vector<std::size_t> &sorted_edge_indexes) const const std::vector<std::size_t> &sorted_edge_indexes) const
{ {
return routing_algorithms::getTileTurns(facade, edges, sorted_edge_indexes); return routing_algorithms::getTileTurns(facade, edges, sorted_edge_indexes);
} }
// CoreCH overrides
template <>
InternalRouteResult inline RoutingAlgorithms<routing_algorithms::corech::Algorithm>::AlternativePathSearch(const PhantomNodes &) 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");
}
// MLD overrides for not implemented // MLD overrides for not implemented
template <> template <>
InternalRouteResult inline RoutingAlgorithms< InternalRouteResult inline RoutingAlgorithms<

View File

@ -18,8 +18,8 @@ namespace routing_algorithms
namespace ch namespace ch
{ {
InternalRouteResult InternalRouteResult
alternativePathSearch(SearchEngineData &search_engine_data, alternativePathSearch(SearchEngineData<Algorithm> &search_engine_data,
const datafacade::ContiguousInternalMemoryDataFacade<ch::Algorithm> &facade, const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
const PhantomNodes &phantom_node_pair); const PhantomNodes &phantom_node_pair);
} // namespace ch } // namespace ch
} // namespace routing_algorithms } // namespace routing_algorithms

View File

@ -21,10 +21,15 @@ namespace routing_algorithms
/// by the previous route. /// by the previous route.
/// This variation is only an optimazation for graphs with slow queries, for example /// This variation is only an optimazation for graphs with slow queries, for example
/// not fully contracted graphs. /// not fully contracted graphs.
template <typename AlgorithmT> template <typename Algorithm>
InternalRouteResult InternalRouteResult
directShortestPathSearch(SearchEngineData &engine_working_data, directShortestPathSearch(SearchEngineData<Algorithm> &engine_working_data,
const datafacade::ContiguousInternalMemoryDataFacade<AlgorithmT> &facade, const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
const PhantomNodes &phantom_nodes);
InternalRouteResult directShortestPathSearch(
SearchEngineData<mld::Algorithm> &engine_working_data,
const datafacade::ContiguousInternalMemoryDataFacade<mld::Algorithm> &facade,
const PhantomNodes &phantom_nodes); const PhantomNodes &phantom_nodes);
} // namespace routing_algorithms } // namespace routing_algorithms

View File

@ -19,7 +19,7 @@ namespace routing_algorithms
namespace ch namespace ch
{ {
std::vector<EdgeWeight> std::vector<EdgeWeight>
manyToManySearch(SearchEngineData &engine_working_data, manyToManySearch(SearchEngineData<Algorithm> &engine_working_data,
const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade, const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
const std::vector<PhantomNode> &phantom_nodes, const std::vector<PhantomNode> &phantom_nodes,
const std::vector<std::size_t> &source_indices, const std::vector<std::size_t> &source_indices,

View File

@ -22,27 +22,15 @@ static const constexpr double DEFAULT_GPS_PRECISION = 5;
//[1] "Hidden Markov Map Matching Through Noise and Sparseness"; //[1] "Hidden Markov Map Matching Through Noise and Sparseness";
// P. Newson and J. Krumm; 2009; ACM GIS // P. Newson and J. Krumm; 2009; ACM GIS
namespace ch template<typename Algorithm>
{ SubMatchingList mapMatching(SearchEngineData<Algorithm> &engine_working_data,
SubMatchingList mapMatching(SearchEngineData &engine_working_data,
const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade, const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
const CandidateLists &candidates_list, const CandidateLists &candidates_list,
const std::vector<util::Coordinate> &trace_coordinates, const std::vector<util::Coordinate> &trace_coordinates,
const std::vector<unsigned> &trace_timestamps, const std::vector<unsigned> &trace_timestamps,
const std::vector<boost::optional<double>> &trace_gps_precision, const std::vector<boost::optional<double>> &trace_gps_precision,
const bool allow_splitting); const bool allow_splitting);
}
namespace corech
{
SubMatchingList mapMatching(SearchEngineData &engine_working_data,
const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
const 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,
const bool allow_splitting);
}
} }
} }
} }

View File

@ -58,7 +58,8 @@ void insertNodesInHeap(Heap &heap, const PhantomNode &phantom_node)
} }
template <bool DIRECTION> template <bool DIRECTION>
void insertNodesInHeap(SearchEngineData::ManyToManyQueryHeap &heap, const PhantomNode &phantom_node) void insertNodesInHeap(SearchEngineData<ch::Algorithm>::ManyToManyQueryHeap &heap,
const PhantomNode &phantom_node)
{ {
BOOST_ASSERT(phantom_node.IsValid()); BOOST_ASSERT(phantom_node.IsValid());

View File

@ -52,7 +52,7 @@ template <bool DIRECTION>
void relaxOutgoingEdges(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade, void relaxOutgoingEdges(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
const NodeID node, const NodeID node,
const EdgeWeight weight, const EdgeWeight weight,
SearchEngineData::QueryHeap &heap) SearchEngineData<Algorithm>::QueryHeap &heap)
{ {
for (const auto edge : facade.GetAdjacentEdgeRange(node)) for (const auto edge : facade.GetAdjacentEdgeRange(node))
{ {
@ -114,8 +114,8 @@ static constexpr bool ENABLE_STALLING = true;
static constexpr bool DISABLE_STALLING = false; static constexpr bool DISABLE_STALLING = false;
template <bool DIRECTION, bool STALLING = ENABLE_STALLING> template <bool DIRECTION, bool STALLING = ENABLE_STALLING>
void routingStep(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade, void routingStep(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
SearchEngineData::QueryHeap &forward_heap, SearchEngineData<Algorithm>::QueryHeap &forward_heap,
SearchEngineData::QueryHeap &reverse_heap, SearchEngineData<Algorithm>::QueryHeap &reverse_heap,
NodeID &middle_node_id, NodeID &middle_node_id,
EdgeWeight &upper_bound, EdgeWeight &upper_bound,
EdgeWeight min_edge_offset, EdgeWeight min_edge_offset,
@ -329,12 +329,12 @@ void unpackEdge(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm>
const NodeID to, const NodeID to,
std::vector<NodeID> &unpacked_path); std::vector<NodeID> &unpacked_path);
void retrievePackedPathFromHeap(const SearchEngineData::QueryHeap &forward_heap, void retrievePackedPathFromHeap(const SearchEngineData<Algorithm>::QueryHeap &forward_heap,
const SearchEngineData::QueryHeap &reverse_heap, const SearchEngineData<Algorithm>::QueryHeap &reverse_heap,
const NodeID middle_node_id, const NodeID middle_node_id,
std::vector<NodeID> &packed_path); std::vector<NodeID> &packed_path);
void retrievePackedPathFromSingleHeap(const SearchEngineData::QueryHeap &search_heap, void retrievePackedPathFromSingleHeap(const SearchEngineData<Algorithm>::QueryHeap &search_heap,
const NodeID middle_node_id, const NodeID middle_node_id,
std::vector<NodeID> &packed_path); std::vector<NodeID> &packed_path);
@ -351,8 +351,8 @@ void retrievePackedPathFromSingleHeap(const SearchEngineData::QueryHeap &search_
// requires // requires
// a force loop, if the heaps have been initialized with positive offsets. // a force loop, if the heaps have been initialized with positive offsets.
void search(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade, void search(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
SearchEngineData::QueryHeap &forward_heap, SearchEngineData<Algorithm>::QueryHeap &forward_heap,
SearchEngineData::QueryHeap &reverse_heap, SearchEngineData<Algorithm>::QueryHeap &reverse_heap,
std::int32_t &weight, std::int32_t &weight,
std::vector<NodeID> &packed_leg, std::vector<NodeID> &packed_leg,
const bool force_loop_forward, const bool force_loop_forward,
@ -361,10 +361,10 @@ void search(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &fac
// Alias to be compatible with the overload for CoreCH that needs 4 heaps // Alias to be compatible with the overload for CoreCH that needs 4 heaps
inline void search(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade, inline void search(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
SearchEngineData::QueryHeap &forward_heap, SearchEngineData<Algorithm>::QueryHeap &forward_heap,
SearchEngineData::QueryHeap &reverse_heap, SearchEngineData<Algorithm>::QueryHeap &reverse_heap,
SearchEngineData::QueryHeap &, SearchEngineData<Algorithm>::QueryHeap &,
SearchEngineData::QueryHeap &, SearchEngineData<Algorithm>::QueryHeap &,
std::int32_t &weight, std::int32_t &weight,
std::vector<NodeID> &packed_leg, std::vector<NodeID> &packed_leg,
const bool force_loop_forward, const bool force_loop_forward,
@ -395,8 +395,8 @@ double getPathDistance(const datafacade::ContiguousInternalMemoryDataFacade<ch::
// the addition of force_loop parameters might be required // the addition of force_loop parameters might be required
double double
getNetworkDistance(const datafacade::ContiguousInternalMemoryDataFacade<ch::Algorithm> &facade, getNetworkDistance(const datafacade::ContiguousInternalMemoryDataFacade<ch::Algorithm> &facade,
SearchEngineData::QueryHeap &forward_heap, SearchEngineData<Algorithm>::QueryHeap &forward_heap,
SearchEngineData::QueryHeap &reverse_heap, SearchEngineData<Algorithm>::QueryHeap &reverse_heap,
const PhantomNode &source_phantom, const PhantomNode &source_phantom,
const PhantomNode &target_phantom, const PhantomNode &target_phantom,
int duration_upper_bound = INVALID_EDGE_WEIGHT); int duration_upper_bound = INVALID_EDGE_WEIGHT);
@ -404,10 +404,10 @@ getNetworkDistance(const datafacade::ContiguousInternalMemoryDataFacade<ch::Algo
// Alias to be compatible with the overload for CoreCH that needs 4 heaps // Alias to be compatible with the overload for CoreCH that needs 4 heaps
inline double inline double
getNetworkDistance(const datafacade::ContiguousInternalMemoryDataFacade<ch::Algorithm> &facade, getNetworkDistance(const datafacade::ContiguousInternalMemoryDataFacade<ch::Algorithm> &facade,
SearchEngineData::QueryHeap &forward_heap, SearchEngineData<Algorithm>::QueryHeap &forward_heap,
SearchEngineData::QueryHeap &reverse_heap, SearchEngineData<Algorithm>::QueryHeap &reverse_heap,
SearchEngineData::QueryHeap &, SearchEngineData<Algorithm>::QueryHeap &,
SearchEngineData::QueryHeap &, SearchEngineData<Algorithm>::QueryHeap &,
const PhantomNode &source_phantom, const PhantomNode &source_phantom,
const PhantomNode &target_phantom, const PhantomNode &target_phantom,
int duration_upper_bound = INVALID_EDGE_WEIGHT) int duration_upper_bound = INVALID_EDGE_WEIGHT)
@ -429,10 +429,10 @@ namespace corech
// requires // requires
// a force loop, if the heaps have been initialized with positive offsets. // a force loop, if the heaps have been initialized with positive offsets.
void search(const datafacade::ContiguousInternalMemoryDataFacade<corech::Algorithm> &facade, void search(const datafacade::ContiguousInternalMemoryDataFacade<corech::Algorithm> &facade,
SearchEngineData::QueryHeap &forward_heap, SearchEngineData<Algorithm>::QueryHeap &forward_heap,
SearchEngineData::QueryHeap &reverse_heap, SearchEngineData<Algorithm>::QueryHeap &reverse_heap,
SearchEngineData::QueryHeap &forward_core_heap, SearchEngineData<Algorithm>::QueryHeap &forward_core_heap,
SearchEngineData::QueryHeap &reverse_core_heap, SearchEngineData<Algorithm>::QueryHeap &reverse_core_heap,
int &weight, int &weight,
std::vector<NodeID> &packed_leg, std::vector<NodeID> &packed_leg,
const bool force_loop_forward, const bool force_loop_forward,
@ -444,10 +444,10 @@ void search(const datafacade::ContiguousInternalMemoryDataFacade<corech::Algorit
// the addition of force_loop parameters might be required // the addition of force_loop parameters might be required
double double
getNetworkDistance(const datafacade::ContiguousInternalMemoryDataFacade<corech::Algorithm> &facade, getNetworkDistance(const datafacade::ContiguousInternalMemoryDataFacade<corech::Algorithm> &facade,
SearchEngineData::QueryHeap &forward_heap, SearchEngineData<Algorithm>::QueryHeap &forward_heap,
SearchEngineData::QueryHeap &reverse_heap, SearchEngineData<Algorithm>::QueryHeap &reverse_heap,
SearchEngineData::QueryHeap &forward_core_heap, SearchEngineData<Algorithm>::QueryHeap &forward_core_heap,
SearchEngineData::QueryHeap &reverse_core_heap, SearchEngineData<Algorithm>::QueryHeap &reverse_core_heap,
const PhantomNode &source_phantom, const PhantomNode &source_phantom,
const PhantomNode &target_phantom, const PhantomNode &target_phantom,
int duration_upper_bound = INVALID_EDGE_WEIGHT); int duration_upper_bound = INVALID_EDGE_WEIGHT);

View File

@ -58,8 +58,8 @@ bool checkParentCellRestriction(CellID cell, LevelID, CellID parent) { return ce
template <bool DIRECTION, typename... Args> template <bool DIRECTION, typename... Args>
void routingStep(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade, void routingStep(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
SearchEngineData::MultiLayerDijkstraHeap &forward_heap, SearchEngineData<Algorithm>::QueryHeap &forward_heap,
SearchEngineData::MultiLayerDijkstraHeap &reverse_heap, SearchEngineData<Algorithm>::QueryHeap &reverse_heap,
NodeID &middle_node, NodeID &middle_node,
EdgeWeight &path_upper_bound, EdgeWeight &path_upper_bound,
Args... args) Args... args)
@ -172,8 +172,8 @@ void routingStep(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm>
template <typename... Args> template <typename... Args>
std::tuple<EdgeWeight, NodeID, NodeID, std::vector<EdgeID>> std::tuple<EdgeWeight, NodeID, NodeID, std::vector<EdgeID>>
search(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade, search(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
SearchEngineData::MultiLayerDijkstraHeap &forward_heap, SearchEngineData<Algorithm>::QueryHeap &forward_heap,
SearchEngineData::MultiLayerDijkstraHeap &reverse_heap, SearchEngineData<Algorithm>::QueryHeap &reverse_heap,
Args... args) Args... args)
{ {

View File

@ -13,15 +13,10 @@ namespace engine
namespace routing_algorithms namespace routing_algorithms
{ {
template<typename Algorithm>
InternalRouteResult InternalRouteResult
shortestPathSearch(SearchEngineData &engine_working_data, shortestPathSearch(SearchEngineData<Algorithm> &engine_working_data,
const datafacade::ContiguousInternalMemoryDataFacade<ch::Algorithm> &facade, const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
const std::vector<PhantomNodes> &phantom_nodes_vector,
const boost::optional<bool> continue_straight_at_waypoint);
InternalRouteResult
shortestPathSearch(SearchEngineData &engine_working_data,
const datafacade::ContiguousInternalMemoryDataFacade<corech::Algorithm> &facade,
const std::vector<PhantomNodes> &phantom_nodes_vector, const std::vector<PhantomNodes> &phantom_nodes_vector,
const boost::optional<bool> continue_straight_at_waypoint); const boost::optional<bool> continue_straight_at_waypoint);

View File

@ -24,14 +24,7 @@ struct ManyToManyHeapData : HeapData
ManyToManyHeapData(NodeID p, EdgeWeight duration) : HeapData(p), duration(duration) {} ManyToManyHeapData(NodeID p, EdgeWeight duration) : HeapData(p), duration(duration) {}
}; };
struct MultiLayerDijkstraHeapData : HeapData template <typename Algorithm> struct SearchEngineData
{
bool from_clique_arc;
MultiLayerDijkstraHeapData(NodeID p) : HeapData(p), from_clique_arc(false) {}
MultiLayerDijkstraHeapData(NodeID p, bool from) : HeapData(p), from_clique_arc(from) {}
};
struct SearchEngineData
{ {
using QueryHeap = util:: using QueryHeap = util::
BinaryHeap<NodeID, NodeID, EdgeWeight, HeapData, util::UnorderedMapStorage<NodeID, int>>; BinaryHeap<NodeID, NodeID, EdgeWeight, HeapData, util::UnorderedMapStorage<NodeID, int>>;
@ -45,58 +38,45 @@ struct SearchEngineData
using ManyToManyHeapPtr = boost::thread_specific_ptr<ManyToManyQueryHeap>; using ManyToManyHeapPtr = boost::thread_specific_ptr<ManyToManyQueryHeap>;
using MultiLayerDijkstraHeap = util::BinaryHeap<NodeID,
NodeID,
EdgeWeight,
MultiLayerDijkstraHeapData,
util::UnorderedMapStorage<NodeID, int>>;
using MultiLayerDijkstraHeapPtr = boost::thread_specific_ptr<MultiLayerDijkstraHeap>;
private:
static SearchEngineHeapPtr forward_heap_1; static SearchEngineHeapPtr forward_heap_1;
static SearchEngineHeapPtr reverse_heap_1; static SearchEngineHeapPtr reverse_heap_1;
static MultiLayerDijkstraHeapPtr mld_forward_heap;
static MultiLayerDijkstraHeapPtr mld_reverse_heap;
public:
static SearchEngineHeapPtr forward_heap_2; static SearchEngineHeapPtr forward_heap_2;
static SearchEngineHeapPtr reverse_heap_2; static SearchEngineHeapPtr reverse_heap_2;
static SearchEngineHeapPtr forward_heap_3; static SearchEngineHeapPtr forward_heap_3;
static SearchEngineHeapPtr reverse_heap_3; static SearchEngineHeapPtr reverse_heap_3;
static ManyToManyHeapPtr many_to_many_heap; static ManyToManyHeapPtr many_to_many_heap;
template <typename Algorithm> void InitializeOrClearFirstThreadLocalStorage(unsigned number_of_nodes);
void InitializeOrClearFirstThreadLocalStorage(Algorithm, const unsigned number_of_nodes);
template <typename Algorithm> auto GetForwardHeapPtr(Algorithm) const void InitializeOrClearSecondThreadLocalStorage(unsigned number_of_nodes);
void InitializeOrClearThirdThreadLocalStorage(unsigned number_of_nodes);
void InitializeOrClearManyToManyThreadLocalStorage(unsigned number_of_nodes);
};
struct MultiLayerDijkstraHeapData
{ {
return forward_heap_1.get(); NodeID parent;
} bool from_clique_arc;
MultiLayerDijkstraHeapData(NodeID p) : parent(p), from_clique_arc(false) {}
MultiLayerDijkstraHeapData(NodeID p, bool from) : parent(p), from_clique_arc(from) {}
};
template <typename Algorithm> auto GetReverseHeapPtr(Algorithm) const template <> struct SearchEngineData<routing_algorithms::mld::Algorithm>
{ {
return reverse_heap_1.get(); using QueryHeap = util::BinaryHeap<NodeID,
} NodeID,
EdgeWeight,
MultiLayerDijkstraHeapData,
util::UnorderedMapStorage<NodeID, int>>;
void InitializeOrClearFirstThreadLocalStorage(routing_algorithms::mld::Algorithm, using SearchEngineHeapPtr = boost::thread_specific_ptr<QueryHeap>;
const unsigned number_of_nodes);
auto GetForwardHeapPtr(routing_algorithms::mld::Algorithm) const static SearchEngineHeapPtr forward_heap_1;
{ static SearchEngineHeapPtr reverse_heap_1;
return mld_forward_heap.get();
}
auto GetReverseHeapPtr(routing_algorithms::mld::Algorithm) const void InitializeOrClearFirstThreadLocalStorage(unsigned number_of_nodes);
{
return mld_reverse_heap.get();
}
void InitializeOrClearSecondThreadLocalStorage(const unsigned number_of_nodes);
void InitializeOrClearThirdThreadLocalStorage(const unsigned number_of_nodes);
void InitializeOrClearManyToManyThreadLocalStorage(const unsigned number_of_nodes);
}; };
} }
} }

View File

@ -28,7 +28,7 @@ const double constexpr VIAPATH_ALPHA = 0.10;
const double constexpr VIAPATH_EPSILON = 0.15; // alternative at most 15% longer const double constexpr VIAPATH_EPSILON = 0.15; // alternative at most 15% longer
const double constexpr VIAPATH_GAMMA = 0.75; // alternative shares at most 75% with the shortest. const double constexpr VIAPATH_GAMMA = 0.75; // alternative shares at most 75% with the shortest.
using QueryHeap = SearchEngineData::QueryHeap; using QueryHeap = SearchEngineData<Algorithm>::QueryHeap;
using SearchSpaceEdge = std::pair<NodeID, NodeID>; using SearchSpaceEdge = std::pair<NodeID, NodeID>;
struct RankedCandidateNode struct RankedCandidateNode
@ -154,7 +154,7 @@ void retrievePackedAlternatePath(const QueryHeap &forward_heap1,
// from v and intersecting against queues. only half-searches have to be // from v and intersecting against queues. only half-searches have to be
// done at this stage // done at this stage
void computeLengthAndSharingOfViaPath( void computeLengthAndSharingOfViaPath(
SearchEngineData &engine_working_data, SearchEngineData<Algorithm> &engine_working_data,
const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade, const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
const NodeID via_node, const NodeID via_node,
int *real_length_of_via_path, int *real_length_of_via_path,
@ -164,10 +164,10 @@ void computeLengthAndSharingOfViaPath(
{ {
engine_working_data.InitializeOrClearSecondThreadLocalStorage(facade.GetNumberOfNodes()); engine_working_data.InitializeOrClearSecondThreadLocalStorage(facade.GetNumberOfNodes());
auto &existing_forward_heap = *engine_working_data.GetForwardHeapPtr(Algorithm{}); auto &existing_forward_heap = *engine_working_data.forward_heap_1;
auto &existing_reverse_heap = *engine_working_data.GetReverseHeapPtr(Algorithm{}); auto &existing_reverse_heap = *engine_working_data.reverse_heap_1;
QueryHeap &new_forward_heap = *engine_working_data.forward_heap_2; auto &new_forward_heap = *engine_working_data.forward_heap_2;
QueryHeap &new_reverse_heap = *engine_working_data.reverse_heap_2; auto &new_reverse_heap = *engine_working_data.reverse_heap_2;
std::vector<NodeID> packed_s_v_path; std::vector<NodeID> packed_s_v_path;
std::vector<NodeID> packed_v_t_path; std::vector<NodeID> packed_v_t_path;
@ -319,7 +319,7 @@ void computeLengthAndSharingOfViaPath(
// conduct T-Test // conduct T-Test
bool viaNodeCandidatePassesTTest( bool viaNodeCandidatePassesTTest(
SearchEngineData &engine_working_data, SearchEngineData<Algorithm> &engine_working_data,
const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade, const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
QueryHeap &existing_forward_heap, QueryHeap &existing_forward_heap,
QueryHeap &existing_reverse_heap, QueryHeap &existing_reverse_heap,
@ -563,7 +563,7 @@ bool viaNodeCandidatePassesTTest(
} }
InternalRouteResult InternalRouteResult
alternativePathSearch(SearchEngineData &engine_working_data, alternativePathSearch(SearchEngineData<Algorithm> &engine_working_data,
const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade, const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
const PhantomNodes &phantom_node_pair) const PhantomNodes &phantom_node_pair)
{ {
@ -575,15 +575,14 @@ alternativePathSearch(SearchEngineData &engine_working_data,
std::vector<SearchSpaceEdge> reverse_search_space; std::vector<SearchSpaceEdge> reverse_search_space;
// Init queues, semi-expensive because access to TSS invokes a sys-call // Init queues, semi-expensive because access to TSS invokes a sys-call
engine_working_data.InitializeOrClearFirstThreadLocalStorage(Algorithm{}, engine_working_data.InitializeOrClearFirstThreadLocalStorage(facade.GetNumberOfNodes());
facade.GetNumberOfNodes());
engine_working_data.InitializeOrClearSecondThreadLocalStorage(facade.GetNumberOfNodes()); engine_working_data.InitializeOrClearSecondThreadLocalStorage(facade.GetNumberOfNodes());
engine_working_data.InitializeOrClearThirdThreadLocalStorage(facade.GetNumberOfNodes()); engine_working_data.InitializeOrClearThirdThreadLocalStorage(facade.GetNumberOfNodes());
auto &forward_heap1 = *engine_working_data.GetForwardHeapPtr(Algorithm{}); auto &forward_heap1 = *engine_working_data.forward_heap_1;
auto &reverse_heap1 = *engine_working_data.GetReverseHeapPtr(Algorithm{}); auto &reverse_heap1 = *engine_working_data.reverse_heap_1;
QueryHeap &forward_heap2 = *(engine_working_data.forward_heap_2); auto &forward_heap2 = *engine_working_data.forward_heap_2;
QueryHeap &reverse_heap2 = *(engine_working_data.reverse_heap_2); auto &reverse_heap2 = *engine_working_data.reverse_heap_2;
EdgeWeight upper_bound_to_shortest_path_weight = INVALID_EDGE_WEIGHT; EdgeWeight upper_bound_to_shortest_path_weight = INVALID_EDGE_WEIGHT;
NodeID middle_node = SPECIAL_NODEID; NodeID middle_node = SPECIAL_NODEID;

View File

@ -47,7 +47,7 @@ extractRoute(const datafacade::ContiguousInternalMemoryDataFacade<AlgorithmT> &f
return raw_route_data; return raw_route_data;
} }
namespace ch namespace detail
{ {
/// 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
@ -57,17 +57,16 @@ namespace ch
/// not fully contracted graphs. /// not fully contracted graphs.
template <typename Algorithm> template <typename Algorithm>
InternalRouteResult directShortestPathSearchImpl( InternalRouteResult directShortestPathSearchImpl(
SearchEngineData &engine_working_data, SearchEngineData<Algorithm> &engine_working_data,
const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade, const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
const PhantomNodes &phantom_nodes) const PhantomNodes &phantom_nodes)
{ {
engine_working_data.InitializeOrClearFirstThreadLocalStorage(Algorithm{}, engine_working_data.InitializeOrClearFirstThreadLocalStorage(facade.GetNumberOfNodes());
facade.GetNumberOfNodes());
engine_working_data.InitializeOrClearSecondThreadLocalStorage(facade.GetNumberOfNodes()); engine_working_data.InitializeOrClearSecondThreadLocalStorage(facade.GetNumberOfNodes());
auto &forward_heap = *engine_working_data.GetForwardHeapPtr(Algorithm{}); auto &forward_heap = *engine_working_data.forward_heap_1;
auto &reverse_heap = *engine_working_data.GetReverseHeapPtr(Algorithm{}); auto &reverse_heap = *engine_working_data.reverse_heap_1;
auto &forward_core_heap = *(engine_working_data.forward_heap_2); auto &forward_core_heap = *engine_working_data.forward_heap_2;
auto &reverse_core_heap = *(engine_working_data.reverse_heap_2); auto &reverse_core_heap = *engine_working_data.reverse_heap_2;
forward_heap.Clear(); forward_heap.Clear();
reverse_heap.Clear(); reverse_heap.Clear();
forward_core_heap.Clear(); forward_core_heap.Clear();
@ -94,7 +93,7 @@ InternalRouteResult directShortestPathSearchImpl(
source_node = packed_leg.front(); source_node = packed_leg.front();
target_node = packed_leg.back(); target_node = packed_leg.back();
unpacked_edges.reserve(packed_leg.size()); unpacked_edges.reserve(packed_leg.size());
unpackPath( ch::unpackPath(
facade, facade,
packed_leg.begin(), packed_leg.begin(),
packed_leg.end(), packed_leg.end(),
@ -109,34 +108,30 @@ InternalRouteResult directShortestPathSearchImpl(
template <> template <>
InternalRouteResult directShortestPathSearch( InternalRouteResult directShortestPathSearch(
SearchEngineData &engine_working_data, SearchEngineData<corech::Algorithm> &engine_working_data,
const datafacade::ContiguousInternalMemoryDataFacade<corech::Algorithm> &facade, const datafacade::ContiguousInternalMemoryDataFacade<corech::Algorithm> &facade,
const PhantomNodes &phantom_nodes) const PhantomNodes &phantom_nodes)
{ {
return ch::directShortestPathSearchImpl(engine_working_data, facade, phantom_nodes); return detail::directShortestPathSearchImpl(engine_working_data, facade, phantom_nodes);
} }
template <> template <>
InternalRouteResult directShortestPathSearch( InternalRouteResult directShortestPathSearch(
SearchEngineData &engine_working_data, SearchEngineData<ch::Algorithm> &engine_working_data,
const datafacade::ContiguousInternalMemoryDataFacade<ch::Algorithm> &facade, const datafacade::ContiguousInternalMemoryDataFacade<ch::Algorithm> &facade,
const PhantomNodes &phantom_nodes) const PhantomNodes &phantom_nodes)
{ {
return ch::directShortestPathSearchImpl(engine_working_data, facade, phantom_nodes); return detail::directShortestPathSearchImpl(engine_working_data, facade, phantom_nodes);
} }
template <>
InternalRouteResult directShortestPathSearch( InternalRouteResult directShortestPathSearch(
SearchEngineData &engine_working_data, SearchEngineData<mld::Algorithm> &engine_working_data,
const datafacade::ContiguousInternalMemoryDataFacade<mld::Algorithm> &facade, const datafacade::ContiguousInternalMemoryDataFacade<mld::Algorithm> &facade,
const PhantomNodes &phantom_nodes) const PhantomNodes &phantom_nodes)
{ {
engine_working_data.InitializeOrClearFirstThreadLocalStorage(mld::Algorithm{}, engine_working_data.InitializeOrClearFirstThreadLocalStorage(facade.GetNumberOfNodes());
facade.GetNumberOfNodes()); auto &forward_heap = *engine_working_data.forward_heap_1;
auto &forward_heap = *engine_working_data.GetForwardHeapPtr(mld::Algorithm{}); auto &reverse_heap = *engine_working_data.reverse_heap_1;
auto &reverse_heap = *engine_working_data.GetReverseHeapPtr(mld::Algorithm{});
forward_heap.Clear();
reverse_heap.Clear();
insertNodesInHeaps(forward_heap, reverse_heap, phantom_nodes); insertNodesInHeaps(forward_heap, reverse_heap, phantom_nodes);
// TODO: when structured bindings will be allowed change to // TODO: when structured bindings will be allowed change to

View File

@ -15,11 +15,11 @@ namespace engine
namespace routing_algorithms namespace routing_algorithms
{ {
using ManyToManyQueryHeap = SearchEngineData::ManyToManyQueryHeap;
namespace ch namespace ch
{ {
using ManyToManyQueryHeap = SearchEngineData<Algorithm>::ManyToManyQueryHeap;
namespace namespace
{ {
struct NodeBucket struct NodeBucket
@ -151,7 +151,7 @@ void backwardRoutingStep(const datafacade::ContiguousInternalMemoryDataFacade<Al
} }
std::vector<EdgeWeight> std::vector<EdgeWeight>
manyToManySearch(SearchEngineData &engine_working_data, manyToManySearch(SearchEngineData<Algorithm> &engine_working_data,
const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade, const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
const std::vector<PhantomNode> &phantom_nodes, const std::vector<PhantomNode> &phantom_nodes,
const std::vector<std::size_t> &source_indices, const std::vector<std::size_t> &source_indices,

View File

@ -49,7 +49,7 @@ unsigned getMedianSampleTime(const std::vector<unsigned> &timestamps)
template <typename Algorithm> template <typename Algorithm>
SubMatchingList SubMatchingList
mapMatchingImpl(SearchEngineData &engine_working_data, mapMatchingImpl(SearchEngineData<Algorithm> &engine_working_data,
const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade, const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
const CandidateLists &candidates_list, const CandidateLists &candidates_list,
const std::vector<util::Coordinate> &trace_coordinates, const std::vector<util::Coordinate> &trace_coordinates,
@ -142,13 +142,13 @@ mapMatchingImpl(SearchEngineData &engine_working_data,
} }
const auto nodes_number = facade.GetNumberOfNodes(); const auto nodes_number = facade.GetNumberOfNodes();
engine_working_data.InitializeOrClearFirstThreadLocalStorage(Algorithm{}, nodes_number); engine_working_data.InitializeOrClearFirstThreadLocalStorage(nodes_number);
engine_working_data.InitializeOrClearSecondThreadLocalStorage(nodes_number); engine_working_data.InitializeOrClearSecondThreadLocalStorage(nodes_number);
auto &forward_heap = *engine_working_data.GetForwardHeapPtr(Algorithm{}); auto &forward_heap = *engine_working_data.forward_heap_1;
auto &reverse_heap = *engine_working_data.GetReverseHeapPtr(Algorithm{}); auto &reverse_heap = *engine_working_data.reverse_heap_1;
auto &forward_core_heap = *(engine_working_data.forward_heap_2); auto &forward_core_heap = *engine_working_data.forward_heap_2;
auto &reverse_core_heap = *(engine_working_data.reverse_heap_2); auto &reverse_core_heap = *engine_working_data.reverse_heap_2;
std::size_t breakage_begin = map_matching::INVALID_STATE; std::size_t breakage_begin = map_matching::INVALID_STATE;
std::vector<std::size_t> split_points; std::vector<std::size_t> split_points;
@ -420,10 +420,9 @@ mapMatchingImpl(SearchEngineData &engine_working_data,
return sub_matchings; return sub_matchings;
} }
namespace ch template<>
{ SubMatchingList mapMatching(SearchEngineData<ch::Algorithm> &engine_working_data,
SubMatchingList mapMatching(SearchEngineData &engine_working_data, const datafacade::ContiguousInternalMemoryDataFacade<ch::Algorithm> &facade,
const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
const CandidateLists &candidates_list, const CandidateLists &candidates_list,
const std::vector<util::Coordinate> &trace_coordinates, const std::vector<util::Coordinate> &trace_coordinates,
const std::vector<unsigned> &trace_timestamps, const std::vector<unsigned> &trace_timestamps,
@ -438,12 +437,10 @@ SubMatchingList mapMatching(SearchEngineData &engine_working_data,
trace_gps_precision, trace_gps_precision,
use_tidying); use_tidying);
} }
}
namespace corech template<>
{ SubMatchingList mapMatching(SearchEngineData<corech::Algorithm> &engine_working_data,
SubMatchingList mapMatching(SearchEngineData &engine_working_data, const datafacade::ContiguousInternalMemoryDataFacade<corech::Algorithm> &facade,
const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
const CandidateLists &candidates_list, const CandidateLists &candidates_list,
const std::vector<util::Coordinate> &trace_coordinates, const std::vector<util::Coordinate> &trace_coordinates,
const std::vector<unsigned> &trace_timestamps, const std::vector<unsigned> &trace_timestamps,
@ -459,7 +456,6 @@ SubMatchingList mapMatching(SearchEngineData &engine_working_data,
trace_gps_precision, trace_gps_precision,
use_tidying); use_tidying);
} }
}
} // namespace routing_algorithms } // namespace routing_algorithms
} // namespace engine } // namespace engine

View File

@ -31,8 +31,8 @@ void unpackEdge(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm>
unpacked_path.emplace_back(to); unpacked_path.emplace_back(to);
} }
void retrievePackedPathFromHeap(const SearchEngineData::QueryHeap &forward_heap, void retrievePackedPathFromHeap(const SearchEngineData<Algorithm>::QueryHeap &forward_heap,
const SearchEngineData::QueryHeap &reverse_heap, const SearchEngineData<Algorithm>::QueryHeap &reverse_heap,
const NodeID middle_node_id, const NodeID middle_node_id,
std::vector<NodeID> &packed_path) std::vector<NodeID> &packed_path)
{ {
@ -42,7 +42,7 @@ void retrievePackedPathFromHeap(const SearchEngineData::QueryHeap &forward_heap,
retrievePackedPathFromSingleHeap(reverse_heap, middle_node_id, packed_path); retrievePackedPathFromSingleHeap(reverse_heap, middle_node_id, packed_path);
} }
void retrievePackedPathFromSingleHeap(const SearchEngineData::QueryHeap &search_heap, void retrievePackedPathFromSingleHeap(const SearchEngineData<Algorithm>::QueryHeap &search_heap,
const NodeID middle_node_id, const NodeID middle_node_id,
std::vector<NodeID> &packed_path) std::vector<NodeID> &packed_path)
{ {
@ -72,8 +72,8 @@ void retrievePackedPathFromSingleHeap(const SearchEngineData::QueryHeap &search_
// requires // requires
// a force loop, if the heaps have been initialized with positive offsets. // a force loop, if the heaps have been initialized with positive offsets.
void search(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade, void search(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
SearchEngineData::QueryHeap &forward_heap, SearchEngineData<Algorithm>::QueryHeap &forward_heap,
SearchEngineData::QueryHeap &reverse_heap, SearchEngineData<Algorithm>::QueryHeap &reverse_heap,
EdgeWeight &weight, EdgeWeight &weight,
std::vector<NodeID> &packed_leg, std::vector<NodeID> &packed_leg,
const bool force_loop_forward, const bool force_loop_forward,
@ -215,8 +215,8 @@ double getPathDistance(const datafacade::ContiguousInternalMemoryDataFacade<Algo
// If heaps should be adjusted to be initialized outside of this function, // If heaps should be adjusted to be initialized outside of this function,
// the addition of force_loop parameters might be required // the addition of force_loop parameters might be required
double getNetworkDistance(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade, double getNetworkDistance(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
SearchEngineData::QueryHeap &forward_heap, SearchEngineData<Algorithm>::QueryHeap &forward_heap,
SearchEngineData::QueryHeap &reverse_heap, SearchEngineData<Algorithm>::QueryHeap &reverse_heap,
const PhantomNode &source_phantom, const PhantomNode &source_phantom,
const PhantomNode &target_phantom, const PhantomNode &target_phantom,
EdgeWeight weight_upper_bound) EdgeWeight weight_upper_bound)
@ -282,10 +282,10 @@ namespace corech
// requires // requires
// a force loop, if the heaps have been initialized with positive offsets. // a force loop, if the heaps have been initialized with positive offsets.
void search(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade, void search(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
SearchEngineData::QueryHeap &forward_heap, SearchEngineData<ch::Algorithm>::QueryHeap &forward_heap,
SearchEngineData::QueryHeap &reverse_heap, SearchEngineData<ch::Algorithm>::QueryHeap &reverse_heap,
SearchEngineData::QueryHeap &forward_core_heap, SearchEngineData<ch::Algorithm>::QueryHeap &forward_core_heap,
SearchEngineData::QueryHeap &reverse_core_heap, SearchEngineData<ch::Algorithm>::QueryHeap &reverse_core_heap,
EdgeWeight &weight, EdgeWeight &weight,
std::vector<NodeID> &packed_leg, std::vector<NodeID> &packed_leg,
const bool force_loop_forward, const bool force_loop_forward,
@ -350,7 +350,7 @@ void search(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &fac
} }
const auto insertInCoreHeap = [](const CoreEntryPoint &p, const auto insertInCoreHeap = [](const CoreEntryPoint &p,
SearchEngineData::QueryHeap &core_heap) { SearchEngineData<ch::Algorithm>::QueryHeap &core_heap) {
NodeID id; NodeID id;
EdgeWeight weight; EdgeWeight weight;
NodeID parent; NodeID parent;
@ -460,10 +460,10 @@ void search(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &fac
// If heaps should be adjusted to be initialized outside of this function, // If heaps should be adjusted to be initialized outside of this function,
// the addition of force_loop parameters might be required // the addition of force_loop parameters might be required
double getNetworkDistance(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade, double getNetworkDistance(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
SearchEngineData::QueryHeap &forward_heap, SearchEngineData<ch::Algorithm>::QueryHeap &forward_heap,
SearchEngineData::QueryHeap &reverse_heap, SearchEngineData<ch::Algorithm>::QueryHeap &reverse_heap,
SearchEngineData::QueryHeap &forward_core_heap, SearchEngineData<ch::Algorithm>::QueryHeap &forward_core_heap,
SearchEngineData::QueryHeap &reverse_core_heap, SearchEngineData<ch::Algorithm>::QueryHeap &reverse_core_heap,
const PhantomNode &source_phantom, const PhantomNode &source_phantom,
const PhantomNode &target_phantom, const PhantomNode &target_phantom,
EdgeWeight weight_upper_bound) EdgeWeight weight_upper_bound)

View File

@ -16,7 +16,7 @@ namespace
{ {
const static constexpr bool DO_NOT_FORCE_LOOP = false; const static constexpr bool DO_NOT_FORCE_LOOP = false;
using QueryHeap = SearchEngineData::QueryHeap; using QueryHeap = SearchEngineData<ch::Algorithm>::QueryHeap;
// allows a uturn at the target_phantom // allows a uturn at the target_phantom
// searches source forward/reverse -> target forward/reverse // searches source forward/reverse -> target forward/reverse
@ -230,7 +230,7 @@ void unpackLegs(const datafacade::ContiguousInternalMemoryDataFacade<ch::Algorit
template <typename Algorithm> template <typename Algorithm>
InternalRouteResult InternalRouteResult
shortestPathSearchImpl(SearchEngineData &engine_working_data, shortestPathSearchImpl(SearchEngineData<Algorithm> &engine_working_data,
const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade, const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
const std::vector<PhantomNodes> &phantom_nodes_vector, const std::vector<PhantomNodes> &phantom_nodes_vector,
const boost::optional<bool> continue_straight_at_waypoint) const boost::optional<bool> continue_straight_at_waypoint)
@ -241,14 +241,13 @@ shortestPathSearchImpl(SearchEngineData &engine_working_data,
!(continue_straight_at_waypoint ? *continue_straight_at_waypoint !(continue_straight_at_waypoint ? *continue_straight_at_waypoint
: facade.GetContinueStraightDefault()); : facade.GetContinueStraightDefault());
engine_working_data.InitializeOrClearFirstThreadLocalStorage(Algorithm{}, engine_working_data.InitializeOrClearFirstThreadLocalStorage(facade.GetNumberOfNodes());
facade.GetNumberOfNodes());
engine_working_data.InitializeOrClearSecondThreadLocalStorage(facade.GetNumberOfNodes()); engine_working_data.InitializeOrClearSecondThreadLocalStorage(facade.GetNumberOfNodes());
auto &forward_heap = *engine_working_data.GetForwardHeapPtr(Algorithm{}); auto &forward_heap = *engine_working_data.forward_heap_1;
auto &reverse_heap = *engine_working_data.GetReverseHeapPtr(Algorithm{}); auto &reverse_heap = *engine_working_data.reverse_heap_1;
QueryHeap &forward_core_heap = *(engine_working_data.forward_heap_2); auto &forward_core_heap = *engine_working_data.forward_heap_2;
QueryHeap &reverse_core_heap = *(engine_working_data.reverse_heap_2); auto &reverse_core_heap = *engine_working_data.reverse_heap_2;
int total_weight_to_forward = 0; int total_weight_to_forward = 0;
int total_weight_to_reverse = 0; int total_weight_to_reverse = 0;
@ -485,8 +484,9 @@ shortestPathSearchImpl(SearchEngineData &engine_working_data,
} }
} }
template<>
InternalRouteResult InternalRouteResult
shortestPathSearch(SearchEngineData &engine_working_data, shortestPathSearch(SearchEngineData<ch::Algorithm> &engine_working_data,
const datafacade::ContiguousInternalMemoryDataFacade<ch::Algorithm> &facade, const datafacade::ContiguousInternalMemoryDataFacade<ch::Algorithm> &facade,
const std::vector<PhantomNodes> &phantom_nodes_vector, const std::vector<PhantomNodes> &phantom_nodes_vector,
const boost::optional<bool> continue_straight_at_waypoint) const boost::optional<bool> continue_straight_at_waypoint)
@ -495,8 +495,9 @@ shortestPathSearch(SearchEngineData &engine_working_data,
engine_working_data, facade, phantom_nodes_vector, continue_straight_at_waypoint); engine_working_data, facade, phantom_nodes_vector, continue_straight_at_waypoint);
} }
template<>
InternalRouteResult InternalRouteResult
shortestPathSearch(SearchEngineData &engine_working_data, shortestPathSearch(SearchEngineData<corech::Algorithm> &engine_working_data,
const datafacade::ContiguousInternalMemoryDataFacade<corech::Algorithm> &facade, const datafacade::ContiguousInternalMemoryDataFacade<corech::Algorithm> &facade,
const std::vector<PhantomNodes> &phantom_nodes_vector, const std::vector<PhantomNodes> &phantom_nodes_vector,
const boost::optional<bool> continue_straight_at_waypoint) const boost::optional<bool> continue_straight_at_waypoint)

View File

@ -7,20 +7,16 @@ namespace osrm
namespace engine namespace engine
{ {
SearchEngineData::SearchEngineHeapPtr SearchEngineData::forward_heap_1; template<typename Algorithm> typename SearchEngineData<Algorithm>::SearchEngineHeapPtr SearchEngineData<Algorithm>::forward_heap_1;
SearchEngineData::SearchEngineHeapPtr SearchEngineData::reverse_heap_1; template<typename Algorithm> typename SearchEngineData<Algorithm>::SearchEngineHeapPtr SearchEngineData<Algorithm>::reverse_heap_1;
SearchEngineData::SearchEngineHeapPtr SearchEngineData::forward_heap_2; template<typename Algorithm> typename SearchEngineData<Algorithm>::SearchEngineHeapPtr SearchEngineData<Algorithm>::forward_heap_2;
SearchEngineData::SearchEngineHeapPtr SearchEngineData::reverse_heap_2; template<typename Algorithm> typename SearchEngineData<Algorithm>::SearchEngineHeapPtr SearchEngineData<Algorithm>::reverse_heap_2;
SearchEngineData::SearchEngineHeapPtr SearchEngineData::forward_heap_3; template<typename Algorithm> typename SearchEngineData<Algorithm>::SearchEngineHeapPtr SearchEngineData<Algorithm>::forward_heap_3;
SearchEngineData::SearchEngineHeapPtr SearchEngineData::reverse_heap_3; template<typename Algorithm> typename SearchEngineData<Algorithm>::SearchEngineHeapPtr SearchEngineData<Algorithm>::reverse_heap_3;
SearchEngineData::ManyToManyHeapPtr SearchEngineData::many_to_many_heap; template<typename Algorithm> typename SearchEngineData<Algorithm>::ManyToManyHeapPtr SearchEngineData<Algorithm>::many_to_many_heap;
SearchEngineData::MultiLayerDijkstraHeapPtr SearchEngineData::mld_forward_heap;
SearchEngineData::MultiLayerDijkstraHeapPtr SearchEngineData::mld_reverse_heap;
template <typename Algorithm> template <typename Algorithm>
void SearchEngineData::InitializeOrClearFirstThreadLocalStorage(Algorithm, void SearchEngineData<Algorithm>::InitializeOrClearFirstThreadLocalStorage(unsigned number_of_nodes)
const unsigned number_of_nodes)
{ {
if (forward_heap_1.get()) if (forward_heap_1.get())
{ {
@ -41,36 +37,9 @@ void SearchEngineData::InitializeOrClearFirstThreadLocalStorage(Algorithm,
} }
} }
template void template <typename Algorithm>
SearchEngineData::InitializeOrClearFirstThreadLocalStorage(routing_algorithms::ch::Algorithm, void SearchEngineData<Algorithm>::InitializeOrClearSecondThreadLocalStorage(
const unsigned number_of_nodes); unsigned number_of_nodes)
template void
SearchEngineData::InitializeOrClearFirstThreadLocalStorage(routing_algorithms::corech::Algorithm,
const unsigned number_of_nodes);
void SearchEngineData::InitializeOrClearFirstThreadLocalStorage(routing_algorithms::mld::Algorithm,
const unsigned number_of_nodes)
{
if (mld_forward_heap.get())
{
mld_forward_heap->Clear();
}
else
{
mld_forward_heap.reset(new MultiLayerDijkstraHeap(number_of_nodes));
}
if (mld_reverse_heap.get())
{
mld_reverse_heap->Clear();
}
else
{
mld_reverse_heap.reset(new MultiLayerDijkstraHeap(number_of_nodes));
}
}
void SearchEngineData::InitializeOrClearSecondThreadLocalStorage(const unsigned number_of_nodes)
{ {
if (forward_heap_2.get()) if (forward_heap_2.get())
{ {
@ -91,7 +60,8 @@ void SearchEngineData::InitializeOrClearSecondThreadLocalStorage(const unsigned
} }
} }
void SearchEngineData::InitializeOrClearThirdThreadLocalStorage(const unsigned number_of_nodes) template <typename Algorithm>
void SearchEngineData<Algorithm>::InitializeOrClearThirdThreadLocalStorage(unsigned number_of_nodes)
{ {
if (forward_heap_3.get()) if (forward_heap_3.get())
{ {
@ -112,7 +82,9 @@ void SearchEngineData::InitializeOrClearThirdThreadLocalStorage(const unsigned n
} }
} }
void SearchEngineData::InitializeOrClearManyToManyThreadLocalStorage(const unsigned number_of_nodes) template <typename Algorithm>
void SearchEngineData<Algorithm>::InitializeOrClearManyToManyThreadLocalStorage(
unsigned number_of_nodes)
{ {
if (many_to_many_heap.get()) if (many_to_many_heap.get())
{ {
@ -123,5 +95,77 @@ void SearchEngineData::InitializeOrClearManyToManyThreadLocalStorage(const unsig
many_to_many_heap.reset(new ManyToManyQueryHeap(number_of_nodes)); many_to_many_heap.reset(new ManyToManyQueryHeap(number_of_nodes));
} }
} }
// CH
using CH = routing_algorithms::ch::Algorithm;
template SearchEngineData<CH>::SearchEngineHeapPtr SearchEngineData<CH>::forward_heap_1;
template SearchEngineData<CH>::SearchEngineHeapPtr SearchEngineData<CH>::reverse_heap_1;
template SearchEngineData<CH>::SearchEngineHeapPtr SearchEngineData<CH>::forward_heap_2;
template SearchEngineData<CH>::SearchEngineHeapPtr SearchEngineData<CH>::reverse_heap_2;
template SearchEngineData<CH>::SearchEngineHeapPtr SearchEngineData<CH>::forward_heap_3;
template SearchEngineData<CH>::SearchEngineHeapPtr SearchEngineData<CH>::reverse_heap_3;
template SearchEngineData<CH>::ManyToManyHeapPtr SearchEngineData<CH>::many_to_many_heap;
template
void SearchEngineData<routing_algorithms::ch::Algorithm>::InitializeOrClearFirstThreadLocalStorage(unsigned number_of_nodes);
template
void SearchEngineData<CH>::InitializeOrClearSecondThreadLocalStorage(unsigned number_of_nodes);
template
void SearchEngineData<CH>::InitializeOrClearThirdThreadLocalStorage(unsigned number_of_nodes);
template
void SearchEngineData<CH>::InitializeOrClearManyToManyThreadLocalStorage(unsigned number_of_nodes);
// CoreCH
using CoreCH = routing_algorithms::corech::Algorithm;
template SearchEngineData<CoreCH>::SearchEngineHeapPtr SearchEngineData<CoreCH>::forward_heap_1;
template SearchEngineData<CoreCH>::SearchEngineHeapPtr SearchEngineData<CoreCH>::reverse_heap_1;
template SearchEngineData<CoreCH>::SearchEngineHeapPtr SearchEngineData<CoreCH>::forward_heap_2;
template SearchEngineData<CoreCH>::SearchEngineHeapPtr SearchEngineData<CoreCH>::reverse_heap_2;
template SearchEngineData<CoreCH>::SearchEngineHeapPtr SearchEngineData<CoreCH>::forward_heap_3;
template SearchEngineData<CoreCH>::SearchEngineHeapPtr SearchEngineData<CoreCH>::reverse_heap_3;
template SearchEngineData<CoreCH>::ManyToManyHeapPtr SearchEngineData<CoreCH>::many_to_many_heap;
template
void SearchEngineData<CoreCH>::InitializeOrClearFirstThreadLocalStorage(unsigned number_of_nodes);
template
void SearchEngineData<CoreCH>::InitializeOrClearSecondThreadLocalStorage(unsigned number_of_nodes);
template
void SearchEngineData<CoreCH>::InitializeOrClearThirdThreadLocalStorage(unsigned number_of_nodes);
template
void SearchEngineData<CoreCH>::InitializeOrClearManyToManyThreadLocalStorage(
unsigned number_of_nodes);
// MLD
using MLD = routing_algorithms::mld::Algorithm;
SearchEngineData<MLD>::SearchEngineHeapPtr SearchEngineData<MLD>::forward_heap_1;
SearchEngineData<MLD>::SearchEngineHeapPtr SearchEngineData<MLD>::reverse_heap_1;
void SearchEngineData<MLD>::InitializeOrClearFirstThreadLocalStorage(unsigned number_of_nodes)
{
if (forward_heap_1.get())
{
forward_heap_1->Clear();
}
else
{
forward_heap_1.reset(new QueryHeap(number_of_nodes));
}
if (reverse_heap_1.get())
{
reverse_heap_1->Clear();
}
else
{
reverse_heap_1.reset(new QueryHeap(number_of_nodes));
}
}
} }
} }