From 6f3b289bd1b39db5df99acc460cf9f99c00c4e2d Mon Sep 17 00:00:00 2001 From: Lev Dragunov Date: Mon, 18 May 2015 19:33:06 +0300 Subject: [PATCH] OSRM engine processing routines extraction --- generator/routing_generator.cpp | 18 ++-- routing/osrm_engine.cpp | 119 +++++++++++++++++++++++ routing/osrm_engine.hpp | 95 ++++++++++++++++++ routing/osrm_router.cpp | 166 ++++++++------------------------ routing/osrm_router.hpp | 61 +++--------- routing/routing.pro | 2 + routing/turns_generator.hpp | 1 + 7 files changed, 278 insertions(+), 184 deletions(-) create mode 100644 routing/osrm_engine.cpp create mode 100644 routing/osrm_engine.hpp diff --git a/generator/routing_generator.cpp b/generator/routing_generator.cpp index 188ea3dffe..aead7685d7 100644 --- a/generator/routing_generator.cpp +++ b/generator/routing_generator.cpp @@ -6,7 +6,7 @@ #include "routing/osrm2feature_map.hpp" #include "routing/osrm_data_facade.hpp" -#include "routing/osrm_router.hpp" +#include "routing/osrm_engine.hpp" #include "routing/cross_routing_context.hpp" #include "indexer/classificator_loader.hpp" @@ -160,19 +160,19 @@ void CalculateCrossAdjacency(string const & mwmRoutingPath, routing::CrossRoutin crossContext.reserveAdjacencyMatrix(); auto const & in = crossContext.GetIngoingIterators(); auto const & out = crossContext.GetOutgoingIterators(); - MultiroutingTaskPointT sources(distance(in.first, in.second)), targets(distance(out.first, out.second)); - size_t index = 0; + RoutingNodesT sources, targets; + sources.reserve(distance(in.first, in.second)); + targets.reserve(distance(out.first, out.second)); // Fill sources and targets with start node task for ingoing (true) and target node task // (false) for outgoing nodes - for (auto i = in.first; i != in.second; ++i, ++index) - OsrmRouter::GenerateRoutingTaskFromNodeId(i->m_nodeId, true, sources[index]); + for (auto i = in.first; i != in.second; ++i) + sources.emplace_back(FeatureGraphNode(i->m_nodeId, true)); - index = 0; - for (auto i = out.first; i != out.second; ++i, ++index) - OsrmRouter::GenerateRoutingTaskFromNodeId(i->m_nodeId, false, targets[index]); + for (auto i = out.first; i != out.second; ++i) + targets.emplace_back(i->m_nodeId, false); vector costs; - OsrmRouter::FindWeightsMatrix(sources, targets, facade, costs); + FindWeightsMatrix(sources, targets, facade, costs); auto res = costs.begin(); for (auto i = in.first; i != in.second; ++i) for (auto j = out.first; j != out.second; ++j) diff --git a/routing/osrm_engine.cpp b/routing/osrm_engine.cpp new file mode 100644 index 0000000000..f92aed7c64 --- /dev/null +++ b/routing/osrm_engine.cpp @@ -0,0 +1,119 @@ +#include "routing/osrm_engine.hpp" +#include "routing/osrm2feature_map.hpp" + +#include "base/logging.hpp" +#include "base/timer.hpp" + +#include "3party/osrm/osrm-backend/data_structures/internal_route_result.hpp" +#include "3party/osrm/osrm-backend/data_structures/search_engine_data.hpp" +#include "3party/osrm/osrm-backend/routing_algorithms/n_to_m_many_to_many.hpp" +#include "3party/osrm/osrm-backend/routing_algorithms/shortest_path.hpp" + +namespace routing +{ + +bool IsRouteExist(InternalRouteResult const & r) +{ + return !(INVALID_EDGE_WEIGHT == r.shortest_path_length || + r.segment_end_coordinates.empty() || + r.source_traversed_in_reverse.empty()); +} + +void GenerateRoutingTaskFromNodeId(NodeID const nodeId, bool const isStartNode, + PhantomNode & taskNode) +{ + taskNode.forward_node_id = isStartNode ? nodeId : INVALID_NODE_ID; + taskNode.reverse_node_id = isStartNode ? INVALID_NODE_ID : nodeId; + taskNode.forward_weight = 0; + taskNode.reverse_weight = 0; + taskNode.forward_offset = 0; + taskNode.reverse_offset = 0; + taskNode.name_id = 1; +} + +void FindWeightsMatrix(const RoutingNodesT &sources, const RoutingNodesT &targets, RawDataFacadeT &facade, vector &result) +{ + SearchEngineData engineData; + NMManyToManyRouting pathFinder(&facade, engineData); + PhantomNodeArray sourcesTaskVector(sources.size()); + PhantomNodeArray targetsTaskVector(targets.size()); + for (int i = 0; i < sources.size(); ++i) + sourcesTaskVector[i].push_back(sources[i].m_node); + for (int i = 0; i < targets.size(); ++i) + targetsTaskVector[i].push_back(targets[i].m_node); + + // Calculate time consumption of a NtoM path finding. + my::HighResTimer timer(true); + shared_ptr> resultTable = pathFinder(sourcesTaskVector, targetsTaskVector); + LOG(LINFO, ("Duration of a single one-to-many routing call", timer.ElapsedNano(), "ns")); + timer.Reset(); + ASSERT_EQUAL(resultTable->size(), sources.size() * targets.size(), ()); + result.swap(*resultTable); +} + +bool FindSingleRoute(const FeatureGraphNode &source, const FeatureGraphNode &target, RawDataFacadeT &facade, RawRoutingResult &rawRoutingResult) +{ + SearchEngineData engineData; + InternalRouteResult result; + ShortestPathRouting pathFinder(&facade, engineData); + PhantomNodes nodes; + nodes.source_phantom = source.m_node; + nodes.target_phantom = target.m_node; + + if ((nodes.source_phantom.forward_node_id != INVALID_NODE_ID || + nodes.source_phantom.reverse_node_id != INVALID_NODE_ID) && + (nodes.target_phantom.forward_node_id != INVALID_NODE_ID || + nodes.target_phantom.reverse_node_id != INVALID_NODE_ID)) + { + result.segment_end_coordinates.push_back(nodes); + pathFinder({nodes}, {}, result); + } + + if (IsRouteExist(result)) + { + rawRoutingResult.m_sourceEdge = source; + rawRoutingResult.m_targetEdge = target; + rawRoutingResult.m_shortestPathLength = result.shortest_path_length; + for (auto const & path: result.unpacked_path_segments) + { + vector data; + data.reserve(path.size()); + for (auto const & element : path) + { + data.emplace_back(RawPathData(element.node, element.segment_duration)); + } + rawRoutingResult.unpacked_path_segments.emplace_back(move(data)); + } + return true; + } + + return false; +} + +FeatureGraphNode::FeatureGraphNode(const NodeID nodeId, const bool isStartNode) +{ + m_node.forward_node_id = isStartNode ? nodeId : INVALID_NODE_ID; + m_node.reverse_node_id = isStartNode ? INVALID_NODE_ID : nodeId; + m_node.forward_weight = 0; + m_node.reverse_weight = 0; + m_node.forward_offset = 0; + m_node.reverse_offset = 0; + m_node.name_id = 1; + m_seg.m_fid = OsrmMappingTypes::FtSeg::INVALID_FID; + m_segPt = m2::PointD::Zero(); +} + +FeatureGraphNode::FeatureGraphNode() +{ + m_node.forward_node_id = INVALID_NODE_ID; + m_node.reverse_node_id = INVALID_NODE_ID; + m_node.forward_weight = 0; + m_node.reverse_weight = 0; + m_node.forward_offset = 0; + m_node.reverse_offset = 0; + m_node.name_id = 1; + m_seg.m_fid = OsrmMappingTypes::FtSeg::INVALID_FID; + m_segPt = m2::PointD::Zero(); +} + +} // namespace routing diff --git a/routing/osrm_engine.hpp b/routing/osrm_engine.hpp new file mode 100644 index 0000000000..a7ab22d635 --- /dev/null +++ b/routing/osrm_engine.hpp @@ -0,0 +1,95 @@ +#pragma once + +#include "routing/osrm2feature_map.hpp" +#include "routing/osrm_data_facade.hpp" + +#include "geometry/point2d.hpp" + +#include "std/vector.hpp" + +#include "3party/osrm/osrm-backend/data_structures/query_edge.hpp" + +namespace routing +{ + +/// Single graph node representation for routing task +struct FeatureGraphNode +{ + PhantomNode m_node; + OsrmMappingTypes::FtSeg m_seg; + m2::PointD m_segPt; + + /*! + * \brief GenerateRoutingTaskFromNodeId fill taskNode with values for making route + * \param nodeId osrm node idetifier + * \param isStartNode true if this node will first in the path + * \param taskNode output point task for router + */ + FeatureGraphNode(NodeID const nodeId, bool const isStartNode); + + /// \brief Invalid graph node constructor + FeatureGraphNode(); +}; + +/*! + * \brief The RawPathData struct is our representation of OSRM PathData struct. + * I use it for excluding dependency from OSRM. Contains OSRM node ID and it's weight. + */ +struct RawPathData +{ + RawPathData() + : node(SPECIAL_NODEID), segment_duration(INVALID_EDGE_WEIGHT) + { + } + + RawPathData(NodeID node, + EdgeWeight segment_duration) + : node(node), segment_duration(segment_duration) + { + } + NodeID node; + EdgeWeight segment_duration; +}; + +/*! + * \brief The OSRM routing result struct. Contains the routing result, it's cost and source and target edges. + * \property m_shortestPathLength Length of a founded route. + * \property m_unpackedPathSegments Segments of a founded route. + * \property sourceEdge Source graph node of a route. + * \property targetEdge Target graph node of a route. + */ +struct RawRoutingResult +{ + int m_shortestPathLength; + vector> unpacked_path_segments; + FeatureGraphNode m_sourceEdge; + FeatureGraphNode m_targetEdge; +}; + +//@todo (dragunov) make proper name and replace FeatureGraphNode with it +using RoutingNodesT = vector; +using RawDataFacadeT = OsrmRawDataFacade; + + +/*! + * \brief FindWeightsMatrix Find weights matrix from sources to targets. WARNING it finds only weights, not pathes. + * \param sources Sources graph nodes vector. Each source is the representation of a start OSRM node. + * \param targets Targets graph nodes vector. Each target is the representation of a finish OSRM node. + * \param facade Osrm data facade reference. + * \param packed Result vector with weights. Source nodes are rows. + * cost(source1 -> target1) cost(source1 -> target2) cost(source2 -> target1) cost(source2 -> target2) + */ +void FindWeightsMatrix(RoutingNodesT const & sources, RoutingNodesT const & targets, + RawDataFacadeT & facade, vector & result); + +/*! Find single shortest path in a single MWM between 2 OSRM nodes + * \param source Source OSRM graph node to make path. + * \param taget Target OSRM graph node to make path. + * \param facade OSRM routing data facade to recover graph information. + * \param rawRoutingResult Routing result structure. + * \return true when path exists, false otherwise. + */ +bool FindSingleRoute(FeatureGraphNode const & source, FeatureGraphNode const & target, RawDataFacadeT & facade, + RawRoutingResult & rawRoutingResult); + +} // namespace routing diff --git a/routing/osrm_router.cpp b/routing/osrm_router.cpp index 6783bb3bdb..d728fc30a7 100644 --- a/routing/osrm_router.cpp +++ b/routing/osrm_router.cpp @@ -27,10 +27,9 @@ #include "3party/osrm/osrm-backend/data_structures/query_edge.hpp" #include "3party/osrm/osrm-backend/data_structures/internal_route_result.hpp" -#include "3party/osrm/osrm-backend/data_structures/search_engine_data.hpp" + #include "3party/osrm/osrm-backend/descriptors/description_factory.hpp" -#include "3party/osrm/osrm-backend/routing_algorithms/shortest_path.hpp" -#include "3party/osrm/osrm-backend/routing_algorithms/n_to_m_many_to_many.hpp" + #define INTERRUPT_WHEN_CANCELLED() \ do \ @@ -50,12 +49,7 @@ double const FEATURES_NEAR_TURN_M = 3.0; // TODO (ldragunov) Switch all RawRouteData and incapsulate to own omim types. using RawRouteData = InternalRouteResult; -struct RawRoutingResultT -{ - RawRouteData m_routePath; - FeatureGraphNode m_sourceEdge; - FeatureGraphNode m_targetEdge; -}; + namespace { @@ -431,98 +425,21 @@ void OsrmRouter::ClearState() m_indexManager.Clear(); } -namespace +bool OsrmRouter::FindRouteFromCases(FeatureGraphNodeVecT const & source, FeatureGraphNodeVecT const & target, DataFacadeT & facade, + RawRoutingResult & rawRoutingResult) { - -bool IsRouteExist(RawRouteData const & r) -{ - return !(INVALID_EDGE_WEIGHT == r.shortest_path_length || - r.segment_end_coordinates.empty() || - r.source_traversed_in_reverse.empty()); -} - -bool IsValidEdgeWeight(EdgeWeight const & w) { return w != INVALID_EDGE_WEIGHT; } - -} - -void OsrmRouter::FindWeightsMatrix(MultiroutingTaskPointT const & sources, MultiroutingTaskPointT const & targets, - RawDataFacadeT &facade, vector &result) -{ - SearchEngineData engineData; - NMManyToManyRouting pathFinder(&facade, engineData); - - PhantomNodeArray sourcesTaskVector(sources.size()); - PhantomNodeArray targetsTaskVector(targets.size()); - for (int i = 0; i < sources.size(); ++i) - { - sourcesTaskVector[i].push_back(sources[i].m_node); - } - for (int i = 0; i < targets.size(); ++i) - { - targetsTaskVector[i].push_back(targets[i].m_node); - } - - // Calculate time consumption of a NtoM path finding. - my::HighResTimer timer(true); - shared_ptr> resultTable = pathFinder(sourcesTaskVector, targetsTaskVector); - LOG(LINFO, ("Duration of a single one-to-many routing call", timer.ElapsedNano(), "ns")); - timer.Reset(); - ASSERT_EQUAL(resultTable->size(), sources.size() * targets.size(), ()); - result.swap(*resultTable); -} - -bool OsrmRouter::FindSingleRoute(FeatureGraphNodeVecT const & source, FeatureGraphNodeVecT const & target, DataFacadeT & facade, - RawRoutingResultT & rawRoutingResult) -{ - /// @todo: make more complex nearest edge turnaround - SearchEngineData engineData; - ShortestPathRouting pathFinder(&facade, engineData); - + /// @todo (ldargunov) make more complex nearest edge turnaround for (auto targetEdge = target.cbegin(); targetEdge != target.cend(); ++targetEdge) { for (auto sourceEdge = source.cbegin(); sourceEdge != source.cend(); ++sourceEdge) { - PhantomNodes nodes; - nodes.source_phantom = sourceEdge->m_node; - nodes.target_phantom = targetEdge->m_node; - - rawRoutingResult.m_routePath = RawRouteData(); - - if ((nodes.source_phantom.forward_node_id != INVALID_NODE_ID || - nodes.source_phantom.reverse_node_id != INVALID_NODE_ID) && - (nodes.target_phantom.forward_node_id != INVALID_NODE_ID || - nodes.target_phantom.reverse_node_id != INVALID_NODE_ID)) - { - rawRoutingResult.m_routePath.segment_end_coordinates.push_back(nodes); - - pathFinder({nodes}, {}, rawRoutingResult.m_routePath); - } - - - if (IsRouteExist(rawRoutingResult.m_routePath)) - { - rawRoutingResult.m_sourceEdge = *sourceEdge; - rawRoutingResult.m_targetEdge = *targetEdge; + if (FindSingleRoute(*sourceEdge, *targetEdge, facade, rawRoutingResult)) return true; - } } } return false; } -void OsrmRouter::GenerateRoutingTaskFromNodeId(NodeID const nodeId, bool const isStartNode, - FeatureGraphNode & taskNode) -{ - taskNode.m_node.forward_node_id = isStartNode ? nodeId : INVALID_NODE_ID; - taskNode.m_node.reverse_node_id = isStartNode ? INVALID_NODE_ID : nodeId; - taskNode.m_node.forward_weight = 0; - taskNode.m_node.reverse_weight = 0; - taskNode.m_node.forward_offset = 0; - taskNode.m_node.reverse_offset = 0; - taskNode.m_node.name_id = 1; - taskNode.m_seg.m_fid = OsrmMappingTypes::FtSeg::INVALID_FID; -} - size_t OsrmRouter::FindNextMwmNode(OutgoingCrossNode const & startNode, RoutingMappingPtrT const & targetMapping) { m2::PointD startPoint = startNode.m_point; @@ -546,7 +463,7 @@ OsrmRouter::ResultCode OsrmRouter::MakeRouteFromCrossesPath(CheckedPathT const & turns::TurnsGeomT TurnsGeom; for (RoutePathCross const & cross: path) { - RawRoutingResultT routingResult; + RawRoutingResult routingResult; // TODO (Dragunov) refactor whole routing to single OSRM node in task instead vector. FeatureGraphNodeVecT startTask(1), targetTask(1); @@ -562,7 +479,7 @@ OsrmRouter::ResultCode OsrmRouter::MakeRouteFromCrossesPath(CheckedPathT const & ASSERT(mwmMapping->IsValid(), ()); MappingGuard mwmMappingGuard(mwmMapping); UNUSED_VALUE(mwmMappingGuard); - if (!FindSingleRoute(startTask, targetTask, mwmMapping->m_dataFacade, routingResult)) + if (!FindSingleRoute(cross.startNode, cross.targetNode, mwmMapping->m_dataFacade, routingResult)) { return OsrmRouter::RouteNotFound; } @@ -611,11 +528,16 @@ OsrmRouter::ResultCode OsrmRouter::MakeRouteFromCrossesPath(CheckedPathT const & return OsrmRouter::NoError; } +namespace +{ +bool IsValidEdgeWeight(EdgeWeight const & w) { return w != INVALID_EDGE_WEIGHT; } +} + class OsrmRouter::LastCrossFinder { CrossRoutingContextReader const & m_targetContext; string const m_mwmName; - MultiroutingTaskPointT m_sources; + RoutingNodesT m_sources; FeatureGraphNode m_target; vector m_weights; @@ -625,18 +547,14 @@ public: m_mwmName(mapping->GetName()) { auto income_iterators = m_targetContext.GetIngoingIterators(); - MultiroutingTaskPointT targets(1); - m_sources.resize(distance(income_iterators.first, income_iterators.second)); - - size_t index = 0; - for (auto i = income_iterators.first; i < income_iterators.second; ++i, ++index) - OsrmRouter::GenerateRoutingTaskFromNodeId(i->m_nodeId, true /*isStartNode*/, m_sources[index]); + m_sources.reserve(distance(income_iterators.first, income_iterators.second)); + for (auto i = income_iterators.first; i < income_iterators.second; ++i) + m_sources.emplace_back(FeatureGraphNode(i->m_nodeId, true)); vector weights; - for (auto const & t : targetTask) + for (FeatureGraphNode const & t : targetTask) { - targets[0] = t; - OsrmRouter::FindWeightsMatrix(m_sources, targets, mapping->m_dataFacade, weights); + FindWeightsMatrix(m_sources, {t}, mapping->m_dataFacade, weights); if (find_if(weights.begin(), weights.end(), &IsValidEdgeWeight) != weights.end()) { ASSERT_EQUAL(weights.size(), m_sources.size(), ()); @@ -738,7 +656,7 @@ OsrmRouter::ResultCode OsrmRouter::CalculateRoute(m2::PointD const & startPoint, timer.Reset(); // 4. Find route. - RawRoutingResultT routingResult; + RawRoutingResult routingResult; // 4.1 Single mwm case if (startMapping->GetName() == targetMapping->GetName()) @@ -748,7 +666,7 @@ OsrmRouter::ResultCode OsrmRouter::CalculateRoute(m2::PointD const & startPoint, { indexPair.second->FreeCrossContext(); }); - if (!FindSingleRoute(startTask, m_CachedTargetTask, startMapping->m_dataFacade, routingResult)) + if (!FindRouteFromCases(startTask, m_CachedTargetTask, startMapping->m_dataFacade, routingResult)) { return RouteNotFound; } @@ -815,7 +733,7 @@ OsrmRouter::ResultCode OsrmRouter::CalculateRoute(m2::PointD const & startPoint, // Load source data auto const mwmOutsIter = startMapping->m_crossContext.GetOutgoingIterators(); - MultiroutingTaskPointT sources(1), targets(distance(mwmOutsIter.first, mwmOutsIter.second)); + MultiroutingTaskPointT sources(1), targets; if (targets.empty()) { @@ -823,9 +741,9 @@ OsrmRouter::ResultCode OsrmRouter::CalculateRoute(m2::PointD const & startPoint, return RouteFileNotExist; } - size_t index = 0; - for (auto j = mwmOutsIter.first; j < mwmOutsIter.second; ++j, ++index) - OsrmRouter::GenerateRoutingTaskFromNodeId(j->m_nodeId, false /*isStartNode*/, targets[index]); + targets.reserve(distance(mwmOutsIter.first, mwmOutsIter.second)); + for (auto j = mwmOutsIter.first; j < mwmOutsIter.second; ++j) + targets.emplace_back(FeatureGraphNode(j->m_nodeId, false)); vector weights; for (auto const & t : startTask) { @@ -885,8 +803,7 @@ OsrmRouter::ResultCode OsrmRouter::CalculateRoute(m2::PointD const & startPoint, ASSERT(nextMwm != startMapping->GetName(), ("single round error!")); if (nextMwm != targetMapping->GetName()) { - FeatureGraphNode tmpNode; - OsrmRouter::GenerateRoutingTaskFromNodeId(nextNodeId, true /*isStartNode*/, tmpNode); + FeatureGraphNode tmpNode(nextNodeId, true); tmpPath.push_back({nextMapping->GetName(), tmpNode, tmpNode, 0}); crossTasks.push(tmpPath); } @@ -964,16 +881,11 @@ OsrmRouter::ResultCode OsrmRouter::CalculateRoute(m2::PointD const & startPoint, if(nextNodeId == INVALID_NODE_ID) continue; CheckedPathT tmpPath(topTask); - FeatureGraphNode startNode, stopNode; - OsrmRouter::GenerateRoutingTaskFromNodeId(iit->m_nodeId, true /*isStartNode*/, - startNode); - OsrmRouter::GenerateRoutingTaskFromNodeId(tNodeId, false /*isStartNode*/, stopNode); + FeatureGraphNode startNode(iit->m_nodeId, true), stopNode(tNodeId, false); tmpPath.back() = {currentMapping->GetName(), startNode, stopNode, outWeight}; if (nextMwm != targetMapping->GetName()) { - FeatureGraphNode tmpNode; - OsrmRouter::GenerateRoutingTaskFromNodeId(nextNodeId, true /*isStartNode*/, - tmpNode); + FeatureGraphNode tmpNode(nextNodeId, true); tmpPath.push_back({nextMapping->GetName(), tmpNode, tmpNode, 0}); crossTasks.emplace(move(tmpPath)); } @@ -1044,7 +956,7 @@ m2::PointD OsrmRouter::GetPointForTurnAngle(OsrmMappingTypes::FtSeg const & seg, return nextPnt; } -OsrmRouter::ResultCode OsrmRouter::MakeTurnAnnotation(RawRoutingResultT const & routingResult, +OsrmRouter::ResultCode OsrmRouter::MakeTurnAnnotation(RawRoutingResult const & routingResult, RoutingMappingPtrT const & mapping, vector & points, Route::TurnsT & turnsDir, @@ -1057,36 +969,36 @@ OsrmRouter::ResultCode OsrmRouter::MakeTurnAnnotation(RawRoutingResultT const & double estimateTime = 0; - LOG(LDEBUG, ("Shortest path length:", routingResult.m_routePath.shortest_path_length)); + LOG(LDEBUG, ("Shortest path length:", routingResult.m_shortestPathLength)); //! @todo: Improve last segment time calculation CarModel carModel; #ifdef _DEBUG size_t lastIdx = 0; #endif - for (auto i : osrm::irange(0, routingResult.m_routePath.unpacked_path_segments.size())) + for (auto i : osrm::irange(0, routingResult.unpacked_path_segments.size())) { INTERRUPT_WHEN_CANCELLED(); // Get all the coordinates for the computed route - size_t const n = routingResult.m_routePath.unpacked_path_segments[i].size(); + size_t const n = routingResult.unpacked_path_segments[i].size(); for (size_t j = 0; j < n; ++j) { - PathData const & path_data = routingResult.m_routePath.unpacked_path_segments[i][j]; + RawPathData const & path_data = routingResult.unpacked_path_segments[i][j]; if (j > 0 && !points.empty()) { TurnItem t; t.m_index = points.size() - 1; - GetTurnDirection(routingResult.m_routePath.unpacked_path_segments[i][j - 1], - routingResult.m_routePath.unpacked_path_segments[i][j], + GetTurnDirection(routingResult.unpacked_path_segments[i][j - 1], + routingResult.unpacked_path_segments[i][j], mapping, t); if (t.m_turn != turns::TurnDirection::NoTurn) { // adding lane info t.m_lanes = - turns::GetLanesInfo(routingResult.m_routePath.unpacked_path_segments[i][j - 1].node, + turns::GetLanesInfo(routingResult.unpacked_path_segments[i][j - 1].node, *mapping, GetLastSegmentPointIndex, *m_pIndex); turnsDir.push_back(move(t)); } @@ -1339,8 +1251,8 @@ size_t OsrmRouter::NumberOfIngoingAndOutgoingSegments(m2::PointD const & junctio } // @todo(vbykoianko) Move this method and all dependencies to turns_generator.cpp -void OsrmRouter::GetTurnDirection(PathData const & node1, - PathData const & node2, +void OsrmRouter::GetTurnDirection(RawPathData const & node1, + RawPathData const & node2, RoutingMappingPtrT const & routingMapping, TurnItem & turn) { ASSERT(routingMapping.get(), ()); diff --git a/routing/osrm_router.hpp b/routing/osrm_router.hpp index e37406f4c2..ad7a3c0e08 100644 --- a/routing/osrm_router.hpp +++ b/routing/osrm_router.hpp @@ -2,6 +2,7 @@ #include "routing/osrm2feature_map.hpp" #include "routing/osrm_data_facade.hpp" +#include "routing/osrm_engine.hpp" #include "routing/route.hpp" #include "routing/router.hpp" #include "routing/routing_mapping.h" @@ -26,30 +27,14 @@ class FeatureType; namespace routing { typedef function CountryFileFnT; -typedef OsrmRawDataFacade RawDataFacadeT; typedef OsrmDataFacade DataFacadeT; -/// Single graph node representation for routing task -struct FeatureGraphNode -{ - PhantomNode m_node; - OsrmMappingTypes::FtSeg m_seg; - m2::PointD m_segPt; -}; /// All edges available for start route while routing typedef vector FeatureGraphNodeVecT; /// Points vector to calculate several routes typedef vector MultiroutingTaskPointT; -/*! - * \brief The OSRM routing result struct. Contains raw routing result and iterators to source and target edges. - * \property routePath: result path data - * \property sourceEdge: iterator to src edge from source vector - * \property targetEdge: iterator to target edge from target vector - */ -struct RawRoutingResultT; - -typedef vector MultipleRoutingResultT; +typedef vector MultipleRoutingResultT; /*! Manager for loading, cashing and building routing indexes. * Builds and shares special routing contexts. @@ -95,34 +80,14 @@ public: virtual void ClearState(); /*! Find single shortest path in a single MWM between 2 sets of edges - * \param source: vector of source edges to make path - * \param taget: vector of target edges to make path - * \param facade: OSRM routing data facade to recover graph information - * \param rawRoutingResult: routing result store - * \return true when path exists, false otherwise. - */ - static bool FindSingleRoute(FeatureGraphNodeVecT const & source, FeatureGraphNodeVecT const & target, DataFacadeT & facade, - RawRoutingResultT & rawRoutingResult); - - /*! - * \brief FindWeightsMatrix Find weights matrix from sources to targets. WARNING it finds only weights, not pathes. - * \param sources vector. Allows only one phantom node for one source. Each source is the start OSRM node. - * \param targets vector. Allows only one phantom node for one target. Each target is the finish OSRM node. - * \param facade osrm data facade reference - * \param packed result vector with weights. Source nodes are rows. - * cost(source1 -> target1) cost(source1 -> target2) cost(source2 -> target1) cost(source2 -> target2) - */ - static void FindWeightsMatrix(MultiroutingTaskPointT const & sources, MultiroutingTaskPointT const & targets, - RawDataFacadeT & facade, vector & result); - - /*! - * \brief GenerateRoutingTaskFromNodeId fill taskNode with values for making route - * \param nodeId osrm node idetifier - * \param isStartNode true if this node will first in the path - * \param taskNode output point task for router - */ - static void GenerateRoutingTaskFromNodeId(const NodeID nodeId, bool const isStartNode, - FeatureGraphNode & taskNode); + * \param source: vector of source edges to make path + * \param taget: vector of target edges to make path + * \param facade: OSRM routing data facade to recover graph information + * \param rawRoutingResult: routing result store + * \return true when path exists, false otherwise. + */ + static bool FindRouteFromCases(FeatureGraphNodeVecT const & source, FeatureGraphNodeVecT const & target, DataFacadeT & facade, + RawRoutingResult & rawRoutingResult); protected: IRouter::ResultCode FindPhantomNodes(string const & fName, m2::PointD const & point, @@ -142,7 +107,7 @@ protected: * \param turnsGeom output turns geometry * \return OSRM routing errors if any */ - ResultCode MakeTurnAnnotation(RawRoutingResultT const & routingResult, + ResultCode MakeTurnAnnotation(RawRoutingResult const & routingResult, RoutingMappingPtrT const & mapping, vector & points, Route::TurnsT & turnsDir, Route::TimesT & times, turns::TurnsGeomT & turnsGeom); @@ -189,8 +154,8 @@ private: void GetPossibleTurns(NodeID node, m2::PointD const & p1, m2::PointD const & p, RoutingMappingPtrT const & routingMapping, turns::TTurnCandidates & candidates); - void GetTurnDirection(PathData const & node1, - PathData const & node2, + void GetTurnDirection(RawPathData const & node1, + RawPathData const & node2, RoutingMappingPtrT const & routingMapping, TurnItem & turn); m2::PointD GetPointForTurnAngle(OsrmMappingTypes::FtSeg const & seg, diff --git a/routing/routing.pro b/routing/routing.pro index 4dd1248cfb..ab7c797f61 100644 --- a/routing/routing.pro +++ b/routing/routing.pro @@ -20,6 +20,7 @@ SOURCES += \ nearest_edge_finder.cpp \ online_cross_fetcher.cpp \ osrm2feature_map.cpp \ + osrm_engine.cpp \ osrm_online_router.cpp \ osrm_router.cpp \ road_graph.cpp \ @@ -41,6 +42,7 @@ HEADERS += \ online_cross_fetcher.hpp \ osrm2feature_map.hpp \ osrm_data_facade.hpp \ + osrm_engine.hpp \ osrm_online_router.hpp \ osrm_router.hpp \ road_graph.hpp \ diff --git a/routing/turns_generator.hpp b/routing/turns_generator.hpp index 162ab3e042..edb8c7131e 100644 --- a/routing/turns_generator.hpp +++ b/routing/turns_generator.hpp @@ -1,6 +1,7 @@ #pragma once #include "routing/osrm2feature_map.hpp" +#include "routing/osrm_engine.hpp" #include "routing/route.hpp" #include "routing/turns.hpp"