From a3a92aa9bac2d29a2c31ff34adb2492cb99f3084 Mon Sep 17 00:00:00 2001 From: Viktor Govako Date: Sat, 14 May 2022 10:34:12 +0300 Subject: [PATCH] [routing] Removed dummy 'prevRoute' param. Signed-off-by: Viktor Govako --- routing/base/astar_algorithm.hpp | 15 ++++++--------- routing/index_router.cpp | 12 ++++++------ routing/regions_router.cpp | 2 +- .../routing_tests/astar_algorithm_test.cpp | 19 +++++++++---------- routing/routing_tests/index_graph_tools.cpp | 9 +++------ routing/routing_tests/routing_algorithm.cpp | 3 +-- 6 files changed, 26 insertions(+), 34 deletions(-) diff --git a/routing/base/astar_algorithm.hpp b/routing/base/astar_algorithm.hpp index 344c236dce..7c5b4bb9bb 100644 --- a/routing/base/astar_algorithm.hpp +++ b/routing/base/astar_algorithm.hpp @@ -71,11 +71,10 @@ public: struct ParamsBase { ParamsBase(Graph & graph, Vertex const & startVertex, Vertex const & finalVertex, - std::vector const * prevRoute, base::Cancellable const & cancellable) + base::Cancellable const & cancellable) : m_graph(graph) , m_startVertex(startVertex) , m_finalVertex(finalVertex) - , m_prevRoute(prevRoute) , m_cancellable(cancellable) { } @@ -86,7 +85,6 @@ public: // Used for FindPath, FindPathBidirectional. Vertex const m_finalVertex; // Used for AdjustRoute. - std::vector const * const m_prevRoute; base::Cancellable const & m_cancellable; std::function m_badReducedWeight = [](Weight, Weight) { return true; }; }; @@ -99,10 +97,10 @@ public: struct Params : public ParamsBase { Params(Graph & graph, Vertex const & startVertex, Vertex const & finalVertex, - std::vector const * prevRoute, base::Cancellable const & cancellable, + base::Cancellable const & cancellable, Visitor && onVisitedVertexCallback = astar::DefaultVisitor(), LengthChecker && checkLengthCallback = astar::DefaultLengthChecker()) - : ParamsBase(graph, startVertex, finalVertex, prevRoute, cancellable) + : ParamsBase(graph, startVertex, finalVertex, cancellable) , m_onVisitedVertexCallback(std::forward(onVisitedVertexCallback)) , m_checkLengthCallback(std::forward(checkLengthCallback)) { @@ -116,9 +114,8 @@ public: struct ParamsForTests : public ParamsBase { ParamsForTests(Graph & graph, Vertex const & startVertex, Vertex const & finalVertex, - std::vector const * prevRoute, LengthChecker && checkLengthCallback = astar::DefaultLengthChecker()) - : ParamsBase(graph, startVertex, finalVertex, prevRoute, m_dummy) + : ParamsBase(graph, startVertex, finalVertex, m_dummy) , m_checkLengthCallback(std::forward(checkLengthCallback)) { } @@ -217,6 +214,7 @@ public: // Expects |params.m_checkLengthCallback| to check wave propagation limit. template typename AStarAlgorithm::Result AdjustRoute(P & params, + std::vector const & prevRoute, RoutingResult & result) const; private: @@ -722,12 +720,11 @@ template template typename AStarAlgorithm::Result AStarAlgorithm::AdjustRoute(P & params, + std::vector const & prevRoute, RoutingResult & result) const { auto & graph = params.m_graph; auto const & startVertex = params.m_startVertex; - auto const & prevRoute = *params.m_prevRoute; - CHECK(!prevRoute.empty(), ()); result.Clear(); diff --git a/routing/index_router.cpp b/routing/index_router.cpp index bc37b851cb..8ece66e6eb 100644 --- a/routing/index_router.cpp +++ b/routing/index_router.cpp @@ -742,7 +742,7 @@ RouterResultCode IndexRouter::CalculateSubrouteJointsMode( AStarAlgorithm::Params params( jointStarter, jointStarter.GetStartJoint(), jointStarter.GetFinishJoint(), - nullptr /* prevRoute */, delegate.GetCancellable(), move(visitor), + delegate.GetCancellable(), move(visitor), AStarLengthChecker(starter)); RoutingResult routingResult; @@ -769,7 +769,7 @@ RouterResultCode IndexRouter::CalculateSubrouteNoLeapsMode( Visitor visitor(starter, delegate, kVisitPeriod, progress); AStarAlgorithm::Params params( - starter, starter.GetStartSegment(), starter.GetFinishSegment(), nullptr /* prevRoute */, + starter, starter.GetStartSegment(), starter.GetFinishSegment(), delegate.GetCancellable(), move(visitor), AStarLengthChecker(starter)); RoutingResult routingResult; @@ -804,7 +804,7 @@ RouterResultCode IndexRouter::CalculateSubrouteLeapsOnlyMode( AStarAlgorithm::Params params( leapsGraph, leapsGraph.GetStartSegment(), leapsGraph.GetFinishSegment(), - nullptr /* prevRoute */, delegate.GetCancellable(), move(visitor), + delegate.GetCancellable(), move(visitor), AStarLengthChecker(starter)); params.m_badReducedWeight = [](Weight const &, Weight const &) @@ -892,12 +892,12 @@ RouterResultCode IndexRouter::AdjustRoute(Checkpoints const & checkpoints, AStarAlgorithm algorithm; AStarAlgorithm::Params params( - starter, starter.GetStartSegment(), {} /* finalVertex */, &prevEdges, + starter, starter.GetStartSegment(), {} /* finalVertex */, delegate.GetCancellable(), move(visitor), AdjustLengthChecker(starter)); RoutingResult result; auto const resultCode = - ConvertResult(algorithm.AdjustRoute(params, result)); + ConvertResult(algorithm.AdjustRoute(params, prevEdges, result)); if (resultCode != RouterResultCode::NoError) return resultCode; @@ -1367,7 +1367,7 @@ RouterResultCode IndexRouter::ProcessLeapsJoints(vector const & input, AStarAlgorithm::Params params( jointStarter, jointStarter.GetStartJoint(), jointStarter.GetFinishJoint(), - nullptr /* prevRoute */, delegate.GetCancellable(), move(visitor), + delegate.GetCancellable(), move(visitor), AStarLengthChecker(starter)); resultCode = FindPath(params, mwmIds, routingResult); diff --git a/routing/regions_router.cpp b/routing/regions_router.cpp index 557e1ea054..aa1bde0b25 100644 --- a/routing/regions_router.cpp +++ b/routing/regions_router.cpp @@ -60,7 +60,7 @@ RouterResultCode RegionsRouter::CalculateSubrouteNoLeapsMode(IndexGraphStarter & Visitor visitor(starter, m_delegate, kVisitPeriod, progress); AStarAlgorithm::Params params( - starter, starter.GetStartSegment(), starter.GetFinishSegment(), nullptr /* prevRoute */, + starter, starter.GetStartSegment(), starter.GetFinishSegment(), m_delegate.GetCancellable(), std::move(visitor), AStarLengthChecker(starter)); params.m_badReducedWeight = [](Weight const & reduced, Weight const & current) diff --git a/routing/routing_tests/astar_algorithm_test.cpp b/routing/routing_tests/astar_algorithm_test.cpp index 0c9ed4edea..4a7ecc50f5 100644 --- a/routing/routing_tests/astar_algorithm_test.cpp +++ b/routing/routing_tests/astar_algorithm_test.cpp @@ -22,8 +22,7 @@ void TestAStar(UndirectedGraph & graph, vector const & expectedRoute, { Algorithm algo; - Algorithm::ParamsForTests<> params(graph, 0u /* startVertex */, 4u /* finishVertex */, - nullptr /* prevRoute */); + Algorithm::ParamsForTests<> params(graph, 0u /* startVertex */, 4u /* finishVertex */); RoutingResult actualRoute; TEST_EQUAL(Algorithm::Result::OK, algo.FindPath(params, actualRoute), ()); @@ -66,7 +65,7 @@ UNIT_TEST(AStarAlgorithm_CheckLength) auto checkLength = [](double weight) { return weight < 23; }; Algorithm algo; Algorithm::ParamsForTests params( - graph, 0u /* startVertex */, 4u /* finishVertex */, nullptr /* prevRoute */, + graph, 0u /* startVertex */, 4u /* finishVertex */, move(checkLength)); RoutingResult routingResult; @@ -97,10 +96,10 @@ UNIT_TEST(AdjustRoute) auto checkLength = [](double weight) { return weight <= 1.0; }; Algorithm algo; Algorithm::ParamsForTests params( - graph, 6 /* startVertex */, {} /* finishVertex */, &prevRoute, move(checkLength)); + graph, 6 /* startVertex */, {} /* finishVertex */, move(checkLength)); RoutingResult result; - auto const code = algo.AdjustRoute(params, result); + auto const code = algo.AdjustRoute(params, prevRoute, result); vector const expectedRoute = {6, 2, 3, 4, 5}; TEST_EQUAL(code, Algorithm::Result::OK, ()); @@ -120,10 +119,10 @@ UNIT_TEST(AdjustRouteNoPath) auto checkLength = [](double weight) { return weight <= 1.0; }; Algorithm algo; - Algorithm::ParamsForTests params(graph, 6 /* startVertex */, {} /* finishVertex */, &prevRoute, - move(checkLength)); + Algorithm::ParamsForTests params( + graph, 6 /* startVertex */, {} /* finishVertex */, move(checkLength)); RoutingResult result; - auto const code = algo.AdjustRoute(params, result); + auto const code = algo.AdjustRoute(params, prevRoute, result); TEST_EQUAL(code, Algorithm::Result::NoPath, ()); TEST(result.m_path.empty(), ()); @@ -144,10 +143,10 @@ UNIT_TEST(AdjustRouteOutOfLimit) auto checkLength = [](double weight) { return weight <= 1.0; }; Algorithm algo; Algorithm::ParamsForTests params( - graph, 6 /* startVertex */, {} /* finishVertex */, &prevRoute, move(checkLength)); + graph, 6 /* startVertex */, {} /* finishVertex */, move(checkLength)); RoutingResult result; - auto const code = algo.AdjustRoute(params, result); + auto const code = algo.AdjustRoute(params, prevRoute, result); TEST_EQUAL(code, Algorithm::Result::NoPath, ()); TEST(result.m_path.empty(), ()); diff --git a/routing/routing_tests/index_graph_tools.cpp b/routing/routing_tests/index_graph_tools.cpp index 295d6dca1c..425f9a7d97 100644 --- a/routing/routing_tests/index_graph_tools.cpp +++ b/routing/routing_tests/index_graph_tools.cpp @@ -78,8 +78,7 @@ void NoUTurnRestrictionTest::TestRouteGeom(Segment const & start, Segment const vector const & expectedRouteGeom) { AlgorithmForWorldGraph algorithm; - AlgorithmForWorldGraph::ParamsForTests<> params(*m_graph, start, finish, - nullptr /* prevRoute */); + AlgorithmForWorldGraph::ParamsForTests<> params(*m_graph, start, finish); RoutingResult routingResult; auto const resultCode = algorithm.FindPathBidirectional(params, routingResult); @@ -274,8 +273,7 @@ bool TestIndexGraphTopology::FindPath(Vertex start, Vertex finish, double & path WorldGraphForAStar graphForAStar(move(worldGraph)); - AlgorithmForWorldGraph::ParamsForTests<> params(graphForAStar, startSegment, finishSegment, - nullptr /* prevRoute */); + AlgorithmForWorldGraph::ParamsForTests<> params(graphForAStar, startSegment, finishSegment); RoutingResult routingResult; auto const resultCode = algorithm.FindPathBidirectional(params, routingResult); @@ -478,8 +476,7 @@ AlgorithmForWorldGraph::Result CalculateRoute(IndexGraphStarter & starter, vecto RoutingResult routingResult; AlgorithmForWorldGraph::ParamsForTests params( - starter, starter.GetStartSegment(), starter.GetFinishSegment(), nullptr /* prevRoute */, - AStarLengthChecker(starter)); + starter, starter.GetStartSegment(), starter.GetFinishSegment(), AStarLengthChecker(starter)); auto const resultCode = algorithm.FindPathBidirectional(params, routingResult); diff --git a/routing/routing_tests/routing_algorithm.cpp b/routing/routing_tests/routing_algorithm.cpp index 1cff616126..043bd86185 100644 --- a/routing/routing_tests/routing_algorithm.cpp +++ b/routing/routing_tests/routing_algorithm.cpp @@ -206,8 +206,7 @@ TestAStarBidirectionalAlgo::Result TestAStarBidirectionalAlgo::CalculateRoute( { RoadGraph roadGraph(graph); base::Cancellable cancellable; - Algorithm::Params<> params(roadGraph, startPos, finalPos, {} /* prevRoute */, - cancellable); + Algorithm::Params<> params(roadGraph, startPos, finalPos, cancellable); Algorithm::Result const res = Algorithm().FindPathBidirectional(params, path); return Convert(res);