Create AStarAlgorithm::Params for Astar input parameters

This commit is contained in:
tatiana-kondakova 2017-12-20 17:55:31 +03:00 committed by Yuri Gorshenin
parent 5cb69f5a87
commit 86dc1ec066
6 changed files with 142 additions and 118 deletions

View file

@ -53,6 +53,36 @@ public:
// Can be used to clip some path which does not meet restrictions.
using CheckLengthCallback = std::function<bool(Weight const &)>;
struct Params
{
Params(Graph & graph, Vertex const & startVertex, Vertex const & finalVertex,
std::vector<Edge> const & prevRoute, my::Cancellable const & cancellable,
OnVisitedVertexCallback const & onVisitedVertexCallback,
CheckLengthCallback const & checkLengthCallback)
: m_graph(graph)
, m_startVertex(startVertex)
, m_finalVertex(finalVertex)
, m_prevRoute(prevRoute)
, m_cancellable(cancellable)
, m_onVisitedVertexCallback(onVisitedVertexCallback ? onVisitedVertexCallback
: [](Vertex const &, Vertex const &) {})
, m_checkLengthCallback(checkLengthCallback
? checkLengthCallback
: [](Weight const & /* weight */) { return true; })
{
}
Graph & m_graph;
Vertex const & m_startVertex;
// Used for FindPath, FindPathBidirectional.
Vertex const & m_finalVertex;
// Used for AdjustRoute.
std::vector<Edge> const & m_prevRoute;
my::Cancellable const & m_cancellable;
OnVisitedVertexCallback m_onVisitedVertexCallback;
CheckLengthCallback m_checkLengthCallback;
};
class Context final
{
public:
@ -101,25 +131,14 @@ public:
void PropagateWave(Graph & graph, Vertex const & startVertex, VisitVertex && visitVertex,
Context & context) const;
Result FindPath(Graph & graph, Vertex const & startVertex, Vertex const & finalVertex,
RoutingResult<Vertex, Weight> & result,
my::Cancellable const & cancellable = my::Cancellable(),
OnVisitedVertexCallback onVisitedVertexCallback = {},
CheckLengthCallback checkLengthCallback = {}) const;
Result FindPath(Params & params, RoutingResult<Vertex, Weight> & result) const;
Result FindPathBidirectional(Graph & graph, Vertex const & startVertex,
Vertex const & finalVertex, RoutingResult<Vertex, Weight> & result,
my::Cancellable const & cancellable = my::Cancellable(),
OnVisitedVertexCallback onVisitedVertexCallback = {},
CheckLengthCallback checkLengthCallback = {}) const;
Result FindPathBidirectional(Params & params, RoutingResult<Vertex, Weight> & result) const;
// Adjust route to the previous one.
// Expects |checkLengthCallback| to check wave propagation limit.
typename AStarAlgorithm<Graph>::Result AdjustRoute(
Graph & graph, Vertex const & startVertex, std::vector<Edge> const & prevRoute,
RoutingResult<Vertex, Weight> & result, my::Cancellable const & cancellable,
OnVisitedVertexCallback onVisitedVertexCallback,
CheckLengthCallback checkLengthCallback) const;
// Expects |params.m_checkLengthCallback| to check wave propagation limit.
typename AStarAlgorithm<Graph>::Result AdjustRoute(Params & params,
RoutingResult<Vertex, Weight> & result) const;
private:
// Periodicity of switching a wave of bidirectional algorithm.
@ -321,19 +340,16 @@ void AStarAlgorithm<Graph>::PropagateWave(Graph & graph, Vertex const & startVer
template <typename Graph>
typename AStarAlgorithm<Graph>::Result AStarAlgorithm<Graph>::FindPath(
Graph & graph, Vertex const & startVertex, Vertex const & finalVertex,
RoutingResult<Vertex, Weight> & result, my::Cancellable const & cancellable,
OnVisitedVertexCallback onVisitedVertexCallback, CheckLengthCallback checkLengthCallback) const
Params & params, RoutingResult<Vertex, Weight> & result) const
{
result.Clear();
if (onVisitedVertexCallback == nullptr)
onVisitedVertexCallback = [](Vertex const &, Vertex const &) {};
if (checkLengthCallback == nullptr)
checkLengthCallback = [](Weight const & /* weight */) { return true; };
auto & graph = params.m_graph;
auto const & finalVertex = params.m_finalVertex;
auto const & startVertex = params.m_startVertex;
Context context;
PeriodicPollCancellable periodicCancellable(cancellable);
PeriodicPollCancellable periodicCancellable(params.m_cancellable);
Result resultCode = Result::NoPath;
auto const heuristicDiff = [&](Vertex const & vertexFrom, Vertex const & vertexTo) {
@ -358,7 +374,7 @@ typename AStarAlgorithm<Graph>::Result AStarAlgorithm<Graph>::FindPath(
return false;
}
onVisitedVertexCallback(vertex, finalVertex);
params.m_onVisitedVertexCallback(vertex, finalVertex);
if (vertex == finalVertex)
{
@ -378,7 +394,8 @@ typename AStarAlgorithm<Graph>::Result AStarAlgorithm<Graph>::FindPath(
};
auto const filterStates = [&](State const & state) {
return checkLengthCallback(reducedToFullLength(startVertex, state.vertex, state.distance));
return params.m_checkLengthCallback(
reducedToFullLength(startVertex, state.vertex, state.distance));
};
PropagateWave(graph, startVertex, visitVertex, adjustEdgeWeight, filterStates, context);
@ -389,7 +406,7 @@ typename AStarAlgorithm<Graph>::Result AStarAlgorithm<Graph>::FindPath(
result.m_distance =
reducedToFullLength(startVertex, finalVertex, context.GetDistance(finalVertex));
if (!checkLengthCallback(result.m_distance))
if (!params.m_checkLengthCallback(result.m_distance))
resultCode = Result::NoPath;
}
@ -398,15 +415,11 @@ typename AStarAlgorithm<Graph>::Result AStarAlgorithm<Graph>::FindPath(
template <typename Graph>
typename AStarAlgorithm<Graph>::Result AStarAlgorithm<Graph>::FindPathBidirectional(
Graph & graph, Vertex const & startVertex, Vertex const & finalVertex,
RoutingResult<Vertex, Weight> & result, my::Cancellable const & cancellable,
OnVisitedVertexCallback onVisitedVertexCallback, CheckLengthCallback checkLengthCallback) const
Params & params, RoutingResult<Vertex, Weight> & result) const
{
if (onVisitedVertexCallback == nullptr)
onVisitedVertexCallback = [](Vertex const &, Vertex const &) {};
if (checkLengthCallback == nullptr)
checkLengthCallback = [](Weight const & /* weight */) { return true; };
auto & graph = params.m_graph;
auto const & finalVertex = params.m_finalVertex;
auto const & startVertex = params.m_startVertex;
BidirectionalStepContext forward(true /* forward */, startVertex, finalVertex, graph);
BidirectionalStepContext backward(false /* forward */, startVertex, finalVertex, graph);
@ -434,7 +447,7 @@ typename AStarAlgorithm<Graph>::Result AStarAlgorithm<Graph>::FindPathBidirectio
// because if we have not found a path by the time one of the
// queues is exhausted, we never will.
uint32_t steps = 0;
PeriodicPollCancellable periodicCancellable(cancellable);
PeriodicPollCancellable periodicCancellable(params.m_cancellable);
while (!cur->queue.empty() && !nxt->queue.empty())
{
@ -464,7 +477,7 @@ typename AStarAlgorithm<Graph>::Result AStarAlgorithm<Graph>::FindPathBidirectio
if (curTop + nxtTop >= bestPathReducedLength - kEpsilon)
{
if (!checkLengthCallback(bestPathRealLength))
if (!params.m_checkLengthCallback(bestPathRealLength))
return Result::NoPath;
ReconstructPathBidirectional(cur->bestVertex, nxt->bestVertex, cur->parent, nxt->parent,
@ -483,7 +496,8 @@ typename AStarAlgorithm<Graph>::Result AStarAlgorithm<Graph>::FindPathBidirectio
if (stateV.distance > cur->bestDistance[stateV.vertex])
continue;
onVisitedVertexCallback(stateV.vertex, cur->forward ? cur->finalVertex : cur->startVertex);
params.m_onVisitedVertexCallback(stateV.vertex,
cur->forward ? cur->finalVertex : cur->startVertex);
cur->GetAdjacencyList(stateV.vertex, adj);
for (auto const & edge : adj)
@ -501,7 +515,7 @@ typename AStarAlgorithm<Graph>::Result AStarAlgorithm<Graph>::FindPathBidirectio
auto const newReducedDist = stateV.distance + std::max(reducedWeight, kZeroDistance);
auto const fullLength = weight + stateV.distance + cur->pS - pV;
if (!checkLengthCallback(fullLength))
if (!params.m_checkLengthCallback(fullLength))
continue;
auto const itCur = cur->bestDistance.find(stateW.vertex);
@ -542,18 +556,18 @@ typename AStarAlgorithm<Graph>::Result AStarAlgorithm<Graph>::FindPathBidirectio
template <typename Graph>
typename AStarAlgorithm<Graph>::Result AStarAlgorithm<Graph>::AdjustRoute(
Graph & graph, Vertex const & startVertex, std::vector<Edge> const & prevRoute,
RoutingResult<Vertex, Weight> & result, my::Cancellable const & cancellable,
OnVisitedVertexCallback onVisitedVertexCallback, CheckLengthCallback checkLengthCallback) const
Params & params, 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(), ());
CHECK(checkLengthCallback != nullptr,
CHECK(params.m_checkLengthCallback != nullptr,
("CheckLengthCallback expected to be set to limit wave propagation."));
result.Clear();
if (onVisitedVertexCallback == nullptr)
onVisitedVertexCallback = [](Vertex const &, Vertex const &) {};
bool wasCancelled = false;
auto minDistance = kInfiniteDistance;
@ -569,7 +583,7 @@ typename AStarAlgorithm<Graph>::Result AStarAlgorithm<Graph>::AdjustRoute(
}
Context context;
PeriodicPollCancellable periodicCancellable(cancellable);
PeriodicPollCancellable periodicCancellable(params.m_cancellable);
auto visitVertex = [&](Vertex const & vertex) {
@ -579,7 +593,7 @@ typename AStarAlgorithm<Graph>::Result AStarAlgorithm<Graph>::AdjustRoute(
return false;
}
onVisitedVertexCallback(startVertex, vertex);
params.m_onVisitedVertexCallback(startVertex, vertex);
auto it = remainingDistances.find(vertex);
if (it != remainingDistances.cend())
@ -600,7 +614,7 @@ typename AStarAlgorithm<Graph>::Result AStarAlgorithm<Graph>::AdjustRoute(
};
auto const filterStates = [&](State const & state) {
return checkLengthCallback(state.distance);
return params.m_checkLengthCallback(state.distance);
};
PropagateWave(graph, startVertex, visitVertex, adjustEdgeWeight, filterStates, context);

View file

@ -16,28 +16,27 @@ IRouter::ResultCode CalculateRoute(BorderCross const & startPos, BorderCross con
CrossMwmRoadGraph & roadGraph, RouterDelegate const & delegate,
RoutingResult<BorderCross, double /* Weight */> & route)
{
using TAlgorithm = AStarAlgorithm<CrossMwmRoadGraph>;
using Algorithm = AStarAlgorithm<CrossMwmRoadGraph>;
TAlgorithm::OnVisitedVertexCallback onVisitedVertex =
[&delegate](BorderCross const & cross, BorderCross const & /* target */)
{
delegate.OnPointCheck(MercatorBounds::FromLatLon(cross.fromNode.point));
};
Algorithm::OnVisitedVertexCallback onVisitedVertex =
[&delegate](BorderCross const & cross, BorderCross const & /* target */) {
delegate.OnPointCheck(MercatorBounds::FromLatLon(cross.fromNode.point));
};
Algorithm::Params params(roadGraph, startPos, finalPos, {} /* prevRoute */, delegate,
onVisitedVertex, {} /* checkLengthCallback */);
my::HighResTimer timer(true);
TAlgorithm::Result const result =
TAlgorithm().FindPath(roadGraph, startPos, finalPos, route, delegate, onVisitedVertex);
Algorithm::Result const result = Algorithm().FindPath(params, route);
LOG(LINFO, ("Duration of the cross MWM path finding", timer.ElapsedNano()));
switch (result)
{
case TAlgorithm::Result::OK:
ASSERT_EQUAL(route.m_path.front(), startPos, ());
ASSERT_EQUAL(route.m_path.back(), finalPos, ());
return IRouter::NoError;
case TAlgorithm::Result::NoPath:
return IRouter::RouteNotFound;
case TAlgorithm::Result::Cancelled:
return IRouter::Cancelled;
case Algorithm::Result::OK:
ASSERT_EQUAL(route.m_path.front(), startPos, ());
ASSERT_EQUAL(route.m_path.back(), finalPos, ());
return IRouter::NoError;
case Algorithm::Result::NoPath: return IRouter::RouteNotFound;
case Algorithm::Result::Cancelled: return IRouter::Cancelled;
}
return IRouter::RouteNotFound;
}

View file

@ -137,18 +137,13 @@ IRouter::ResultCode ConvertResult(typename AStarAlgorithm<Graph>::Result result)
template <typename Graph>
IRouter::ResultCode FindPath(
typename Graph::Vertex const & start, typename Graph::Vertex const & finish,
RouterDelegate const & delegate, Graph & graph,
typename AStarAlgorithm<Graph>::OnVisitedVertexCallback const & onVisitedVertexCallback,
typename AStarAlgorithm<Graph>::CheckLengthCallback const & checkLengthCallback,
typename AStarAlgorithm<Graph>::Params & params,
RoutingResult<typename Graph::Vertex, typename Graph::Weight> & routingResult)
{
AStarAlgorithm<Graph> algorithm;
auto findPath = mem_fn(graph.GetMode() == WorldGraph::Mode::LeapsOnly
? &AStarAlgorithm<Graph>::FindPath
: &AStarAlgorithm<Graph>::FindPathBidirectional);
return ConvertResult<Graph>(findPath(algorithm, graph, start, finish, routingResult, delegate,
onVisitedVertexCallback, checkLengthCallback));
if (params.m_graph.GetMode() == WorldGraph::Mode::LeapsOnly)
return ConvertResult<Graph>(algorithm.FindPath(params, routingResult));
return ConvertResult<Graph>(algorithm.FindPathBidirectional(params, routingResult));
}
bool IsDeadEnd(Segment const & segment, bool isOutgoing, WorldGraph & worldGraph)
@ -565,11 +560,14 @@ IRouter::ResultCode IndexRouter::CalculateSubroute(Checkpoints const & checkpoin
delegate.OnPointCheck(pointFrom);
};
auto checkLength = [&starter](RouteWeight const & weight) { return starter.CheckLength(weight); };
RoutingResult<Segment, RouteWeight> routingResult;
IRouter::ResultCode const result = FindPath(
starter.GetStartSegment(), starter.GetFinishSegment(), delegate, starter, onVisitJunction,
[&starter](RouteWeight const & weight) { return starter.CheckLength(weight); },
routingResult);
AStarAlgorithm<IndexGraphStarter>::Params params(starter, starter.GetStartSegment(),
starter.GetFinishSegment(), {} /* prevRoute */,
delegate, onVisitJunction, checkLength);
IRouter::ResultCode const result = FindPath<IndexGraphStarter>(params, routingResult);
if (result != IRouter::NoError)
return result;
@ -643,10 +641,11 @@ IRouter::ResultCode IndexRouter::AdjustRoute(Checkpoints const & checkpoints,
};
AStarAlgorithm<IndexGraphStarter> algorithm;
AStarAlgorithm<IndexGraphStarter>::Params params(starter, starter.GetStartSegment(),
{} /* finalVertex */, prevEdges, delegate,
onVisitJunction, checkLength);
RoutingResult<Segment, RouteWeight> result;
auto resultCode = ConvertResult<IndexGraphStarter>(
algorithm.AdjustRoute(starter, starter.GetStartSegment(), prevEdges, result, delegate,
onVisitJunction, checkLength));
auto const resultCode = ConvertResult<IndexGraphStarter>(algorithm.AdjustRoute(params, result));
if (resultCode != IRouter::NoError)
return resultCode;
@ -780,6 +779,10 @@ IRouter::ResultCode IndexRouter::ProcessLeaps(vector<Segment> const & input,
CHECK_LESS(i, input.size(), ());
auto const & next = input[i];
auto checkLength = [&starter](RouteWeight const & weight) {
return starter.CheckLength(weight);
};
IRouter::ResultCode result = IRouter::InternalError;
RoutingResult<Segment, RouteWeight> routingResult;
if (i == 1 || i + 1 == input.size())
@ -788,10 +791,10 @@ IRouter::ResultCode IndexRouter::ProcessLeaps(vector<Segment> const & input,
// In case of leaps from the start to its mwm transition and from finish to mwm transition
// route calculation should be made on the world graph (WorldGraph::Mode::NoLeaps).
worldGraph.SetMode(WorldGraph::Mode::NoLeaps);
result =
FindPath(current, next, delegate, starter, {} /* onVisitedVertexCallback */,
[&starter](RouteWeight const & weight) { return starter.CheckLength(weight); },
routingResult);
AStarAlgorithm<IndexGraphStarter>::Params params(starter, current, next, {} /* prevRoute */,
delegate, {} /* onVisitedVertexCallback */,
checkLength);
result = FindPath<IndexGraphStarter>(params, routingResult);
}
else
{
@ -805,10 +808,10 @@ IRouter::ResultCode IndexRouter::ProcessLeaps(vector<Segment> const & input,
worldGraph.SetMode(WorldGraph::Mode::SingleMwm);
// It's not start-to-mwm-exit leap, we already have its first segment in previous mwm.
dropFirstSegment = true;
result =
FindPath(current, next, delegate, worldGraph, {} /* onVisitedVertexCallback */,
[&starter](RouteWeight const & weight) { return starter.CheckLength(weight); },
routingResult);
AStarAlgorithm<WorldGraph>::Params params(worldGraph, current, next, {} /* prevRoute */,
delegate, {} /* onVisitedVertexCallback */,
checkLength);
result = FindPath<WorldGraph>(params, routingResult);
}
if (result != IRouter::NoError)

View file

@ -157,8 +157,9 @@ IRoutingAlgorithm::Result AStarRoutingAlgorithm::CalculateRoute(IRoadGraph const
my::Cancellable const & cancellable = delegate;
progress.Initialize(startPos.GetPoint(), finalPos.GetPoint());
RoadGraph roadGraph(graph);
TAlgorithmImpl::Result const res = TAlgorithmImpl().FindPath(
roadGraph, startPos, finalPos, path, cancellable, onVisitJunctionFn);
TAlgorithmImpl::Params params(roadGraph, startPos, finalPos, {} /* prevRoute */, cancellable,
onVisitJunctionFn, {} /* checkLength */);
TAlgorithmImpl::Result const res = TAlgorithmImpl().FindPath(params, path);
return Convert(res);
}
@ -186,8 +187,9 @@ IRoutingAlgorithm::Result AStarBidirectionalRoutingAlgorithm::CalculateRoute(
my::Cancellable const & cancellable = delegate;
progress.Initialize(startPos.GetPoint(), finalPos.GetPoint());
RoadGraph roadGraph(graph);
TAlgorithmImpl::Result const res = TAlgorithmImpl().FindPathBidirectional(
roadGraph, startPos, finalPos, path, cancellable, onVisitJunctionFn);
TAlgorithmImpl::Params params(roadGraph, startPos, finalPos, {} /* prevRoute */, cancellable,
onVisitJunctionFn, {} /* checkLength */);
TAlgorithmImpl::Result const res = TAlgorithmImpl().FindPathBidirectional(params, path);
return Convert(res);
}

View file

@ -66,13 +66,17 @@ void TestAStar(UndirectedGraph & graph, vector<unsigned> const & expectedRoute,
{
TAlgorithm algo;
TAlgorithm::Params params(graph, 0u /* startVertex */, 4u /* finishVertex */, {} /* prevRoute */,
{} /* cancellable */, {} /* onVisitedVerteCallback */,
{} /* checkLengthCallback */);
RoutingResult<unsigned /* Vertex */, double /* Weight */> actualRoute;
TEST_EQUAL(TAlgorithm::Result::OK, algo.FindPath(graph, 0u, 4u, actualRoute), ());
TEST_EQUAL(TAlgorithm::Result::OK, algo.FindPath(params, actualRoute), ());
TEST_EQUAL(expectedRoute, actualRoute.m_path, ());
TEST_ALMOST_EQUAL_ULPS(expectedDistance, actualRoute.m_distance, ());
actualRoute.m_path.clear();
TEST_EQUAL(TAlgorithm::Result::OK, algo.FindPathBidirectional(graph, 0u, 4u, actualRoute), ());
TEST_EQUAL(TAlgorithm::Result::OK, algo.FindPathBidirectional(params, actualRoute), ());
TEST_EQUAL(expectedRoute, actualRoute.m_path, ());
TEST_ALMOST_EQUAL_ULPS(expectedDistance, actualRoute.m_distance, ());
}
@ -105,17 +109,16 @@ UNIT_TEST(AStarAlgorithm_CheckLength)
graph.AddEdge(3, 4, 3);
TAlgorithm algo;
TAlgorithm::Params params(graph, 0u /* startVertex */, 4u /* finishVertex */, {} /* prevRoute */,
{} /* cancellable */, {} /* onVisitedVerteCallback */,
[](double weight) { return weight < 23; });
RoutingResult<unsigned /* Vertex */, double /* Weight */> routingResult;
TAlgorithm::Result result =
algo.FindPath(graph, 0u, 4u, routingResult, {} /* cancellable */,
{} /* onVisitedVertexCallback */, [](double weight) { return weight < 23; });
TAlgorithm::Result result = algo.FindPath(params, routingResult);
// Best route weight is 23 so we expect to find no route with restriction |weight < 23|.
TEST_EQUAL(result, TAlgorithm::Result::NoPath, ());
routingResult = {};
result = algo.FindPathBidirectional(graph, 0u, 4u, routingResult, {} /* cancellable */,
{} /* onVisitedVertexCallback */,
[](double weight) { return weight < 23; });
result = algo.FindPathBidirectional(params, routingResult);
// Best route weight is 23 so we expect to find no route with restriction |weight < 23|.
TEST_EQUAL(result, TAlgorithm::Result::NoPath, ());
}
@ -135,10 +138,11 @@ UNIT_TEST(AdjustRoute)
vector<Edge> const prevRoute = {{0, 0}, {1, 1}, {2, 1}, {3, 1}, {4, 1}, {5, 1}};
TAlgorithm algo;
TAlgorithm::Params params(graph, 6 /* startVertex */, {} /* finishVertex */, prevRoute,
{} /* cancellable */, {} /* onVisitedVerteCallback */,
[](double weight) { return weight <= 1.0; });
RoutingResult<unsigned /* Vertex */, double /* Weight */> result;
auto code = algo.AdjustRoute(graph, 6 /* start */, prevRoute, result,
my::Cancellable(), nullptr /* onVisitedVertexCallback */,
[](double weight){ return weight <= 1.0; });
auto const code = algo.AdjustRoute(params, result);
vector<unsigned> const expectedRoute = {6, 2, 3, 4, 5};
TEST_EQUAL(code, TAlgorithm::Result::OK, ());
@ -157,10 +161,11 @@ UNIT_TEST(AdjustRouteNoPath)
vector<Edge> const prevRoute = {{0, 0}, {1, 1}, {2, 1}, {3, 1}, {4, 1}, {5, 1}};
TAlgorithm algo;
TAlgorithm::Params params(graph, 6 /* startVertex */, {} /* finishVertex */, prevRoute,
{} /* cancellable */, {} /* onVisitedVerteCallback */,
[](double weight) { return weight <= 1.0; });
RoutingResult<unsigned /* Vertex */, double /* Weight */> result;
auto code = algo.AdjustRoute(graph, 6 /* start */, prevRoute, result,
my::Cancellable(), nullptr /* onVisitedVertexCallback */,
[](double weight){ return weight <= 1.0; });
auto const code = algo.AdjustRoute(params, result);
TEST_EQUAL(code, TAlgorithm::Result::NoPath, ());
TEST(result.m_path.empty(), ());
@ -179,10 +184,11 @@ UNIT_TEST(AdjustRouteOutOfLimit)
vector<Edge> const prevRoute = {{0, 0}, {1, 1}, {2, 1}, {3, 1}, {4, 1}, {5, 1}};
TAlgorithm algo;
TAlgorithm::Params params(graph, 6 /* startVertex */, {} /* finishVertex */, prevRoute,
{} /* cancellable */, {} /* onVisitedVerteCallback */,
[](double weight) { return weight <= 1.0; });
RoutingResult<unsigned /* Vertex */, double /* Weight */> result;
auto code = algo.AdjustRoute(graph, 6 /* start */, prevRoute, result,
my::Cancellable(), nullptr /* onVisitedVertexCallback */,
[](double weight){ return weight <= 1.0; });
auto const code = algo.AdjustRoute(params, result);
TEST_EQUAL(code, TAlgorithm::Result::NoPath, ());
TEST(result.m_path.empty(), ());

View file

@ -172,18 +172,16 @@ bool TestIndexGraphTopology::FindPath(Vertex start, Vertex finish, double & path
AStarAlgorithm<WorldGraph> algorithm;
RoutingResult<Segment, RouteWeight> routingResult;
auto const resultCode = algorithm.FindPathBidirectional(
*worldGraph, startSegment, finishSegment, routingResult, {} /* cancellable */,
AStarAlgorithm<WorldGraph>::Params params(
*worldGraph, startSegment, finishSegment, {} /* prevRoute */, {} /* cancellable */,
{} /* onVisitedVertexCallback */, {} /* checkLengthCallback */);
RoutingResult<Segment, RouteWeight> routingResult;
auto const resultCode = algorithm.FindPathBidirectional(params, routingResult);
// Check unidirectional AStar returns same result.
{
RoutingResult<Segment, RouteWeight> unidirectionalRoutingResult;
auto const unidirectionalResultCode = algorithm.FindPath(
*worldGraph, startSegment, finishSegment, unidirectionalRoutingResult, {} /* cancellable */,
{} /* onVisitedVertexCallback */, {} /* checkLengthCallback */);
auto const unidirectionalResultCode = algorithm.FindPath(params, unidirectionalRoutingResult);
CHECK_EQUAL(resultCode, unidirectionalResultCode, ());
CHECK(routingResult.m_distance.IsAlmostEqualForTests(unidirectionalRoutingResult.m_distance,
kEpsilon),
@ -366,11 +364,13 @@ AStarAlgorithm<IndexGraphStarter>::Result CalculateRoute(IndexGraphStarter & sta
AStarAlgorithm<IndexGraphStarter> algorithm;
RoutingResult<Segment, RouteWeight> routingResult;
auto resultCode = algorithm.FindPathBidirectional(
starter, starter.GetStartSegment(), starter.GetFinishSegment(), routingResult,
AStarAlgorithm<IndexGraphStarter>::Params params(
starter, starter.GetStartSegment(), starter.GetFinishSegment(), {} /* prevRoute */,
{} /* cancellable */, {} /* onVisitedVertexCallback */,
[&](RouteWeight const & weight) { return starter.CheckLength(weight); });
auto const resultCode = algorithm.FindPathBidirectional(params, routingResult);
timeSec = routingResult.m_distance.GetWeight();
roadPoints = routingResult.m_path;
return resultCode;