From fd528e35d9d3e1a7b0a305f3cb0c289643e340f2 Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Thu, 27 Apr 2017 15:01:44 +0300 Subject: [PATCH] Checking phantom nodes for acceptability by trying go with BFS. --- routing/index_graph_starter.hpp | 9 ++-- routing/index_router.cpp | 50 +++++++++++----------- routing/index_router.hpp | 13 +++--- routing/road_graph_router.cpp | 10 +++-- routing/routing_helpers.hpp | 1 + routing/routing_tests/index_graph_test.cpp | 6 +-- 6 files changed, 48 insertions(+), 41 deletions(-) diff --git a/routing/index_graph_starter.hpp b/routing/index_graph_starter.hpp index 93e1edc6e4..4741cc5358 100644 --- a/routing/index_graph_starter.hpp +++ b/routing/index_graph_starter.hpp @@ -23,15 +23,14 @@ public: class FakeVertex final { public: - FakeVertex(NumMwmId mwmId, uint32_t featureId, uint32_t segmentIdx, m2::PointD const & point) - : m_segment(mwmId, featureId, segmentIdx, true /* forward */), m_point(point) - { - } - FakeVertex(Segment const & segment, m2::PointD const & point) : m_segment(segment), m_point(point) { } + FakeVertex(NumMwmId mwmId, uint32_t featureId, uint32_t segmentIdx, m2::PointD const & point) + : m_segment(mwmId, featureId, segmentIdx, true /* forward */), m_point(point) + { + } NumMwmId GetMwmId() const { return m_segment.GetMwmId(); } uint32_t GetFeatureId() const { return m_segment.GetFeatureId(); } diff --git a/routing/index_router.cpp b/routing/index_router.cpp index 2773bcd22e..c2db21eeca 100644 --- a/routing/index_router.cpp +++ b/routing/index_router.cpp @@ -36,17 +36,18 @@ size_t constexpr kMaxRoadCandidates = 6; float constexpr kProgressInterval = 2; uint32_t constexpr kDrawPointsPeriod = 10; -bool IsDeadEnd(Segment const & segment, bool isOutgoing, WorldGraph & worldGraph) +bool IsDeadEnd(Segment const & segment, bool fromPoint, WorldGraph & worldGraph) { size_t constexpr kDeadEndTestLimit = 50; - auto const getVertexByEdgeFn = [](SegmentEdge const & edge) { return edge.GetTarget(); }; + auto const getVertexByEdgeFn = [](SegmentEdge const & edge) { + return edge.GetTarget(); + }; - // Note. If |isOutgoing| == true outgoing edges are looked for. - // If |isOutgoing| == false it's the finish. So ingoing edges are looked for. - auto const getOutgoingEdgesFn = [isOutgoing](WorldGraph & graph, Segment const & u, - vector & edges) { - graph.GetEdgeList(u, isOutgoing, false /* isLeap */, edges); + // Note. If |fromPoint| == true outgoing edges are looked for. + // If |fromPoint| == false it's the finish. So ingoing edges are looked for. + auto const getOutgoingEdgesFn = [fromPoint](WorldGraph & graph, Segment const & u, vector & edges){ + graph.GetEdgeList(u, fromPoint, false /* isLeap */, edges); }; return !CheckGraphConnectivity(segment, kDeadEndTestLimit, worldGraph, @@ -136,27 +137,25 @@ IRouter::ResultCode IndexRouter::DoCalculateRoute(string const & startCountry, TrafficStash::Guard guard(*m_trafficStash); WorldGraph graph( - make_unique(m_numMwmIds, m_numMwmTree, m_vehicleModelFactory, m_countryRectFn, - m_index, m_indexManager), - IndexGraphLoader::Create(m_numMwmIds, m_vehicleModelFactory, m_estimator, m_index), - m_estimator); + make_unique(m_numMwmIds, m_numMwmTree, m_vehicleModelFactory, m_countryRectFn, + m_index, m_indexManager), + IndexGraphLoader::Create(m_numMwmIds, m_vehicleModelFactory, m_estimator, m_index), + m_estimator); Edge startEdge; - if (!FindClosestEdge(startFile, startPoint, true /* isOutgoing */, graph, startEdge)) + if (!FindClosestEdge(graph, startFile, startPoint, true /* fromPoint */, startEdge)) return IRouter::StartPointNotFound; Edge finishEdge; - if (!FindClosestEdge(finishFile, finalPoint, false /* isOutgoing */, graph, finishEdge)) + if (!FindClosestEdge(graph, finishFile, finalPoint, false /* fromPoint */, finishEdge)) return IRouter::EndPointNotFound; - IndexGraphStarter::FakeVertex const start( - Segment(m_numMwmIds->GetId(startFile), startEdge.GetFeatureId().m_index, startEdge.GetSegId(), - true /* forward */), - startPoint); - IndexGraphStarter::FakeVertex const finish( - Segment(m_numMwmIds->GetId(finishFile), finishEdge.GetFeatureId().m_index, - finishEdge.GetSegId(), true /* forward */), - finalPoint); + IndexGraphStarter::FakeVertex const start(Segment(m_numMwmIds->GetId(startFile), + startEdge.GetFeatureId().m_index, startEdge.GetSegId(), true /* forward */), + startPoint); + IndexGraphStarter::FakeVertex const finish(Segment(m_numMwmIds->GetId(finishFile), + finishEdge.GetFeatureId().m_index, + finishEdge.GetSegId(), true /* forward */), finalPoint); WorldGraph::Mode mode = WorldGraph::Mode::SingleMwm; if (forSingleMwm) @@ -214,8 +213,10 @@ IRouter::ResultCode IndexRouter::DoCalculateRoute(string const & startCountry, } } -bool IndexRouter::FindClosestEdge(platform::CountryFile const & file, m2::PointD const & point, - bool isOutgoing, WorldGraph & worldGraph, +bool IndexRouter::FindClosestEdge(WorldGraph & worldGraph, + platform::CountryFile const & file, + m2::PointD const & point, + bool fromPoint, Edge & closestEdge) const { MwmSet::MwmHandle handle = m_index.GetMwmHandleByCountryFile(file); @@ -235,7 +236,8 @@ bool IndexRouter::FindClosestEdge(platform::CountryFile const & file, m2::PointD { Edge const & edge = candidates[i].first; Segment const segment(numMwmId, edge.GetFeatureId().m_index, edge.GetSegId(), edge.IsForward()); - if (edge.GetFeatureId().m_mwmId != mwmId || IsDeadEnd(segment, isOutgoing, worldGraph)) + + if (edge.GetFeatureId().m_mwmId != mwmId || IsDeadEnd(segment, fromPoint, worldGraph)) continue; m2::DistanceToLineSquare squaredDistance; diff --git a/routing/index_router.hpp b/routing/index_router.hpp index 037c9509b7..1bb8c00b40 100644 --- a/routing/index_router.hpp +++ b/routing/index_router.hpp @@ -70,11 +70,14 @@ private: m2::PointD const & finalPoint, RouterDelegate const & delegate, Route & route); - /// \brief Finds closest edges which may be considered as start or finish of the route. - /// \param isOutgoing == true is |point| is considered as the start of the route. - /// isOutgoing == false is |point| is considered as the finish of the route. - bool FindClosestEdge(platform::CountryFile const & file, m2::PointD const & point, - bool isOutgoing, WorldGraph & worldGraph, Edge & closestEdge) const; + /// \brief Finds closest edges which may be considered as start of finish of the route. + /// \param fromPoint == true is |point| is considered as the start of the route. + /// fromPoint == false is |point| is considered as the finish of the route. + bool FindClosestEdge(WorldGraph & worldGraph, + platform::CountryFile const & file, + m2::PointD const & point, + bool fromPoint, + Edge & closestEdge) const; // Input route may contains 'leaps': shortcut edges from mwm border enter to exit. // ProcessLeaps replaces each leap with calculated route through mwm. IRouter::ResultCode ProcessLeaps(vector const & input, RouterDelegate const & delegate, diff --git a/routing/road_graph_router.cpp b/routing/road_graph_router.cpp index 97f7ae2bc2..59371cbc78 100644 --- a/routing/road_graph_router.cpp +++ b/routing/road_graph_router.cpp @@ -81,9 +81,13 @@ void FindClosestEdges(IRoadGraph const & graph, m2::PointD const & point, for (auto const & candidate : candidates) { auto const & edge = candidate.first; - auto const getVertexByEdgeFn = [](Edge const & edge) { return edge.GetEndJunction(); }; - auto const getOutgoingEdgesFn = [](IRoadGraph const & graph, Junction const & u, - vector & edges) { graph.GetOutgoingEdges(u, edges); }; + + auto const getVertexByEdgeFn = [](Edge const & edge) { + return edge.GetEndJunction(); + }; + auto const getOutgoingEdgesFn = [](IRoadGraph const & graph, Junction const & u, vector & edges){ + graph.GetOutgoingEdges(u, edges); + }; if (CheckGraphConnectivity(edge.GetEndJunction(), kTestConnectivityVisitJunctionsLimit, graph, getVertexByEdgeFn, getOutgoingEdgesFn)) diff --git a/routing/routing_helpers.hpp b/routing/routing_helpers.hpp index 4d5024ffee..47c08ae4d7 100644 --- a/routing/routing_helpers.hpp +++ b/routing/routing_helpers.hpp @@ -34,6 +34,7 @@ void ReconstructRoute(IDirectionsEngine & engine, RoadGraphBase const & graph, my::Cancellable const & cancellable, bool hasAltitude, vector & path, Route & route); + /// \brief Checks is edge connected with world graph. Function does BFS while it finds some number /// of edges, /// if graph ends before this number is reached then junction is assumed as not connected to the diff --git a/routing/routing_tests/index_graph_test.cpp b/routing/routing_tests/index_graph_test.cpp index 1a996fe129..586f2f0b73 100644 --- a/routing/routing_tests/index_graph_test.cpp +++ b/routing/routing_tests/index_graph_test.cpp @@ -200,8 +200,7 @@ UNIT_TEST(FindPathCross) uint32_t expectedLength = 0; if (start.GetFeatureId() == finish.GetFeatureId()) { - expectedLength = - AbsDelta(start.GetSegmentIdxForTesting(), finish.GetSegmentIdxForTesting()) + 1; + expectedLength = AbsDelta(start.GetSegmentIdxForTesting(), finish.GetSegmentIdxForTesting()) + 1; } else { @@ -286,8 +285,7 @@ UNIT_TEST(FindPathManhattan) if (start.GetFeatureId() < kCitySize == finish.GetFeatureId() < kCitySize) { - uint32_t segDelta = - AbsDelta(start.GetSegmentIdxForTesting(), finish.GetSegmentIdxForTesting()); + uint32_t segDelta = AbsDelta(start.GetSegmentIdxForTesting(), finish.GetSegmentIdxForTesting()); if (segDelta == 0 && start.GetFeatureId() != finish.GetFeatureId()) segDelta = 1; expectedLength += segDelta;