Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closest station per route #104

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/routing/start_times.cc
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,38 @@ void get_starts(direction const search_dir,
});
}

auto nearest = std::vector<pair<location_idx_t, duration_t>>{};
nearest.reserve(shortest_start.size());
for (auto const& s : shortest_start) {
nearest.emplace_back(s.first, s.second);
}
std::sort(begin(nearest), end(nearest),
[](auto const& a, auto const& b) { return a.second < b.second; });
auto routes = std::set<route_idx_t>{};
auto closest_per_route = std::vector<pair<location_idx_t, duration_t>>{};
closest_per_route.reserve(shortest_start.size());
for (auto const& l_d : nearest) {
auto new_route = false;
for (auto const& route : tt.location_routes_[l_d.first]) {
auto const loc_seq = tt.route_location_seq_[route];
auto i = fwd ? 0U : 1U;
auto const last = fwd ? loc_seq.size() - 1 : loc_seq.size();
for (; i != last; ++i) {
auto const stp = stop{loc_seq[i]};
if (stp.location_idx() == l_d.first &&
((fwd && stp.in_allowed()) || (!fwd && stp.out_allowed())) &&
!routes.contains(route)) {
routes.emplace(route);
new_route = true;
}
}
}
if (new_route) {
closest_per_route.emplace_back(l_d);
}
}

for (auto const& s : closest_per_route) {
auto const l = s.first;
auto const o = s.second;
std::visit(utl::overloaded{[&](interval<unixtime_t> const interval) {
Expand Down
Loading