Skip to content

Commit

Permalink
[routing] Removed dummy 'prevRoute' param.
Browse files Browse the repository at this point in the history
Signed-off-by: Viktor Govako <[email protected]>
  • Loading branch information
vng committed May 17, 2022
1 parent 2140d44 commit a3a92aa
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 34 deletions.
15 changes: 6 additions & 9 deletions routing/base/astar_algorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,10 @@ class AStarAlgorithm
struct ParamsBase
{
ParamsBase(Graph & graph, Vertex const & startVertex, Vertex const & finalVertex,
std::vector<Edge> 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)
{
}
Expand All @@ -86,7 +85,6 @@ class AStarAlgorithm
// Used for FindPath, FindPathBidirectional.
Vertex const m_finalVertex;
// Used for AdjustRoute.
std::vector<Edge> const * const m_prevRoute;
base::Cancellable const & m_cancellable;
std::function<bool(Weight, Weight)> m_badReducedWeight = [](Weight, Weight) { return true; };
};
Expand All @@ -99,10 +97,10 @@ class AStarAlgorithm
struct Params : public ParamsBase
{
Params(Graph & graph, Vertex const & startVertex, Vertex const & finalVertex,
std::vector<Edge> 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<Visitor>(onVisitedVertexCallback))
, m_checkLengthCallback(std::forward<LengthChecker>(checkLengthCallback))
{
Expand All @@ -116,9 +114,8 @@ class AStarAlgorithm
struct ParamsForTests : public ParamsBase
{
ParamsForTests(Graph & graph, Vertex const & startVertex, Vertex const & finalVertex,
std::vector<Edge> const * prevRoute,
LengthChecker && checkLengthCallback = astar::DefaultLengthChecker())
: ParamsBase(graph, startVertex, finalVertex, prevRoute, m_dummy)
: ParamsBase(graph, startVertex, finalVertex, m_dummy)
, m_checkLengthCallback(std::forward<LengthChecker>(checkLengthCallback))
{
}
Expand Down Expand Up @@ -217,6 +214,7 @@ class AStarAlgorithm
// Expects |params.m_checkLengthCallback| to check wave propagation limit.
template <typename P>
typename AStarAlgorithm<Vertex, Edge, Weight>::Result AdjustRoute(P & params,
std::vector<Edge> const & prevRoute,
RoutingResult<Vertex, Weight> & result) const;

private:
Expand Down Expand Up @@ -722,12 +720,11 @@ template <typename Vertex, typename Edge, typename Weight>
template <typename P>
typename AStarAlgorithm<Vertex, Edge, Weight>::Result
AStarAlgorithm<Vertex, Edge, Weight>::AdjustRoute(P & params,
std::vector<Edge> const & prevRoute,
RoutingResult<Vertex, Weight> & result) const
{
auto & graph = params.m_graph;
auto const & startVertex = params.m_startVertex;
auto const & prevRoute = *params.m_prevRoute;

CHECK(!prevRoute.empty(), ());

result.Clear();
Expand Down
12 changes: 6 additions & 6 deletions routing/index_router.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ RouterResultCode IndexRouter::CalculateSubrouteJointsMode(

AStarAlgorithm<Vertex, Edge, Weight>::Params<Visitor, AStarLengthChecker> params(
jointStarter, jointStarter.GetStartJoint(), jointStarter.GetFinishJoint(),
nullptr /* prevRoute */, delegate.GetCancellable(), move(visitor),
delegate.GetCancellable(), move(visitor),
AStarLengthChecker(starter));

RoutingResult<Vertex, Weight> routingResult;
Expand All @@ -769,7 +769,7 @@ RouterResultCode IndexRouter::CalculateSubrouteNoLeapsMode(
Visitor visitor(starter, delegate, kVisitPeriod, progress);

AStarAlgorithm<Vertex, Edge, Weight>::Params<Visitor, AStarLengthChecker> params(
starter, starter.GetStartSegment(), starter.GetFinishSegment(), nullptr /* prevRoute */,
starter, starter.GetStartSegment(), starter.GetFinishSegment(),
delegate.GetCancellable(), move(visitor), AStarLengthChecker(starter));

RoutingResult<Vertex, Weight> routingResult;
Expand Down Expand Up @@ -804,7 +804,7 @@ RouterResultCode IndexRouter::CalculateSubrouteLeapsOnlyMode(

AStarAlgorithm<Vertex, Edge, Weight>::Params<Visitor, AStarLengthChecker> 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 &)
Expand Down Expand Up @@ -892,12 +892,12 @@ RouterResultCode IndexRouter::AdjustRoute(Checkpoints const & checkpoints,

AStarAlgorithm<Vertex, Edge, Weight> algorithm;
AStarAlgorithm<Vertex, Edge, Weight>::Params<Visitor, AdjustLengthChecker> params(
starter, starter.GetStartSegment(), {} /* finalVertex */, &prevEdges,
starter, starter.GetStartSegment(), {} /* finalVertex */,
delegate.GetCancellable(), move(visitor), AdjustLengthChecker(starter));

RoutingResult<Segment, RouteWeight> result;
auto const resultCode =
ConvertResult<Vertex, Edge, Weight>(algorithm.AdjustRoute(params, result));
ConvertResult<Vertex, Edge, Weight>(algorithm.AdjustRoute(params, prevEdges, result));
if (resultCode != RouterResultCode::NoError)
return resultCode;

Expand Down Expand Up @@ -1367,7 +1367,7 @@ RouterResultCode IndexRouter::ProcessLeapsJoints(vector<Segment> const & input,

AStarAlgorithm<Vertex, Edge, Weight>::Params<Visitor, AStarLengthChecker> params(
jointStarter, jointStarter.GetStartJoint(), jointStarter.GetFinishJoint(),
nullptr /* prevRoute */, delegate.GetCancellable(), move(visitor),
delegate.GetCancellable(), move(visitor),
AStarLengthChecker(starter));

resultCode = FindPath<Vertex, Edge, Weight>(params, mwmIds, routingResult);
Expand Down
2 changes: 1 addition & 1 deletion routing/regions_router.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ RouterResultCode RegionsRouter::CalculateSubrouteNoLeapsMode(IndexGraphStarter &
Visitor visitor(starter, m_delegate, kVisitPeriod, progress);

AStarAlgorithm<Vertex, Edge, Weight>::Params<Visitor, AStarLengthChecker> 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)
Expand Down
19 changes: 9 additions & 10 deletions routing/routing_tests/astar_algorithm_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ void TestAStar(UndirectedGraph & graph, vector<unsigned> const & expectedRoute,
{
Algorithm algo;

Algorithm::ParamsForTests<> params(graph, 0u /* startVertex */, 4u /* finishVertex */,
nullptr /* prevRoute */);
Algorithm::ParamsForTests<> params(graph, 0u /* startVertex */, 4u /* finishVertex */);

RoutingResult<unsigned /* Vertex */, double /* Weight */> actualRoute;
TEST_EQUAL(Algorithm::Result::OK, algo.FindPath(params, actualRoute), ());
Expand Down Expand Up @@ -66,7 +65,7 @@ UNIT_TEST(AStarAlgorithm_CheckLength)
auto checkLength = [](double weight) { return weight < 23; };
Algorithm algo;
Algorithm::ParamsForTests<decltype(checkLength)> params(
graph, 0u /* startVertex */, 4u /* finishVertex */, nullptr /* prevRoute */,
graph, 0u /* startVertex */, 4u /* finishVertex */,
move(checkLength));

RoutingResult<unsigned /* Vertex */, double /* Weight */> routingResult;
Expand Down Expand Up @@ -97,10 +96,10 @@ UNIT_TEST(AdjustRoute)
auto checkLength = [](double weight) { return weight <= 1.0; };
Algorithm algo;
Algorithm::ParamsForTests<decltype(checkLength)> params(
graph, 6 /* startVertex */, {} /* finishVertex */, &prevRoute, move(checkLength));
graph, 6 /* startVertex */, {} /* finishVertex */, move(checkLength));

RoutingResult<unsigned /* Vertex */, double /* Weight */> result;
auto const code = algo.AdjustRoute(params, result);
auto const code = algo.AdjustRoute(params, prevRoute, result);

vector<unsigned> const expectedRoute = {6, 2, 3, 4, 5};
TEST_EQUAL(code, Algorithm::Result::OK, ());
Expand All @@ -120,10 +119,10 @@ UNIT_TEST(AdjustRouteNoPath)

auto checkLength = [](double weight) { return weight <= 1.0; };
Algorithm algo;
Algorithm::ParamsForTests<decltype(checkLength)> params(graph, 6 /* startVertex */, {} /* finishVertex */, &prevRoute,
move(checkLength));
Algorithm::ParamsForTests<decltype(checkLength)> params(
graph, 6 /* startVertex */, {} /* finishVertex */, move(checkLength));
RoutingResult<unsigned /* Vertex */, double /* Weight */> 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(), ());
Expand All @@ -144,10 +143,10 @@ UNIT_TEST(AdjustRouteOutOfLimit)
auto checkLength = [](double weight) { return weight <= 1.0; };
Algorithm algo;
Algorithm::ParamsForTests<decltype(checkLength)> params(
graph, 6 /* startVertex */, {} /* finishVertex */, &prevRoute, move(checkLength));
graph, 6 /* startVertex */, {} /* finishVertex */, move(checkLength));

RoutingResult<unsigned /* Vertex */, double /* Weight */> 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(), ());
Expand Down
9 changes: 3 additions & 6 deletions routing/routing_tests/index_graph_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ void NoUTurnRestrictionTest::TestRouteGeom(Segment const & start, Segment const
vector<m2::PointD> const & expectedRouteGeom)
{
AlgorithmForWorldGraph algorithm;
AlgorithmForWorldGraph::ParamsForTests<> params(*m_graph, start, finish,
nullptr /* prevRoute */);
AlgorithmForWorldGraph::ParamsForTests<> params(*m_graph, start, finish);

RoutingResult<Segment, RouteWeight> routingResult;
auto const resultCode = algorithm.FindPathBidirectional(params, routingResult);
Expand Down Expand Up @@ -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<Segment, RouteWeight> routingResult;
auto const resultCode = algorithm.FindPathBidirectional(params, routingResult);

Expand Down Expand Up @@ -478,8 +476,7 @@ AlgorithmForWorldGraph::Result CalculateRoute(IndexGraphStarter & starter, vecto
RoutingResult<Segment, RouteWeight> routingResult;

AlgorithmForWorldGraph::ParamsForTests<AStarLengthChecker> params(
starter, starter.GetStartSegment(), starter.GetFinishSegment(), nullptr /* prevRoute */,
AStarLengthChecker(starter));
starter, starter.GetStartSegment(), starter.GetFinishSegment(), AStarLengthChecker(starter));

auto const resultCode = algorithm.FindPathBidirectional(params, routingResult);

Expand Down
3 changes: 1 addition & 2 deletions routing/routing_tests/routing_algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a3a92aa

Please sign in to comment.