diff options
author | Vladimir Byko-Ianko <v.bykoianko@corp.mail.ru> | 2017-01-18 15:46:43 +0300 |
---|---|---|
committer | Vladimir Byko-Ianko <v.bykoianko@corp.mail.ru> | 2017-01-23 13:24:53 +0300 |
commit | b3455075835cb5b31fe7e1d88390b4b415c81e1f (patch) | |
tree | a5384670418f073b2fac776a04b37744f8ab754d /routing | |
parent | 81ed08055f4d20ee7540d60892fd7c9d2c2c681b (diff) |
Dynamic restriction bugfix and review fixes.
Diffstat (limited to 'routing')
-rw-r--r-- | routing/index_graph.cpp | 61 | ||||
-rw-r--r-- | routing/index_graph_starter.cpp | 10 | ||||
-rw-r--r-- | routing/index_graph_starter.hpp | 12 | ||||
-rw-r--r-- | routing/restriction_loader.hpp | 1 | ||||
-rw-r--r-- | routing/restrictions_serialization.cpp | 1 | ||||
-rw-r--r-- | routing/restrictions_serialization.hpp | 2 |
6 files changed, 45 insertions, 42 deletions
diff --git a/routing/index_graph.cpp b/routing/index_graph.cpp index f660d3940f..f1aaaf6ded 100644 --- a/routing/index_graph.cpp +++ b/routing/index_graph.cpp @@ -53,31 +53,33 @@ bool IsRestricted(RestrictionVec const & restrictions, vector<SegmentEdge> const auto const lower = range.first; auto const upper = range.second; - // Checking if there's at least one restrictions of type Only from |featureIdFrom| and - // ending with |featureIdTo|. If yes, returns false. - if (lower != upper && lower->m_featureIds[1] == featureIdTo) + // Checking if there's restriction of type Only starting from |featureIdFrom|. If not returns false. + if (lower == upper) return false; - // Checking if there's at least one Only starting from |featureIdFrom|. - // If not, returns false. - if (lower == restrictions.cend() || lower->m_type != Restriction::Type::Only || - lower->m_featureIds[0] != featureIdFrom) + // Note. The loop is necessary because it's possible that there's several restriction + // of type Only starting from |featureIdFrom|. + for (auto i = lower; i != upper; ++i) { - return false; - } - - // Note. At this point it's clear that there is an item in |restrictions| with type Only - // and starting with |featureIdFrom|. So there are two possibilities: - // * |edges| contains |it->m_featureIds[1]| => the end of |featureIdFrom| which implies in - // |restrictions| is considered. - // * |edges| does not contain |it->m_featureIds[1]| => either the other end or an intermediate - // point of |featureIdFrom| is considered. - // See test FGraph_RestrictionF0F2Only for details. - CHECK_EQUAL(lower->m_featureIds.size(), 2, ("Only two link restrictions are support.")); - for (SegmentEdge const & e : edges) - { - if (e.GetTarget().GetFeatureId() == lower->m_featureIds[isOutgoing ? 1 /* to */ : 0 /* from */]) - return true; + CHECK_EQUAL(i->m_featureIds.size(), 2, ("Only two link restrictions are support.")); + + // Checking if there's a restriction of type Only starting from |featureIdFrom| and + // ending with |featureIdTo|. If yes, returns false. + if (i->m_featureIds[isOutgoing ? 1 /* to */ : 0 /* from */] == (isOutgoing ? featureIdTo : featureIdFrom)) + return false; + + // Note. At this point it's clear that there is an item in |restrictions| with type Only + // and starting with |featureIdFrom|. So there are two possibilities: + // * |edges| contains |it->m_featureIds[1]| => the end of |featureIdFrom| which implies in + // |restrictions| is considered. + // * |edges| does not contain |it->m_featureIds[1]| => either the other end or an intermediate + // point of |featureIdFrom| is considered. + // See test FGraph_RestrictionF0F2Only for details. + for (SegmentEdge const & e : edges) + { + if (e.GetTarget().GetFeatureId() == i->m_featureIds[isOutgoing ? 1 /* to */ : 0 /* from */]) + return true; + } } return false; } @@ -103,26 +105,25 @@ void IndexGraph::GetEdgeList(Segment const & segment, bool isOutgoing, vector<Se RoadPoint const roadPoint = segment.GetRoadPoint(isOutgoing); Joint::Id const jointId = m_roadIndex.GetJointId(roadPoint); + vector<SegmentEdge> rawEdges; if (jointId != Joint::kInvalidId) { m_jointIndex.ForEachPoint(jointId, [&](RoadPoint const & rp) { - GetNeighboringEdges(segment, rp, isOutgoing, edges); + GetNeighboringEdges(segment, rp, isOutgoing, rawEdges); }); } else { - GetNeighboringEdges(segment, roadPoint, isOutgoing, edges); + GetNeighboringEdges(segment, roadPoint, isOutgoing, rawEdges); } // Removing some edges according to restriction rules. - vector<SegmentEdge> filteredEdges; - filteredEdges.reserve(edges.size()); - for (SegmentEdge const & e : edges) + edges.reserve(rawEdges.size()); + for (SegmentEdge const & e : rawEdges) { - if (!IsRestricted(m_restrictions, edges, segment, e.GetTarget(), isOutgoing)) - filteredEdges.push_back(e); + if (!IsRestricted(m_restrictions, rawEdges, segment, e.GetTarget(), isOutgoing)) + edges.push_back(e); } - edges.swap(filteredEdges); } void IndexGraph::Build(uint32_t numJoints) { m_jointIndex.Build(m_roadIndex, numJoints); } diff --git a/routing/index_graph_starter.cpp b/routing/index_graph_starter.cpp index 58e9d63053..0ba068c559 100644 --- a/routing/index_graph_starter.cpp +++ b/routing/index_graph_starter.cpp @@ -47,16 +47,6 @@ m2::PointD const & IndexGraphStarter::GetRoutePoint(vector<Segment> const & segm return GetPoint(segments[pointIndex], true /* front */); } -void IndexGraphStarter::GetOutgoingEdgesList(TVertexType const & segment, vector<TEdgeType> & edges) -{ - GetEdgesList(segment, true /* isOutgoing */, edges); -} - -void IndexGraphStarter::GetIngoingEdgesList(TVertexType const & segment, vector<TEdgeType> & edges) -{ - GetEdgesList(segment, false /* isOutgoing */, edges); -} - void IndexGraphStarter::GetEdgesList(Segment const & segment, bool isOutgoing, vector<SegmentEdge> & edges) { diff --git a/routing/index_graph_starter.hpp b/routing/index_graph_starter.hpp index cf5d415108..4ad31a298a 100644 --- a/routing/index_graph_starter.hpp +++ b/routing/index_graph_starter.hpp @@ -52,8 +52,16 @@ public: m2::PointD const & GetRoutePoint(vector<Segment> const & route, size_t pointIndex); void GetEdgesList(Segment const & segment, bool isOutgoing, vector<SegmentEdge> & edges); - void GetOutgoingEdgesList(TVertexType const & segment, vector<TEdgeType> & edges); - void GetIngoingEdgesList(TVertexType const & segment, vector<TEdgeType> & edges); + + void GetOutgoingEdgesList(TVertexType const & segment, vector<TEdgeType> & edges) + { + GetEdgesList(segment, true /* isOutgoing */, edges); + } + + void GetIngoingEdgesList(TVertexType const & segment, vector<TEdgeType> & edges) + { + GetEdgesList(segment, false /* isOutgoing */, edges); + } double HeuristicCostEstimate(TVertexType const & from, TVertexType const & to) { diff --git a/routing/restriction_loader.hpp b/routing/restriction_loader.hpp index 6e58134225..bae5c07aba 100644 --- a/routing/restriction_loader.hpp +++ b/routing/restriction_loader.hpp @@ -18,6 +18,7 @@ public: bool HasRestrictions() const { return !m_restrictions.empty(); } RestrictionVec && StealRestrictions() { return move(m_restrictions); } + private: unique_ptr<FilesContainerR::TReader> m_reader; RestrictionHeader m_header; diff --git a/routing/restrictions_serialization.cpp b/routing/restrictions_serialization.cpp index 1a72524b68..a9efc8d6f3 100644 --- a/routing/restrictions_serialization.cpp +++ b/routing/restrictions_serialization.cpp @@ -42,6 +42,7 @@ string ToString(Restriction::Type const & type) } string DebugPrint(Restriction::Type const & type) { return ToString(type); } + string DebugPrint(Restriction const & restriction) { ostringstream out; diff --git a/routing/restrictions_serialization.hpp b/routing/restrictions_serialization.hpp index f0a75cb7df..dbba6417bc 100644 --- a/routing/restrictions_serialization.hpp +++ b/routing/restrictions_serialization.hpp @@ -37,6 +37,7 @@ struct Restriction }; Restriction(Type type, vector<uint32_t> const & links) : m_featureIds(links), m_type(type) {} + bool IsValid() const; bool operator==(Restriction const & restriction) const; bool operator<(Restriction const & restriction) const; @@ -55,6 +56,7 @@ string DebugPrint(Restriction const & restriction); struct RestrictionHeader { RestrictionHeader() { Reset(); } + template <class Sink> void Serialize(Sink & sink) const { |