Skip to content
Draft
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
22 changes: 12 additions & 10 deletions .pkg.lock
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
6383257829560100747
cista 1fb6f1d9bb8ac9fdb4ca648df69695dd819dc07e
9718959010576347214
cista abbbf9cfc1484b3a2737eff7a8f2f96d8dab85e4
PEGTL 0d37dcf8f02c12a84fdf521973801a5baab78e8f
res b759b93316afeb529b6cb5b2548b24c41e382fb0
date ce88cc33b5551f66655614eeebb7c5b7189025fb
googletest 9758d168fd1ccff2d76f3bd6ef802943d0f8f7e5
docs 75dc89a53e9c2d78574fc0ffda698e69f1682ed2
fmt dc10f83be70ac2873d5f8d1ce317596f1fd318a2
utl 9081181d194c45fb0c6840cefa7a3be7017d9dbc
fmt 34a5bee1df1f0d144de0e127807d161d08670472
utl 3d6d0c626d124b8a1625be1c6cb6d5c76c140195
oh d9eb908452e808179afeb7954e8beaa5b3626c36
LuaJIT f4bc3f109a4cc5bc262b2a2c683dae5a75f61377
LuaJIT dfa894a9c571bedc26f3a45573917a8af07603e4
json ccc94522e752a13a0273dfb837ab36f7dbcda5ab
sqlite3 04e60de4ab15c5072b8c7ee2ac7335eb06f2588b
PROJ 27ed257526ddf6e2fd7a1a3c92a1d3de913ce34b
zlib-ng d68e1d908e789c31c1f2fafe4bd8e09cb91e21c5
boost f0eca85b563887be8f26c4856c53d4e5080e6976
boost 77467bf580d98ea06716e2931cbe3b1f28e0cd37
doctest 832431f2d9dc77e51cc8b364337c186660bf267d
geo d862550fd867cd5435225b5f0998981ec4fc2ae3
rtree.c 6ed73a7dc4f1184f2b5b2acd8ac1c2b28a273057
tg 20c0f298b8ce58de29a790290f44dca7c4ecc364
geo 1450091a6ee2d541e91d26bf06157342ec0599f6
miniz e857234a23de8e5a2d05d266e518220a495db0ce
libressl 24acd9e710fbe842e863572da9d738715fbc74b8
curl 39c8a51e8ee0ab7ea712886df79c068405a2e008
libressl 660f532fa29e1e934e530f22faa79cf7ea345a40
curl 0743359585cf0d2bd15b9792c0460470a231d8d0
opentelemetry-proto 1624689398a3226c45994d70cb544a1e781dc032
abseil-cpp ba5240842d352b4b67a32092453a2fe5fe53a62e
protobuf df2dd518c68b882c9dce5346393f8c388108e733
opentelemetry-cpp 60770dc9dc63e3543fc87d605b2e88fd53d7a414
opentelemetry-cpp 57a4c01aff876e08d9d37a3dec2c9899f0606909
pugixml bb45e30c5bf21b3599eb5b4b7fa20547043c3e24
sol2 40c7cbc7c5cfed1e8c7f1bbe6fcbe23d7a67fc75
unordered_dense 2c7230ae7f9c30849a5b089fb4a5d11896b45dcf
Expand Down
40 changes: 39 additions & 1 deletion include/nigiri/routing/raptor/raptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ enum class search_mode { kOneToOne, kOneToAll };
template <direction SearchDir,
bool Rt,
via_offset_t Vias,
search_mode SearchMode>
search_mode SearchMode,
bool LbGreedy>
struct raptor {
using algo_state_t = raptor_state;
using algo_stats_t = raptor_stats;
Expand All @@ -86,6 +87,8 @@ struct raptor {
a.fill(kInvalid);
return a;
}();
static constexpr auto LbGreedyAcceptableLoss = 1.42;
static constexpr auto LbGreedyThreshold = std::uint16_t{60};

static bool is_better(auto a, auto b) { return kFwd ? a < b : a > b; }
static bool is_better_or_eq(auto a, auto b) { return kFwd ? a <= b : a >= b; }
Expand Down Expand Up @@ -166,6 +169,11 @@ struct raptor {
if constexpr (Rt) {
utl::fill(state_.rt_transport_mark_.blocks_, 0U);
}
if constexpr (LbGreedy) {
utl::fill(state_.route_lb_, kUnreachable);
utl::fill(state_.rt_transport_lb_, kUnreachable);
start_lb_ = kUnreachable;
}
}

void add_start(location_idx_t const l, unixtime_t const t) {
Expand All @@ -181,6 +189,11 @@ struct raptor {
round_times_[0U][to_idx(l)][v] =
get_best(unix_to_delta(base(), t), round_times_[0U][to_idx(l)][v]);
state_.station_mark_.set(to_idx(l), true);
if constexpr (LbGreedy) {
start_lb_ = std::min(
start_lb_,
static_cast<std::uint16_t>(lb_[to_idx(l)] * LbGreedyAcceptableLoss));
}
}

void execute(unixtime_t const start_time,
Expand Down Expand Up @@ -212,12 +225,22 @@ struct raptor {
for (auto const& r : tt_.location_routes_[location_idx_t{i}]) {
any_marked = true;
state_.route_mark_.set(to_idx(r), true);
if constexpr (LbGreedy) {
state_.route_lb_[r] = std::min(
start_lb_,
static_cast<std::uint16_t>(lb_[i] * LbGreedyAcceptableLoss));
}
}
if constexpr (Rt) {
for (auto const& rt_t :
rtt_->location_rt_transports_[location_idx_t{i}]) {
any_marked = true;
state_.rt_transport_mark_.set(to_idx(rt_t), true);
if constexpr (LbGreedy) {
state_.rt_transport_lb_[rt_t] = std::min(
start_lb_,
static_cast<std::uint16_t>(lb_[i] * LbGreedyAcceptableLoss));
}
}
}
});
Expand Down Expand Up @@ -802,6 +825,13 @@ struct raptor {
auto const is_first = i == 0U;
auto const is_last = i == stop_seq.size() - 1U;

if constexpr (LbGreedy) {
if (lb_[l_idx] > LbGreedyThreshold &&
lb_[l_idx] > state_.rt_transport_lb_[rt_t]) {
continue;
}
}

if constexpr (WithSectionBikeFilter) {
if (!is_first &&
!rtt_->rt_bikes_allowed_per_section_[rt_t][kFwd ? stop_idx - 1
Expand Down Expand Up @@ -906,6 +936,13 @@ struct raptor {
auto const is_first = i == 0U;
auto const is_last = i == stop_seq.size() - 1U;

if constexpr (LbGreedy) {
if (lb_[l_idx] > LbGreedyThreshold &&
lb_[l_idx] > state_.route_lb_[r]) {
continue;
}
}

auto current_best = std::array<delta_t, Vias + 1>{};
current_best.fill(kInvalid);

Expand Down Expand Up @@ -1264,6 +1301,7 @@ struct raptor {
bool require_car_transport_;
bool is_wheelchair_;
transfer_time_settings transfer_time_settings_;
std::uint16_t start_lb_;
};

} // namespace nigiri::routing
2 changes: 2 additions & 0 deletions include/nigiri/routing/raptor/raptor_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ struct raptor_state {
bitvec prev_station_mark_;
bitvec route_mark_;
bitvec rt_transport_mark_;
vector_map<route_idx_t, std::uint16_t> route_lb_;
vector_map<rt_transport_idx_t, std::uint16_t> rt_transport_lb_;
};

} // namespace nigiri::routing
4 changes: 2 additions & 2 deletions src/abi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,15 @@ nigiri::pareto_set<nigiri::routing::journey> raptor_search(
if (backward_search) {
using algo_t =
nigiri::routing::raptor<nigiri::direction::kBackward, true, 0,
nigiri::routing::search_mode::kOneToOne>;
nigiri::routing::search_mode::kOneToOne, false>;
return *(nigiri::routing::search<nigiri::direction::kBackward, algo_t>{
tt, rtt, search_state, algo_state, std::move(q)}
.execute()
.journeys_);
} else {
using algo_t =
nigiri::routing::raptor<nigiri::direction::kForward, true, 0,
nigiri::routing::search_mode::kOneToOne>;
nigiri::routing::search_mode::kOneToOne, false>;
return *(nigiri::routing::search<nigiri::direction::kForward, algo_t>{
tt, rtt, search_state, algo_state, std::move(q)}
.execute()
Expand Down
11 changes: 6 additions & 5 deletions src/routing/one_to_all.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ day_idx_t make_base(timetable const& tt, unixtime_t start_time) {
}

template <direction SearchDir, bool Rt>
void run_raptor(raptor<SearchDir, Rt, kVias, search_mode::kOneToAll>&& algo,
timetable const& tt,
unixtime_t const& start_time,
query const& q) {
void run_raptor(
raptor<SearchDir, Rt, kVias, search_mode::kOneToAll, false>&& algo,
timetable const& tt,
unixtime_t const& start_time,
query const& q) {
auto results = pareto_set<journey>{};
algo.next_start_time();
for (auto const& s : q.start_) {
Expand Down Expand Up @@ -69,7 +70,7 @@ raptor_state one_to_all(timetable const& tt,
auto const base = make_base(tt, start_time);
auto const is_wheelchair = q.prf_idx_ == kWheelchairProfile;

auto r = raptor<SearchDir, Rt, kVias, search_mode::kOneToAll>{
auto r = raptor<SearchDir, Rt, kVias, search_mode::kOneToAll, false>{
tt,
rtt,
state,
Expand Down
4 changes: 2 additions & 2 deletions src/routing/raptor/pong.cc
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ routing_result pong(timetable const& tt,
collect_via_destinations(tt, via.location_, ping_is_via[i]);
}

auto ping = raptor<SearchDir, Rt, Vias, search_mode::kOneToOne>{
auto ping = raptor<SearchDir, Rt, Vias, search_mode::kOneToOne, false>{
tt,
rtt,
r_state,
Expand Down Expand Up @@ -350,7 +350,7 @@ routing_result pong(timetable const& tt,
collect_via_destinations(tt, via.location_, pong_is_via[i]);
}

auto pong = raptor<flip(SearchDir), Rt, Vias, search_mode::kOneToOne>{
auto pong = raptor<flip(SearchDir), Rt, Vias, search_mode::kOneToOne, false>{
tt,
rtt,
r_state,
Expand Down
2 changes: 2 additions & 0 deletions src/routing/raptor/raptor_state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ raptor_state& raptor_state::resize(unsigned const n_locations,
prev_station_mark_.resize(n_locations);
route_mark_.resize(n_routes);
rt_transport_mark_.resize(n_rt_transports);
route_lb_.resize(n_routes);
rt_transport_lb_.resize(n_rt_transports);
return *this;
}

Expand Down
5 changes: 3 additions & 2 deletions src/routing/raptor_search.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ routing_result raptor_search_with_vias(
query q,
std::optional<std::chrono::seconds> const timeout) {
if (rtt == nullptr) {
using algo_t = raptor<SearchDir, false, Vias, search_mode::kOneToOne>;
using algo_t =
raptor<SearchDir, false, Vias, search_mode::kOneToOne, false>;
return search<SearchDir, algo_t>{tt, rtt, s_state,
r_state, std::move(q), timeout}
.execute();
} else {
using algo_t = raptor<SearchDir, true, Vias, search_mode::kOneToOne>;
using algo_t = raptor<SearchDir, true, Vias, search_mode::kOneToOne, false>;
return search<SearchDir, algo_t>{tt, rtt, s_state,
r_state, std::move(q), timeout}
.execute();
Expand Down
Loading