Skip to content

Commit

Permalink
platforms (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixguendling authored Jul 20, 2024
1 parent d4d147c commit 02a5bb8
Show file tree
Hide file tree
Showing 28 changed files with 1,266 additions and 846 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
/*build*
/deps
/.pkg.mutex
/.clang-tidy
/.clang-tidy
/.vs
/out
6 changes: 3 additions & 3 deletions .pkg
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@
[geo]
[email protected]:motis-project/geo.git
branch=master
commit=ee76668f0f0454e4acd3c769e00c6868620e3490
commit=10fde5b467825c059881c93aeea00412338a9b06
[cista]
[email protected]:felixguendling/cista.git
branch=master
commit=ebd5eb5cc7f82c414d3e060a3937d497189a103f
commit=bcabd041ddf07baf1b544bbe46ef195c2b6d22bd
[googletest]
[email protected]:motis-project/googletest.git
branch=master
commit=34a46558609e05865c197f0260ab36daa7cbbb6e
[utl]
[email protected]:motis-project/utl.git
branch=master
commit=4c1503afe58e209977d9a1e3db6a6b271a50c521
commit=80df7a6f1e2de4d290c48e9218d48eb9792b7289
[protozero]
[email protected]:motis-project/protozero.git
branch=master
Expand Down
8 changes: 4 additions & 4 deletions .pkg.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
8573834864848100359
cista ebd5eb5cc7f82c414d3e060a3937d497189a103f
16761676331022936617
cista bcabd041ddf07baf1b544bbe46ef195c2b6d22bd
zlib d1c943390ba4f97aa2f50bedc629b6d29027fa0e
boost 60cae66449fa3c9599b2b7d3d5d44c65301ed3a3
conf f9bf4bd83bf55a2170725707e526cbacc45dcc66
expat 636c9861e8e7c119f3626d1e6c260603ab624516
fmt edb385ac526c24bc917ec4a41bb0edb28f0ca59e
doctest 70e8f76437b76dd5e9c0a2eb9b907df190ab71a0
geo ee76668f0f0454e4acd3c769e00c6868620e3490
geo 10fde5b467825c059881c93aeea00412338a9b06
googletest 34a46558609e05865c197f0260ab36daa7cbbb6e
libosmium 6e6d6b3081cc8bdf25dda89730e25c36eb995516
mimalloc 0087f000848de31b0090cb6f282348bd2fd3a9b8
Expand All @@ -22,7 +22,7 @@ miniz 1edbdece9d71dc65c6ff405572ee37cbdcef7af4
res 7d97784ba785ce8a2677ea77164040fde484fb04
pbf-sdf-fonts 91b369e4eb8a618e0a83b0c04b1b08632ea872c4
sol2 fdb0f8a60e48aa737f0a8d73edede48627f0c984
utl 4c1503afe58e209977d9a1e3db6a6b271a50c521
utl 80df7a6f1e2de4d290c48e9218d48eb9792b7289
variant 5aa73631dc969087c77433a5cdef246303051f69
tiles 64f297ea0f782d04c89e82c6d478a1dd453e5f70
unordered_dense c11595a7743d20622637584bddf77243d72ae152
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ else ()
set(osr-compile-options
-Wall
-Wextra
-Wno-changes-meaning
-Wno-maybe-uninitialized)
if (NOT CMAKE_CROSSCOMPILING)
set(osr-compile-options ${osr-compile-options} -Werror)
Expand All @@ -115,7 +116,6 @@ target_link_libraries(osr
rtree
unordered_dense
boost-thread
rapidjson
)

# --- MAIN ---
Expand Down
34 changes: 34 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,40 @@
"patch": 0
},
"configurePresets": [
{
"name": "windows-debug",
"displayName": "Windows x64 Debug",
"generator": "Ninja",
"architecture": {
"value": "x64",
"strategy": "external"
},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
},
"vendor": {
"microsoft.com/VisualStudioSettings/CMake/1.0": {
"hostOS": [ "Windows" ]
}
}
},
{
"name": "windows-release",
"displayName": "Windows x64 Release",
"generator": "Ninja",
"architecture": {
"value": "x64",
"strategy": "external"
},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
},
"vendor": {
"microsoft.com/VisualStudioSettings/CMake/1.0": {
"hostOS": [ "Windows" ]
}
}
},
{
"name": "macos-x86_64",
"displayName": "MacOS x86_64 Release",
Expand Down
2 changes: 2 additions & 0 deletions exe/backend/include/osr/backend/http_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "boost/asio/io_context.hpp"

#include "osr/lookup.h"
#include "osr/platforms.h"
#include "osr/ways.h"

namespace osr::backend {
Expand All @@ -15,6 +16,7 @@ struct http_server {
boost::asio::io_context& thread_pool,
ways const&,
lookup const&,
platforms const*,
std::string const& static_file_path);
~http_server();
http_server(http_server const&) = delete;
Expand Down
103 changes: 49 additions & 54 deletions exe/backend/src/http_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
#include "boost/asio/post.hpp"
#include "boost/beast/version.hpp"
#include "boost/json.hpp"
#include "boost/thread/tss.hpp"

#include "rapidjson/error/en.h"

#include "fmt/core.h"

Expand Down Expand Up @@ -77,8 +74,14 @@ struct http_server::impl {
boost::asio::io_context& thread_pool,
ways const& g,
lookup const& l,
platforms const* pl,
std::string const& static_file_path)
: ioc_{ios}, thread_pool_{thread_pool}, w_{g}, l_{l}, server_{ioc_} {
: ioc_{ios},
thread_pool_{thread_pool},
w_{g},
l_{l},
pl_{pl},
server_{ioc_} {
try {
if (!static_file_path.empty() && fs::is_directory(static_file_path)) {
static_file_path_ = fs::canonical(static_file_path).string();
Expand All @@ -89,15 +92,6 @@ struct http_server::impl {
}
}

template <typename Profile>
dijkstra<Profile>& get_dijkstra() {
static auto s = boost::thread_specific_ptr<dijkstra<Profile>>{};
if (s.get() == nullptr) {
s.reset(new dijkstra<Profile>{});
}
return *s.get();
}

static search_profile get_search_profile_from_request(
boost::json::object const& q) {
auto const profile_it = q.find("profile");
Expand All @@ -111,49 +105,16 @@ struct http_server::impl {
auto const q = boost::json::parse(req.body()).as_object();
auto const profile = get_search_profile_from_request(q);
auto const direction_it = q.find("direction");
auto const direction = to_direction(
direction_it == q.end() || !direction_it->value().is_string()
? to_str(direction::kForward)
: direction_it->value().as_string());
auto const dir = to_direction(direction_it == q.end() ||
!direction_it->value().is_string()
? to_str(direction::kForward)
: direction_it->value().as_string());
auto const from = parse_location(q.at("start"));
auto const to = parse_location(q.at("destination"));
auto const max_it = q.find("max");
auto const max = static_cast<cost_t>(
max_it == q.end() ? 3600 : max_it->value().as_int64());

auto p = std::optional<path>{};

switch (profile) {
case search_profile::kFoot:
handle_routing<foot<false>>(req, cb, from, to, max, direction);
break;
case search_profile::kWheelchair:
handle_routing<foot<true>>(req, cb, from, to, max, direction);
break;
case search_profile::kBike:
handle_routing<bike>(req, cb, from, to, max, direction);
break;
case search_profile::kCar:
handle_routing<car>(req, cb, from, to, max, direction);
break;
case search_profile::kCarParking:
handle_routing<car_parking<false>>(req, cb, from, to, max, direction);
break;
case search_profile::kCarParkingWheelchair:
handle_routing<car_parking<true>>(req, cb, from, to, max, direction);
break;
default: throw utl::fail("not implemented");
}
}

template <typename Profile>
void handle_routing(web_server::http_req_t const& req,
web_server::http_res_cb_t const& cb,
location const from,
location const to,
cost_t const max,
direction const dir) {
auto const p = route(w_, l_, get_dijkstra<Profile>(), from, to, max, dir);
auto const p = route(w_, l_, profile, from, to, max, dir, 100);
if (!p.has_value()) {
cb(json_response(req, "could not find a valid path",
http::status::not_found));
Expand Down Expand Up @@ -245,7 +206,8 @@ struct http_server::impl {
void send_graph_response(web_server::http_req_t const& req,
web_server::http_res_cb_t const& cb,
geojson_writer& gj) {
cb(json_response(req, gj.finish(get_dijkstra<Profile>())));
gj.finish(&get_dijkstra<Profile>());
cb(json_response(req, gj.string()));
}

void handle_static(web_server::http_req_t const& req,
Expand All @@ -256,6 +218,30 @@ struct http_server::impl {
}
}

void handle_platforms(web_server::http_req_t const& req,
web_server::http_res_cb_t const& cb) {
utl::verify(pl_ != nullptr, "no platforms");

auto const query = boost::json::parse(req.body()).as_object();
auto const level = query.contains("level")
? to_level(query.at("level").to_number<float>())
: level_t::invalid();
auto const waypoints = query.at("waypoints").as_array();
auto const min = point::from_latlng(
{waypoints[1].as_double(), waypoints[0].as_double()});
auto const max = point::from_latlng(
{waypoints[3].as_double(), waypoints[2].as_double()});

auto gj = geojson_writer{.w_ = w_, .platforms_ = pl_};
pl_->find(min, max, [&](platform_idx_t const i) {
if (level == level_t::invalid() || pl_->get_level(w_, i) == level) {
gj.write_platform(i);
}
});

cb(json_response(req, gj.string()));
}

void handle_request(web_server::http_req_t const& req,
web_server::http_res_cb_t const& cb) {
std::cout << "[" << req.method_string() << "] " << req.target() << '\n';
Expand Down Expand Up @@ -284,6 +270,13 @@ struct http_server::impl {
handle_graph(req1, cb1);
},
req, cb);
} else if (target.starts_with("/api/platforms")) {
return run_parallel(
[this](web_server::http_req_t const& req1,
web_server::http_res_cb_t const& cb1) {
handle_platforms(req1, cb1);
},
req, cb);
} else {
return cb(json_response(req, R"({"error": "Not found"})",
http::status::not_found));
Expand Down Expand Up @@ -353,6 +346,7 @@ struct http_server::impl {
boost::asio::io_context& thread_pool_;
ways const& w_;
lookup const& l_;
platforms const* pl_;
web_server server_;
bool serve_static_files_{false};
std::string static_file_path_;
Expand All @@ -362,8 +356,9 @@ http_server::http_server(boost::asio::io_context& ioc,
boost::asio::io_context& thread_pool,
ways const& w,
lookup const& l,
platforms const* pl,
std::string const& static_file_path)
: impl_(new impl(ioc, thread_pool, w, l, static_file_path)) {}
: impl_(new impl(ioc, thread_pool, w, l, pl, static_file_path)) {}

http_server::~http_server() = default;

Expand All @@ -373,4 +368,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
16 changes: 15 additions & 1 deletion exe/backend/src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "osr/backend/http_server.h"
#include "osr/lookup.h"
#include "osr/platforms.h"
#include "osr/ways.h"

namespace fs = std::filesystem;
Expand Down Expand Up @@ -76,11 +77,24 @@ int main(int argc, char const* argv[]) {
}

auto const w = ways{opt.data_dir_, cista::mmap::protection::READ};

auto const platforms_check_path = opt.data_dir_ / "node_is_platform.bin";
if (!fs::exists(platforms_check_path)) {
std::cout << platforms_check_path << " does not exist\n";
}
auto const pl = (!fs::exists(platforms_check_path))
? std::unique_ptr<platforms>{}
: std::make_unique<platforms>(
opt.data_dir_, cista::mmap::protection::READ);
if (pl != nullptr) {
pl->build_rtree(w);
}

auto const l = lookup{w};

auto ioc = boost::asio::io_context{};
auto pool = boost::asio::io_context{};
auto server = http_server{ioc, pool, w, 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 exe/benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ int main(int argc, char const* argv[]) {
d.reset(opt.max_dist_);
d.add_start(car::label{car::node{start, 0, direction::kForward}, 0U});
d.add_start(car::label{car::node{start, 0, direction::kBackward}, 0U});
d.run(*w.r_, opt.max_dist_, direction::kForward);
d.run<direction::kForward, false>(*w.r_, opt.max_dist_, nullptr);
}
});
}
Expand Down
4 changes: 3 additions & 1 deletion exe/extract.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ struct config : public conf::configuration {
: configuration{"Options"}, in_{std::move(in)}, out_{std::move(out)} {
param(in_, "in,i", "OpenStreetMap .osm.pbf input path");
param(out_, "out,o", "output directory");
param(with_platforms_, "with_platforms,p", "extract platform info");
}

std::filesystem::path in_, out_;
bool with_platforms_{false};
};

int main(int ac, char const** av) {
Expand All @@ -42,5 +44,5 @@ int main(int ac, char const** av) {
utl::activate_progress_tracker("osr");
auto const silencer = utl::global_progress_bars{false};

extract(c.in_, c.out_);
extract(c.with_platforms_, c.in_, c.out_);
}
4 changes: 3 additions & 1 deletion include/osr/extract/extract.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace osr {

void extract(std::filesystem::path const& in, std::filesystem::path const& out);
void extract(bool with_platforms,
std::filesystem::path const& in,
std::filesystem::path const& out);

} // namespace osr
Loading

0 comments on commit 02a5bb8

Please sign in to comment.