Check cross mwm route in single mwm case.

This commit is contained in:
Lev Dragunov 2016-02-09 19:09:11 +03:00 committed by Sergey Yershov
parent ab603ec81c
commit c8a5ed6a93
6 changed files with 38 additions and 9 deletions

View file

@ -49,6 +49,7 @@ public:
Result FindPath(TGraphType const & graph,
TVertexType const & startVertex, TVertexType const & finalVertex,
vector<TVertexType> & path,
double & distance,
my::Cancellable const & cancellable = my::Cancellable(),
TOnVisitedVertexCallback onVisitedVertexCallback = nullptr) const;
@ -170,6 +171,7 @@ typename AStarAlgorithm<TGraph>::Result AStarAlgorithm<TGraph>::FindPath(
TGraphType const & graph,
TVertexType const & startVertex, TVertexType const & finalVertex,
vector<TVertexType> & path,
double & distance,
my::Cancellable const & cancellable,
TOnVisitedVertexCallback onVisitedVertexCallback) const
{
@ -205,6 +207,7 @@ typename AStarAlgorithm<TGraph>::Result AStarAlgorithm<TGraph>::FindPath(
if (stateV.vertex == finalVertex)
{
ReconstructPath(stateV.vertex, parent, path);
distance = stateV.distance;
return Result::OK;
}

View file

@ -11,7 +11,7 @@ namespace
/// Function to run AStar Algorithm from the base.
IRouter::ResultCode CalculateRoute(BorderCross const & startPos, BorderCross const & finalPos,
CrossMwmGraph const & roadGraph, vector<BorderCross> & route,
RouterDelegate const & delegate)
double & cost, RouterDelegate const & delegate)
{
using TAlgorithm = AStarAlgorithm<CrossMwmGraph>;
@ -23,7 +23,7 @@ IRouter::ResultCode CalculateRoute(BorderCross const & startPos, BorderCross con
my::HighResTimer timer(true);
TAlgorithm::Result const result =
TAlgorithm().FindPath(roadGraph, startPos, finalPos, route, delegate, onVisitedVertex);
TAlgorithm().FindPath(roadGraph, startPos, finalPos, route, cost, delegate, onVisitedVertex);
LOG(LINFO, ("Duration of the cross MWM path finding", timer.ElapsedNano()));
switch (result)
{
@ -43,6 +43,7 @@ IRouter::ResultCode CalculateRoute(BorderCross const & startPos, BorderCross con
IRouter::ResultCode CalculateCrossMwmPath(TRoutingNodes const & startGraphNodes,
TRoutingNodes const & finalGraphNodes,
RoutingIndexManager & indexManager,
double & cost,
RouterDelegate const & delegate, TCheckedPath & route)
{
CrossMwmGraph roadGraph(indexManager);
@ -88,7 +89,7 @@ IRouter::ResultCode CalculateCrossMwmPath(TRoutingNodes const & startGraphNodes,
// Finding path through maps.
vector<BorderCross> tempRoad;
code = CalculateRoute({startNode, startNode}, {finalNode, finalNode}, roadGraph, tempRoad,
code = CalculateRoute({startNode, startNode}, {finalNode, finalNode}, roadGraph, tempRoad, cost,
delegate);
if (code != IRouter::NoError)
return code;

View file

@ -34,11 +34,12 @@ using TCheckedPath = vector<RoutePathCross>;
* \param finalGraphNodes The vector of final routing graph nodes.
* \param route Storage for the result records about crossing maps.
* \param indexManager Manager for getting indexes of new countries.
* \param cost Found path cost.
* \param RoutingVisualizerFn Debug visualization function.
* \return NoError if the path exists, error code otherwise.
*/
IRouter::ResultCode CalculateCrossMwmPath(TRoutingNodes const & startGraphNodes,
TRoutingNodes const & finalGraphNodes,
RoutingIndexManager & indexManager,
RoutingIndexManager & indexManager, double & cost,
RouterDelegate const & delegate, TCheckedPath & route);
} // namespace routing

View file

@ -294,6 +294,8 @@ OsrmRouter::ResultCode OsrmRouter::CalculateRoute(m2::PointD const & startPoint,
// 4. Find route.
RawRoutingResult routingResult;
double crossCost = 0;
TCheckedPath finalPath;
// Manually load facade to avoid unmaping files we routing on.
startMapping->LoadFacade();
@ -306,11 +308,32 @@ OsrmRouter::ResultCode OsrmRouter::CalculateRoute(m2::PointD const & startPoint,
{
indexPair.second->FreeCrossContext();
});
ResultCode crossCode = CalculateCrossMwmPath(startTask, m_cachedTargets, m_indexManager, crossCost,
delegate, finalPath);
LOG(LINFO, ("Found cross path", timer.ElapsedNano()));
if (!FindRouteFromCases(startTask, m_cachedTargets, startMapping->m_dataFacade,
routingResult))
{
if (crossCode == NoError)
{
LOG(LINFO, ("Found only cross path."));
auto code = MakeRouteFromCrossesPath(finalPath, delegate, route);
LOG(LINFO, ("Make final route", timer.ElapsedNano()));
return code;
}
return RouteNotFound;
}
INTERRUPT_WHEN_CANCELLED(delegate);
if (crossCode == NoError && crossCost < routingResult.shortestPathLength)
{
LOG(LINFO, ("Cross mwm path shorter. Cross cost:", crossCost, "single cost:", routingResult.shortestPathLength));
auto code = MakeRouteFromCrossesPath(finalPath, delegate, route);
LOG(LINFO, ("Make final route", timer.ElapsedNano()));
timer.Reset();
return code;
}
INTERRUPT_WHEN_CANCELLED(delegate);
delegate.OnProgress(kPathFoundProgress);
@ -335,9 +358,8 @@ OsrmRouter::ResultCode OsrmRouter::CalculateRoute(m2::PointD const & startPoint,
else //4.2 Multiple mwm case
{
LOG(LINFO, ("Multiple mwm routing case"));
TCheckedPath finalPath;
ResultCode code = CalculateCrossMwmPath(startTask, m_cachedTargets, m_indexManager, delegate,
finalPath);
ResultCode code = CalculateCrossMwmPath(startTask, m_cachedTargets, m_indexManager, crossCost,
delegate, finalPath);
timer.Reset();
INTERRUPT_WHEN_CANCELLED(delegate);
delegate.OnProgress(kCrossPathFoundProgress);

View file

@ -145,8 +145,9 @@ IRoutingAlgorithm::Result AStarRoutingAlgorithm::CalculateRoute(IRoadGraph const
my::Cancellable const & cancellable = delegate;
progress.Initialize(startPos.GetPoint(), finalPos.GetPoint());
double cost = 0;
TAlgorithmImpl::Result const res = TAlgorithmImpl().FindPath(
RoadGraph(graph), startPos, finalPos, path, cancellable, onVisitJunctionFn);
RoadGraph(graph), startPos, finalPos, path, cost, cancellable, onVisitJunctionFn);
return Convert(res);
}

View file

@ -62,9 +62,10 @@ void TestAStar(UndirectedGraph const & graph, vector<unsigned> const & expectedR
using TAlgorithm = AStarAlgorithm<UndirectedGraph>;
TAlgorithm algo;
double cost = 0;
vector<unsigned> actualRoute;
TEST_EQUAL(TAlgorithm::Result::OK, algo.FindPath(graph, 0u, 4u, actualRoute), ());
TEST_EQUAL(TAlgorithm::Result::OK, algo.FindPath(graph, 0u, 4u, actualRoute, cost), ());
TEST_EQUAL(expectedRoute, actualRoute, ());
actualRoute.clear();