diff --git a/routing/leaps_postprocessor.cpp b/routing/leaps_postprocessor.cpp index 336befd7dc..bc7b524ebe 100644 --- a/routing/leaps_postprocessor.cpp +++ b/routing/leaps_postprocessor.cpp @@ -41,15 +41,57 @@ namespace routing // static size_t const LeapsPostProcessor::kMaxStep = 5; -LeapsPostProcessor::LeapsPostProcessor(std::vector const & path, IndexGraphStarter & starter) - : m_path(path), - m_starter(starter), - m_bfs(starter), - m_prefixSumETA(path.size(), 0.0) +LeapsPostProcessor::LeapsPostProcessor(std::vector const & path, + IndexGraphStarter & starter) + : m_starter(starter), + m_bfs(starter) { - for (size_t i = 1; i < path.size(); ++i) + std::map jumps; + std::map segmentToIndex; + + for (size_t i = 0; i < path.size(); ++i) { - auto const & segment = path[i]; + auto const it = segmentToIndex.find(path[i]); + if (it == segmentToIndex.cend()) + { + segmentToIndex[path[i]] = i; + continue; + } + + auto const prevIndex = it->second; + jumps[prevIndex] = i; + it->second = i; + } + + for (size_t i = 0; i < path.size(); ++i) + { + auto it = jumps.find(i); + if (it == jumps.end()) + { + m_path.emplace_back(path[i]); + continue; + } + + while (it != jumps.end()) + { + i = it->second; + it = jumps.find(i); + } + + CHECK_LESS(i, path.size(), ()); + m_path.emplace_back(path[i]); + } + + Init(starter); +} + +void LeapsPostProcessor::Init(IndexGraphStarter & starter) +{ + m_prefixSumETA = std::vector(m_path.size(), 0.0); + + for (size_t i = 1; i < m_path.size(); ++i) + { + auto const & segment = m_path[i]; m_prefixSumETA[i] = m_prefixSumETA[i - 1] + starter.CalcSegmentETA(segment); CHECK_EQUAL(m_segmentToIndex.count(segment), 0, ()); diff --git a/routing/leaps_postprocessor.hpp b/routing/leaps_postprocessor.hpp index 2590f1fb6d..a8354f6757 100644 --- a/routing/leaps_postprocessor.hpp +++ b/routing/leaps_postprocessor.hpp @@ -67,10 +67,12 @@ private: double m_summaryETA = 0.0; }; + void Init(IndexGraphStarter & starter); + std::set CalculateIntervalsToRelax(); void FillIngoingPaths(Segment const & start, std::map & segmentsData); - std::vector const & m_path; + std::vector m_path; IndexGraphStarter & m_starter; BFS m_bfs;