From 131a3e3218ca46be423529642fa265bc001551c9 Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Thu, 25 May 2017 08:28:18 +0300 Subject: [PATCH] Review fixes. --- routing/index_router.cpp | 34 +++++++++++++++++----- routing/index_router.hpp | 26 ++++------------- routing/routing_tests/index_graph_test.cpp | 2 +- 3 files changed, 33 insertions(+), 29 deletions(-) diff --git a/routing/index_router.cpp b/routing/index_router.cpp index c2cf0bdf6a..68ff22163e 100644 --- a/routing/index_router.cpp +++ b/routing/index_router.cpp @@ -1,5 +1,6 @@ #include "routing/index_router.hpp" +#include "routing/base/astar_algorithm.hpp" #include "routing/base/astar_progress.hpp" #include "routing/bicycle_directions.hpp" #include "routing/index_graph.hpp" @@ -35,6 +36,24 @@ size_t constexpr kMaxRoadCandidates = 6; float constexpr kProgressInterval = 2; uint32_t constexpr kDrawPointsPeriod = 10; +template +IRouter::ResultCode FindPath( + typename Graph::TVertexType const & start, typename Graph::TVertexType const & finish, + RouterDelegate const & delegate, Graph & graph, + typename AStarAlgorithm::TOnVisitedVertexCallback const & onVisitedVertexCallback, + RoutingResult & routingResult) +{ + AStarAlgorithm algorithm; + auto const resultCode = algorithm.FindPathBidirectional(graph, start, finish, routingResult, + delegate, onVisitedVertexCallback); + switch (resultCode) + { + case AStarAlgorithm::Result::NoPath: return IRouter::RouteNotFound; + case AStarAlgorithm::Result::Cancelled: return IRouter::Cancelled; + case AStarAlgorithm::Result::OK: return IRouter::NoError; + } +} + bool IsDeadEnd(Segment const & segment, bool isOutgoing, WorldGraph & worldGraph) { size_t constexpr kDeadEndTestLimit = 50; @@ -235,7 +254,7 @@ IRouter::ResultCode IndexRouter::DoCalculateRoute(string const & startCountry, vector segments; IRouter::ResultCode const leapsResult = - ProcessLeaps(routingResult.path, delegate, starter, segments); + ProcessLeaps(routingResult.path, delegate, mode, starter, segments); if (leapsResult != IRouter::NoError) return leapsResult; @@ -292,20 +311,21 @@ bool IndexRouter::FindClosestEdge(platform::CountryFile const & file, m2::PointD IRouter::ResultCode IndexRouter::ProcessLeaps(vector const & input, RouterDelegate const & delegate, - IndexGraphStarter & starter, vector & output) + WorldGraph::Mode prevMode, + IndexGraphStarter & starter, + vector & output) { output.reserve(input.size()); WorldGraph & worldGraph = starter.GetGraph(); - WorldGraph::Mode const worldRouteMode = worldGraph.GetMode(); worldGraph.SetMode(WorldGraph::Mode::NoLeaps); for (size_t i = 0; i < input.size(); ++i) { Segment const & current = input[i]; - if ((worldRouteMode == WorldGraph::Mode::LeapsOnly && IndexGraphStarter::IsFakeSegment(current)) - || (worldRouteMode != WorldGraph::Mode::LeapsOnly && !starter.IsLeap(current.GetMwmId()))) + if ((prevMode == WorldGraph::Mode::LeapsOnly && IndexGraphStarter::IsFakeSegment(current)) + || (prevMode != WorldGraph::Mode::LeapsOnly && !starter.IsLeap(current.GetMwmId()))) { output.push_back(current); continue; @@ -327,10 +347,10 @@ IRouter::ResultCode IndexRouter::ProcessLeaps(vector const & input, IRouter::ResultCode result = IRouter::InternalError; RoutingResult routingResult; // In case of leaps from the start to its mwm transition and from finish mwm transition - // Route calculation should be made on the world graph (WorldGraph::Mode::NoLeaps). + // route calculation should be made on the world graph (WorldGraph::Mode::NoLeaps). if ((current.GetMwmId() == starter.GetStartVertex().GetMwmId() || current.GetMwmId() == starter.GetFinishVertex().GetMwmId()) - && worldRouteMode == WorldGraph::Mode::LeapsOnly) + && prevMode == WorldGraph::Mode::LeapsOnly) { // World graph route. result = FindPath(current, next, delegate, worldGraph, {} /* onVisitedVertexCallback */, routingResult); diff --git a/routing/index_router.hpp b/routing/index_router.hpp index 69343a6c0e..7770d4ab4b 100644 --- a/routing/index_router.hpp +++ b/routing/index_router.hpp @@ -1,6 +1,5 @@ #pragma once -#include "routing/base/astar_algorithm.hpp" #include "routing/cross_mwm_graph.hpp" #include "routing/directions_engine.hpp" #include "routing/edge_estimator.hpp" @@ -78,29 +77,14 @@ private: 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, - IndexGraphStarter & starter, vector & output); + IRouter::ResultCode ProcessLeaps(vector const & input, + RouterDelegate const & delegate, + WorldGraph::Mode prevMode, + IndexGraphStarter & starter, + vector & output); bool RedressRoute(vector const & segments, RouterDelegate const & delegate, bool forSingleMwm, IndexGraphStarter & starter, Route & route) const; - template - IRouter::ResultCode FindPath( - typename Graph::TVertexType const & start, typename Graph::TVertexType const & finish, - RouterDelegate const & delegate, Graph & graph, - typename AStarAlgorithm::TOnVisitedVertexCallback const & onVisitedVertexCallback, - RoutingResult & routingResult) - { - AStarAlgorithm algorithm; - auto const resultCode = algorithm.FindPathBidirectional(graph, start, finish, routingResult, - delegate, onVisitedVertexCallback); - switch (resultCode) - { - case AStarAlgorithm::Result::NoPath: return IRouter::RouteNotFound; - case AStarAlgorithm::Result::Cancelled: return IRouter::Cancelled; - case AStarAlgorithm::Result::OK: return IRouter::NoError; - } - } - bool AreMwmsNear(NumMwmId startId, NumMwmId finishId) const; string const m_name; diff --git a/routing/routing_tests/index_graph_test.cpp b/routing/routing_tests/index_graph_test.cpp index 0dd7702792..86eae175ac 100644 --- a/routing/routing_tests/index_graph_test.cpp +++ b/routing/routing_tests/index_graph_test.cpp @@ -375,7 +375,7 @@ UNIT_TEST(OneSegmentWay) IndexGraphStarter::FakeVertex const start(kTestNumMwmId, 0, 0, m2::PointD(1, 0)); IndexGraphStarter::FakeVertex const finish(kTestNumMwmId, 0, 0, m2::PointD(2, 0)); - // According to picture above it seems that direction of route segment should be true but it's false + // According to picture below it seems that direction of route segment should be true but it's false // according to current code. The reason is the start and the finish of the route are projected to // the same segment. In IndexGraphStarter::GetEdgesList() two fake edges are added. One of them // from start to end of the segment. The other one is from beginning of the segment to the finish.