diff options
author | Mikhail Gorbushin <m.gorbushin@corp.mail.ru> | 2019-05-06 15:39:08 +0300 |
---|---|---|
committer | Vladimir Byko-Ianko <bykoianko@gmail.com> | 2019-05-17 12:52:46 +0300 |
commit | c699d1c55b158a0473ed65a8660e1aaf2c4c7ef3 (patch) | |
tree | 67cd40dd24b46360551d9452deb6eb15c35908a5 /routing | |
parent | 6b1b0aa9e49c05ebdf15175e15842875f86ce601 (diff) |
[routing] fix restiction only convertation
Diffstat (limited to 'routing')
-rw-r--r-- | routing/restriction_loader.cpp | 62 | ||||
-rw-r--r-- | routing/restriction_loader.hpp | 2 |
2 files changed, 43 insertions, 21 deletions
diff --git a/routing/restriction_loader.cpp b/routing/restriction_loader.cpp index 1543dcd501..b5ef10efaf 100644 --- a/routing/restriction_loader.cpp +++ b/routing/restriction_loader.cpp @@ -80,11 +80,17 @@ RestrictionVec && RestrictionLoader::StealRestrictions() return std::move(m_restrictions); } +/// \brief We store |Only| restriction in mwm, like +/// Only, featureId_1, ... , featureId_N +/// We convert such restriction to |No| following way: +/// For each pair of neighbouring features (featureId_1 and featureId_2 for ex.) +/// we forbid to go from featureId_1 to wherever except featureId_2. +/// Then do this for featureId_2 and featureId_3 and so on. void ConvertRestrictionsOnlyToNoAndSort(IndexGraph const & graph, - RestrictionVec & restrictionsOnly, + RestrictionVec const & restrictionsOnly, RestrictionVec & restrictionsNo) { - for (auto & restriction : restrictionsOnly) + for (auto const & restriction : restrictionsOnly) { if (std::any_of(restriction.begin(), restriction.end(), [&graph](auto const & item) @@ -96,28 +102,44 @@ void ConvertRestrictionsOnlyToNoAndSort(IndexGraph const & graph, } CHECK_GREATER_OR_EQUAL(restriction.size(), 2, ()); - auto const lastFeatureId = *(restriction.end() - 1); - auto const prevLastFeatureId = *(restriction.end() - 2); - - // Looking for a joint of an intersection of |o| features. - Joint::Id const common = - GetCommonEndJoint(graph.GetRoad(prevLastFeatureId), graph.GetRoad(lastFeatureId)); + // vector of simple no_restriction - from|to. + std::vector<std::pair<uint32_t, uint32_t>> toAdd; + bool error = false; + for (size_t i = 1; i < restriction.size(); ++i) + { + auto const curFeatureId = restriction[i]; + auto const prevFeatureId = restriction[i - 1]; - if (common == Joint::kInvalidId) - continue; + // Looking for a joint of an intersection of prev and cur features. + Joint::Id const common = + GetCommonEndJoint(graph.GetRoad(curFeatureId), graph.GetRoad(prevFeatureId)); - // Delete last feature id ("to" member). - restriction.pop_back(); - // Adding restriction of type No for all features of joint |common| except for - // the second feature of restriction |o|. - graph.ForEachPoint(common, [&](RoadPoint const & rp) { - if (rp.GetFeatureId() != lastFeatureId) + if (common == Joint::kInvalidId) { - std::vector<uint32_t> result(restriction); - result.emplace_back(rp.GetFeatureId()); - restrictionsNo.emplace_back(std::move(result)); + error = true; + break; } - }); + + // Adding restriction of type No for all features of joint |common| except for + // |prevFeatureId| -> |curFeatureId|. + graph.ForEachPoint(common, + [&](RoadPoint const & rp) + { + if (rp.GetFeatureId() != curFeatureId) + toAdd.emplace_back(prevFeatureId, rp.GetFeatureId()); + }); + } + + if (error) + continue; + + for (auto const & fromToPair : toAdd) + { + std::vector<uint32_t> newRestriction = + {fromToPair.first /* from */, fromToPair.second /* to */}; + + restrictionsNo.emplace_back(std::move(newRestriction)); + } } base::SortUnique(restrictionsNo); diff --git a/routing/restriction_loader.hpp b/routing/restriction_loader.hpp index 1a9d2cfa26..d0a1d27dfe 100644 --- a/routing/restriction_loader.hpp +++ b/routing/restriction_loader.hpp @@ -28,6 +28,6 @@ private: }; void ConvertRestrictionsOnlyToNoAndSort(IndexGraph const & graph, - RestrictionVec & restrictionsOnly, + RestrictionVec const & restrictionsOnly, RestrictionVec & restrictionsNo); } // namespace routing |