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

Protobuf update #63

Merged
merged 6 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/deps
/.idea
/.clang-tidy
/.vscode
4 changes: 2 additions & 2 deletions .pkg
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@
commit=77e91016354e6d8cba24a86c5abb807de2534c02
[protobuf]
url=git@github.com:motis-project/protobuf.git
branch=master
commit=297171ade5e9bd01d823ffe8b203a5443ec03f15
branch=main
commit=690e03babf0963d3da9615a2dae0891777842719
11 changes: 6 additions & 5 deletions .pkg.lock
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
6084367865481574367
cista 05ba0e6c74195bb7921e178e9f7d850407172772
507627293430859032
cista 04f84b0490e0e91ead20ae6eabed5add8f243ba0
res 7d97784ba785ce8a2677ea77164040fde484fb04
date 26d109612ddb8ba331edba7619a6452667f842bb
fmt c68ab4be8f3cb0e5c6eb181b3f419622e15e02bd
zlib 1e1dfdedddb54a2e2cb8fec3b67f925233c495aa
zlib fe8e13ffca867612951bc6baf114e5ac8b00f305
boost be5235eb2258d2ec19e32546ab767a62311d9b46
doctest 70e8f76437b76dd5e9c0a2eb9b907df190ab71a0
geo f455b76d5894bb156e3bcb1f85c3e2915820fe3a
googletest 34a46558609e05865c197f0260ab36daa7cbbb6e
miniz 1edbdece9d71dc65c6ff405572ee37cbdcef7af4
protobuf 297171ade5e9bd01d823ffe8b203a5443ec03f15
abseil-cpp f2b3825f36e37fddd47c5c395096e9b1e99eca12
protobuf 690e03babf0963d3da9615a2dae0891777842719
unordered_dense 77e91016354e6d8cba24a86c5abb807de2534c02
Catch2 47d56f28a9801911c048d011b375e5631dbb658f
utl 71144d441da35f934e14904ac1e9492925017058
utl b81cfdccda166cef3c20dd41b4c9697b4137cea4
wyhash 1e012b57fc2227a9e583a57e2eacb3da99816d99
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ add_custom_command(
add_library(gtfsrt ${CMAKE_CURRENT_BINARY_DIR}/generated/gtfsrt/gtfs-realtime.pb.cc)
target_compile_features(gtfsrt PUBLIC cxx_std_23)
target_include_directories(gtfsrt SYSTEM PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/generated)
target_link_libraries(gtfsrt protobuf)
target_link_libraries(gtfsrt protobuf::libprotobuf)


# --- LINT ---
Expand Down
2 changes: 1 addition & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
},
{
"name": "linux-sanitizer",
"displayName": "Linux Debug",
"displayName": "Linux Sanitizer",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build/sanitizer",
"cacheVariables": {
Expand Down
7 changes: 4 additions & 3 deletions include/nigiri/loader/build_lb_graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

#include "nigiri/logging.h"
#include "nigiri/timetable.h"
#include "nigiri/types.h"

namespace nigiri::loader {

template <direction SearchDir>
void build_lb_graph(timetable& tt) {
void build_lb_graph(timetable& tt, profile_idx_t const prf_idx = 0) {
hash_map<location_idx_t, duration_t> weights;

auto const update_weight = [&](location_idx_t const target,
Expand All @@ -26,8 +27,8 @@ void build_lb_graph(timetable& tt) {
: tt.locations_.parents_[l];

auto const& footpaths = SearchDir == direction::kForward
? tt.locations_.footpaths_in_[l]
: tt.locations_.footpaths_out_[l];
? tt.locations_.footpaths_in_[prf_idx][l]
: tt.locations_.footpaths_out_[prf_idx][l];
for (auto const& fp : footpaths) {
auto const parent = tt.locations_.parents_[fp.target()];
auto const target =
Expand Down
8 changes: 1 addition & 7 deletions include/nigiri/location.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "geo/latlng.h"

#include "nigiri/common/it_range.h"
#include "nigiri/footpath.h"
#include "nigiri/types.h"

namespace nigiri {
Expand All @@ -21,25 +20,20 @@ struct location {
geo::latlng pos,
source_idx_t,
location_type,
osm_node_id_t,
location_idx_t parent,
timezone_idx_t,
duration_t transfer_time,
it_range<vector<location_idx_t>::const_iterator> equivalences,
std::span<footpath const> footpaths_in,
std::span<footpath const> footpaths_out);
it_range<vector<location_idx_t>::const_iterator> equivalences);
location_idx_t l_{location_idx_t::invalid()};
std::string_view id_;
std::string_view name_;
geo::latlng pos_;
source_idx_t src_;
location_type type_;
osm_node_id_t osm_id_;
location_idx_t parent_;
timezone_idx_t timezone_idx_;
duration_t transfer_time_;
it_range<vector<location_idx_t>::const_iterator> equivalences_;
std::span<footpath const> footpaths_out_, footpaths_in_;
};

} // namespace nigiri
1 change: 1 addition & 0 deletions include/nigiri/routing/query.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ struct query {
unsigned min_connection_count_{0U};
bool extend_interval_earlier_{false};
bool extend_interval_later_{false};
profile_idx_t prf_idx_{0};
};

} // namespace nigiri::routing
10 changes: 6 additions & 4 deletions include/nigiri/routing/raptor/raptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "nigiri/rt/rt_timetable.h"
#include "nigiri/special_stations.h"
#include "nigiri/timetable.h"
#include "nigiri/types.h"

namespace nigiri::routing {

Expand Down Expand Up @@ -99,6 +100,7 @@ struct raptor {
void execute(unixtime_t const start_time,
std::uint8_t const max_transfers,
unixtime_t const worst_time_at_dest,
profile_idx_t const prf_idx,
pareto_set<journey>& results) {
auto const end_k = std::min(max_transfers, kMaxTransfers) + 1U;

Expand Down Expand Up @@ -171,7 +173,7 @@ struct raptor {
utl::fill(state_.station_mark_, false);

update_transfers(k);
update_footpaths(k);
update_footpaths(k, prf_idx);
update_intermodal_footpaths(k);

trace_print_state_after_round();
Expand Down Expand Up @@ -245,15 +247,15 @@ struct raptor {
}
}

void update_footpaths(unsigned const k) {
void update_footpaths(unsigned const k, profile_idx_t const prf_idx) {
for (auto i = 0U; i != n_locations_; ++i) {
if (!state_.prev_station_mark_[i]) {
continue;
}

auto const l_idx = location_idx_t{i};
auto const& fps = kFwd ? tt_.locations_.footpaths_out_[l_idx]
: tt_.locations_.footpaths_in_[l_idx];
auto const& fps = kFwd ? tt_.locations_.footpaths_out_[prf_idx][l_idx]
: tt_.locations_.footpaths_in_[prf_idx][l_idx];
for (auto const& fp : fps) {
++stats_.n_footpaths_visited_;

Expand Down
4 changes: 2 additions & 2 deletions include/nigiri/routing/search.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ struct search {
bool const add_ontrip) {
get_starts(SearchDir, tt_, rtt_, start_interval, q_.start_,
q_.start_match_mode_, q_.use_start_footpaths_, state_.starts_,
add_ontrip);
add_ontrip, q_.prf_idx_);
}

void remove_ontrip_results() {
Expand Down Expand Up @@ -318,7 +318,7 @@ struct search {
start_time +
(kFwd ? 1 : -1) * std::min(fastest_direct_, kMaxTravelTime);
algo_.execute(start_time, q_.max_transfers_, worst_time_at_dest,
state_.results_);
q_.prf_idx_, state_.results_);

for (auto& j : state_.results_) {
if (j.legs_.empty() &&
Expand Down
3 changes: 2 additions & 1 deletion include/nigiri/routing/start_times.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ void get_starts(direction,
location_match_mode,
bool use_start_footpaths,
std::vector<start>&,
bool add_ontrip);
bool add_ontrip,
profile_idx_t);

void collect_destinations(timetable const&,
std::vector<offset> const& destinations,
Expand Down
14 changes: 6 additions & 8 deletions include/nigiri/timetable.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ struct timetable {
preprocessing_footpaths_out_.emplace_back();
preprocessing_footpaths_in_.emplace_back();
transfer_time_.emplace_back(l.transfer_time_);
osm_ids_.emplace_back(osm_node_id_t::invalid());
parents_.emplace_back(l.parent_);
} else {
log(log_lvl::error, "timetable.register_location",
Expand All @@ -67,7 +66,6 @@ struct timetable {
assert(preprocessing_footpaths_out_.size() == next_idx + 1);
assert(preprocessing_footpaths_in_.size() == next_idx + 1);
assert(transfer_time_.size() == next_idx + 1);
assert(osm_ids_.size() == next_idx + 1);
assert(parents_.size() == next_idx + 1);

return it->second;
Expand All @@ -79,13 +77,10 @@ struct timetable {
coordinates_[idx],
src_[idx],
types_[idx],
osm_ids_[idx],
parents_[idx],
location_timezones_[idx],
transfer_time_[idx],
it_range{equivalences_[idx]},
std::span<footpath const>{footpaths_out_[idx]},
std::span<footpath const>{footpaths_in_[idx]}};
it_range{equivalences_[idx]}};
l.l_ = idx;
return l;
}
Expand All @@ -104,14 +99,14 @@ struct timetable {
vector_map<location_idx_t, source_idx_t> src_;
vector_map<location_idx_t, u8_minutes> transfer_time_;
vector_map<location_idx_t, location_type> types_;
vector_map<location_idx_t, osm_node_id_t> osm_ids_;
vector_map<location_idx_t, location_idx_t> parents_;
vector_map<location_idx_t, timezone_idx_t> location_timezones_;
mutable_fws_multimap<location_idx_t, location_idx_t> equivalences_;
mutable_fws_multimap<location_idx_t, location_idx_t> children_;
mutable_fws_multimap<location_idx_t, footpath> preprocessing_footpaths_out_;
mutable_fws_multimap<location_idx_t, footpath> preprocessing_footpaths_in_;
vecvec<location_idx_t, footpath> footpaths_out_, footpaths_in_;
array<vecvec<location_idx_t, footpath>, kMaxProfiles> footpaths_out_;
array<vecvec<location_idx_t, footpath>, kMaxProfiles> footpaths_in_;
vector_map<timezone_idx_t, timezone> timezones_;
} locations_;

Expand Down Expand Up @@ -442,6 +437,9 @@ struct timetable {
// Lower bound graph.
vecvec<location_idx_t, footpath> fwd_search_lb_graph_;
vecvec<location_idx_t, footpath> bwd_search_lb_graph_;

// profile name -> profile_idx_t
hash_map<string, profile_idx_t> profiles_;
};

} // namespace nigiri
8 changes: 7 additions & 1 deletion include/nigiri/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "ankerl/cista_adapter.h"

#include "cista/containers/array.h"
#include "cista/containers/bitset.h"
#include "cista/containers/bitvec.h"
#include "cista/containers/flat_matrix.h"
Expand Down Expand Up @@ -59,6 +60,9 @@ using pair = cista::pair<A, B>;
template <typename K, typename V>
using vector_map = cista::raw::vector_map<K, V>;

template <typename V, std::size_t SIZE>
using array = cista::raw::array<V, SIZE>;

template <typename T>
using vector = cista::raw::vector<T>;

Expand Down Expand Up @@ -102,7 +106,6 @@ using nvec = cista::raw::nvec<Key, T, N>;

using bitfield_idx_t = cista::strong<std::uint32_t, struct _bitfield_idx>;
using location_idx_t = cista::strong<std::uint32_t, struct _location_idx>;
using osm_node_id_t = cista::strong<std::int64_t, struct _osm_node_idx>;
using route_idx_t = cista::strong<std::uint32_t, struct _location_idx>;
using section_idx_t = cista::strong<std::uint32_t, struct _section_idx>;
using section_db_idx_t = cista::strong<std::uint32_t, struct _section_db_idx>;
Expand All @@ -117,6 +120,9 @@ using merged_trips_idx_t =
using footpath_idx_t = cista::strong<std::uint32_t, struct _footpath_idx>;
using source_file_idx_t = cista::strong<std::uint16_t, struct _source_file_idx>;

using profile_idx_t = std::uint8_t;
static constexpr auto const kMaxProfiles = profile_idx_t{8};

using rt_trip_idx_t = cista::strong<std::uint32_t, struct _trip_idx>;
using rt_add_trip_id_idx_t =
cista::strong<std::uint32_t, struct _trip_id_str_idx>;
Expand Down
11 changes: 7 additions & 4 deletions src/loader/build_footpaths.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "nigiri/common/day_list.h"
#include "nigiri/logging.h"
#include "nigiri/rt/frun.h"
#include "nigiri/types.h"
#include "utl/erase_duplicates.h"
#include "utl/erase_if.h"
#include "utl/pairwise.h"
Expand Down Expand Up @@ -586,18 +587,20 @@ void add_links_to_and_between_children(timetable& tt) {
}

void write_footpaths(timetable& tt) {
assert(tt.locations_.footpaths_out_.empty());
assert(tt.locations_.footpaths_in_.empty());
assert(tt.locations_.footpaths_out_.size() == kMaxProfiles);
assert(tt.locations_.footpaths_in_.size() == kMaxProfiles);
assert(tt.locations_.preprocessing_footpaths_out_.size() == tt.n_locations());
assert(tt.locations_.preprocessing_footpaths_in_.size() == tt.n_locations());

profile_idx_t const prf_idx{0};

for (auto i = location_idx_t{0U}; i != tt.n_locations(); ++i) {
tt.locations_.footpaths_out_.emplace_back(
tt.locations_.footpaths_out_[prf_idx].emplace_back(
tt.locations_.preprocessing_footpaths_out_[i]);
}

for (auto i = location_idx_t{0U}; i != tt.n_locations(); ++i) {
tt.locations_.footpaths_in_.emplace_back(
tt.locations_.footpaths_in_[prf_idx].emplace_back(
tt.locations_.preprocessing_footpaths_in_[i]);
}

Expand Down
6 changes: 2 additions & 4 deletions src/loader/gtfs/stop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -242,19 +242,17 @@ locations_map read_stops(source_idx_t const src,
}

auto empty_idx_vec = vector<location_idx_t>{};
auto empty_footpath_vec = vector<footpath>{};
for (auto const& [id, s] : stops) {
auto const is_track = s->parent_ != nullptr && !s->platform_code_.empty();
locations.emplace(
std::string{id},
s->location_ = tt.locations_.register_location(location{
id, is_track ? s->platform_code_ : s->name_, s->coord_, src,
is_track ? location_type::kTrack : location_type::kStation,
osm_node_id_t::invalid(), location_idx_t::invalid(),
location_idx_t::invalid(),
s->timezone_.empty() ? timezone_idx_t::invalid()
: get_tz_idx(tt, timezones, s->timezone_),
2_minutes, it_range{empty_idx_vec}, std::span{empty_footpath_vec},
std::span{empty_footpath_vec}}));
2_minutes, it_range{empty_idx_vec}}));
}

read_transfers(stops, transfers_file_content);
Expand Down
6 changes: 2 additions & 4 deletions src/loader/hrd/stamm/station.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ location_map_t parse_stations(config const& c,
auto const timer = scoped_timer{"parse stations"};

auto empty_idx_vec = vector<location_idx_t>{};
auto empty_footpath_vec = vector<footpath>{};

location_map_t stations;
parse_station_names(c, stations, station_names_file);
Expand All @@ -194,9 +193,8 @@ location_map_t parse_stations(config const& c,
auto const transfer_time = duration_t{eva_int < 1000000 ? 2 : 5};
auto const idx = tt.locations_.register_location(
location{id.id_, s.name_, s.pos_, src, location_type::kStation,
osm_node_id_t::invalid(), location_idx_t::invalid(),
st.get_tz(s.id_).first, transfer_time, it_range{empty_idx_vec},
std::span{empty_footpath_vec}, std::span{empty_footpath_vec}});
location_idx_t::invalid(), st.get_tz(s.id_).first,
transfer_time, it_range{empty_idx_vec}});
s.idx_ = idx;
}

Expand Down
6 changes: 1 addition & 5 deletions src/loader/init_finish.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,16 @@ namespace nigiri::loader {

void register_special_stations(timetable& tt) {
auto empty_idx_vec = vector<location_idx_t>{};
auto empty_footpath_vec = vector<footpath>{};
for (auto const& name : special_stations_names) {
tt.locations_.register_location(location{name,
name,
{0.0, 0.0},
source_idx_t::invalid(),
location_type::kStation,
osm_node_id_t::invalid(),
location_idx_t::invalid(),
timezone_idx_t::invalid(),
0_minutes,
it_range{empty_idx_vec},
std::span{empty_footpath_vec},
std::span{empty_footpath_vec}});
it_range{empty_idx_vec}});
}
tt.location_routes_.resize(tt.n_locations());
tt.bitfields_.emplace_back(bitfield{}); // bitfield_idx 0 = 000...00 bitfield
Expand Down
Loading