Skip to content

Commit

Permalink
address some review issues
Browse files Browse the repository at this point in the history
  • Loading branch information
djfhe committed Jul 16, 2024
1 parent bf6deca commit 8470c5a
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 94 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:

- name: Format files
run: |
find base libs modules test \
find exe include src test \
-type f -a \( -name "*.cc" -o -name "*.h" -o -name ".cuh" -o -name ".cu" \) \
-print0 | xargs -0 clang-format-17 -i
Expand Down
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cmake.configureOnOpen": false,
"files.associations": {
"bitset": "cpp"
}
}
2 changes: 1 addition & 1 deletion exe/backend/src/http_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "osr/routing/profiles/bike.h"
#include "osr/routing/profiles/car.h"
#include "osr/routing/profiles/foot.h"
#include "osr/routing/profiles/hybrid.h"
#include "osr/routing/profiles/car_foot.h"
#include "osr/routing/route.h"

using namespace net;
Expand Down
12 changes: 2 additions & 10 deletions include/osr/extract/tags.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,7 @@ struct foot_profile {
case cista::hash("designated"): return override::kWhitelist;
}

if (t.is_platform_) {
return override::kWhitelist;
}

if (t.is_parking_) {
if (t.is_platform_ || t.is_parking_) {
return override::kWhitelist;
}

Expand All @@ -209,11 +205,7 @@ struct foot_profile {

static bool default_access(tags const& t, osm_obj_type const type) {
if (type == osm_obj_type::kWay) {
if (t.is_elevator_) {
return true;
}

if (t.is_parking_) {
if (t.is_elevator_ || t.is_parking_) {
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions include/osr/routing/profiles/bike.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct bike {

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

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

Expand Down Expand Up @@ -71,7 +71,7 @@ struct bike {
};

template <typename Fn>
static void resolve(
static void resolve_start_node(
ways::routing const&, way_idx_t, node_idx_t const n, level_t, direction, Fn&& f) {
f(node{n});
}
Expand Down
8 changes: 4 additions & 4 deletions include/osr/routing/profiles/car.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

#include <bitset>

#include "boost/json/object.hpp"

#include "utl/helpers/algorithm.h"

#include "osr/ways.h"

#include <boost/json/object.hpp>

namespace osr {

struct car {
Expand All @@ -26,7 +26,7 @@ struct car {

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

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

Expand Down Expand Up @@ -121,7 +121,7 @@ struct car {
};

template <typename Fn>
static void resolve(ways::routing const& w,
static void resolve_start_node(ways::routing const& w,
way_idx_t const way,
node_idx_t const n,
level_t,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

#include <bitset>

#include "boost/graph/graph_traits.hpp"

#include "utl/helpers/algorithm.h"

#include "osr/ways.h"

#include <boost/graph/graph_traits.hpp>

namespace osr {

struct hybrid {
Expand Down Expand Up @@ -44,31 +44,11 @@ struct node {
return node{};
}

constexpr node() : type_{node_type::kInvalid}, idx_{node_idx_t::invalid()}, lvl_{level_t::invalid()} {}

constexpr node(node_idx_t const n, level_t const lvl, bool const is_parking)
: type_{node_type::kFoot}, idx_{n}, lvl_{lvl}, is_parking_{is_parking} {}

constexpr node(node_idx_t const n, level_t const lvl, bool const is_parking, direction const dir, way_pos_t const way)
: type_{node_type::kCar}, idx_{n}, lvl_{lvl}, is_parking_{is_parking}, dir_{dir}, node_way_index_{way} {}

constexpr node(node_type const t, node_idx_t const n, level_t const lvl, bool const is_parking, direction const dir, way_pos_t const way)
: type_{t}, idx_{n}, lvl_{lvl}, is_parking_{is_parking}, dir_{dir}, node_way_index_{way} {}

node_type type_;
node_idx_t idx_;

level_t lvl_;
bool is_parking_{false};

direction dir_{};
way_pos_t node_way_index_{};

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

boost::json::object custom_geojson_properties(ways const& w) const {
boost::json::object geojson_properties(ways const& w) const {
auto properties = boost::json::object{
{"node_id", idx_.v_},
{"level", to_float(lvl_)},
Expand Down Expand Up @@ -105,6 +85,15 @@ struct node {
constexpr bool is_invalid_node() const noexcept {
return type_ == node_type::kInvalid;
}

node_type type_{node_type::kInvalid};
node_idx_t idx_{node_idx_t::invalid()};

level_t lvl_{level_t::invalid()};
bool is_parking_;

direction dir_{};
way_pos_t node_way_index_{};
};

struct entry {
Expand All @@ -114,7 +103,6 @@ struct node {
entry() {
utl::fill(cost_, kInfeasible);
utl::fill(pred_, node_idx_t::invalid());
utl::fill(pred_way_, way_pos_t{0U});
}

constexpr std::optional<node> pred(node const n) const noexcept {
Expand All @@ -124,24 +112,13 @@ struct node {
return std::nullopt;
}

if (pred_type_[idx]) {
return std::optional {
node{
pred_[idx],
pred_lvl_[idx],
pred_parking_[idx],
}
};
}

return std::optional {
node{
pred_[idx],
pred_lvl_[idx],
pred_parking_[idx],
to_dir(pred_dir_[idx]),
pred_way_[idx],
}
return node{
to_node_type(pred_type_[idx]),
pred_[idx],
pred_lvl_[idx],
pred_parking_[idx],
to_dir(pred_dir_[idx]),
pred_way_[idx],
};
}

Expand All @@ -152,22 +129,16 @@ struct node {
constexpr bool update(node const n,
cost_t const c,
node const pred) noexcept {
if (pred.is_invalid_node()) {
cost_[get_index(n)] = c;
return true;
}
auto const idx = get_index(n);

if (auto const idx = get_index(n); c < cost_[idx]) {
if (c < cost_[idx]) {
cost_[idx] = c;
pred_[idx] = pred.idx_;
pred_lvl_[idx] = pred.lvl_;
pred_parking_[idx] = pred.is_parking_;
pred_type_[idx] = to_bool(pred.type_);

if (pred.is_car_node()) {
pred_way_[idx] = pred.node_way_index_;
pred_dir_[idx] = to_bool(pred.dir_);
}
pred_way_[idx] = pred.node_way_index_;
pred_dir_[idx] = to_bool(pred.dir_);

return true;
}
Expand Down Expand Up @@ -241,7 +212,7 @@ struct node {
* mode depending on search direction.
*/
template <typename Fn>
static void resolve(ways::routing const& w,
static void resolve_start_node(ways::routing const& w,
way_idx_t const way,
node_idx_t const n,
level_t const lvl,
Expand All @@ -250,22 +221,23 @@ struct node {
auto const way_properties = w.way_properties_[way];
auto const ways = w.node_ways_[n];


level_t const node_level = lvl == level_t::invalid() ? way_properties.from_level() : lvl;
bool const is_parking = w.node_properties_[n].is_parking_;

if (search_dir == direction::kBackward) {
// when seraching backward, we have to start with the foot node
if (lvl == level_t::invalid() || (way_properties.from_level() == lvl || way_properties.to_level() == lvl || can_use_elevator(w, n, lvl))) {
f(node{n, node_level, is_parking});
f(node{node_type::kFoot, n, node_level, is_parking});
}

return;
}

for (auto i = way_pos_t{0U}; i != ways.size(); ++i) {
if (ways[i] == way) {
f(node{n, node_level, is_parking, direction::kForward, i});
f(node{n, node_level, is_parking, direction::kBackward, i});
f(node{node_type::kCar, n, node_level, is_parking, direction::kForward, i});
f(node{node_type::kCar, n, node_level, is_parking, direction::kBackward, i});
}
}
}
Expand All @@ -280,27 +252,27 @@ struct node {

auto levels = hash_set<level_t>{};

bool const is_parking = node_properties.is_parking_;
auto const is_parking = node_properties.is_parking_;

for (auto i = way_pos_t{0U}; i != ways.size(); ++i) {
auto const p = w.way_properties_[w.node_ways_[n][i]];

level_t const node_level = lvl == level_t::invalid() ? p.from_level() : lvl;
auto const node_level = lvl == level_t::invalid() ? p.from_level() : lvl;

f(node{n, node_level, is_parking, direction::kForward, i});
f(node{n, node_level, is_parking, direction::kBackward, i});
f(node{node_type::kCar, n, node_level, is_parking, direction::kForward, i});
f(node{node_type::kCar, n, node_level, is_parking, direction::kBackward, i});

if (lvl == level_t::invalid()) {
if (levels.emplace(p.from_level()).second) {
f(node{n, p.from_level(), is_parking});
f(node{node_type::kFoot, n, p.from_level(), is_parking});
}
if (levels.emplace(p.to_level()).second) {
f(node{n, p.to_level(), is_parking});
f(node{node_type::kFoot, n, p.to_level(), is_parking});
}
} else if ((p.from_level() == lvl || p.to_level() == lvl ||
can_use_elevator(w, n, lvl)) &&
levels.emplace(lvl).second) {
f(node{n, lvl, is_parking});
f(node{node_type::kFoot, n, lvl, is_parking});
}
}
}
Expand Down Expand Up @@ -348,7 +320,7 @@ struct node {
w, target_node, [&](level_t const target_lvl) {
auto const dist = w.way_node_dist_[way][std::min(from, to)];
auto const cost = foot_way_cost(target_way_prop, dist) + target_node_cost;
fn(node{target_node, target_lvl, target_node_prop.is_parking_}, cost, dist, way, from, to);
fn(node{node_type::kFoot, target_node, target_lvl, target_node_prop.is_parking_}, cost, dist, way, from, to);
});

return; // node is an elevator
Expand All @@ -362,7 +334,7 @@ struct node {

auto const dist = w.way_node_dist_[way][std::min(from, to)];
auto const cost = foot_way_cost(target_way_prop, dist) + target_node_cost;
fn(node{target_node, *target_lvl, target_node_prop.is_parking_}, cost, dist, way, from, to);
fn(node{node_type::kFoot, target_node, *target_lvl, target_node_prop.is_parking_}, cost, dist, way, from, to);
}

template <direction SearchDir, typename Fn>
Expand All @@ -384,7 +356,7 @@ struct node {

auto const target_node = w.way_nodes_[way][to];
auto const target_node_prop = w.node_properties_[target_node];
cost_t const target_node_cost = car_node_cost(target_node_prop);
auto const target_node_cost = car_node_cost(target_node_prop);

if (target_node_cost == kInfeasible) {
return;
Expand All @@ -400,7 +372,7 @@ struct node {
auto const target_level = way_prop.from_level() == n.lvl_ ? way_prop.to_level() : way_prop.from_level();

auto const target =
node{target_node, target_level, target_node_prop.is_parking_, way_dir, w.get_way_pos(target_node, way)};
node{node_type::kCar, target_node, target_level, target_node_prop.is_parking_, way_dir, w.get_way_pos(target_node, way)};

if(n.is_foot_node()) {
if (!n.is_parking_) {
Expand All @@ -410,7 +382,6 @@ struct node {
auto const dist = w.way_node_dist_[way][std::min(from, to)];
cost_t const cost = car_way_cost(target_way_prop, way_dir, dist) + target_node_cost + kSwitchPenalty;
fn(target, cost, dist, way, from, to);
return;
}

if (w.is_restricted<SearchDir>(n.idx_, n.node_way_index_, way_pos)) {
Expand Down Expand Up @@ -505,6 +476,7 @@ struct node {
static constexpr cost_t way_cost(way_properties const& e,
direction const dir,
std::uint16_t const dist) {

return foot_way_cost(e, dist);
}

Expand Down
4 changes: 2 additions & 2 deletions include/osr/routing/profiles/foot.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct foot {
}
constexpr node_idx_t get_node() const noexcept { return n_; }

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

Expand Down Expand Up @@ -78,7 +78,7 @@ struct foot {
};

template <typename Fn>
static void resolve(ways::routing const& w,
static void resolve_start_node(ways::routing const& w,
way_idx_t const way,
node_idx_t const n,
level_t const lvl,
Expand Down
Loading

0 comments on commit 8470c5a

Please sign in to comment.