MCPcopy Create free account
hub / github.com/comaps/comaps / GetTransferPenalty

Method GetTransferPenalty

libs/routing/transit_graph.cpp:113–176  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

111}
112
113RouteWeight TransitGraph::GetTransferPenalty(Segment const & from, Segment const & to) const
114{
115 if (m_transitVersion == ::transit::TransitVersion::OnlySubway)
116 {
117 // We need to wait transport and apply additional penalty only if we change to transit::Edge.
118 if (!IsEdge(to))
119 return GetAStarWeightZero<RouteWeight>();
120
121 auto const & edgeTo = GetEdge(to);
122
123 // We are changing to transfer and do not need to apply extra penalty here. We'll do it while
124 // changing from transfer.
125 if (edgeTo.GetTransfer())
126 return GetAStarWeightZero<RouteWeight>();
127
128 auto const lineIdTo = edgeTo.GetLineId();
129
130 if (IsEdge(from) && GetEdge(from).GetLineId() == lineIdTo)
131 return GetAStarWeightZero<RouteWeight>();
132
133 // We need to apply extra penalty when:
134 // 1. |from| is gate, |to| is edge
135 // 2. |from| is transfer, |to| is edge
136 // 3. |from| is edge, |to| is edge from another line directly connected to |from|.
137 auto const it = m_transferPenaltiesSubway.find(lineIdTo);
138 CHECK(it != m_transferPenaltiesSubway.cend(), ("Segment", to, "belongs to unknown line:", lineIdTo));
139 return RouteWeight(it->second /* weight */, 0 /* nonPassThrougCross */, 0 /* numAccessChanges */,
140 0 /* numAccessConditionalPenalties */, it->second /* transitTime */);
141 }
142 else if (m_transitVersion == ::transit::TransitVersion::AllPublicTransport)
143 {
144 // We need to wait transport and apply additional penalty only if we change to transit::Edge.
145 if (!IsEdge(to))
146 return GetAStarWeightZero<RouteWeight>();
147
148 auto const & edgeTo = GetEdgePT(to);
149
150 // We are changing to transfer and do not need to apply extra penalty here. We'll do it while
151 // changing from transfer.
152 if (edgeTo.IsTransfer())
153 return GetAStarWeightZero<RouteWeight>();
154
155 auto const lineIdTo = edgeTo.GetLineId();
156
157 if (IsEdge(from) && GetEdgePT(from).GetLineId() == lineIdTo)
158 return GetAStarWeightZero<RouteWeight>();
159
160 // We need to apply extra penalty when:
161 // 1. |from| is gate, |to| is edge
162 // 2. |from| is transfer, |to| is edge
163 // 3. |from| is edge, |to| is edge from another line directly connected to |from|.
164 auto const it = m_transferPenaltiesPT.find(lineIdTo);
165 CHECK(it != m_transferPenaltiesPT.end(), ("Segment", to, "belongs to unknown line:", lineIdTo));
166 // TODO(o.khlopkova) If we know exact start time for trip we can extract more precise headway.
167 // We need to call GetFrequency(time).
168 size_t const headwayS = it->second.GetFrequency() / 2;
169
170 return RouteWeight(static_cast<double>(headwayS) /* weight */, 0 /* nonPassThroughCross */,

Callers

nothing calls this directly

Calls 7

GetLineIdMethod · 0.80
IsTransferMethod · 0.80
RouteWeightClass · 0.70
findMethod · 0.45
cendMethod · 0.45
endMethod · 0.45
GetFrequencyMethod · 0.45

Tested by

no test coverage detected