| 111 | } |
| 112 | |
| 113 | RouteWeight 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 */, |
nothing calls this directly
no test coverage detected