Skip to content

Commit dc598c3

Browse files
authored
Bikesharing profile (#20)
* add bike_sharing profile * clang-format-18 * fix compile errors * clang-format * fix windows mimalloc build * update pkg.cmake
1 parent 48ac3ab commit dc598c3

19 files changed

Lines changed: 697 additions & 119 deletions

File tree

CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ if (MSVC)
2121
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4996") # ignore deprecated fileno in tiles
2222
endif ()
2323

24+
option(OSR_MIMALLOC "use mimalloc" OFF)
25+
2426
if (NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY)
2527
if (OSR_MIMALLOC)
2628
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
@@ -29,7 +31,6 @@ if (NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY)
2931
endif ()
3032
endif ()
3133

32-
option(OSR_MIMALLOC "use mimalloc" OFF)
3334
if (OSR_MIMALLOC AND WIN32)
3435
set(MI_BUILD_SHARED ON)
3536
endif ()
@@ -155,9 +156,9 @@ if (OSR_MIMALLOC)
155156
add_custom_command(
156157
TARGET osr-extract POST_BUILD
157158
COMMAND "${CMAKE_COMMAND}" -E copy
158-
"${CMAKE_CURRENT_BINARY_DIR}/deps/mimalloc/mimalloc-redirect.dll"
159+
"${CMAKE_BINARY_DIR}/deps/mimalloc/mimalloc-redirect.dll"
159160
$<TARGET_FILE_DIR:osr>
160161
COMMENT "Copy mimalloc-redirect.dll to output directory"
161162
)
162163
endif ()
163-
endif ()
164+
endif ()

cmake/pkg.cmake

Lines changed: 54 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,63 @@
11
if (NOT DEFINED PROJECT_IS_TOP_LEVEL OR PROJECT_IS_TOP_LEVEL)
2-
find_program(pkg-bin pkg HINTS /opt/pkg)
3-
if (pkg-bin)
4-
message(STATUS "found pkg ${pkg-bin}")
5-
else ()
6-
set(pkg-bin "${CMAKE_BINARY_DIR}/dl/pkg")
7-
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" AND ${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "aarch64")
8-
set(pkg-url "pkg-linux-arm64")
9-
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
10-
set(pkg-url "pkg")
11-
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
12-
set(pkg-url "pkg.exe")
13-
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
14-
set(pkg-url "pkgosx")
2+
find_program(pkg-bin pkg HINTS /opt/pkg)
3+
if (pkg-bin)
4+
message(STATUS "found pkg ${pkg-bin}")
155
else ()
16-
message(STATUS "Not downloading pkg tool. Using pkg from PATH.")
17-
set(pkg-bin "pkg")
18-
endif ()
6+
set(pkg-bin "${CMAKE_BINARY_DIR}/dl/pkg")
7+
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" AND ${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "aarch64")
8+
set(pkg-url "pkg-linux-arm64")
9+
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
10+
set(pkg-url "pkg")
11+
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
12+
set(pkg-url "pkg.exe")
13+
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
14+
set(pkg-url "pkgosx")
15+
else ()
16+
message(STATUS "Not downloading pkg tool. Using pkg from PATH.")
17+
set(pkg-bin "pkg")
18+
endif ()
1919

20-
if (pkg-url)
21-
if (NOT EXISTS ${pkg-bin})
22-
message(STATUS "Downloading pkg binary from https://github.com/motis-project/pkg/releases/latest/download/${pkg-url}")
23-
file(DOWNLOAD "https://github.com/motis-project/pkg/releases/latest/download/${pkg-url}" ${pkg-bin})
24-
if (UNIX)
25-
execute_process(COMMAND chmod +x ${pkg-bin})
20+
if (pkg-url)
21+
if (NOT EXISTS ${pkg-bin})
22+
message(STATUS "Downloading pkg binary from https://github.com/motis-project/pkg/releases/latest/download/${pkg-url}")
23+
file(DOWNLOAD "https://github.com/motis-project/pkg/releases/latest/download/${pkg-url}" ${pkg-bin})
24+
if (UNIX)
25+
execute_process(COMMAND chmod +x ${pkg-bin})
26+
endif ()
27+
else ()
28+
message(STATUS "Pkg binary located in project.")
29+
endif ()
2630
endif ()
27-
else ()
28-
message(STATUS "Pkg binary located in project.")
29-
endif ()
3031
endif ()
31-
endif ()
3232

33-
message(STATUS ${pkg-bin})
33+
if (DEFINED ENV{GITHUB_ACTIONS})
34+
message(STATUS "${pkg-bin} -l -h -f")
35+
execute_process(
36+
COMMAND ${pkg-bin} -l -h -f
37+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
38+
RESULT_VARIABLE pkg-result
39+
)
40+
else ()
41+
message(STATUS "${pkg-bin} -l")
42+
execute_process(
43+
COMMAND ${pkg-bin} -l
44+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
45+
RESULT_VARIABLE pkg-result
46+
)
47+
endif ()
3448

35-
if (DEFINED ENV{GITHUB_ACTIONS})
36-
execute_process(
37-
COMMAND ${pkg-bin} -l -h
38-
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
39-
)
40-
else ()
41-
execute_process(
42-
COMMAND ${pkg-bin} -l
43-
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
44-
)
45-
endif ()
46-
endif ()
49+
if (NOT pkg-result EQUAL 0)
50+
message(FATAL_ERROR "pkg failed: ${pkg-result}")
51+
endif ()
4752

48-
if (IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/deps")
49-
add_subdirectory(deps)
53+
if (IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/deps")
54+
add_subdirectory(deps)
55+
endif ()
56+
57+
set_property(
58+
DIRECTORY
59+
APPEND
60+
PROPERTY CMAKE_CONFIGURE_DEPENDS
61+
"${CMAKE_CURRENT_SOURCE_DIR}/.pkg"
62+
)
5063
endif ()

exe/backend/src/http_server.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "osr/geojson.h"
2121
#include "osr/lookup.h"
2222
#include "osr/routing/profiles/bike.h"
23+
#include "osr/routing/profiles/bike_sharing.h"
2324
#include "osr/routing/profiles/car.h"
2425
#include "osr/routing/profiles/car_parking.h"
2526
#include "osr/routing/profiles/foot.h"
@@ -196,6 +197,9 @@ struct http_server::impl {
196197
case search_profile::kCarParkingWheelchair:
197198
send_graph_response<car_parking<true>>(req, cb, gj);
198199
break;
200+
case search_profile::kBikeSharing:
201+
send_graph_response<bike_sharing>(req, cb, gj);
202+
break;
199203
default: throw utl::fail("not implemented");
200204
}
201205
}
@@ -369,4 +373,4 @@ void http_server::listen(std::string const& host, std::string const& port) {
369373

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

372-
} // namespace osr::backend
376+
} // namespace osr::backend

exe/benchmark.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ int main(int argc, char const* argv[]) {
7373
d.reset(opt.max_dist_);
7474
d.add_start(car::label{car::node{start, 0, direction::kForward}, 0U});
7575
d.add_start(car::label{car::node{start, 0, direction::kBackward}, 0U});
76-
d.run<direction::kForward, false>(*w.r_, opt.max_dist_, nullptr);
76+
d.run<direction::kForward, false>(*w.r_, opt.max_dist_, nullptr,
77+
nullptr);
7778
}
7879
});
7980
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#pragma once
2+
3+
#include "osr/types.h"
4+
5+
namespace osr {
6+
7+
struct additional_edge {
8+
friend bool operator==(additional_edge, additional_edge) = default;
9+
10+
node_idx_t node_{};
11+
distance_t distance_{};
12+
};
13+
14+
} // namespace osr

include/osr/routing/dijkstra.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
#pragma once
22

3+
#include "osr/routing/additional_edge.h"
34
#include "osr/routing/dial.h"
45
#include "osr/types.h"
56
#include "osr/ways.h"
67

78
namespace osr {
89

10+
struct sharing_data;
11+
912
template <typename Profile>
1013
struct dijkstra {
1114
using profile_t = Profile;
@@ -40,7 +43,8 @@ struct dijkstra {
4043
template <direction SearchDir, bool WithBlocked>
4144
void run(ways::routing const& r,
4245
cost_t const max,
43-
bitvec<node_idx_t> const* blocked) {
46+
bitvec<node_idx_t> const* blocked,
47+
sharing_data const* sharing) {
4448
while (!pq_.empty()) {
4549
auto l = pq_.pop();
4650
if (get_cost(l.get_node()) < l.cost()) {
@@ -49,7 +53,7 @@ struct dijkstra {
4953

5054
auto const curr = l.get_node();
5155
Profile::template adjacent<SearchDir, WithBlocked>(
52-
r, curr, blocked,
56+
r, curr, blocked, sharing,
5357
[&](node const neighbor, std::uint32_t const cost, distance_t,
5458
way_idx_t const way, std::uint16_t, std::uint16_t) {
5559
auto const total = l.cost() + cost;
@@ -67,20 +71,21 @@ struct dijkstra {
6771
void run(ways::routing const& r,
6872
cost_t const max,
6973
bitvec<node_idx_t> const* blocked,
74+
sharing_data const* sharing,
7075
direction const dir) {
7176
if (blocked == nullptr) {
7277
dir == direction::kForward
73-
? run<direction::kForward, false>(r, max, blocked)
74-
: run<direction::kBackward, false>(r, max, blocked);
78+
? run<direction::kForward, false>(r, max, blocked, sharing)
79+
: run<direction::kBackward, false>(r, max, blocked, sharing);
7580
} else {
7681
dir == direction::kForward
77-
? run<direction::kForward, true>(r, max, blocked)
78-
: run<direction::kBackward, true>(r, max, blocked);
82+
? run<direction::kForward, true>(r, max, blocked, sharing)
83+
: run<direction::kBackward, true>(r, max, blocked, sharing);
7984
}
8085
}
8186

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

86-
} // namespace osr
91+
} // namespace osr

include/osr/routing/mode.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#pragma once
2+
3+
#include <cinttypes>
4+
#include <string_view>
5+
6+
namespace osr {
7+
8+
enum class mode : std::uint8_t {
9+
kFoot,
10+
kWheelchair,
11+
kBike,
12+
kCar,
13+
};
14+
15+
std::string_view to_str(mode);
16+
17+
} // namespace osr

include/osr/routing/profile.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ enum class search_profile : std::uint8_t {
1111
kBike,
1212
kCar,
1313
kCarParking,
14-
kCarParkingWheelchair
14+
kCarParkingWheelchair,
15+
kBikeSharing,
1516
};
1617

1718
search_profile to_profile(std::string_view);
1819

1920
std::string_view to_str(search_profile);
2021

21-
} // namespace osr
22+
} // namespace osr

include/osr/routing/profiles/bike.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
#pragma once
22

3+
#include "osr/routing/mode.h"
34
#include "osr/routing/route.h"
45
#include "osr/ways.h"
56

67
namespace osr {
78

9+
struct sharing_data;
10+
811
struct bike {
912
static constexpr auto const kMaxMatchDistance = 100U;
1013
static constexpr auto const kOffroadPenalty = 1U;
@@ -20,6 +23,8 @@ struct bike {
2023

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

26+
static constexpr mode get_mode() noexcept { return mode::kBike; }
27+
2328
std::ostream& print(std::ostream& out, ways const& w) const {
2429
return out << w.node_to_osm_[n_];
2530
}
@@ -101,6 +106,7 @@ struct bike {
101106
static void adjacent(ways::routing const& w,
102107
node const n,
103108
bitvec<node_idx_t> const* blocked,
109+
sharing_data const*,
104110
Fn&& fn) {
105111
for (auto const [way, i] :
106112
utl::zip_unchecked(w.node_ways_[n.n_], w.node_in_way_idx_[n.n_])) {
@@ -154,4 +160,4 @@ struct bike {
154160
}
155161
};
156162

157-
} // namespace osr
163+
} // namespace osr

0 commit comments

Comments
 (0)