Ejemplo n.º 1
0
AStarAlgorithm<IndexGraphStarter>::Result CalculateRoute(IndexGraphStarter & starter,
                                                         vector<RoadPoint> & roadPoints)
{
  AStarAlgorithm<IndexGraphStarter> algorithm;
  RoutingResult<Joint::Id> routingResult;
  auto const resultCode = algorithm.FindPath(
      starter, starter.GetStartJoint(), starter.GetFinishJoint(), routingResult, {}, {});

  starter.RedressRoute(routingResult.path, roadPoints);
  return resultCode;
}
Ejemplo n.º 2
0
bool SingleMwmRouter::BuildRoute(MwmSet::MwmId const & mwmId, vector<Joint::Id> const & joints,
                                 RouterDelegate const & delegate, IndexGraphStarter & starter,
                                 Route & route) const
{
  vector<RoutePoint> routePoints;
  starter.RedressRoute(joints, routePoints);

  vector<Junction> junctions;
  junctions.reserve(routePoints.size());

  Geometry & geometry = starter.GetGraph().GetGeometry();
  // TODO: Use real altitudes for pedestrian and bicycle routing.
  for (RoutePoint const & routePoint : routePoints)
  {
    junctions.emplace_back(geometry.GetPoint(routePoint.GetRoadPoint()),
                           feature::kDefaultAltitudeMeters);
  }

  shared_ptr<traffic::TrafficInfo::Coloring> trafficColoring = m_trafficCache.GetTrafficInfo(mwmId);
  ReconstructRoute(m_directionsEngine.get(), m_roadGraph, trafficColoring, delegate, junctions,
                   route);

  // ReconstructRoute duplicates all points except start and finish.
  // Therefore one needs fix time indexes to fit reconstructed polyline.
  // TODO: rework ReconstructRoute and remove this stuff.
  if (routePoints.size() < 2 || route.GetPoly().GetSize() + 2 != routePoints.size() * 2)
  {
    LOG(LERROR, ("Can't fix route times: polyline size =", route.GetPoly().GetSize(),
                 "route points size =", routePoints.size()));
    return false;
  }

  Route::TTimes times;
  times.reserve(route.GetPoly().GetSize());
  times.emplace_back(0, routePoints.front().GetTime());

  for (size_t i = 1; i < routePoints.size() - 1; ++i)
  {
    times.emplace_back(i * 2 - 1, routePoints[i].GetTime());
    times.emplace_back(i * 2, routePoints[i].GetTime());
  }

  times.emplace_back(route.GetPoly().GetSize() - 1, routePoints.back().GetTime());
  route.SetSectionTimes(move(times));
  return true;
}