diff --git a/pedestrian_routing_benchmarks/pedestrian_routing_test.cpp b/pedestrian_routing_benchmarks/pedestrian_routing_test.cpp index c47719486b..39efe56631 100644 --- a/pedestrian_routing_benchmarks/pedestrian_routing_test.cpp +++ b/pedestrian_routing_benchmarks/pedestrian_routing_test.cpp @@ -56,7 +56,8 @@ void TestTwoPoints(uint32_t featureIdStart, uint32_t segIdStart, uint32_t featur my::Timer timer; LOG(LINFO, ("Calculating routing...")); - router.CalculateM2MRoute(startPos, finalPos, route); + routing::IRouter::ResultCode resultCode = router.CalculateRouteM2M(startPos, finalPos, route); + CHECK_EQUAL(routing::IRouter::NoError, resultCode, ()); LOG(LINFO, ("Route length:", route.size())); LOG(LINFO, ("Elapsed:", timer.ElapsedSeconds(), "seconds")); } diff --git a/routing/astar_router.cpp b/routing/astar_router.cpp index 76bdac64dd..8004cd29ad 100644 --- a/routing/astar_router.cpp +++ b/routing/astar_router.cpp @@ -23,8 +23,9 @@ static double const kMaxSpeedMPS = 5000.0 / 3600; // // The vertices of the graph are of type RoadPos. // The edges of the graph are of type PossibleTurn. -void AStarRouter::CalculateM2MRoute(vector const & startPos, - vector const & finalPos, vector & route) +IRouter::ResultCode AStarRouter::CalculateRouteM2M(vector const & startPos, + vector const & finalPos, + vector & route) { #if defined(DEBUG) for (auto const & roadPos : finalPos) @@ -71,7 +72,7 @@ void AStarRouter::CalculateM2MRoute(vector const & startPos, if (isStartFeature && binary_search(sortedStartPos.begin(), sortedStartPos.end(), v.GetPos())) { ReconstructRoute(v.GetPos(), route); - return; + return IRouter::NoError; } IRoadGraph::TurnsVectorT turns; @@ -98,8 +99,7 @@ void AStarRouter::CalculateM2MRoute(vector const & startPos, queue.push(w); } } - - LOG(LDEBUG, ("No route found!")); + return IRouter::RouteNotFound; } double AStarRouter::HeuristicCostEstimate(Vertex const & v, vector const & goals) diff --git a/routing/astar_router.hpp b/routing/astar_router.hpp index 953ae2c535..95cd27a885 100644 --- a/routing/astar_router.hpp +++ b/routing/astar_router.hpp @@ -14,10 +14,12 @@ class AStarRouter : public RoadGraphRouter public: AStarRouter(Index const * pIndex = 0) : BaseT(pIndex) {} - virtual string GetName() const { return "pedestrian"; } - // TODO (Dragunov) ResultCode returning - void CalculateM2MRoute(vector const & startPos, vector const & finalPos, - vector & route) override; + // IRouter overrides: + string GetName() const override { return "pedestrian"; } + + // RoadGraphRouter overrides: + ResultCode CalculateRouteM2M(vector const & startPos, vector const & finalPos, + vector & route) override; protected: diff --git a/routing/dijkstra_router.cpp b/routing/dijkstra_router.cpp index 920b825988..df7f1aa877 100644 --- a/routing/dijkstra_router.cpp +++ b/routing/dijkstra_router.cpp @@ -9,8 +9,9 @@ namespace routing DijkstraRouter::ShortestPath const * const DijkstraRouter::ShortestPath::FINAL_POS = reinterpret_cast(1); -void DijkstraRouter::CalculateM2MRoute(vector const & startPos, - vector const & finalPos, vector & route) +IRouter::ResultCode DijkstraRouter::CalculateRouteM2M(vector const & startPos, + vector const & finalPos, + vector & route) { m_entries = PathSet(); m_queue = PossiblePathQueue(); @@ -62,7 +63,7 @@ void DijkstraRouter::CalculateM2MRoute(vector const & startPos, for (ShortestPath const * pE = pEntry; pE != ShortestPath::FINAL_POS; pE = pE->GetParentEntry()) route.push_back(pE->GetPos()); LOG(LDEBUG, (route)); - return; + return IRouter::NoError; } IRoadGraph::TurnsVectorT turns; @@ -81,9 +82,7 @@ void DijkstraRouter::CalculateM2MRoute(vector const & startPos, } } } - - LOG(LDEBUG, ("No route found!")); - // Route not found. + return IRouter::RouteNotFound; } diff --git a/routing/dijkstra_router.hpp b/routing/dijkstra_router.hpp index c7f48a31f4..4a86e61e21 100644 --- a/routing/dijkstra_router.hpp +++ b/routing/dijkstra_router.hpp @@ -19,9 +19,12 @@ class DijkstraRouter : public RoadGraphRouter public: DijkstraRouter(Index const * pIndex = 0) : BaseT(pIndex) {} - virtual string GetName() const { return "routeme"; } - virtual void CalculateM2MRoute(vector const & startPos, vector const & finalPos, - vector & route); + // IRouter overrides: + string GetName() const override { return "routeme"; } + + // RoadGraphRouter overrides: + ResultCode CalculateRouteM2M(vector const & startPos, vector const & finalPos, + vector & route) override; private: class ShortestPath diff --git a/routing/road_graph_router.cpp b/routing/road_graph_router.cpp index bba292cc7a..3297ba87a9 100644 --- a/routing/road_graph_router.cpp +++ b/routing/road_graph_router.cpp @@ -131,12 +131,12 @@ IRouter::ResultCode RoadGraphRouter::CalculateRoute(m2::PointD const & startPoin vector routePos; - CalculateM2MRoute(startPos, finalPos, routePos); + IRouter::ResultCode resultCode = CalculateRouteM2M(startPos, finalPos, routePos); - LOG(LINFO, ("Route calculation time: ", timer.ElapsedSeconds())); + LOG(LINFO, ("Route calculation time:", timer.ElapsedSeconds(), "result code:", resultCode)); m_pRoadGraph->ReconstructPath(routePos, route); - return NoError; + return resultCode; } } // namespace routing diff --git a/routing/road_graph_router.hpp b/routing/road_graph_router.hpp index 4fc94ce9ab..fff6d43a7e 100644 --- a/routing/road_graph_router.hpp +++ b/routing/road_graph_router.hpp @@ -22,12 +22,12 @@ public: RoadGraphRouter(Index const * pIndex); ~RoadGraphRouter(); - virtual void CalculateM2MRoute(vector const & startPos, vector const & finalPos, - vector & route) = 0; - virtual void SetRoadGraph(IRoadGraph * pRoadGraph) { m_pRoadGraph.reset(pRoadGraph); } - ResultCode CalculateRoute(m2::PointD const & startPoint, m2::PointD const & startDirection, m2::PointD const & finalPoint, Route & route) override; + virtual ResultCode CalculateRouteM2M(vector const & startPos, + vector const & finalPos, + vector & route) = 0; + virtual void SetRoadGraph(IRoadGraph * pRoadGraph) { m_pRoadGraph.reset(pRoadGraph); } protected: size_t GetRoadPos(m2::PointD const & pt, vector & pos); diff --git a/routing/routing_tests/astar_router_test.cpp b/routing/routing_tests/astar_router_test.cpp index e410fa52e9..e176b6df78 100644 --- a/routing/routing_tests/astar_router_test.cpp +++ b/routing/routing_tests/astar_router_test.cpp @@ -29,18 +29,17 @@ void TestAStarRouterMock(RoadPos (&finalPos)[finalPosSize], AStarRouter router; router.SetRoadGraph(graph); vector result; - router.CalculateM2MRoute(vector(&startPos[0], &startPos[0] + ARRAY_SIZE(startPos)), - vector(&finalPos[0], &finalPos[0] + ARRAY_SIZE(finalPos)), - result); + IRouter::ResultCode resultCode = router.CalculateRouteM2M( + vector(&startPos[0], &startPos[0] + ARRAY_SIZE(startPos)), + vector(&finalPos[0], &finalPos[0] + ARRAY_SIZE(finalPos)), result); + TEST_EQUAL(IRouter::NoError, resultCode, ()); TEST_EQUAL(vector(&expected[0], &expected[0] + ARRAY_SIZE(expected)), result, ()); } // Use mwm features graph source. template -void TestAStarRouterMWM(RoadPos (&finalPos)[finalPosSize], - RoadPos (&startPos)[startPosSize], - RoadPos (&expected)[expectedSize], - size_t pointsCount) +void TestAStarRouterMWM(RoadPos(&finalPos)[finalPosSize], RoadPos(&startPos)[startPosSize], + RoadPos(&expected)[expectedSize], size_t pointsCount) { FeatureRoadGraphTester tester("route_test2.mwm"); @@ -54,7 +53,8 @@ void TestAStarRouterMWM(RoadPos (&finalPos)[finalPosSize], tester.Name2FeatureID(startV); vector result; - router.CalculateM2MRoute(startV, finalV, result); + IRouter::ResultCode resultCode = router.CalculateRouteM2M(startV, finalV, result); + TEST_EQUAL(IRouter::NoError, resultCode, ()); LOG(LDEBUG, (result)); Route route(router.GetName()); @@ -66,7 +66,6 @@ void TestAStarRouterMWM(RoadPos (&finalPos)[finalPosSize], TEST_EQUAL(vector(&expected[0], &expected[0] + ARRAY_SIZE(expected)), result, ()); } - UNIT_TEST(AStar_Router_City_Simple) { classificator::Load(); diff --git a/routing/routing_tests/dijkstra_router_test.cpp b/routing/routing_tests/dijkstra_router_test.cpp index ad2ea1da41..740cfe1e50 100644 --- a/routing/routing_tests/dijkstra_router_test.cpp +++ b/routing/routing_tests/dijkstra_router_test.cpp @@ -31,9 +31,10 @@ void TestDijkstraRouterMock(RoadPos (&finalPos)[finalPosSize], router.SetRoadGraph(graph); vector result; - router.CalculateM2MRoute(vector(&startPos[0], &startPos[0] + ARRAY_SIZE(startPos)), - vector(&finalPos[0], &finalPos[0] + ARRAY_SIZE(finalPos)), - result); + IRouter::ResultCode resultCode = router.CalculateRouteM2M( + vector(&startPos[0], &startPos[0] + ARRAY_SIZE(startPos)), + vector(&finalPos[0], &finalPos[0] + ARRAY_SIZE(finalPos)), result); + TEST_EQUAL(IRouter::NoError, resultCode, ()); TEST_EQUAL(vector(&expected[0], &expected[0] + ARRAY_SIZE(expected)), result, ()); } @@ -56,7 +57,8 @@ void TestDijkstraRouterMWM(RoadPos (&finalPos)[finalPosSize], tester.Name2FeatureID(startV); vector result; - router.CalculateM2MRoute(startV, finalV, result); + IRouter::ResultCode resultCode = router.CalculateRouteM2M(startV, finalV, result); + TEST_EQUAL(IRouter::NoError, resultCode, ()); LOG(LDEBUG, (result)); Route route(router.GetName());