Skip to content

Commit

Permalink
merge follow up
Browse files Browse the repository at this point in the history
  • Loading branch information
felixguendling committed Jul 19, 2024
1 parent ace9432 commit bbdcdf9
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 43 deletions.
2 changes: 1 addition & 1 deletion exe/backend/src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ int main(int argc, char const* argv[]) {

auto ioc = boost::asio::io_context{};
auto pool = boost::asio::io_context{};
auto server = http_server{ioc, pool, w, pl.get(), l, opt.static_file_path_};
auto server = http_server{ioc, pool, w, l, pl.get(), opt.static_file_path_};

auto work_guard = boost::asio::make_work_guard(pool);
auto threads = std::vector<std::thread>(std::max(1U, opt.threads_));
Expand Down
2 changes: 1 addition & 1 deletion include/osr/routing/profiles/bike.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct bike {

constexpr node_idx_t get_node() const noexcept { return n_; }

boost::json::object geojson_properties(ways const& w) const {
boost::json::object geojson_properties(ways const&) const {
return boost::json::object{{"node_id", n_.v_}, {"type", "bike"}};
}

Expand Down
2 changes: 1 addition & 1 deletion include/osr/routing/profiles/car.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct car {

constexpr node_idx_t get_node() const noexcept { return n_; }

boost::json::object geojson_properties(ways const& w) const {
boost::json::object geojson_properties(ways const&) const {
return boost::json::object{{"node_id", n_.v_}, {"type", "car"}};
}

Expand Down
80 changes: 45 additions & 35 deletions include/osr/routing/profiles/car_parking.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "osr/routing/profiles/car.h"
#include "osr/routing/profiles/foot.h"
#include "osr/routing/route.h"
#include "osr/ways.h"

namespace osr {
Expand Down Expand Up @@ -76,6 +77,32 @@ struct car_parking {
way_pos_t way_;
};

struct label {
label(node const n, cost_t const c)
: n_{n.n_},
cost_{c},
type_{n.type_},
lvl_{n.lvl_},
dir_{n.dir_},
way_(n.way_) {}

constexpr node get_node() const noexcept {
return {
.n_ = n_, .type_ = type_, .lvl_ = lvl_, .dir_ = dir_, .way_ = way_};
}

constexpr cost_t cost() const noexcept { return cost_; }

void track(ways::routing const&, way_idx_t, node_idx_t) {}

node_idx_t n_;
cost_t cost_;
node_type type_;
level_t lvl_;
direction dir_;
way_pos_t way_;
};

struct entry {
static constexpr auto const kMaxWays = way_pos_t{16U};
static constexpr auto const kN = kMaxWays * 2U + 1 /* FWD+BWD + foot */;
Expand All @@ -97,7 +124,8 @@ struct car_parking {
return cost_[get_index(n)];
}

constexpr bool update(node const n,
constexpr bool update(label const,
node const n,
cost_t const c,
node const pred) noexcept {
auto const idx = get_index(n);
Expand Down Expand Up @@ -136,6 +164,8 @@ struct car_parking {
return t == node_type::kFoot;
}

void write(node, path&) const {}

std::array<node_idx_t, kN> pred_;
std::array<cost_t, kN> cost_;
std::array<way_pos_t, kN> pred_way_;
Expand All @@ -145,30 +175,6 @@ struct car_parking {
std::bitset<kN> pred_parking_;
};

struct label {
label(node const n, cost_t const c)
: n_{n.n_},
cost_{c},
type_{n.type_},
lvl_{n.lvl_},
dir_{n.dir_},
way_(n.way_) {}

constexpr node get_node() const noexcept {
return {
.n_ = n_, .type_ = type_, .lvl_ = lvl_, .dir_ = dir_, .way_ = way_};
}

constexpr cost_t cost() const noexcept { return cost_; }

node_idx_t n_;
cost_t cost_;
node_type type_;
level_t lvl_;
direction dir_;
way_pos_t way_;
};

struct hash {
using is_avalanching = void;
auto operator()(key const n) const noexcept -> std::uint64_t {
Expand Down Expand Up @@ -215,16 +221,19 @@ struct car_parking {
});
}

template <direction SearchDir, typename Fn>
static void adjacent(ways::routing const& w, node const n, Fn&& fn) {
template <direction SearchDir, bool WithBlocked, typename Fn>
static void adjacent(ways::routing const& w,
node const n,
bitvec<node_idx_t> const* blocked,
Fn&& fn) {
static constexpr auto const kFwd = SearchDir == direction::kForward;
static constexpr auto const kBwd = SearchDir == direction::kBackward;

auto const is_parking = w.node_properties_[n.n_].is_parking();

if (n.is_foot_node() || (kFwd && n.is_car_node() && is_parking)) {
foot::template adjacent<SearchDir>(
w, to_foot(n),
foot::template adjacent<SearchDir, WithBlocked>(
w, to_foot(n), blocked,
[&](foot::node const neighbor, std::uint32_t const cost,
distance_t const dist, way_idx_t const way,
std::uint16_t const from, std::uint16_t const to) {
Expand All @@ -235,8 +244,8 @@ struct car_parking {
}

if (n.is_car_node() || (kBwd && n.is_foot_node() && is_parking)) {
car::template adjacent<SearchDir>(
w, to_car(n),
car::template adjacent<SearchDir, WithBlocked>(
w, to_car(n), blocked,
[&](car::node const neighbor, std::uint32_t const cost,
distance_t const dist, way_idx_t const way,
std::uint16_t const from, std::uint16_t const to) {
Expand All @@ -261,15 +270,16 @@ struct car_parking {
auto const way_properties = w.way_properties_[way];
search_dir == direction::kForward
? car::resolve_start_node(w, way, n, lvl, search_dir,
[&](car::node const n) {
[&](car::node const cn) {
auto const node_level =
lvl == level_t::invalid()
? way_properties.from_level()
: lvl;
f(to_node(n, node_level));
f(to_node(cn, node_level));
})
: foot::resolve_start_node(w, way, n, lvl, search_dir,
[&](foot::node const n) { f(to_node(n)); });
: foot::resolve_start_node(
w, way, n, lvl, search_dir,
[&](foot::node const fn) { f(to_node(fn)); });
}

static bool is_dest_reachable(ways::routing const& w,
Expand Down
2 changes: 1 addition & 1 deletion include/osr/routing/profiles/foot.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct foot {
}
constexpr node_idx_t get_node() const noexcept { return n_; }

boost::json::object geojson_properties(ways const& w) const {
boost::json::object geojson_properties(ways const&) const {
return boost::json::object{{"node_id", n_.v_}, {"type", "foot"}};
}

Expand Down
2 changes: 2 additions & 0 deletions include/osr/routing/route.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <string_view>
#include <vector>

#include "boost/json/object.hpp"

#include "osr/lookup.h"
#include "osr/routing/dijkstra.h"
#include "osr/types.h"
Expand Down
6 changes: 3 additions & 3 deletions src/extract.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ struct way_handler : public osm::handler::Handler {
return;
}

auto const p = (t.is_platform_ || t.is_parking_ || !t.highway_.empty())
? get_way_properties(t)
: it->second;
auto p = (t.is_platform_ || t.is_parking_ || !t.highway_.empty())
? get_way_properties(t)
: it->second.p_;
if (!p.is_accessible()) {
return;
}
Expand Down
3 changes: 2 additions & 1 deletion src/route.cc
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ path reconstruct(ways const& w,
auto const& e = d.cost_.at(n.get_key());
auto const pred = e.pred(n);
if (pred.has_value()) {
auto const expected_cost = e.cost(n) - d.get_cost(*pred);
auto const expected_cost =
static_cast<cost_t>(e.cost(n) - d.get_cost(*pred));
dist += add_path<Profile>(w, *w.r_, blocked, *pred, n, expected_cost,
segments, dir);
} else {
Expand Down

0 comments on commit bbdcdf9

Please sign in to comment.