diff --git a/routing/async_router.cpp b/routing/async_router.cpp index adc47afb133..c6f06627104 100644 --- a/routing/async_router.cpp +++ b/routing/async_router.cpp @@ -398,7 +398,7 @@ void AsyncRouter::CalculateRoute() absentFetcher->GenerateRequest(checkpoints); // Run basic request. - code = router->CalculateRoute(checkpoints, startDirection, adjustToPrevRoute, + code = router->CalculateRoute(checkpoints, startDirection, true /* useTwoThreads */, adjustToPrevRoute, delegateProxy->GetDelegate(), *route); router->SetGuides({}); elapsedSec = timer.ElapsedSeconds(); // routing time diff --git a/routing/base/astar_algorithm.hpp b/routing/base/astar_algorithm.hpp index 0265bcf7677..0595f9cd689 100644 --- a/routing/base/astar_algorithm.hpp +++ b/routing/base/astar_algorithm.hpp @@ -222,11 +222,10 @@ class AStarAlgorithm /// If the decision is made to use two thread version it should be taken into account: /// - |isOutgoing| flag in each method specified which thread calls the method /// - All callbacks which are called from |wave| lambda such as |params.m_onVisitedVertexCallback| - /// or |params.m_checkLengthCallback| should be ready for calling from two threads + /// or |params.m_checkLengthCallback| should be ready for calling from two threads. template Result FindPathBidirectional(P & params, RoutingResult & result) const; - // Adjust route to the previous one. // Expects |params.m_checkLengthCallback| to check wave propagation limit. template @@ -630,6 +629,8 @@ AStarAlgorithm::FindPathBidirectional(P & params, auto const & startVertex = params.m_startVertex; auto const useTwoThreads = graph.IsTwoThreadsReady(); + LOG(LINFO, + (useTwoThreads ? "Bidirectional A* in two threads." : "Bidirectional A* in one thread.")); std::optional mtx; BidirectionalStepContext forward(mtx, true /* forward */, startVertex, finalVertex, graph); diff --git a/routing/index_router.cpp b/routing/index_router.cpp index 57acb2775ff..450e050ce62 100644 --- a/routing/index_router.cpp +++ b/routing/index_router.cpp @@ -367,7 +367,7 @@ bool IndexRouter::FindClosestProjectionToRoad(m2::PointD const & point, void IndexRouter::SetGuides(GuidesTracks && guides) { m_guides = GuidesConnections(guides); } RouterResultCode IndexRouter::CalculateRoute(Checkpoints const & checkpoints, - m2::PointD const & startDirection, + m2::PointD const & startDirection, bool useTwoThreads, bool adjustToPrevRoute, RouterDelegate const & delegate, Route & route) { @@ -407,19 +407,7 @@ RouterResultCode IndexRouter::CalculateRoute(Checkpoints const & checkpoints, } } - RouterResultCode lastReturn = RouterResultCode::InternalError; - for (auto twoThreadsReady : {false, true, true, false}) - { - LOG(LINFO, ("---------------------", twoThreadsReady ? "Two threads" : "One threads", "---------------------")); - // TODO |twoThreadsReady| is passed to DoCalculateRoute(), CalculateSubroute() and - // to CalculateSubrouteJointsMode() for test purposes only. It should be removed in - // these methods. - m_guides.Clear(); - lastReturn = DoCalculateRoute(checkpoints, startDirection, delegate, twoThreadsReady, route); - LOG(LINFO, ("---------------------", twoThreadsReady ? "Two threads" : "One threads", "END---------------------")); - } -// return DoCalculateRoute(checkpoints, startDirection, delegate, false, route); - return lastReturn; + return DoCalculateRoute(checkpoints, startDirection, delegate, useTwoThreads, route); } catch (RootException const & e) { @@ -565,7 +553,7 @@ void IndexRouter::AddGuidesOsmConnectionsToGraphStarter(size_t checkpointIdxFrom RouterResultCode IndexRouter::DoCalculateRoute(Checkpoints const & checkpoints, m2::PointD const & startDirection, RouterDelegate const & delegate, - bool twoThreadsReady, Route & route) + bool useTwoThreads, Route & route) { m_lastRoute.reset(); // MwmId used for guides segments in RedressRoute(). @@ -598,7 +586,7 @@ RouterResultCode IndexRouter::DoCalculateRoute(Checkpoints const & checkpoints, return RouterResultCode::NeedMoreMaps; TrafficStash::Guard guard(m_trafficStash); - unique_ptr graph = MakeWorldGraph(twoThreadsReady); + unique_ptr graph = MakeWorldGraph(useTwoThreads); vector segments; diff --git a/routing/index_router.hpp b/routing/index_router.hpp index 93b76f2a34d..543b462ebb9 100644 --- a/routing/index_router.hpp +++ b/routing/index_router.hpp @@ -97,8 +97,9 @@ class IndexRouter : public IRouter void SetGuides(GuidesTracks && guides) override; RouterResultCode CalculateRoute(Checkpoints const & checkpoints, - m2::PointD const & startDirection, bool adjustToPrevRoute, - RouterDelegate const & delegate, Route & route) override; + m2::PointD const & startDirection, bool useTwoThreads, + bool adjustToPrevRoute, RouterDelegate const & delegate, + Route & route) override; bool FindClosestProjectionToRoad(m2::PointD const & point, m2::PointD const & direction, double radius, EdgeProj & proj) override; @@ -122,7 +123,7 @@ class IndexRouter : public IRouter RouterResultCode DoCalculateRoute(Checkpoints const & checkpoints, m2::PointD const & startDirection, - RouterDelegate const & delegate, bool twoThreadsReady, + RouterDelegate const & delegate, bool useTwoThreads, Route & route); RouterResultCode CalculateSubroute(Checkpoints const & checkpoints, size_t subrouteIdx, RouterDelegate const & delegate, diff --git a/routing/router.hpp b/routing/router.hpp index 73c76ebc5b6..3f03f95d81b 100644 --- a/routing/router.hpp +++ b/routing/router.hpp @@ -79,8 +79,9 @@ class IRouter /// @return ResultCode error code or NoError if route was initialised /// @see Cancellable virtual RouterResultCode CalculateRoute(Checkpoints const & checkpoints, - m2::PointD const & startDirection, bool adjust, - RouterDelegate const & delegate, Route & route) = 0; + m2::PointD const & startDirection, bool useTwoThreads, + bool adjust, RouterDelegate const & delegate, + Route & route) = 0; virtual bool FindClosestProjectionToRoad(m2::PointD const & point, m2::PointD const & direction, double radius, EdgeProj & proj) = 0; diff --git a/routing/routes_builder/routes_builder.cpp b/routing/routes_builder/routes_builder.cpp index 0e71515479b..36757d7ada9 100644 --- a/routing/routes_builder/routes_builder.cpp +++ b/routing/routes_builder/routes_builder.cpp @@ -302,7 +302,8 @@ RoutesBuilder::Processor::operator()(Params const & params) m_delegate->SetTimeout(params.m_timeoutSeconds); base::Timer timer; resultCode = m_router->CalculateRoute(params.m_checkpoints, m2::PointD::Zero(), - false /* adjustToPrevRoute */, *m_delegate, route); + false /* useTwoThreads */, false /* adjustToPrevRoute */, + *m_delegate, route); if (resultCode != RouterResultCode::NoError) break; diff --git a/routing/routing_benchmarks/helpers.cpp b/routing/routing_benchmarks/helpers.cpp index 6f8e8ceb34f..5a16bb829bb 100644 --- a/routing/routing_benchmarks/helpers.cpp +++ b/routing/routing_benchmarks/helpers.cpp @@ -154,9 +154,9 @@ void TestRouter(routing::IRouter & router, m2::PointD const & startPos, routing::RouterDelegate delegate; LOG(LINFO, ("Calculating routing ...", router.GetName())); base::Timer timer; - auto const resultCode = router.CalculateRoute(routing::Checkpoints(startPos, finalPos), - m2::PointD::Zero() /* startDirection */, - false /* adjust */, delegate, route); + auto const resultCode = router.CalculateRoute( + routing::Checkpoints(startPos, finalPos), m2::PointD::Zero() /* startDirection */, + false /* useTwoThreads */, false /* adjust */, delegate, route); double const elapsedSec = timer.ElapsedSeconds(); TEST_EQUAL(routing::RouterResultCode::NoError, resultCode, ()); TEST(route.IsValid(), ()); diff --git a/routing/routing_integration_tests/routing_test_tools.cpp b/routing/routing_integration_tests/routing_test_tools.cpp index eca84aaebd0..d8665ab4dda 100644 --- a/routing/routing_integration_tests/routing_test_tools.cpp +++ b/routing/routing_integration_tests/routing_test_tools.cpp @@ -153,12 +153,13 @@ IRouterComponents & GetVehicleComponents(VehicleType vehicleType) TRouteResult CalculateRoute(IRouterComponents const & routerComponents, m2::PointD const & startPoint, m2::PointD const & startDirection, - m2::PointD const & finalPoint) + m2::PointD const & finalPoint, bool useTwoThreads /* = false */) { RouterDelegate delegate; shared_ptr route = make_shared("mapsme", 0 /* route id */); RouterResultCode result = routerComponents.GetRouter().CalculateRoute( - Checkpoints(startPoint, finalPoint), startDirection, false /* adjust */, delegate, *route); + Checkpoints(startPoint, finalPoint), startDirection, useTwoThreads, false /* adjust */, + delegate, *route); ASSERT(route, ()); routerComponents.GetRouter().SetGuides({}); return TRouteResult(route, result); @@ -171,7 +172,8 @@ TRouteResult CalculateRoute(IRouterComponents const & routerComponents, shared_ptr route = make_shared("mapsme", 0 /* route id */); routerComponents.GetRouter().SetGuides(move(guides)); RouterResultCode result = routerComponents.GetRouter().CalculateRoute( - checkpoints, m2::PointD::Zero() /* startDirection */, false /* adjust */, delegate, *route); + checkpoints, m2::PointD::Zero() /* startDirection */, false /* useTwoThreads */, + false /* adjust */, delegate, *route); ASSERT(route, ()); routerComponents.GetRouter().SetGuides({}); return TRouteResult(route, result); diff --git a/routing/routing_integration_tests/routing_test_tools.hpp b/routing/routing_integration_tests/routing_test_tools.hpp index e25de08bf7e..fcf09ddb560 100644 --- a/routing/routing_integration_tests/routing_test_tools.hpp +++ b/routing/routing_integration_tests/routing_test_tools.hpp @@ -108,7 +108,7 @@ IRouterComponents & GetVehicleComponents(VehicleType vehicleType); TRouteResult CalculateRoute(IRouterComponents const & routerComponents, m2::PointD const & startPoint, m2::PointD const & startDirection, - m2::PointD const & finalPoint); + m2::PointD const & finalPoint, bool useTwoThreads = false); TRouteResult CalculateRoute(IRouterComponents const & routerComponents, Checkpoints const & checkpoints, GuidesTracks && guides); diff --git a/routing/routing_tests/async_router_test.cpp b/routing/routing_tests/async_router_test.cpp index 0d0cf7b840b..bb6af047eeb 100644 --- a/routing/routing_tests/async_router_test.cpp +++ b/routing/routing_tests/async_router_test.cpp @@ -37,9 +37,10 @@ class DummyRouter : public IRouter // IRouter overrides: string GetName() const override { return "Dummy"; } void SetGuides(GuidesTracks && /* guides */) override {} - RouterResultCode CalculateRoute(Checkpoints const & checkpoints, m2::PointD const & startDirection, - bool adjustToPrevRoute, RouterDelegate const & delegate, - Route & route) override + RouterResultCode CalculateRoute(Checkpoints const & checkpoints, + m2::PointD const & startDirection, bool useTwoThreads, + bool adjustToPrevRoute, RouterDelegate const & delegate, + Route & route) override { route = Route("dummy", checkpoints.GetPoints().cbegin(), checkpoints.GetPoints().cend(), 0 /* route id */); diff --git a/routing/routing_tests/routing_session_test.cpp b/routing/routing_tests/routing_session_test.cpp index 206c1cf204e..4ea1db84ddc 100644 --- a/routing/routing_tests/routing_session_test.cpp +++ b/routing/routing_tests/routing_session_test.cpp @@ -58,9 +58,8 @@ class DummyRouter : public IRouter void ClearState() override {} void SetGuides(GuidesTracks && /* guides */) override {} - RouterResultCode CalculateRoute(Checkpoints const & /* checkpoints */, - m2::PointD const & /* startDirection */, bool /* adjust */, - RouterDelegate const & /* delegate */, Route & route) override + RouterResultCode CalculateRoute(Checkpoints const & /* checkpoints */, m2::PointD const & /* startDirection */, bool /* useTwoThreads */, + bool /* adjust */, RouterDelegate const & /* delegate */, Route & route) override { ++m_buildCount; route = m_route; @@ -90,8 +89,9 @@ class ReturnCodesRouter : public IRouter void SetGuides(GuidesTracks && /* guides */) override {} RouterResultCode CalculateRoute(Checkpoints const & /* checkpoints */, - m2::PointD const & /* startDirection */, bool /* adjust */, - RouterDelegate const & /* delegate */, Route & route) override + m2::PointD const & /* startDirection */, bool /* useTwoThreads */, + bool /* adjust */, RouterDelegate const & /* delegate */, + Route & route) override { TEST_LESS(m_returnCodesIdx, m_returnCodes.size(), ()); route = Route(GetName(), m_route.begin(), m_route.end(), 0 /* route id */);