Skip to content

Commit ad80882

Browse files
wip
1 parent b3ec2a6 commit ad80882

File tree

5 files changed

+241
-175
lines changed

5 files changed

+241
-175
lines changed

include/nigiri/loader/gtfs/seated.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ struct expanded_seated {
1515
vecvec<seated_idx_t, utc_trip> expanded_;
1616
};
1717

18-
void build_seated_trips(timetable&,
19-
trip_data&,
20-
expanded_seated&,
21-
std::function<void(utc_trip&&)> const& consumer);
18+
std::vector<utc_trip> build_seated_trips(
19+
timetable&,
20+
hash_map<bitfield, bitfield_idx_t>&,
21+
trip_data&,
22+
expanded_seated&,
23+
mutable_fws_multimap<location_idx_t, route_idx_t>&);
2224

2325
template <typename Fn>
2426
expanded_seated expand_seated_trips(trip_data const& trip_data, Fn&& expand) {

include/nigiri/seated_transfer.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#pragma once
2+
3+
#include "nigiri/types.h"
4+
5+
namespace nigiri {
6+
7+
struct seated_transfer {
8+
using value_t = route_idx_t;
9+
10+
seated_transfer(value_t const val) {
11+
std::memcpy(this, &val, sizeof(value_t));
12+
}
13+
seated_transfer(route_idx_t const target, std::int8_t const day_offset)
14+
: target_{to_idx(target)},
15+
day_offset_{static_cast<route_idx_t::value_t>(day_offset)} {}
16+
17+
route_idx_t::value_t value() const noexcept {
18+
return *reinterpret_cast<location_idx_t::value_t const*>(this);
19+
}
20+
21+
cista::hash_t hash() const {
22+
return cista::hash_combine(cista::BASE_HASH, value());
23+
}
24+
25+
std::uint8_t day_offset() const noexcept { return day_offset_; }
26+
route_idx_t target() const noexcept { return route_idx_t{target_}; }
27+
28+
route_idx_t::value_t target_ : 24;
29+
route_idx_t::value_t day_offset_ : 8;
30+
};
31+
32+
static_assert(sizeof(seated_transfer) == sizeof(route_idx_t));
33+
34+
} // namespace nigiri

include/nigiri/timetable.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "nigiri/footpath.h"
2121
#include "nigiri/location.h"
2222
#include "nigiri/logging.h"
23+
#include "nigiri/seated_transfer.h"
2324
#include "nigiri/stop.h"
2425
#include "nigiri/string_store.h"
2526
#include "nigiri/td_footpath.h"
@@ -183,6 +184,11 @@ struct timetable {
183184
}
184185
}
185186

187+
route_has_seated_in_.resize(route_has_seated_in_.size() + 1U);
188+
route_has_seated_out_.resize(route_has_seated_out_.size() + 1U);
189+
route_seated_transfers_in_.add_back_sized(0U);
190+
route_seated_transfers_out_.add_back_sized(0U);
191+
186192
return route_idx_t{idx};
187193
}
188194

@@ -461,6 +467,16 @@ struct timetable {
461467
// same for cars
462468
vecvec<route_idx_t, bool> route_cars_allowed_per_section_;
463469

470+
// Route -> has outgoing stay-seated transfers
471+
bitvec route_has_seated_out_;
472+
473+
// Route -> has incoming stay-seated transfers
474+
bitvec route_has_seated_in_;
475+
476+
// Route -> seated transfers
477+
vecvec<route_idx_t, seated_transfer::value_t> route_seated_transfers_out_;
478+
vecvec<route_idx_t, seated_transfer::value_t> route_seated_transfers_in_;
479+
464480
// Location -> list of routes
465481
vecvec<location_idx_t, route_idx_t> location_routes_;
466482

src/loader/gtfs/load_timetable.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ void load_timetable(loader_config const& config,
337337
}
338338
}
339339

340+
auto location_routes = mutable_fws_multimap<location_idx_t, route_idx_t>{};
340341
{
341342
auto const timer = scoped_timer{"loader.gtfs.write_seated"};
342343
auto expanded_seated = expand_seated_trips(
@@ -345,7 +346,8 @@ void load_timetable(loader_config const& config,
345346
trip_data.get(i).service_, tt.date_range_, assistance,
346347
[&](utc_trip&& s) { consume(std::move(s)); });
347348
});
348-
build_seated_trips(tt, trip_data, expanded_seated, add_expanded_trip);
349+
build_seated_trips(tt, bitfield_indices, trip_data, expanded_seated,
350+
location_routes);
349351
}
350352

351353
{
@@ -361,7 +363,6 @@ void load_timetable(loader_config const& config,
361363
auto section_directions = basic_string<trip_direction_idx_t>{};
362364
auto route_colors = basic_string<route_color>{};
363365
auto external_trip_ids = basic_string<merged_trips_idx_t>{};
364-
auto location_routes = mutable_fws_multimap<location_idx_t, route_idx_t>{};
365366
for (auto const& [key, sub_routes] : route_services) {
366367
for (auto const& services : sub_routes) {
367368
auto const route_idx = tt.register_route(

0 commit comments

Comments
 (0)