Skip to content

Commit

Permalink
add bike_sharing profile
Browse files Browse the repository at this point in the history
  • Loading branch information
pablohoch committed Oct 25, 2024
1 parent 48ac3ab commit 9ff28a7
Show file tree
Hide file tree
Showing 16 changed files with 625 additions and 77 deletions.
6 changes: 5 additions & 1 deletion exe/backend/src/http_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "osr/routing/profiles/car.h"
#include "osr/routing/profiles/car_parking.h"
#include "osr/routing/profiles/foot.h"
#include "osr/routing/profiles/bike_sharing.h"
#include "osr/routing/route.h"

using namespace net;
Expand Down Expand Up @@ -196,6 +197,9 @@ struct http_server::impl {
case search_profile::kCarParkingWheelchair:
send_graph_response<car_parking<true>>(req, cb, gj);
break;
case search_profile::kBikeSharing:
send_graph_response<bike_sharing>(req, cb, gj);
break;
default: throw utl::fail("not implemented");
}
}
Expand Down Expand Up @@ -369,4 +373,4 @@ void http_server::listen(std::string const& host, std::string const& port) {

void http_server::stop() { impl_->stop(); }

} // namespace osr::backend
} // namespace osr::backend
14 changes: 14 additions & 0 deletions include/osr/routing/additional_edge.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

#include "osr/types.h"

namespace osr {

struct additional_edge {
friend bool operator==(additional_edge, additional_edge) = default;

node_idx_t node_{};
distance_t distance_{};
};

} // namespace osr
19 changes: 12 additions & 7 deletions include/osr/routing/dijkstra.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#pragma once

#include "osr/routing/additional_edge.h"
#include "osr/routing/dial.h"
#include "osr/types.h"
#include "osr/ways.h"

namespace osr {

struct sharing_data;

template <typename Profile>
struct dijkstra {
using profile_t = Profile;
Expand Down Expand Up @@ -40,7 +43,8 @@ struct dijkstra {
template <direction SearchDir, bool WithBlocked>
void run(ways::routing const& r,
cost_t const max,
bitvec<node_idx_t> const* blocked) {
bitvec<node_idx_t> const* blocked,
sharing_data const* sharing) {
while (!pq_.empty()) {
auto l = pq_.pop();
if (get_cost(l.get_node()) < l.cost()) {
Expand All @@ -49,7 +53,7 @@ struct dijkstra {

auto const curr = l.get_node();
Profile::template adjacent<SearchDir, WithBlocked>(
r, curr, blocked,
r, curr, blocked, sharing,
[&](node const neighbor, std::uint32_t const cost, distance_t,
way_idx_t const way, std::uint16_t, std::uint16_t) {
auto const total = l.cost() + cost;
Expand All @@ -67,20 +71,21 @@ struct dijkstra {
void run(ways::routing const& r,
cost_t const max,
bitvec<node_idx_t> const* blocked,
sharing_data const* sharing,
direction const dir) {
if (blocked == nullptr) {
dir == direction::kForward
? run<direction::kForward, false>(r, max, blocked)
: run<direction::kBackward, false>(r, max, blocked);
? run<direction::kForward, false>(r, max, blocked, sharing)
: run<direction::kBackward, false>(r, max, blocked, sharing);
} else {
dir == direction::kForward
? run<direction::kForward, true>(r, max, blocked)
: run<direction::kBackward, true>(r, max, blocked);
? run<direction::kForward, true>(r, max, blocked, sharing)
: run<direction::kBackward, true>(r, max, blocked, sharing);
}
}

dial<label, get_bucket> pq_{get_bucket{}};
ankerl::unordered_dense::map<key, entry, hash> cost_;
};

} // namespace osr
} // namespace osr
17 changes: 17 additions & 0 deletions include/osr/routing/mode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#include <cinttypes>
#include <string_view>

namespace osr {

enum class mode : std::uint8_t {
kFoot,
kWheelchair,
kBike,
kCar,
};

std::string_view to_str(mode);

} // namespace osr
5 changes: 3 additions & 2 deletions include/osr/routing/profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ enum class search_profile : std::uint8_t {
kBike,
kCar,
kCarParking,
kCarParkingWheelchair
kCarParkingWheelchair,
kBikeSharing,
};

search_profile to_profile(std::string_view);

std::string_view to_str(search_profile);

} // namespace osr
} // namespace osr
8 changes: 7 additions & 1 deletion include/osr/routing/profiles/bike.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#pragma once

#include "osr/routing/mode.h"
#include "osr/routing/route.h"
#include "osr/ways.h"

namespace osr {

struct sharing_data;

struct bike {
static constexpr auto const kMaxMatchDistance = 100U;
static constexpr auto const kOffroadPenalty = 1U;
Expand All @@ -20,6 +23,8 @@ struct bike {

constexpr node get_key() const noexcept { return *this; }

static constexpr mode get_mode() noexcept { return mode::kBike; }

std::ostream& print(std::ostream& out, ways const& w) const {
return out << w.node_to_osm_[n_];
}
Expand Down Expand Up @@ -101,6 +106,7 @@ struct bike {
static void adjacent(ways::routing const& w,
node const n,
bitvec<node_idx_t> const* blocked,
sharing_data const*,
Fn&& fn) {
for (auto const [way, i] :
utl::zip_unchecked(w.node_ways_[n.n_], w.node_in_way_idx_[n.n_])) {
Expand Down Expand Up @@ -154,4 +160,4 @@ struct bike {
}
};

} // namespace osr
} // namespace osr
Loading

0 comments on commit 9ff28a7

Please sign in to comment.