-
Notifications
You must be signed in to change notification settings - Fork 68
reduce footpaths #238
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
Open
felixguendling
wants to merge
8
commits into
master
Choose a base branch
from
reduced-fps
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
reduce footpaths #238
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0d63f26
reduce footpaths
felixguendling b266a72
wip
felixguendling b881784
wip
felixguendling 094d87d
wip
felixguendling a2cec5d
wip
felixguendling 3b6ecbb
wip
felixguendling bb42d19
Merge branch 'master' of github.com:motis-project/nigiri into reduced…
felixguendling 0e70b23
wip
felixguendling File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| #pragma once | ||
|
|
||
| #include "nigiri/timetable.h" | ||
| #include "nigiri/types.h" | ||
|
|
||
| namespace nigiri { | ||
| struct timatable; | ||
| } | ||
|
|
||
| namespace nigiri::loader { | ||
|
|
||
| vecvec<location_idx_t, footpath> reduce_footpaths( | ||
| timetable&, vecvec<location_idx_t, footpath> const&); | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| #include "nigiri/loader/reduce_footpaths.h" | ||
|
|
||
| #include "utl/erase_duplicates.h" | ||
| #include "utl/insert_sorted.h" | ||
| #include "utl/parallel_for.h" | ||
| #include "utl/timer.h" | ||
|
|
||
| #include "nigiri/timetable.h" | ||
|
|
||
| namespace nigiri::loader { | ||
|
|
||
| constexpr auto const kN = 2U; | ||
|
|
||
| vecvec<location_idx_t, footpath> reduce_footpaths( | ||
| timetable& tt, vecvec<location_idx_t, footpath> const& fps) { | ||
| auto const timer = utl::scoped_timer{"reduce-footpaths"}; | ||
|
|
||
| auto const init = []() { | ||
| auto x = std::array<footpath, kN>{}; | ||
| x.fill(footpath{footpath::kMaxTarget, footpath::kMaxDuration}); | ||
| return x; | ||
| }(); | ||
|
|
||
| auto reduced = | ||
| vector_map<location_idx_t, std::vector<footpath>>(tt.n_locations()); | ||
|
|
||
| struct state { | ||
| vector_map<route_idx_t, std::array<footpath, kN>> route_fps_; | ||
| bitvec_map<route_idx_t> route_is_reachable_; | ||
| }; | ||
|
|
||
| utl::parallel_for_run_threadlocal<state>( | ||
| tt.n_locations(), [&](state& s, std::size_t const l_idx) { | ||
| auto const l = location_idx_t{l_idx}; | ||
|
|
||
| if (s.route_fps_.size() != tt.n_locations()) { | ||
| s.route_fps_ = vector_map<route_idx_t, std::array<footpath, kN>>{ | ||
| tt.n_locations(), init}; | ||
| s.route_is_reachable_.resize(tt.n_locations()); | ||
| } | ||
|
|
||
| // Group by route (duplicates footpaths). | ||
| // This eliminates footpaths to locations w/o scheduled traffic. | ||
| auto const l_routes = tt.location_routes_[l]; | ||
| for (auto const& fp : fps[l]) { | ||
| for (auto const& r : tt.location_routes_[fp.target()]) { | ||
| if (utl::find(l_routes, r) != end(l_routes)) { | ||
| continue; // Skip routes that are already available at this stop. | ||
| } | ||
|
|
||
| s.route_is_reachable_.set(r, true); | ||
|
|
||
| auto& r_reachable = s.route_fps_[r]; | ||
|
|
||
| auto insert = fp; | ||
| for (auto i = 0U; i != r_reachable.size(); ++i) { | ||
| if (insert.duration() < r_reachable[i].duration()) { | ||
| std::swap(insert, r_reachable[i]); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Join fastest N footpaths per route. | ||
| s.route_is_reachable_.for_each_set_bit([&](route_idx_t const r) { | ||
| auto& route_fps = s.route_fps_[r]; | ||
| for (auto j = 0U; j != route_fps.size(); ++j) { | ||
| if (route_fps[j].target() != footpath::kMaxTarget) { | ||
| reduced[l].push_back(route_fps[j]); | ||
| } | ||
| } | ||
| route_fps = init; | ||
| }); | ||
| s.route_is_reachable_.zero_out(); | ||
|
|
||
| // Deduplicate and sort by duration. | ||
| utl::erase_duplicates(reduced[l], | ||
| [](footpath const& a, footpath const& b) { | ||
| return std::tuple{a.duration(), a.target()} < | ||
| std::tuple{b.duration(), b.target()}; | ||
| }); | ||
| }); | ||
|
|
||
| // Copy to vecvec. | ||
| auto compact = vecvec<location_idx_t, footpath>{}; | ||
| for (auto const& r : reduced) { | ||
| compact.emplace_back(r); | ||
| } | ||
|
|
||
| // Count. | ||
| auto n_full = 0U; | ||
| for (auto const x : fps) { | ||
| n_full += x.size(); | ||
| } | ||
| auto n_reduced = 0U; | ||
| for (auto const x : compact) { | ||
| n_reduced += x.size(); | ||
| } | ||
|
|
||
| log(log_lvl::info, "nigiri.loader.reduce_footpaths", | ||
| "reduce footpaths: #full={}, #reduced={} ({}%)", n_full, n_reduced, | ||
| 100.0 * n_reduced / n_full); | ||
|
|
||
| return compact; | ||
| } | ||
|
|
||
| } // namespace nigiri::loader | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about footpaths to locations which doesn't have scheduled traffic, but are intended to be used for real-time trips, for example, stops reserved for rail replacement buses or spare rail platforms?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They will be recovered from
footpaths_full_out_which stores the full set of footpaths (unfiltered) and have to be copied to thert_timetablein case a previously unused stop will be visited.The main goal of this branch was to figure out the speedup potential. Results so far:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The update of rt_timetable is not yet implemented.
I expected a greater speedup and put the PR on hold as it turns out the speedup is less than expected.