diff options
Diffstat (limited to 'routing')
25 files changed, 340 insertions, 293 deletions
diff --git a/routing/car_router.cpp b/routing/car_router.cpp index 08c13421a1..24ac35d1e4 100644 --- a/routing/car_router.cpp +++ b/routing/car_router.cpp @@ -244,7 +244,7 @@ bool CarRouter::CheckRoutingAbility(m2::PointD const & startPoint, m2::PointD co } CarRouter::CarRouter(Index & index, TCountryFileFn const & countryFileFn, - unique_ptr<AStarRouter> localRouter) + unique_ptr<SingleMwmRouter> localRouter) : m_index(index), m_indexManager(countryFileFn, index), m_router(move(localRouter)) { } diff --git a/routing/car_router.hpp b/routing/car_router.hpp index 4f974869d5..29f6693813 100644 --- a/routing/car_router.hpp +++ b/routing/car_router.hpp @@ -1,11 +1,11 @@ #pragma once -#include "routing/astar_router.hpp" #include "routing/osrm_data_facade.hpp" #include "routing/osrm_engine.hpp" #include "routing/route.hpp" #include "routing/router.hpp" #include "routing/routing_mapping.hpp" +#include "routing/single_mwm_router.hpp" #include "std/unique_ptr.hpp" #include "std/vector.hpp" @@ -35,7 +35,7 @@ public: typedef vector<double> GeomTurnCandidateT; CarRouter(Index & index, TCountryFileFn const & countryFileFn, - unique_ptr<AStarRouter> localRouter); + unique_ptr<SingleMwmRouter> localRouter); virtual string GetName() const override; @@ -115,6 +115,6 @@ private: RoutingIndexManager m_indexManager; - unique_ptr<AStarRouter> m_router; + unique_ptr<SingleMwmRouter> m_router; }; } // namespace routing diff --git a/routing/directions_engine.cpp b/routing/directions_engine.cpp index c054c9a74f..53d5ed602a 100644 --- a/routing/directions_engine.cpp +++ b/routing/directions_engine.cpp @@ -87,39 +87,4 @@ bool IDirectionsEngine::ReconstructPath(IRoadGraph const & graph, vector<Junctio return true; } - -void ReconstructRoute(IDirectionsEngine * engine, IRoadGraph const & graph, - my::Cancellable const & cancellable, vector<Junction> & path, Route & route) -{ - if (path.empty()) - { - LOG(LERROR, ("Can't reconstruct route from an empty list of positions.")); - return; - } - - // By some reason there're two adjacent positions on a road with - // the same end-points. This could happen, for example, when - // direction on a road was changed. But it doesn't matter since - // this code reconstructs only geometry of a route. - path.erase(unique(path.begin(), path.end()), path.end()); - - Route::TTimes times; - Route::TTurns turnsDir; - vector<Junction> junctions; - // @TODO(bykoianko) streetNames is not filled in Generate(). It should be done. - Route::TStreets streetNames; - if (engine) - engine->Generate(graph, path, times, turnsDir, junctions, cancellable); - - vector<m2::PointD> routeGeometry; - JunctionsToPoints(junctions, routeGeometry); - feature::TAltitudes altitudes; - JunctionsToAltitudes(junctions, altitudes); - - route.SetGeometry(routeGeometry.begin(), routeGeometry.end()); - route.SetSectionTimes(move(times)); - route.SetTurnInstructions(move(turnsDir)); - route.SetStreetNames(move(streetNames)); - route.SetAltitudes(move(altitudes)); -} } // namespace routing diff --git a/routing/directions_engine.hpp b/routing/directions_engine.hpp index c82b1c5d59..7893e9b5c4 100644 --- a/routing/directions_engine.hpp +++ b/routing/directions_engine.hpp @@ -28,7 +28,4 @@ protected: void CalculateTimes(IRoadGraph const & graph, vector<Junction> const & path, Route::TTimes & times) const; }; - -void ReconstructRoute(IDirectionsEngine * engine, IRoadGraph const & graph, - my::Cancellable const & cancellable, vector<Junction> & path, Route & route); } // namespace routing diff --git a/routing/edge_estimator.cpp b/routing/edge_estimator.cpp index 4bf6f8579e..52cb10905a 100644 --- a/routing/edge_estimator.cpp +++ b/routing/edge_estimator.cpp @@ -17,7 +17,7 @@ inline double TimeBetweenSec(m2::PointD const & from, m2::PointD const & to, dou class CarEdgeEstimator : public EdgeEstimator { public: - CarEdgeEstimator(shared_ptr<IVehicleModel> vehicleModel); + CarEdgeEstimator(IVehicleModel const & vehicleModel); // EdgeEstimator overrides: double CalcEdgesWeight(RoadGeometry const & road, uint32_t pointFrom, @@ -28,8 +28,8 @@ private: double const m_maxSpeedMPS; }; -CarEdgeEstimator::CarEdgeEstimator(shared_ptr<IVehicleModel> vehicleModel) - : m_maxSpeedMPS(vehicleModel->GetMaxSpeed() * kKMPH2MPS) +CarEdgeEstimator::CarEdgeEstimator(IVehicleModel const & vehicleModel) + : m_maxSpeedMPS(vehicleModel.GetMaxSpeed() * kKMPH2MPS) { } @@ -56,7 +56,8 @@ double CarEdgeEstimator::CalcHeuristic(m2::PointD const & from, m2::PointD const namespace routing { -shared_ptr<EdgeEstimator> CreateCarEdgeEstimator(shared_ptr<IVehicleModel> vehicleModel) +// static +shared_ptr<EdgeEstimator> EdgeEstimator::CreateForCar(IVehicleModel const & vehicleModel) { return make_shared<CarEdgeEstimator>(vehicleModel); } diff --git a/routing/edge_estimator.hpp b/routing/edge_estimator.hpp index 50a6591a47..0a6ec2d1e0 100644 --- a/routing/edge_estimator.hpp +++ b/routing/edge_estimator.hpp @@ -18,7 +18,7 @@ public: virtual double CalcEdgesWeight(RoadGeometry const & road, uint32_t pointFrom, uint32_t pointTo) const = 0; virtual double CalcHeuristic(m2::PointD const & from, m2::PointD const & to) const = 0; -}; -shared_ptr<EdgeEstimator> CreateCarEdgeEstimator(shared_ptr<IVehicleModel> vehicleModel); + static shared_ptr<EdgeEstimator> CreateForCar(IVehicleModel const & vehicleModel); +}; } // namespace routing diff --git a/routing/geometry.cpp b/routing/geometry.cpp index 38c3359b0b..218aa0eb03 100644 --- a/routing/geometry.cpp +++ b/routing/geometry.cpp @@ -1,4 +1,6 @@ -#include "geometry.hpp" +#include "routing/geometry.hpp" + +#include "routing/routing_exception.hpp" #include "geometry/mercator.hpp" @@ -36,10 +38,7 @@ void GeometryLoaderImpl::Load(uint32_t featureId, RoadGeometry & road) const FeatureType feature; bool const isFound = m_guard.GetFeatureByIndex(featureId, feature); if (!isFound) - { - LOG(LERROR, ("Feature", featureId, "not found")); - return; - } + MYTHROW(RoutingException, ("Feature", featureId, "not found")); feature.ParseGeometry(FeatureType::BEST_GEOMETRY); road.Load(*m_vehicleModel, feature); @@ -48,6 +47,8 @@ void GeometryLoaderImpl::Load(uint32_t featureId, RoadGeometry & road) const namespace routing { +// RoadGeometry ------------------------------------------------------------------------------------ + RoadGeometry::RoadGeometry(bool oneWay, double speed, Points const & points) : m_isRoad(true), m_isOneWay(oneWay), m_speed(speed), m_points(points) { @@ -64,11 +65,24 @@ void RoadGeometry::Load(IVehicleModel const & vehicleModel, FeatureType const & m_points.emplace_back(feature.GetPoint(i)); } +// Geometry ---------------------------------------------------------------------------------------- + Geometry::Geometry(unique_ptr<GeometryLoader> loader) : m_loader(move(loader)) { ASSERT(m_loader, ()); } +RoadGeometry const & Geometry::GetRoad(uint32_t featureId) const +{ + auto const & it = m_roads.find(featureId); + if (it != m_roads.cend()) + return it->second; + + RoadGeometry & road = m_roads[featureId]; + m_loader->Load(featureId, road); + return road; +} + unique_ptr<GeometryLoader> CreateGeometryLoader(Index const & index, MwmSet::MwmId const & mwmId, shared_ptr<IVehicleModel> vehicleModel) { diff --git a/routing/geometry.hpp b/routing/geometry.hpp index a98f649cf3..f10cb6dd78 100644 --- a/routing/geometry.hpp +++ b/routing/geometry.hpp @@ -29,7 +29,8 @@ public: bool IsOneWay() const { return m_isOneWay; } - bool GetSpeed() const { return m_speed; } + // Kilometers per hour. + double GetSpeed() const { return m_speed; } m2::PointD const & GetPoint(uint32_t pointId) const { @@ -60,16 +61,7 @@ public: Geometry() = default; explicit Geometry(unique_ptr<GeometryLoader> loader); - RoadGeometry const & GetRoad(uint32_t featureId) const - { - auto const & it = m_roads.find(featureId); - if (it != m_roads.cend()) - return it->second; - - RoadGeometry & road = m_roads[featureId]; - m_loader->Load(featureId, road); - return road; - } + RoadGeometry const & GetRoad(uint32_t featureId) const; m2::PointD const & GetPoint(RoadPoint const & rp) const { diff --git a/routing/index_graph.cpp b/routing/index_graph.cpp index 6e3e0136c3..f2c8131298 100644 --- a/routing/index_graph.cpp +++ b/routing/index_graph.cpp @@ -14,7 +14,7 @@ IndexGraph::IndexGraph(unique_ptr<GeometryLoader> loader, shared_ptr<EdgeEstimat void IndexGraph::GetEdgesList(Joint::Id jointId, bool isOutgoing, vector<JointEdge> & edges) const { m_jointIndex.ForEachPoint(jointId, [this, &edges, isOutgoing](RoadPoint const & rp) { - AddNeighboringEdges(rp, isOutgoing, edges); + GetNeighboringEdges(rp, isOutgoing, edges); }); } @@ -40,7 +40,7 @@ Joint::Id IndexGraph::InsertJoint(RoadPoint const & rp) return jointId; } -bool IndexGraph::JointLaysOnRoad(Joint::Id jointId, uint32_t featureId) const +bool IndexGraph::JointLiesOnRoad(Joint::Id jointId, uint32_t featureId) const { bool result = false; m_jointIndex.ForEachPoint(jointId, [&result, featureId](RoadPoint const & rp) { @@ -51,7 +51,7 @@ bool IndexGraph::JointLaysOnRoad(Joint::Id jointId, uint32_t featureId) const return result; } -inline void IndexGraph::AddNeighboringEdges(RoadPoint rp, bool isOutgoing, +inline void IndexGraph::GetNeighboringEdges(RoadPoint rp, bool isOutgoing, vector<JointEdge> & edges) const { RoadGeometry const & road = m_geometry.GetRoad(rp.GetFeatureId()); @@ -60,13 +60,13 @@ inline void IndexGraph::AddNeighboringEdges(RoadPoint rp, bool isOutgoing, bool const bidirectional = !road.IsOneWay(); if (!isOutgoing || bidirectional) - AddNeighboringEdge(road, rp, false /* forward */, edges); + GetNeighboringEdge(road, rp, false /* forward */, edges); if (isOutgoing || bidirectional) - AddNeighboringEdge(road, rp, true /* forward */, edges); + GetNeighboringEdge(road, rp, true /* forward */, edges); } -inline void IndexGraph::AddNeighboringEdge(RoadGeometry const & road, RoadPoint rp, bool forward, +inline void IndexGraph::GetNeighboringEdge(RoadGeometry const & road, RoadPoint rp, bool forward, vector<JointEdge> & edges) const { pair<Joint::Id, uint32_t> const & neighbor = m_roadIndex.FindNeighbor(rp, forward); @@ -77,8 +77,8 @@ inline void IndexGraph::AddNeighboringEdge(RoadGeometry const & road, RoadPoint } } -void IndexGraph::AddDirectEdge(uint32_t featureId, uint32_t pointFrom, uint32_t pointTo, - Joint::Id target, bool forward, vector<JointEdge> & edges) const +void IndexGraph::GetDirectedEdge(uint32_t featureId, uint32_t pointFrom, uint32_t pointTo, + Joint::Id target, bool forward, vector<JointEdge> & edges) const { RoadGeometry const & road = m_geometry.GetRoad(featureId); if (!road.IsRoad()) diff --git a/routing/index_graph.hpp b/routing/index_graph.hpp index 77ec8bb2a4..0d7f576b58 100644 --- a/routing/index_graph.hpp +++ b/routing/index_graph.hpp @@ -39,25 +39,28 @@ public: IndexGraph() = default; explicit IndexGraph(unique_ptr<GeometryLoader> loader, shared_ptr<EdgeEstimator> estimator); - void AddDirectEdge(uint32_t featureId, uint32_t pointFrom, uint32_t pointTo, Joint::Id target, - bool forward, vector<JointEdge> & edges) const; - void AddNeighboringEdges(RoadPoint rp, bool isOutgoing, vector<JointEdge> & edges) const; + // Creates edge for points in same feature. + void GetDirectedEdge(uint32_t featureId, uint32_t pointFrom, uint32_t pointTo, Joint::Id target, + bool forward, vector<JointEdge> & edges) const; + void GetNeighboringEdges(RoadPoint rp, bool isOutgoing, vector<JointEdge> & edges) const; void GetEdgesList(Joint::Id jointId, bool forward, vector<JointEdge> & edges) const; Joint::Id GetJointId(RoadPoint rp) const { return m_roadIndex.GetJointId(rp); } + m2::PointD const & GetPoint(Joint::Id jointId) const; + Geometry const & GetGeometry() const { return m_geometry; } EdgeEstimator const & GetEstimator() const { return *m_estimator; } - m2::PointD const & GetPoint(Joint::Id jointId) const; uint32_t GetNumRoads() const { return m_roadIndex.GetSize(); } uint32_t GetNumJoints() const { return m_jointIndex.GetNumJoints(); } uint32_t GetNumPoints() const { return m_jointIndex.GetNumPoints(); } + void Import(vector<Joint> const & joints); Joint::Id InsertJoint(RoadPoint const & rp); - bool JointLaysOnRoad(Joint::Id jointId, uint32_t featureId) const; + bool JointLiesOnRoad(Joint::Id jointId, uint32_t featureId) const; template <typename F> void ForEachPoint(Joint::Id jointId, F && f) const { - m_jointIndex.ForEachPoint(jointId, f); + m_jointIndex.ForEachPoint(jointId, forward<F>(f)); } template <class Sink> @@ -76,7 +79,7 @@ public: } private: - void AddNeighboringEdge(RoadGeometry const & road, RoadPoint rp, bool forward, + void GetNeighboringEdge(RoadGeometry const & road, RoadPoint rp, bool forward, vector<JointEdge> & edges) const; Geometry m_geometry; diff --git a/routing/index_graph_starter.cpp b/routing/index_graph_starter.cpp index 53f64a7b1b..e58e63eec8 100644 --- a/routing/index_graph_starter.cpp +++ b/routing/index_graph_starter.cpp @@ -1,90 +1,27 @@ #include "routing/index_graph_starter.hpp" +#include "routing/routing_exception.hpp" + namespace routing { IndexGraphStarter::IndexGraphStarter(IndexGraph const & graph, RoadPoint startPoint, RoadPoint finishPoint) : m_graph(graph) - , m_startPoint(startPoint) - , m_finishPoint(finishPoint) - , m_startImplant(graph.GetNumJoints()) - , m_finishImplant(graph.GetNumJoints() + 1) - , m_startJoint(CalcStartJoint()) - , m_finishJoint(CalcFinishJoint()) -{ -} - -Joint::Id IndexGraphStarter::CalcStartJoint() const + , m_start(graph, startPoint, graph.GetNumJoints(), graph.GetJointId(startPoint)) + , m_finish(graph, finishPoint, graph.GetNumJoints() + 1, + startPoint == finishPoint ? m_start.m_jointId : graph.GetJointId(finishPoint)) { - Joint::Id const jointId = m_graph.GetJointId(m_startPoint); - if (jointId == Joint::kInvalidId) - return m_startImplant; - - return jointId; } -Joint::Id IndexGraphStarter::CalcFinishJoint() const +m2::PointD const & IndexGraphStarter::GetPoint(Joint::Id jointId) const { - if (m_startPoint == m_finishPoint) - return CalcStartJoint(); + if (jointId == m_start.m_fakeId) + return m_graph.GetGeometry().GetPoint(m_start.m_point); - Joint::Id const jointId = m_graph.GetJointId(m_finishPoint); - if (jointId == Joint::kInvalidId) - return m_finishImplant; + if (jointId == m_finish.m_fakeId) + return m_graph.GetGeometry().GetPoint(m_finish.m_point); - return jointId; -} - -void IndexGraphStarter::GetEdgesList(Joint::Id jointId, bool isOutgoing, - vector<JointEdge> & edges) const -{ - edges.clear(); - - if (jointId == m_startImplant) - { - m_graph.AddNeighboringEdges(m_startPoint, isOutgoing, edges); - - if (FinishIsImplant() && m_startPoint.GetFeatureId() == m_finishPoint.GetFeatureId()) - m_graph.AddDirectEdge(m_startPoint.GetFeatureId(), m_startPoint.GetPointId(), - m_finishPoint.GetPointId(), m_finishJoint, isOutgoing, edges); - - return; - } - - if (jointId == m_finishImplant) - { - m_graph.AddNeighboringEdges(m_finishPoint, isOutgoing, edges); - - if (StartIsImplant() && m_startPoint.GetFeatureId() == m_finishPoint.GetFeatureId()) - m_graph.AddDirectEdge(m_finishPoint.GetFeatureId(), m_finishPoint.GetPointId(), - m_startPoint.GetPointId(), m_startJoint, isOutgoing, edges); - - return; - } - - m_graph.GetEdgesList(jointId, isOutgoing, edges); - - if (StartIsImplant() && m_graph.JointLaysOnRoad(jointId, m_startPoint.GetFeatureId())) - { - vector<JointEdge> startEdges; - m_graph.AddNeighboringEdges(m_startPoint, !isOutgoing, startEdges); - for (JointEdge const & edge : startEdges) - { - if (edge.GetTarget() == jointId) - edges.emplace_back(m_startJoint, edge.GetWeight()); - } - } - - if (FinishIsImplant() && m_graph.JointLaysOnRoad(jointId, m_finishPoint.GetFeatureId())) - { - vector<JointEdge> finishEdges; - m_graph.AddNeighboringEdges(m_finishPoint, !isOutgoing, finishEdges); - for (JointEdge const & edge : finishEdges) - { - if (edge.GetTarget() == jointId) - edges.emplace_back(m_finishJoint, edge.GetWeight()); - } - } + return m_graph.GetPoint(jointId); } void IndexGraphStarter::RedressRoute(vector<Joint::Id> const & route, @@ -93,7 +30,7 @@ void IndexGraphStarter::RedressRoute(vector<Joint::Id> const & route, if (route.size() < 2) { if (route.size() == 1) - roadPoints.emplace_back(m_startPoint); + roadPoints.emplace_back(m_start.m_point); return; } @@ -126,7 +63,7 @@ void IndexGraphStarter::RedressRoute(vector<Joint::Id> const & route, } else { - MYTHROW(RootException, + MYTHROW(RoutingException, ("Wrong equality pointFrom = pointTo =", pointFrom, ", featureId = ", featureId)); } @@ -134,6 +71,60 @@ void IndexGraphStarter::RedressRoute(vector<Joint::Id> const & route, } } +void IndexGraphStarter::GetEdgesList(Joint::Id jointId, bool isOutgoing, + vector<JointEdge> & edges) const +{ + edges.clear(); + + if (jointId == m_start.m_fakeId) + { + GetFakeEdges(m_start, m_finish, isOutgoing, edges); + return; + } + + if (jointId == m_finish.m_fakeId) + { + GetFakeEdges(m_finish, m_start, isOutgoing, edges); + return; + } + + m_graph.GetEdgesList(jointId, isOutgoing, edges); + GetArrivalFakeEdges(jointId, m_start, isOutgoing, edges); + GetArrivalFakeEdges(jointId, m_finish, isOutgoing, edges); +} + +void IndexGraphStarter::GetFakeEdges(IndexGraphStarter::FakeJoint const & from, + IndexGraphStarter::FakeJoint const & to, bool isOutgoing, + vector<JointEdge> & edges) const +{ + m_graph.GetNeighboringEdges(from.m_point, isOutgoing, edges); + + if (to.IsFake() && from.m_point.GetFeatureId() == to.m_point.GetFeatureId()) + { + m_graph.GetDirectedEdge(from.m_point.GetFeatureId(), from.m_point.GetPointId(), + to.m_point.GetPointId(), to.m_jointId, isOutgoing, edges); + } +} + +inline void IndexGraphStarter::GetArrivalFakeEdges(Joint::Id jointId, + IndexGraphStarter::FakeJoint const & fakeJoint, + bool isOutgoing, vector<JointEdge> & edges) const +{ + if (!fakeJoint.IsFake()) + return; + + if (!m_graph.JointLiesOnRoad(jointId, fakeJoint.m_point.GetFeatureId())) + return; + + vector<JointEdge> startEdges; + m_graph.GetNeighboringEdges(fakeJoint.m_point, !isOutgoing, startEdges); + for (JointEdge const & edge : startEdges) + { + if (edge.GetTarget() == jointId) + edges.emplace_back(fakeJoint.m_jointId, edge.GetWeight()); + } +} + void IndexGraphStarter::FindPointsWithCommonFeature(Joint::Id jointId0, Joint::Id jointId1, RoadPoint & result0, RoadPoint & result1) const { @@ -142,46 +133,63 @@ void IndexGraphStarter::FindPointsWithCommonFeature(Joint::Id jointId0, Joint::I ForEachPoint(jointId0, [&](RoadPoint const & rp0) { ForEachPoint(jointId1, [&](RoadPoint const & rp1) { - if (rp0.GetFeatureId() == rp1.GetFeatureId()) - { - RoadGeometry const & road = m_graph.GetGeometry().GetRoad(rp0.GetFeatureId()); - if (!road.IsRoad()) - return; + if (rp0.GetFeatureId() != rp1.GetFeatureId()) + return; + + RoadGeometry const & road = m_graph.GetGeometry().GetRoad(rp0.GetFeatureId()); + if (!road.IsRoad()) + return; - if (road.IsOneWay() && rp0.GetPointId() > rp1.GetPointId()) - return; + if (road.IsOneWay() && rp0.GetPointId() > rp1.GetPointId()) + return; - if (found) + if (found) + { + if (minWeight < 0.0) { - if (minWeight < 0.0) - { - // CalcEdgesWeight is very expensive. - // So calculate it only if second common feature found. - RoadGeometry const & prevRoad = m_graph.GetGeometry().GetRoad(result0.GetFeatureId()); - minWeight = m_graph.GetEstimator().CalcEdgesWeight(prevRoad, result0.GetPointId(), - result1.GetPointId()); - } - - double const weight = - m_graph.GetEstimator().CalcEdgesWeight(road, rp0.GetPointId(), rp1.GetPointId()); - if (weight < minWeight) - { - minWeight = weight; - result0 = rp0; - result1 = rp1; - } + // CalcEdgesWeight is very expensive. + // So calculate it only if second common feature found. + RoadGeometry const & prevRoad = m_graph.GetGeometry().GetRoad(result0.GetFeatureId()); + minWeight = m_graph.GetEstimator().CalcEdgesWeight(prevRoad, result0.GetPointId(), + result1.GetPointId()); } - else + + double const weight = + m_graph.GetEstimator().CalcEdgesWeight(road, rp0.GetPointId(), rp1.GetPointId()); + if (weight < minWeight) { + minWeight = weight; result0 = rp0; result1 = rp1; - found = true; } } + else + { + result0 = rp0; + result1 = rp1; + found = true; + } }); }); if (!found) - MYTHROW(RootException, ("Can't find common feature for joints", jointId0, jointId1)); + MYTHROW(RoutingException, ("Can't find common feature for joints", jointId0, jointId1)); +} + +// IndexGraphStarter::FakeJoint -------------------------------------------------------------------- + +IndexGraphStarter::FakeJoint::FakeJoint(IndexGraph const & graph, RoadPoint point, Joint::Id fakeId, + Joint::Id suggestedId) + : m_point(point), m_fakeId(fakeId), m_jointId(CalcJointId(graph, suggestedId)) +{ +} + +Joint::Id IndexGraphStarter::FakeJoint::CalcJointId(IndexGraph const & graph, + Joint::Id suggestedId) const +{ + if (suggestedId == Joint::kInvalidId) + return m_fakeId; + + return suggestedId; } } // namespace routing diff --git a/routing/index_graph_starter.hpp b/routing/index_graph_starter.hpp index c036c0bd14..bcf5448306 100644 --- a/routing/index_graph_starter.hpp +++ b/routing/index_graph_starter.hpp @@ -3,13 +3,15 @@ #include "routing/index_graph.hpp" #include "routing/joint.hpp" +#include "std/utility.hpp" + namespace routing { // The problem: // IndexGraph contains only road points connected in joints. // So it is possible IndexGraph doesn't contain start and finish. // -// IndexGraphStarter implants start and finish for AStarAlgorithm. +// IndexGraphStarter adds fake start and finish joint ids for AStarAlgorithm. // class IndexGraphStarter final { @@ -21,19 +23,10 @@ public: IndexGraphStarter(IndexGraph const & graph, RoadPoint startPoint, RoadPoint finishPoint); IndexGraph const & GetGraph() const { return m_graph; } - Joint::Id GetStartJoint() const { return m_startJoint; } - Joint::Id GetFinishJoint() const { return m_finishJoint; } - - m2::PointD const & GetPoint(Joint::Id jointId) const - { - if (jointId == m_startImplant) - return m_graph.GetGeometry().GetPoint(m_startPoint); + Joint::Id GetStartJoint() const { return m_start.m_jointId; } + Joint::Id GetFinishJoint() const { return m_finish.m_jointId; } - if (jointId == m_finishImplant) - return m_graph.GetGeometry().GetPoint(m_finishPoint); - - return m_graph.GetPoint(jointId); - } + m2::PointD const & GetPoint(Joint::Id jointId) const; void GetOutgoingEdgesList(Joint::Id jointId, vector<JointEdge> & edges) const { @@ -45,8 +38,6 @@ public: GetEdgesList(jointId, false, edges); } - void GetEdgesList(Joint::Id jointId, bool isOutgoing, vector<JointEdge> & edges) const; - double HeuristicCostEstimate(Joint::Id from, Joint::Id to) const { return m_graph.GetEstimator().CalcHeuristic(GetPoint(from), GetPoint(to)); @@ -58,39 +49,47 @@ public: void RedressRoute(vector<Joint::Id> const & route, vector<RoadPoint> & roadPoints) const; private: - Joint::Id CalcStartJoint() const; - Joint::Id CalcFinishJoint() const; + struct FakeJoint final + { + FakeJoint(IndexGraph const & graph, RoadPoint point, Joint::Id fakeId, Joint::Id suggestedId); + + Joint::Id CalcJointId(IndexGraph const & graph, Joint::Id suggestedId) const; + bool IsFake() const { return m_jointId == m_fakeId; } - bool StartIsImplant() const { return m_startJoint == m_startImplant; } - bool FinishIsImplant() const { return m_finishJoint == m_finishImplant; } + RoadPoint const m_point; + Joint::Id const m_fakeId; + Joint::Id const m_jointId; + }; template <typename F> void ForEachPoint(Joint::Id jointId, F && f) const { - if (jointId == m_startImplant) + if (jointId == m_start.m_fakeId) { - f(m_startPoint); + f(m_start.m_point); return; } - if (jointId == m_finishImplant) + if (jointId == m_finish.m_fakeId) { - f(m_finishPoint); + f(m_finish.m_point); return; } - m_graph.ForEachPoint(jointId, f); + m_graph.ForEachPoint(jointId, forward<F>(f)); } + void GetEdgesList(Joint::Id jointId, bool isOutgoing, vector<JointEdge> & edges) const; + void GetFakeEdges(FakeJoint const & from, FakeJoint const & to, bool isOutgoing, + vector<JointEdge> & edges) const; + void GetArrivalFakeEdges(Joint::Id jointId, FakeJoint const & fakeJoint, bool isOutgoing, + vector<JointEdge> & edges) const; + void FindPointsWithCommonFeature(Joint::Id jointId0, Joint::Id jointId1, RoadPoint & result0, RoadPoint & result1) const; IndexGraph const & m_graph; - RoadPoint const m_startPoint; - RoadPoint const m_finishPoint; - Joint::Id const m_startImplant; - Joint::Id const m_finishImplant; - Joint::Id const m_startJoint; - Joint::Id const m_finishJoint; + FakeJoint const m_start; + FakeJoint const m_finish; }; } // namespace routing diff --git a/routing/joint_index.cpp b/routing/joint_index.cpp index 2efd1c5bb8..b073848d97 100644 --- a/routing/joint_index.cpp +++ b/routing/joint_index.cpp @@ -1,5 +1,7 @@ #include "routing/joint_index.hpp" +#include "routing/routing_exception.hpp" + namespace routing { Joint::Id JointIndex::InsertJoint(RoadPoint const & rp) @@ -23,48 +25,39 @@ void JointIndex::Build(RoadIndex const & roadIndex, uint32_t numJoints) // And m_offsets.back() == m_points.size() m_offsets.assign(numJoints + 1, 0); - // Calculate shifted sizes. + // Calculate sizes. // Example for numJoints = 6: - // Original sizes: 2, 5, 3, 4, 2, 3, 0 - // Shifted sizes: 0, 2, 5, 3, 4, 2, 3 - roadIndex.ForEachRoad([this](uint32_t /* featureId */, RoadJointIds const & road) { - road.ForEachJoint([this](uint32_t /* pointId */, Joint::Id jointId) { - Joint::Id nextId = jointId + 1; - ASSERT_LESS(jointId, m_offsets.size(), ()); - ++m_offsets[nextId]; + // 2, 5, 3, 4, 2, 3, 0 + roadIndex.ForEachRoad([this, numJoints](uint32_t /* featureId */, RoadJointIds const & road) { + road.ForEachJoint([this, numJoints](uint32_t /* pointId */, Joint::Id jointId) { + ASSERT_LESS(jointId, numJoints, ()); + ++m_offsets[jointId]; }); }); - // Calculate twice shifted offsets. - // Example: 0, 0, 2, 7, 10, 14, 16 - uint32_t sum = 0; - uint32_t prevSum = 0; + // Fill offsets with end bounds. + // Example: 2, 7, 10, 14, 16, 19, 19 for (size_t i = 1; i < m_offsets.size(); ++i) - { - sum += m_offsets[i]; - m_offsets[i] = prevSum; - prevSum = sum; - } + m_offsets[i] += m_offsets[i - 1]; - m_points.resize(sum); + m_points.resize(m_offsets.back()); - // Now fill points, m_offsets[nextId] is current incrementing begin. - // Offsets after this operation: 0, 2, 7, 10, 14, 16, 19 + // Now fill points. + // Offsets after this operation are begin bounds: + // 0, 2, 7, 10, 14, 16, 19 roadIndex.ForEachRoad([this](uint32_t featureId, RoadJointIds const & road) { road.ForEachJoint([this, featureId](uint32_t pointId, Joint::Id jointId) { - Joint::Id nextId = jointId + 1; - ASSERT_LESS(nextId, m_offsets.size(), ()); - uint32_t & offset = m_offsets[nextId]; + uint32_t & offset = m_offsets[jointId]; + --offset; m_points[offset] = {featureId, pointId}; - ++offset; }); }); if (m_offsets[0] != 0) - MYTHROW(RootException, ("Wrong offsets calculation: m_offsets[0] =", m_offsets[0])); + MYTHROW(RoutingException, ("Wrong offsets calculation: m_offsets[0] =", m_offsets[0])); if (m_offsets.back() != m_points.size()) - MYTHROW(RootException, ("Wrong offsets calculation: m_offsets.back() =", m_offsets.back(), - ", m_points.size()=", m_points.size())); + MYTHROW(RoutingException, ("Wrong offsets calculation: m_offsets.back() =", m_offsets.back(), + ", m_points.size()=", m_points.size())); } } // namespace routing diff --git a/routing/joint_index.hpp b/routing/joint_index.hpp index 0bc95a6b3b..0e3c8c0441 100644 --- a/routing/joint_index.hpp +++ b/routing/joint_index.hpp @@ -4,6 +4,8 @@ #include "routing/road_index.hpp" #include "routing/road_point.hpp" +#include "base/assert.hpp" + #include "std/vector.hpp" namespace routing @@ -16,7 +18,12 @@ class JointIndex final { public: // Read comments in Build method about -1. - uint32_t GetNumJoints() const { return m_offsets.size() - 1; } + uint32_t GetNumJoints() const + { + CHECK_GREATER(m_offsets.size(), 0, ()); + return m_offsets.size() - 1; + } + uint32_t GetNumPoints() const { return m_points.size(); } RoadPoint GetPoint(Joint::Id jointId) const { return m_points[Begin(jointId)]; } diff --git a/routing/road_graph_router.cpp b/routing/road_graph_router.cpp index a4a8db19d7..e22de1bcd8 100644 --- a/routing/road_graph_router.cpp +++ b/routing/road_graph_router.cpp @@ -1,6 +1,5 @@ #include "routing/road_graph_router.hpp" -#include "routing/astar_router.hpp" #include "routing/bicycle_directions.hpp" #include "routing/bicycle_model.hpp" #include "routing/car_model.hpp" @@ -9,6 +8,8 @@ #include "routing/pedestrian_directions.hpp" #include "routing/pedestrian_model.hpp" #include "routing/route.hpp" +#include "routing/routing_helpers.hpp" +#include "routing/single_mwm_router.hpp" #include "coding/reader_wrapper.hpp" diff --git a/routing/road_index.cpp b/routing/road_index.cpp index acc1a9d8e8..e6668e8a0d 100644 --- a/routing/road_index.cpp +++ b/routing/road_index.cpp @@ -1,8 +1,6 @@ #include "routing/road_index.hpp" -#include "base/exception.hpp" - -#include "std/utility.hpp" +#include "routing/routing_exception.hpp" namespace routing { @@ -24,7 +22,7 @@ pair<Joint::Id, uint32_t> RoadIndex::FindNeighbor(RoadPoint rp, bool forward) co { auto const it = m_roads.find(rp.GetFeatureId()); if (it == m_roads.cend()) - MYTHROW(RootException, ("RoadIndex doesn't contains feature", rp.GetFeatureId())); + MYTHROW(RoutingException, ("RoadIndex doesn't contains feature", rp.GetFeatureId())); return it->second.FindNeighbor(rp.GetPointId(), forward); } diff --git a/routing/road_index.hpp b/routing/road_index.hpp index 1ceb9214aa..90bd61e70a 100644 --- a/routing/road_index.hpp +++ b/routing/road_index.hpp @@ -27,7 +27,11 @@ public: void AddJoint(uint32_t pointId, Joint::Id jointId) { if (pointId >= m_jointIds.size()) - m_jointIds.insert(m_jointIds.end(), pointId + 1 - m_jointIds.size(), Joint::kInvalidId); + { + size_t const insertCount = pointId + 1 - m_jointIds.size(); + CHECK_GREATER(insertCount, 0, ()); + m_jointIds.insert(m_jointIds.end(), insertCount, Joint::kInvalidId); + } ASSERT_EQUAL(m_jointIds[pointId], Joint::kInvalidId, ()); m_jointIds[pointId] = jointId; diff --git a/routing/routing.pro b/routing/routing.pro index b3c500cfc7..cff8f507b6 100644 --- a/routing/routing.pro +++ b/routing/routing.pro @@ -13,7 +13,6 @@ INCLUDEPATH += $$ROOT_DIR/3party/jansson/src \ $$ROOT_DIR/3party/osrm/osrm-backend/third_party SOURCES += \ - astar_router.cpp \ async_router.cpp \ base/followed_polyline.cpp \ bicycle_directions.cpp \ @@ -48,9 +47,11 @@ SOURCES += \ router.cpp \ router_delegate.cpp \ routing_algorithm.cpp \ + routing_helpers.cpp \ routing_mapping.cpp \ routing_serialization.cpp \ routing_session.cpp \ + single_mwm_router.cpp \ speed_camera.cpp \ turns.cpp \ turns_generator.cpp \ @@ -61,7 +62,6 @@ SOURCES += \ HEADERS += \ - astar_router.hpp \ async_router.hpp \ base/astar_algorithm.hpp \ base/followed_polyline.hpp \ @@ -100,12 +100,14 @@ HEADERS += \ router.hpp \ router_delegate.hpp \ routing_algorithm.hpp \ + routing_exception.hpp \ routing_helpers.hpp \ routing_mapping.hpp \ routing_result_graph.hpp \ routing_serialization.hpp \ routing_session.hpp \ routing_settings.hpp \ + single_mwm_router.hpp \ speed_camera.hpp \ turn_candidate.hpp \ turns.hpp \ diff --git a/routing/routing_exception.hpp b/routing/routing_exception.hpp new file mode 100644 index 0000000000..cf80b58eea --- /dev/null +++ b/routing/routing_exception.hpp @@ -0,0 +1,8 @@ +#pragma once + +#include "base/exception.hpp" + +namespace routing +{ +DECLARE_EXCEPTION(RoutingException, RootException); +} // namespace routing diff --git a/routing/routing_helpers.cpp b/routing/routing_helpers.cpp new file mode 100644 index 0000000000..c7450b9852 --- /dev/null +++ b/routing/routing_helpers.cpp @@ -0,0 +1,39 @@ +#include "routing/routing_helpers.hpp" + +namespace routing +{ +void ReconstructRoute(IDirectionsEngine * engine, IRoadGraph const & graph, + my::Cancellable const & cancellable, vector<Junction> & path, Route & route) +{ + if (path.empty()) + { + LOG(LERROR, ("Can't reconstruct route from an empty list of positions.")); + return; + } + + // By some reason there're two adjacent positions on a road with + // the same end-points. This could happen, for example, when + // direction on a road was changed. But it doesn't matter since + // this code reconstructs only geometry of a route. + path.erase(unique(path.begin(), path.end()), path.end()); + + Route::TTimes times; + Route::TTurns turnsDir; + vector<Junction> junctions; + // @TODO(bykoianko) streetNames is not filled in Generate(). It should be done. + Route::TStreets streetNames; + if (engine) + engine->Generate(graph, path, times, turnsDir, junctions, cancellable); + + vector<m2::PointD> routeGeometry; + JunctionsToPoints(junctions, routeGeometry); + feature::TAltitudes altitudes; + JunctionsToAltitudes(junctions, altitudes); + + route.SetGeometry(routeGeometry.begin(), routeGeometry.end()); + route.SetSectionTimes(move(times)); + route.SetTurnInstructions(move(turnsDir)); + route.SetStreetNames(move(streetNames)); + route.SetAltitudes(move(altitudes)); +} +} // namespace rouing diff --git a/routing/routing_helpers.hpp b/routing/routing_helpers.hpp index 76440a457e..e05d4f0093 100644 --- a/routing/routing_helpers.hpp +++ b/routing/routing_helpers.hpp @@ -2,7 +2,14 @@ #include "routing/bicycle_model.hpp" #include "routing/car_model.hpp" +#include "routing/directions_engine.hpp" #include "routing/pedestrian_model.hpp" +#include "routing/road_graph.hpp" +#include "routing/route.hpp" + +#include "base/cancellable.hpp" + +#include "std/vector.hpp" namespace routing { @@ -14,4 +21,7 @@ bool IsRoad(TTypes const & types) PedestrianModel::AllLimitsInstance().HasRoadType(types) || BicycleModel::AllLimitsInstance().HasRoadType(types); } + +void ReconstructRoute(IDirectionsEngine * engine, IRoadGraph const & graph, + my::Cancellable const & cancellable, vector<Junction> & path, Route & route); } // namespace rouing diff --git a/routing/routing_integration_tests/routing_test_tools.cpp b/routing/routing_integration_tests/routing_test_tools.cpp index 3010f4813c..a982361670 100644 --- a/routing/routing_integration_tests/routing_test_tools.cpp +++ b/routing/routing_integration_tests/routing_test_tools.cpp @@ -7,12 +7,12 @@ #include "geometry/distance_on_sphere.hpp" #include "geometry/latlon.hpp" -#include "routing/astar_router.hpp" #include "routing/online_absent_fetcher.hpp" #include "routing/online_cross_fetcher.hpp" #include "routing/road_graph_router.hpp" #include "routing/route.hpp" #include "routing/router_delegate.hpp" +#include "routing/single_mwm_router.hpp" #include "indexer/index.hpp" @@ -83,7 +83,7 @@ namespace integration }; auto carRouter = make_unique<CarRouter>( - index, countryFileGetter, CreateCarAStarBidirectionalRouter(index)); + index, countryFileGetter, SingleMwmRouter::CreateCarRouter(index)); return carRouter; } diff --git a/routing/routing_tests/index_graph_test.cpp b/routing/routing_tests/index_graph_test.cpp index 4a853baf8a..3458b7cd8e 100644 --- a/routing/routing_tests/index_graph_test.cpp +++ b/routing/routing_tests/index_graph_test.cpp @@ -64,7 +64,7 @@ Joint MakeJoint(vector<RoadPoint> const & points) shared_ptr<EdgeEstimator> CreateEstimator() { - return CreateCarEdgeEstimator(make_shared<CarModelFactory>()->GetVehicleModel()); + return EdgeEstimator::CreateForCar(*make_shared<CarModelFactory>()->GetVehicleModel()); } void TestRoute(IndexGraph const & graph, RoadPoint const & start, RoadPoint const & finish, diff --git a/routing/astar_router.cpp b/routing/single_mwm_router.cpp index 17c1abd2cf..f139a1fc5a 100644 --- a/routing/astar_router.cpp +++ b/routing/single_mwm_router.cpp @@ -1,15 +1,15 @@ -#include "routing/astar_router.hpp" +#include "routing/single_mwm_router.hpp" #include "routing/base/astar_algorithm.hpp" #include "routing/base/astar_progress.hpp" #include "routing/bicycle_directions.hpp" #include "routing/bicycle_model.hpp" #include "routing/car_model.hpp" -#include "routing/features_road_graph.hpp" #include "routing/index_graph.hpp" #include "routing/index_graph_starter.hpp" #include "routing/pedestrian_model.hpp" #include "routing/route.hpp" +#include "routing/routing_helpers.hpp" #include "routing/turns_generator.hpp" #include "indexer/feature_altitude.hpp" @@ -49,14 +49,13 @@ vector<Junction> ConvertToJunctions(IndexGraphStarter const & starter, namespace routing { -AStarRouter::AStarRouter(string const & name, Index const & index, - shared_ptr<VehicleModelFactory> vehicleModelFactory, - shared_ptr<EdgeEstimator> estimator, - unique_ptr<IDirectionsEngine> directionsEngine) +SingleMwmRouter::SingleMwmRouter(string const & name, Index const & index, + shared_ptr<VehicleModelFactory> vehicleModelFactory, + shared_ptr<EdgeEstimator> estimator, + unique_ptr<IDirectionsEngine> directionsEngine) : m_name(name) , m_index(index) - , m_roadGraph( - make_unique<FeaturesRoadGraph>(index, IRoadGraph::Mode::ObeyOnewayTag, vehicleModelFactory)) + , m_roadGraph(index, IRoadGraph::Mode::ObeyOnewayTag, vehicleModelFactory) , m_vehicleModelFactory(vehicleModelFactory) , m_estimator(estimator) , m_directionsEngine(move(directionsEngine)) @@ -67,11 +66,11 @@ AStarRouter::AStarRouter(string const & name, Index const & index, ASSERT(m_directionsEngine, ()); } -IRouter::ResultCode AStarRouter::CalculateRoute(MwmSet::MwmId const & mwmId, - m2::PointD const & startPoint, - m2::PointD const & startDirection, - m2::PointD const & finalPoint, - RouterDelegate const & delegate, Route & route) +IRouter::ResultCode SingleMwmRouter::CalculateRoute(MwmSet::MwmId const & mwmId, + m2::PointD const & startPoint, + m2::PointD const & startDirection, + m2::PointD const & finalPoint, + RouterDelegate const & delegate, Route & route) { try { @@ -85,12 +84,16 @@ IRouter::ResultCode AStarRouter::CalculateRoute(MwmSet::MwmId const & mwmId, } } -IRouter::ResultCode AStarRouter::DoCalculateRoute(MwmSet::MwmId const & mwmId, - m2::PointD const & startPoint, - m2::PointD const & /* startDirection */, - m2::PointD const & finalPoint, - RouterDelegate const & delegate, Route & route) +IRouter::ResultCode SingleMwmRouter::DoCalculateRoute(MwmSet::MwmId const & mwmId, + m2::PointD const & startPoint, + m2::PointD const & /* startDirection */, + m2::PointD const & finalPoint, + RouterDelegate const & delegate, + Route & route) { + if (!mwmId.IsAlive()) + return IRouter::RouteFileNotExist; + string const & country = mwmId.GetInfo()->GetCountryName(); Edge startEdge; @@ -117,15 +120,15 @@ IRouter::ResultCode AStarRouter::DoCalculateRoute(MwmSet::MwmId const & mwmId, progress.Initialize(graph.GetGeometry().GetPoint(start), graph.GetGeometry().GetPoint(finish)); uint32_t drawPointsStep = 0; - auto onVisitJunction = [&](Joint::Id const & from, Joint::Id const & target) { - m2::PointD const & point = starter.GetPoint(from); - m2::PointD const & targetPoint = starter.GetPoint(target); + auto onVisitJunction = [&](Joint::Id const & from, Joint::Id const & to) { + m2::PointD const & pointFrom = starter.GetPoint(from); + m2::PointD const & pointTo = starter.GetPoint(to); auto const lastValue = progress.GetLastValue(); - auto const newValue = progress.GetProgressForBidirectedAlgo(point, targetPoint); + auto const newValue = progress.GetProgressForBidirectedAlgo(pointFrom, pointTo); if (newValue - lastValue > kProgressInterval) delegate.OnProgress(newValue); if (drawPointsStep % kDrawPointsPeriod == 0) - delegate.OnPointCheck(point); + delegate.OnPointCheck(pointFrom); ++drawPointsStep; }; @@ -142,16 +145,16 @@ IRouter::ResultCode AStarRouter::DoCalculateRoute(MwmSet::MwmId const & mwmId, case AStarAlgorithm<IndexGraphStarter>::Result::Cancelled: return IRouter::Cancelled; case AStarAlgorithm<IndexGraphStarter>::Result::OK: vector<Junction> path = ConvertToJunctions(starter, routingResult.path); - ReconstructRoute(m_directionsEngine.get(), *m_roadGraph, delegate, path, route); + ReconstructRoute(m_directionsEngine.get(), m_roadGraph, delegate, path, route); return IRouter::NoError; } } -bool AStarRouter::FindClosestEdge(MwmSet::MwmId const & mwmId, m2::PointD const & point, - Edge & closestEdge) const +bool SingleMwmRouter::FindClosestEdge(MwmSet::MwmId const & mwmId, m2::PointD const & point, + Edge & closestEdge) const { vector<pair<Edge, Junction>> candidates; - m_roadGraph->FindClosestEdges(point, kMaxRoadCandidates, candidates); + m_roadGraph.FindClosestEdges(point, kMaxRoadCandidates, candidates); double minDistance = numeric_limits<double>::max(); size_t minIndex = candidates.size(); @@ -179,7 +182,8 @@ bool AStarRouter::FindClosestEdge(MwmSet::MwmId const & mwmId, m2::PointD const return true; } -bool AStarRouter::LoadIndex(MwmSet::MwmId const & mwmId, string const & country, IndexGraph & graph) +bool SingleMwmRouter::LoadIndex(MwmSet::MwmId const & mwmId, string const & country, + IndexGraph & graph) { MwmSet::MwmHandle mwmHandle = m_index.GetMwmHandleById(mwmId); if (!mwmHandle.IsAlive()) @@ -206,16 +210,17 @@ bool AStarRouter::LoadIndex(MwmSet::MwmId const & mwmId, string const & country, } } -unique_ptr<AStarRouter> CreateCarAStarBidirectionalRouter(Index & index) +// static +unique_ptr<SingleMwmRouter> SingleMwmRouter::CreateCarRouter(Index const & index) { auto vehicleModelFactory = make_shared<CarModelFactory>(); // @TODO Bicycle turn generation engine is used now. It's ok for the time being. // But later a special car turn generation engine should be implemented. auto directionsEngine = make_unique<BicycleDirectionsEngine>(index); - auto estimator = CreateCarEdgeEstimator(vehicleModelFactory->GetVehicleModel()); + auto estimator = EdgeEstimator::CreateForCar(*vehicleModelFactory->GetVehicleModel()); auto router = - make_unique<AStarRouter>("astar-bidirectional-car", index, move(vehicleModelFactory), - estimator, move(directionsEngine)); + make_unique<SingleMwmRouter>("astar-bidirectional-car", index, move(vehicleModelFactory), + estimator, move(directionsEngine)); return router; } } // namespace routing diff --git a/routing/astar_router.hpp b/routing/single_mwm_router.hpp index e61906bca3..96cd241453 100644 --- a/routing/astar_router.hpp +++ b/routing/single_mwm_router.hpp @@ -2,7 +2,7 @@ #include "routing/directions_engine.hpp" #include "routing/edge_estimator.hpp" -#include "routing/road_graph.hpp" +#include "routing/features_road_graph.hpp" #include "routing/router.hpp" #include "routing/vehicle_model.hpp" @@ -16,12 +16,13 @@ namespace routing { class IndexGraph; -class AStarRouter +class SingleMwmRouter { public: - AStarRouter(string const & name, Index const & index, - shared_ptr<VehicleModelFactory> vehicleModelFactory, - shared_ptr<EdgeEstimator> estimator, unique_ptr<IDirectionsEngine> directionsEngine); + SingleMwmRouter(string const & name, Index const & index, + shared_ptr<VehicleModelFactory> vehicleModelFactory, + shared_ptr<EdgeEstimator> estimator, + unique_ptr<IDirectionsEngine> directionsEngine); string const & GetName() const { return m_name; } @@ -30,6 +31,8 @@ public: m2::PointD const & finalPoint, RouterDelegate const & delegate, Route & route); + static unique_ptr<SingleMwmRouter> CreateCarRouter(Index const & index); + private: IRouter::ResultCode DoCalculateRoute(MwmSet::MwmId const & mwmId, m2::PointD const & startPoint, m2::PointD const & startDirection, @@ -39,13 +42,11 @@ private: Edge & closestEdge) const; bool LoadIndex(MwmSet::MwmId const & mwmId, string const & country, IndexGraph & graph); - string m_name; + string const m_name; Index const & m_index; - unique_ptr<IRoadGraph> m_roadGraph; + FeaturesRoadGraph m_roadGraph; shared_ptr<VehicleModelFactory> m_vehicleModelFactory; shared_ptr<EdgeEstimator> m_estimator; unique_ptr<IDirectionsEngine> m_directionsEngine; }; - -unique_ptr<AStarRouter> CreateCarAStarBidirectionalRouter(Index & index); } // namespace routing |