From 2c8fed6fc196c4851c163f3939eac90296858e42 Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Thu, 27 Apr 2017 15:01:44 +0300 Subject: [PATCH 1/3] Checking phantom nodes for acceptability by trying go with BFS. --- routing/index_graph_starter.cpp | 3 +- routing/index_graph_starter.hpp | 23 +++++---- routing/index_router.cpp | 57 +++++++++++++++------- routing/index_router.hpp | 10 +++- routing/road_graph_router.cpp | 43 ++++------------ routing/routing_helpers.hpp | 36 ++++++++++++++ routing/routing_tests/index_graph_test.cpp | 28 +++++------ 7 files changed, 123 insertions(+), 77 deletions(-) diff --git a/routing/index_graph_starter.cpp b/routing/index_graph_starter.cpp index a7585487d9..e222e17ddc 100644 --- a/routing/index_graph_starter.cpp +++ b/routing/index_graph_starter.cpp @@ -87,8 +87,7 @@ void IndexGraphStarter::GetFakeToNormalEdges(FakeVertex const & fakeVertex, bool void IndexGraphStarter::GetFakeToNormalEdge(FakeVertex const & fakeVertex, bool forward, vector & edges) { - Segment const segment(fakeVertex.GetMwmId(), fakeVertex.GetFeatureId(), - fakeVertex.GetSegmentIdx(), forward); + Segment const segment = fakeVertex.GetSegmentWithDirection(forward); m2::PointD const & pointTo = GetPoint(segment, true /* front */); double const weight = m_graph.GetEstimator().CalcLeapWeight(fakeVertex.GetPoint(), pointTo); edges.emplace_back(segment, weight); diff --git a/routing/index_graph_starter.hpp b/routing/index_graph_starter.hpp index 3403fba00f..e4caaef534 100644 --- a/routing/index_graph_starter.hpp +++ b/routing/index_graph_starter.hpp @@ -23,27 +23,32 @@ public: class FakeVertex final { public: + 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) { } - FakeVertex(Segment const & segment, m2::PointD const & point) - : m_segment(segment), m_point(point) - { - } - NumMwmId GetMwmId() const { return m_segment.GetMwmId(); } uint32_t GetFeatureId() const { return m_segment.GetFeatureId(); } - uint32_t GetSegmentIdx() const { return m_segment.GetSegmentIdx(); } - Segment const & GetSegment() const { return m_segment; } m2::PointD const & GetPoint() const { return m_point; } + + Segment GetSegmentWithDirection(bool forward) const + { + return Segment(m_segment.GetMwmId(), m_segment.GetFeatureId(), m_segment.GetSegmentIdx(), forward); + } + bool Fits(Segment const & segment) const { - return segment.GetMwmId() == GetMwmId() && segment.GetFeatureId() == GetFeatureId() && - segment.GetSegmentIdx() == GetSegmentIdx(); + return segment.GetMwmId() == m_segment.GetMwmId() && segment.GetFeatureId() == m_segment.GetFeatureId() && + segment.GetSegmentIdx() == m_segment.GetSegmentIdx(); } + uint32_t GetSegmentIdxForTesting() const { return m_segment.GetSegmentIdx(); } + private: Segment m_segment; m2::PointD const m_point; diff --git a/routing/index_router.cpp b/routing/index_router.cpp index 73dbc7f262..34a49a6927 100644 --- a/routing/index_router.cpp +++ b/routing/index_router.cpp @@ -35,6 +35,24 @@ namespace size_t constexpr kMaxRoadCandidates = 6; float constexpr kProgressInterval = 2; uint32_t constexpr kDrawPointsPeriod = 10; + +bool IsDeadEnd(Segment const & segment, bool fromPoint, WorldGraph & worldGraph) +{ + size_t constexpr kDeadEndTestLimit = 50; + + auto const getVertexByEdgeFn = [](SegmentEdge const & edge){ + return edge.GetTarget(); + }; + + // 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(worldGraph, segment, kDeadEndTestLimit, + getVertexByEdgeFn, getOutgoingEdgesFn); +} } // namespace namespace routing @@ -117,21 +135,6 @@ IRouter::ResultCode IndexRouter::DoCalculateRoute(string const & startCountry, auto const startFile = platform::CountryFile(startCountry); auto const finishFile = platform::CountryFile(finishCountry); - Edge startEdge; - if (!FindClosestEdge(startFile, startPoint, startEdge)) - return IRouter::StartPointNotFound; - - Edge finishEdge; - if (!FindClosestEdge(finishFile, finalPoint, finishEdge)) - return IRouter::EndPointNotFound; - - IndexGraphStarter::FakeVertex const start(m_numMwmIds->GetId(startFile), - startEdge.GetFeatureId().m_index, startEdge.GetSegId(), - startPoint); - IndexGraphStarter::FakeVertex const finish(m_numMwmIds->GetId(finishFile), - finishEdge.GetFeatureId().m_index, - finishEdge.GetSegId(), finalPoint); - TrafficStash::Guard guard(*m_trafficStash); WorldGraph graph( make_unique(m_numMwmIds, m_numMwmTree, m_vehicleModelFactory, m_countryRectFn, @@ -139,6 +142,21 @@ IRouter::ResultCode IndexRouter::DoCalculateRoute(string const & startCountry, IndexGraphLoader::Create(m_numMwmIds, m_vehicleModelFactory, m_estimator, m_index), m_estimator); + Edge startEdge; + if (!FindClosestEdge(graph, startFile, startPoint, true /* fromPoint */, startEdge)) + return IRouter::StartPointNotFound; + + Edge 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); + WorldGraph::Mode mode = WorldGraph::Mode::SingleMwm; if (forSingleMwm) mode = WorldGraph::Mode::SingleMwm; @@ -195,7 +213,10 @@ IRouter::ResultCode IndexRouter::DoCalculateRoute(string const & startCountry, } } -bool IndexRouter::FindClosestEdge(platform::CountryFile const & file, m2::PointD const & point, +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); @@ -203,6 +224,7 @@ bool IndexRouter::FindClosestEdge(platform::CountryFile const & file, m2::PointD MYTHROW(RoutingException, ("Can't get mwm handle for", file)); auto const mwmId = MwmSet::MwmId(handle.GetInfo()); + NumMwmId const numMwmId = m_numMwmIds->GetId(file); vector> candidates; m_roadGraph.FindClosestEdges(point, kMaxRoadCandidates, candidates); @@ -213,7 +235,8 @@ bool IndexRouter::FindClosestEdge(platform::CountryFile const & file, m2::PointD for (size_t i = 0; i < candidates.size(); ++i) { Edge const & edge = candidates[i].first; - if (edge.GetFeatureId().m_mwmId != mwmId) + Segment const segment(numMwmId, edge.GetFeatureId().m_index, edge.GetSegId(), edge.IsForward()); + 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 5bc3049939..1bb8c00b40 100644 --- a/routing/index_router.hpp +++ b/routing/index_router.hpp @@ -8,6 +8,7 @@ #include "routing/num_mwm_id.hpp" #include "routing/router.hpp" #include "routing/routing_mapping.hpp" +#include "routing/world_graph.hpp" #include "routing_common/vehicle_model.hpp" @@ -68,7 +69,14 @@ private: m2::PointD const & startDirection, m2::PointD const & finalPoint, RouterDelegate const & delegate, Route & route); - bool FindClosestEdge(platform::CountryFile const & file, m2::PointD const & point, + + /// \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. diff --git a/routing/road_graph_router.cpp b/routing/road_graph_router.cpp index 903fc83a4a..bcf8784ec9 100644 --- a/routing/road_graph_router.cpp +++ b/routing/road_graph_router.cpp @@ -64,39 +64,6 @@ bool CheckMwmVersion(vector> const & vicinities, vector q; - q.push(junction); - - set visited; - visited.insert(junction); - - vector edges; - while (!q.empty() && visited.size() < limit) - { - Junction const u = q.front(); - q.pop(); - - edges.clear(); - graph.GetOutgoingEdges(u, edges); - for (Edge const & edge : edges) - { - Junction const & v = edge.GetEndJunction(); - if (visited.count(v) == 0) - { - q.push(v); - visited.insert(v); - } - } - } - - return visited.size() >= limit; -} - // Find closest candidates in the world graph void FindClosestEdges(IRoadGraph const & graph, m2::PointD const & point, vector> & vicinity) @@ -114,7 +81,15 @@ void FindClosestEdges(IRoadGraph const & graph, m2::PointD const & point, for (auto const & candidate : candidates) { auto const & edge = candidate.first; - if (CheckGraphConnectivity(graph, edge.GetEndJunction(), kTestConnectivityVisitJunctionsLimit)) + 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(graph, edge.GetEndJunction(), kTestConnectivityVisitJunctionsLimit, + getVertexByEdgeFn, getOutgoingEdgesFn)) { vicinity.emplace_back(candidate); diff --git a/routing/routing_helpers.hpp b/routing/routing_helpers.hpp index ee8103bac5..d8af77d25e 100644 --- a/routing/routing_helpers.hpp +++ b/routing/routing_helpers.hpp @@ -13,6 +13,8 @@ #include "base/cancellable.hpp" +#include "std/queue.hpp" +#include "std/set.hpp" #include "std/shared_ptr.hpp" #include "std/vector.hpp" @@ -30,4 +32,38 @@ bool IsRoad(TTypes const & types) void ReconstructRoute(IDirectionsEngine & engine, RoadGraphBase const & graph, shared_ptr const & trafficStash, my::Cancellable const & cancellable, 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 world graph. +template +bool CheckGraphConnectivity(Graph & graph, GraphVertex const & vertex, size_t limit, + GetVertexByEdgeFn && getVertexByEdgeFn, GetOutgoingEdgesFn && getOutgoingEdgesFn) +{ + queue q; + q.push(vertex); + + set visited; + visited.insert(vertex); + + vector edges; + while (!q.empty() && visited.size() < limit) + { + GraphVertex const u = q.front(); + q.pop(); + + edges.clear(); + getOutgoingEdgesFn(graph, u, edges); + for (GraphEdge const edge : edges) + { + GraphVertex const & v = getVertexByEdgeFn(edge); + if (visited.count(v) == 0) + { + q.push(v); + visited.insert(v); + } + } + } + + return visited.size() >= limit; +} } // namespace rouing diff --git a/routing/routing_tests/index_graph_test.cpp b/routing/routing_tests/index_graph_test.cpp index ef92644d38..828ba533ec 100644 --- a/routing/routing_tests/index_graph_test.cpp +++ b/routing/routing_tests/index_graph_test.cpp @@ -218,19 +218,19 @@ UNIT_TEST(FindPathCross) uint32_t expectedLength = 0; if (start.GetFeatureId() == finish.GetFeatureId()) { - expectedLength = AbsDelta(start.GetSegmentIdx(), finish.GetSegmentIdx()) + 1; + expectedLength = AbsDelta(start.GetSegmentIdxForTesting(), finish.GetSegmentIdxForTesting()) + 1; } else { - if (start.GetSegmentIdx() < 2) - expectedLength += 2 - start.GetSegmentIdx(); + if (start.GetSegmentIdxForTesting() < 2) + expectedLength += 2 - start.GetSegmentIdxForTesting(); else - expectedLength += start.GetSegmentIdx() - 1; + expectedLength += start.GetSegmentIdxForTesting() - 1; - if (finish.GetSegmentIdx() < 2) - expectedLength += 2 - finish.GetSegmentIdx(); + if (finish.GetSegmentIdxForTesting() < 2) + expectedLength += 2 - finish.GetSegmentIdxForTesting(); else - expectedLength += finish.GetSegmentIdx() - 1; + expectedLength += finish.GetSegmentIdxForTesting() - 1; } TestRoute(start, finish, expectedLength, nullptr, *worldGraph); } @@ -303,7 +303,7 @@ UNIT_TEST(FindPathManhattan) if (start.GetFeatureId() < kCitySize == finish.GetFeatureId() < kCitySize) { - uint32_t segDelta = AbsDelta(start.GetSegmentIdx(), finish.GetSegmentIdx()); + uint32_t segDelta = AbsDelta(start.GetSegmentIdxForTesting(), finish.GetSegmentIdxForTesting()); if (segDelta == 0 && start.GetFeatureId() != finish.GetFeatureId()) segDelta = 1; expectedLength += segDelta; @@ -311,15 +311,15 @@ UNIT_TEST(FindPathManhattan) } else { - if (start.GetSegmentIdx() < finishFeatureOffset) - expectedLength += finishFeatureOffset - start.GetSegmentIdx(); + if (start.GetSegmentIdxForTesting() < finishFeatureOffset) + expectedLength += finishFeatureOffset - start.GetSegmentIdxForTesting(); else - expectedLength += start.GetSegmentIdx() - finishFeatureOffset + 1; + expectedLength += start.GetSegmentIdxForTesting() - finishFeatureOffset + 1; - if (finish.GetSegmentIdx() < startFeatureOffset) - expectedLength += startFeatureOffset - finish.GetSegmentIdx(); + if (finish.GetSegmentIdxForTesting() < startFeatureOffset) + expectedLength += startFeatureOffset - finish.GetSegmentIdxForTesting(); else - expectedLength += finish.GetSegmentIdx() - startFeatureOffset + 1; + expectedLength += finish.GetSegmentIdxForTesting() - startFeatureOffset + 1; } TestRoute(start, finish, expectedLength, nullptr, *worldGraph); From 9b1408346286246495f0ba6c2e4618a05047987a Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Tue, 2 May 2017 17:50:15 +0300 Subject: [PATCH 2/3] Review fixes. --- routing/index_graph_starter.hpp | 20 ++++---- routing/index_router.cpp | 55 +++++++++++----------- routing/index_router.hpp | 11 ++--- routing/road_graph.hpp | 4 +- routing/road_graph_router.cpp | 13 ++--- routing/routing_helpers.hpp | 34 ++++++------- routing/routing_tests/index_graph_test.cpp | 6 ++- routing/world_graph.hpp | 4 ++ 8 files changed, 77 insertions(+), 70 deletions(-) diff --git a/routing/index_graph_starter.hpp b/routing/index_graph_starter.hpp index e4caaef534..93e1edc6e4 100644 --- a/routing/index_graph_starter.hpp +++ b/routing/index_graph_starter.hpp @@ -17,33 +17,37 @@ class IndexGraphStarter final { public: // AStarAlgorithm types aliases: - using TVertexType = Segment; - using TEdgeType = SegmentEdge; + using TVertexType = WorldGraph::Vertex; + using TEdgeType = WorldGraph::Edge; class FakeVertex final { public: - 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) { } + FakeVertex(Segment const & segment, m2::PointD const & point) + : m_segment(segment), m_point(point) + { + } + NumMwmId GetMwmId() const { return m_segment.GetMwmId(); } uint32_t GetFeatureId() const { return m_segment.GetFeatureId(); } m2::PointD const & GetPoint() const { return m_point; } Segment GetSegmentWithDirection(bool forward) const { - return Segment(m_segment.GetMwmId(), m_segment.GetFeatureId(), m_segment.GetSegmentIdx(), forward); + return Segment(m_segment.GetMwmId(), m_segment.GetFeatureId(), m_segment.GetSegmentIdx(), + forward); } bool Fits(Segment const & segment) const { - return segment.GetMwmId() == m_segment.GetMwmId() && segment.GetFeatureId() == m_segment.GetFeatureId() && + // Note. Comparing |segment| and |m_segment| without field |Segment::m_forward|. + return segment.GetMwmId() == m_segment.GetMwmId() && + segment.GetFeatureId() == m_segment.GetFeatureId() && segment.GetSegmentIdx() == m_segment.GetSegmentIdx(); } diff --git a/routing/index_router.cpp b/routing/index_router.cpp index 34a49a6927..4ad1f2f411 100644 --- a/routing/index_router.cpp +++ b/routing/index_router.cpp @@ -36,22 +36,21 @@ size_t constexpr kMaxRoadCandidates = 6; float constexpr kProgressInterval = 2; uint32_t constexpr kDrawPointsPeriod = 10; -bool IsDeadEnd(Segment const & segment, bool fromPoint, WorldGraph & worldGraph) +bool IsDeadEnd(Segment const & segment, bool isOutgoing, 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(worldGraph, segment, kDeadEndTestLimit, - getVertexByEdgeFn, getOutgoingEdgesFn); + return !CheckGraphConnectivity(segment, kDeadEndTestLimit, worldGraph, + getVertexByEdgeFn, getOutgoingEdgesFn); } } // namespace @@ -137,25 +136,27 @@ 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(graph, startFile, startPoint, true /* fromPoint */, startEdge)) + if (!FindClosestEdge(startFile, startPoint, true /* isOutgoing */, graph, startEdge)) return IRouter::StartPointNotFound; Edge finishEdge; - if (!FindClosestEdge(graph, finishFile, finalPoint, false /* fromPoint */, finishEdge)) + if (!FindClosestEdge(finishFile, finalPoint, false /* isOutgoing */, graph, 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) @@ -213,10 +214,8 @@ IRouter::ResultCode IndexRouter::DoCalculateRoute(string const & startCountry, } } -bool IndexRouter::FindClosestEdge(WorldGraph & worldGraph, - platform::CountryFile const & file, - m2::PointD const & point, - bool fromPoint, +bool IndexRouter::FindClosestEdge(platform::CountryFile const & file, m2::PointD const & point, + bool isOutgoing, WorldGraph & worldGraph, Edge & closestEdge) const { MwmSet::MwmHandle handle = m_index.GetMwmHandleByCountryFile(file); @@ -236,7 +235,7 @@ bool IndexRouter::FindClosestEdge(WorldGraph & worldGraph, { 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, fromPoint, worldGraph)) + if (edge.GetFeatureId().m_mwmId != mwmId || IsDeadEnd(segment, isOutgoing, worldGraph)) continue; m2::DistanceToLineSquare squaredDistance; diff --git a/routing/index_router.hpp b/routing/index_router.hpp index 1bb8c00b40..43875f9352 100644 --- a/routing/index_router.hpp +++ b/routing/index_router.hpp @@ -71,13 +71,10 @@ private: RouterDelegate const & delegate, Route & route); /// \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; + /// \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; // 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.hpp b/routing/road_graph.hpp index 6fcc21a6c9..ccd0bff734 100644 --- a/routing/road_graph.hpp +++ b/routing/road_graph.hpp @@ -123,7 +123,9 @@ public: class IRoadGraph : public RoadGraphBase { public: - typedef vector TJunctionVector; + // CheckGraphConnectivity() types aliases: + using Vertex = Junction; + using Edge = routing::Edge; enum class Mode { diff --git a/routing/road_graph_router.cpp b/routing/road_graph_router.cpp index bcf8784ec9..52f059d7f3 100644 --- a/routing/road_graph_router.cpp +++ b/routing/road_graph_router.cpp @@ -81,15 +81,12 @@ 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(graph, edge.GetEndJunction(), kTestConnectivityVisitJunctionsLimit, - getVertexByEdgeFn, getOutgoingEdgesFn)) + if (CheckGraphConnectivity(edge.GetEndJunction(), kTestConnectivityVisitJunctionsLimit, + graph, getVertexByEdgeFn, getOutgoingEdgesFn)) { vicinity.emplace_back(candidate); diff --git a/routing/routing_helpers.hpp b/routing/routing_helpers.hpp index d8af77d25e..2633dd2ba7 100644 --- a/routing/routing_helpers.hpp +++ b/routing/routing_helpers.hpp @@ -33,37 +33,39 @@ void ReconstructRoute(IDirectionsEngine & engine, RoadGraphBase const & graph, shared_ptr const & trafficStash, my::Cancellable const & cancellable, 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 world graph. -template -bool CheckGraphConnectivity(Graph & graph, GraphVertex const & vertex, size_t limit, +/// \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 +/// world graph. +template +bool CheckGraphConnectivity(typename Graph::Vertex const & start, size_t limit, Graph & graph, GetVertexByEdgeFn && getVertexByEdgeFn, GetOutgoingEdgesFn && getOutgoingEdgesFn) { - queue q; - q.push(vertex); + queue q; + q.push(start); - set visited; - visited.insert(vertex); + set marked; + marked.insert(start); - vector edges; - while (!q.empty() && visited.size() < limit) + vector edges; + while (!q.empty() && marked.size() < limit) { - GraphVertex const u = q.front(); + auto const u = q.front(); q.pop(); edges.clear(); getOutgoingEdgesFn(graph, u, edges); - for (GraphEdge const edge : edges) + for (auto const & edge : edges) { - GraphVertex const & v = getVertexByEdgeFn(edge); - if (visited.count(v) == 0) + auto const & v = getVertexByEdgeFn(edge); + if (marked.count(v) == 0) { q.push(v); - visited.insert(v); + marked.insert(v); } } } - return visited.size() >= limit; + return marked.size() >= limit; } } // namespace rouing diff --git a/routing/routing_tests/index_graph_test.cpp b/routing/routing_tests/index_graph_test.cpp index 828ba533ec..e027dcf29f 100644 --- a/routing/routing_tests/index_graph_test.cpp +++ b/routing/routing_tests/index_graph_test.cpp @@ -218,7 +218,8 @@ 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 { @@ -303,7 +304,8 @@ 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; diff --git a/routing/world_graph.hpp b/routing/world_graph.hpp index 984cafe1f5..3846238154 100644 --- a/routing/world_graph.hpp +++ b/routing/world_graph.hpp @@ -17,6 +17,10 @@ namespace routing class WorldGraph final { public: + // CheckGraphConnectivity() types aliases: + using Vertex = Segment; + using Edge = SegmentEdge; + enum class Mode { SingleMwm, // Mode for building a route within single mwm. From 61ba332a02b7f4dd6b6207c02fe123a7a4fdcbac Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Wed, 3 May 2017 16:19:01 +0300 Subject: [PATCH 3/3] Review fixes. --- routing/index_graph_starter.cpp | 2 +- routing/index_router.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/routing/index_graph_starter.cpp b/routing/index_graph_starter.cpp index e222e17ddc..ab5516b455 100644 --- a/routing/index_graph_starter.cpp +++ b/routing/index_graph_starter.cpp @@ -87,7 +87,7 @@ void IndexGraphStarter::GetFakeToNormalEdges(FakeVertex const & fakeVertex, bool void IndexGraphStarter::GetFakeToNormalEdge(FakeVertex const & fakeVertex, bool forward, vector & edges) { - Segment const segment = fakeVertex.GetSegmentWithDirection(forward); + auto const segment = fakeVertex.GetSegmentWithDirection(forward); m2::PointD const & pointTo = GetPoint(segment, true /* front */); double const weight = m_graph.GetEstimator().CalcLeapWeight(fakeVertex.GetPoint(), pointTo); edges.emplace_back(segment, weight); diff --git a/routing/index_router.hpp b/routing/index_router.hpp index 43875f9352..037c9509b7 100644 --- a/routing/index_router.hpp +++ b/routing/index_router.hpp @@ -70,7 +70,7 @@ private: m2::PointD const & finalPoint, RouterDelegate const & delegate, Route & route); - /// \brief Finds closest edges which may be considered as start of finish of the 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,