[routing] Support cancelling of route search requests.

This commit is contained in:
Maxim Pimenov 2015-04-10 22:33:33 +03:00 committed by Alex Zolotarev
parent d7f92d435e
commit 46a6d089b7
2 changed files with 24 additions and 2 deletions

View file

@ -8,8 +8,9 @@
namespace routing
{
static double const kMaxSpeedMPS = 5000.0 / 3600;
static double const kEpsilon = 1e-6;
double const kMaxSpeedMPS = 5000.0 / 3600;
double const kEpsilon = 1e-6;
int const kCancelledPollPeriod = 100;
namespace
{
@ -117,8 +118,17 @@ IRouter::ResultCode AStarRouter::CalculateRouteM2M(vector<RoadPos> const & start
queue.push(Vertex(rp, 0.0));
}
int steps = 0;
while (!queue.empty())
{
++steps;
if (steps % kCancelledPollPeriod == 0)
{
if (IsCancelled())
return IRouter::Cancelled;
}
Vertex const v = queue.top();
queue.pop();

View file

@ -10,6 +10,8 @@
namespace routing
{
int const kCancelledPollPeriod = 100;
namespace
{
template <typename E>
@ -76,10 +78,20 @@ IRouter::ResultCode DijkstraRouter::CalculateRouteM2M(vector<RoadPos> const & st
for (auto const & p : dist)
queue.push(Vertex(p.first, 0.0 /* distance */));
int steps = 0;
while (!queue.empty())
{
++steps;
if (steps % kCancelledPollPeriod == 0)
{
if (IsCancelled())
return IRouter::Cancelled;
}
Vertex const v = queue.top();
queue.pop();
if (v.dist > dist[v.pos])
continue;