From 0c05ae934384048cd265465db76bd514242bfa50 Mon Sep 17 00:00:00 2001 From: tatiana-kondakova Date: Tue, 31 Oct 2017 15:56:00 +0300 Subject: [PATCH] Add penalty for transit lines transfer --- routing/transit_graph.cpp | 33 +++++++++++++++++++++++++++++--- routing/transit_graph.hpp | 6 ++++-- routing/transit_graph_loader.cpp | 12 +++++++++--- 3 files changed, 43 insertions(+), 8 deletions(-) diff --git a/routing/transit_graph.cpp b/routing/transit_graph.cpp index 229d503803..0e20d40228 100644 --- a/routing/transit_graph.cpp +++ b/routing/transit_graph.cpp @@ -58,13 +58,33 @@ RouteWeight TransitGraph::CalcSegmentWeight(Segment const & segment, 0 /* nontransitCross */); } +RouteWeight TransitGraph::GetTransferPenalty(Segment const & from, Segment const & to) const +{ + if (!IsEdge(from) || !IsEdge(to)) + return RouteWeight(0 /* weight */, 0 /* nontransitCross */); + + auto lineIdFrom = GetEdge(from).GetLineId(); + auto lineIdTo = GetEdge(to).GetLineId(); + + if (lineIdFrom == lineIdTo) + return RouteWeight(0 /* weight */, 0 /* nontransitCross */); + + auto const it = m_transferPenalties.find(lineIdTo); + CHECK(it != m_transferPenalties.cend(), ("Segment", to, "belongs to unknown line:", lineIdTo)); + return RouteWeight(it->second, 0 /* nontransitCross */); +} + void TransitGraph::GetTransitEdges(Segment const & segment, bool isOutgoing, vector & edges, EdgeEstimator const & estimator) const { CHECK(IsTransitSegment(segment), ("Nontransit segment passed to TransitGraph.")); for (auto const & s : m_fake.GetEdges(segment, isOutgoing)) - edges.emplace_back(s, CalcSegmentWeight(isOutgoing ? s : segment, estimator)); + { + auto const & from = isOutgoing ? segment : s; + auto const & to = isOutgoing ? s : segment; + edges.emplace_back(s, CalcSegmentWeight(to, estimator) + GetTransferPenalty(from, to)); + } } set const & TransitGraph::GetFake(Segment const & real) const @@ -78,10 +98,17 @@ bool TransitGraph::FindReal(Segment const & fake, Segment & real) const } void TransitGraph::Fill(vector const & stops, vector const & gates, - vector const & edges, EdgeEstimator const & estimator, - NumMwmId numMwmId, IndexGraph & indexGraph) + vector const & edges, vector const & lines, + EdgeEstimator const & estimator, NumMwmId numMwmId, IndexGraph & indexGraph) { m_mwmId = numMwmId; + + // TODO: replace kTransferPenaltySec with line.GetTransferPenalty() as soon as transit::Line will + // have GetTransferPenalty() method + double constexpr kTransferPenaltySec = 120.0; + for (auto const & line : lines) + m_transferPenalties[line.GetId()] = kTransferPenaltySec; + map stopCoords; for (auto const & stop : stops) stopCoords[stop.GetId()] = Junction(stop.GetPoint(), feature::kDefaultAltitudeMeters); diff --git a/routing/transit_graph.hpp b/routing/transit_graph.hpp index 65f5dc77e8..7368a3ec94 100644 --- a/routing/transit_graph.hpp +++ b/routing/transit_graph.hpp @@ -26,6 +26,7 @@ public: Junction const & GetJunction(Segment const & segment, bool front) const; RouteWeight CalcSegmentWeight(Segment const & segment, EdgeEstimator const & estimator) const; + RouteWeight GetTransferPenalty(Segment const & from, Segment const & to) const; void GetTransitEdges(Segment const & segment, bool isOutgoing, std::vector & edges, EdgeEstimator const & estimator) const; std::set const & GetFake(Segment const & real) const; @@ -36,8 +37,8 @@ public: // modifications of geometry cache. // TODO (t.yan) get rid of indexGraph and estimator void Fill(std::vector const & stops, std::vector const & gates, - std::vector const & edges, EdgeEstimator const & estimator, - NumMwmId numMwmId, IndexGraph & indexGraph); + std::vector const & edges, std::vector const & lines, + EdgeEstimator const & estimator, NumMwmId numMwmId, IndexGraph & indexGraph); bool IsGate(Segment const & segment) const; bool IsEdge(Segment const & segment) const; @@ -61,6 +62,7 @@ private: FakeGraph m_fake; std::map m_segmentToEdge; std::map m_segmentToGate; + std::map m_transferPenalties; // TODO (@t.yan) move m_edgeToSegment, m_stopToBack, m_stopToFront to Fill std::map> m_stopToBack; std::map> m_stopToFront; diff --git a/routing/transit_graph_loader.cpp b/routing/transit_graph_loader.cpp index cffce6b41b..a916971f28 100644 --- a/routing/transit_graph_loader.cpp +++ b/routing/transit_graph_loader.cpp @@ -64,18 +64,24 @@ unique_ptr TransitGraphLoader::CreateTransitGraph(NumMwmId numMwmI transit::TransitHeader header; numberDeserializer(header); + CHECK_EQUAL(src.Pos(), header.m_stopsOffset, ("Wrong section format.")); vector stops; deserializer(stops); - CHECK_EQUAL(src.Pos(), header.m_gatesOffset,("Wrong section format.")); + CHECK_EQUAL(src.Pos(), header.m_gatesOffset, ("Wrong section format.")); vector gates; deserializer(gates); - CHECK_EQUAL(src.Pos(), header.m_edgesOffset,("Wrong section format.")); + CHECK_EQUAL(src.Pos(), header.m_edgesOffset, ("Wrong section format.")); vector edges; deserializer(edges); - graphPtr->Fill(stops, gates, edges, *m_estimator, numMwmId, indexGraph); + src.Skip(header.m_linesOffset - src.Pos()); + CHECK_EQUAL(src.Pos(), header.m_linesOffset, ("Wrong section format.")); + vector lines; + deserializer(lines); + + graphPtr->Fill(stops, gates, edges, lines, *m_estimator, numMwmId, indexGraph); } catch (Reader::OpenException const & e) {