From e1315400688c95400abc9c33de833d285d9a8f40 Mon Sep 17 00:00:00 2001 From: Olga Khlopkova Date: Thu, 26 Nov 2020 12:24:48 +0300 Subject: [PATCH] [routing] Methods for handling RegionsGraphMode in IndexGraphStarter. --- routing/CMakeLists.txt | 7 ++++++ routing/index_graph_starter.cpp | 40 ++++++++++++++++++++++++++++++--- routing/index_graph_starter.hpp | 8 +++++++ 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/routing/CMakeLists.txt b/routing/CMakeLists.txt index 93e3bd9bdc..c445d23b47 100644 --- a/routing/CMakeLists.txt +++ b/routing/CMakeLists.txt @@ -7,6 +7,8 @@ include_directories( set( SRC + absent_regions_finder.cpp + absent_regions_finder.hpp async_router.cpp async_router.hpp base/astar_algorithm.hpp @@ -42,6 +44,7 @@ set( directions_engine.hpp directions_engine_helpers.cpp directions_engine_helpers.hpp + dummy_world_graph.hpp edge_estimator.cpp edge_estimator.hpp fake_edges_container.hpp @@ -106,6 +109,10 @@ set( pedestrian_directions.hpp position_accumulator.cpp position_accumulator.hpp + regions_router.cpp + regions_router.hpp + regions_sparse_graph.cpp + regions_sparse_graph.hpp restriction_loader.cpp restriction_loader.hpp restrictions_serialization.cpp diff --git a/routing/index_graph_starter.cpp b/routing/index_graph_starter.cpp index ccc13413d5..0d9661a96b 100644 --- a/routing/index_graph_starter.cpp +++ b/routing/index_graph_starter.cpp @@ -91,6 +91,12 @@ void IndexGraphStarter::Append(FakeEdgesContainer const & container) void IndexGraphStarter::SetGuides(GuidesGraph const & guides) { m_guides = guides; } +void IndexGraphStarter::SetRegionsGraphMode(std::shared_ptr regionsSparseGraph) +{ + m_regionsGraph = move(regionsSparseGraph); + m_graph.SetRegionsGraphMode(true); +} + LatLonWithAltitude const & IndexGraphStarter::GetStartJunction() const { auto const & startSegment = GetStartSegment(); @@ -113,6 +119,9 @@ bool IndexGraphStarter::ConvertToReal(Segment & segment) const LatLonWithAltitude const & IndexGraphStarter::GetJunction(Segment const & segment, bool front) const { + if (IsRegionsGraphMode() && !IsFakeSegment(segment)) + return m_regionsGraph->GetJunction(segment, front); + if (IsGuidesSegment(segment)) return m_guides.GetJunction(segment, front); @@ -216,6 +225,10 @@ void IndexGraphStarter::GetEdgesList(astar::VertexData const & v { m_guides.GetEdgeList(real, isOutgoing, edges, ingoingSegmentWeight); } + else if (IsRegionsGraphMode()) + { + m_regionsGraph->GetEdgeList(real, isOutgoing, edges, ingoingSegmentWeight); + } else { astar::VertexData const replacedFakeSegment(real, vertexData.m_realDistance); @@ -235,6 +248,10 @@ void IndexGraphStarter::GetEdgesList(astar::VertexData const & v { m_guides.GetEdgeList(segment, isOutgoing, edges, ingoingSegmentWeight); } + else if (IsRegionsGraphMode()) + { + m_regionsGraph->GetEdgeList(segment, isOutgoing, edges, ingoingSegmentWeight); + } else { m_graph.GetEdgeList(vertexData, isOutgoing, true /* useRoutingOptions */, useAccessConditional, @@ -260,6 +277,9 @@ RouteWeight IndexGraphStarter::CalcSegmentWeight(Segment const & segment, if (IsGuidesSegment(segment)) return CalcGuidesSegmentWeight(segment, purpose); + if (IsRegionsGraphMode() && !IsFakeSegment(segment)) + return m_regionsGraph->CalcSegmentWeight(segment); + if (!IsFakeSegment(segment)) return m_graph.CalcSegmentWeight(segment, purpose); @@ -276,8 +296,13 @@ RouteWeight IndexGraphStarter::CalcSegmentWeight(Segment const & segment, // Theoretically it may be differ from |RouteWeight(0)| because some road access block // may be kept in it and it is up to |RouteWeight| to know how to multiply by zero. - Weight const weight = IsGuidesSegment(real) ? CalcGuidesSegmentWeight(real, purpose) - : m_graph.CalcSegmentWeight(real, purpose); + Weight weight; + if (IsGuidesSegment(real)) + weight = CalcGuidesSegmentWeight(real, purpose); + else if (IsRegionsGraphMode()) + weight = m_regionsGraph->CalcSegmentWeight(real); + else + weight = m_graph.CalcSegmentWeight(real, purpose); if (fullLen == 0.0) return 0.0 * weight; @@ -312,6 +337,12 @@ double IndexGraphStarter::CalculateETA(Segment const & from, Segment const & to) return res; } + if (IsRegionsGraphMode()) + { + return m_regionsGraph->CalcSegmentWeight(from).GetWeight() + + m_regionsGraph->CalcSegmentWeight(to).GetWeight(); + } + return m_graph.CalculateETA(from, to); } @@ -323,6 +354,9 @@ double IndexGraphStarter::CalculateETAWithoutPenalty(Segment const & segment) co if (IsGuidesSegment(segment)) return CalcGuidesSegmentWeight(segment, EdgeEstimator::Purpose::ETA).GetWeight(); + if (IsRegionsGraphMode()) + return m_regionsGraph->CalcSegmentWeight(segment).GetWeight(); + return m_graph.CalculateETAWithoutPenalty(segment); } @@ -551,7 +585,7 @@ void IndexGraphStarter::AddFakeEdges(Segment const & segment, bool isOutgoing, v bool IndexGraphStarter::EndingPassThroughAllowed(Ending const & ending) { return any_of(ending.m_real.cbegin(), ending.m_real.cend(), [this](Segment const & s) { - if (IsGuidesSegment(s)) + if (IsGuidesSegment(s) || IsRegionsGraphMode()) return true; return m_graph.IsPassThroughAllowed(s.GetMwmId(), s.GetFeatureId()); }); diff --git a/routing/index_graph_starter.hpp b/routing/index_graph_starter.hpp index 1b476a76b6..a09e23aac3 100644 --- a/routing/index_graph_starter.hpp +++ b/routing/index_graph_starter.hpp @@ -11,6 +11,7 @@ #include "routing/index_graph.hpp" #include "routing/joint.hpp" #include "routing/latlon_with_altitude.hpp" +#include "routing/regions_sparse_graph.hpp" #include "routing/route_point.hpp" #include "routing/route_weight.hpp" #include "routing/segment.hpp" @@ -23,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -63,6 +65,9 @@ public: void SetGuides(GuidesGraph const & guides); + void SetRegionsGraphMode(std::shared_ptr regionsSparseGraph); + bool IsRegionsGraphMode() const { return m_regionsGraph != nullptr; } + WorldGraph & GetGraph() const { return m_graph; } WorldGraphMode GetMode() const { return m_graph.GetMode(); } LatLonWithAltitude const & GetStartJunction() const; @@ -258,5 +263,8 @@ private: uint32_t m_fakeNumerationStart; std::vector m_otherEndings; + + // Field for routing in mode for finding all route mwms. + std::shared_ptr m_regionsGraph = nullptr; }; } // namespace routing