Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indoor Routing #35

Merged
merged 19 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .pkg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[cista]
url=git@github.com:felixguendling/cista.git
branch=master
commit=d14b70b9f45d249d1c9a20bcc13877cc4b771188
commit=fce53787252d749727eddf2bfbb40c679b4306ba
[conf]
url=git@github.com:motis-project/conf.git
branch=master
Expand Down Expand Up @@ -44,8 +44,8 @@
commit=2a557cafb2e9e7c872358a83a63c62a7e14330b3
[unordered_dense]
url=git@github.com:motis-project/unordered_dense.git
branch=master
commit=77e91016354e6d8cba24a86c5abb807de2534c02
branch=main
commit=4f380fb1d64f1843ca2c993ed39a8342a8747e5d
[fmt]
url=git@github.com:motis-project/fmt.git
branch=master
Expand Down
6 changes: 3 additions & 3 deletions .pkg.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
1568225318232232742
cista d14b70b9f45d249d1c9a20bcc13877cc4b771188
6314464215482173470
cista fce53787252d749727eddf2bfbb40c679b4306ba
zlib fe8e13ffca867612951bc6baf114e5ac8b00f305
boost be5235eb2258d2ec19e32546ab767a62311d9b46
conf aab49490c6b77027938b74265f386144364aa266
Expand All @@ -11,6 +11,6 @@ libressl 390253a44ceef00eb620c38606588414326e9f23
net 44674d2f3917e20b7019a0f7254d332522c36fb7
protozero 8c9f3fa97c2cfdceef86d0b61818ae98e9328f29
rapidjson e4a599d2b5dec065b1ea2af5d8dac52baa9df5f5
unordered_dense 77e91016354e6d8cba24a86c5abb807de2534c02
unordered_dense 4f380fb1d64f1843ca2c993ed39a8342a8747e5d
Catch2 47d56f28a9801911c048d011b375e5631dbb658f
utl 3d3b9f2d45fd6e864cfda0b32a924e8d445c8b69
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ target_link_libraries(ppr-common
boost
utl
cista
unordered_dense
)
target_compile_features(ppr-common PUBLIC cxx_std_20)
set_target_properties(ppr-common PROPERTIES CXX_EXTENSIONS OFF)
Expand Down
49 changes: 49 additions & 0 deletions include/ppr/backend/request_parser.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#include <string_view>

#include "rapidjson/document.h"

#include "utl/verify.h"

#include "ppr/common/location.h"
#include "ppr/routing/input_location.h"

#include "ppr/profiles/parse_search_profile.h"

Expand All @@ -19,6 +24,21 @@ inline void get_waypoints(std::vector<location>& waypoints,
}
}

inline ppr::routing::osm_namespace parse_osm_namespace(
rapidjson::Value const& val) {
using ppr::routing::osm_namespace;
auto const sv = std::string_view{val.GetString(), val.GetStringLength()};
if (sv == "node") {
return osm_namespace::NODE;
} else if (sv == "way") {
return osm_namespace::WAY;
} else if (sv == "relation") {
return osm_namespace::RELATION;
} else {
throw utl::fail("invalid osm type in request: {}", sv);
}
}

inline void get_location(location& loc, rapidjson::Value const& doc,
char const* key) {
if (doc.HasMember(key)) {
Expand All @@ -34,6 +54,35 @@ inline void get_location(location& loc, rapidjson::Value const& doc,
}
}

inline void get_input_location(ppr::routing::input_location& loc,
rapidjson::Value const& doc, char const* key) {
if (doc.HasMember(key)) {
auto const& val = doc[key];
if (val.IsObject()) {
auto const& lng = val.FindMember("lng");
auto const& lat = val.FindMember("lat");
if (lng != val.MemberEnd() && lat != val.MemberEnd() &&
lng->value.IsNumber() && lat->value.IsNumber()) {
loc.location_ =
make_location(lng->value.GetDouble(), lat->value.GetDouble());
}

auto const& osm_id = val.FindMember("osm_id");
auto const& osm_type = val.FindMember("osm_type");
if (osm_id != val.MemberEnd() && osm_type != val.MemberEnd() &&
osm_id->value.IsNumber() && osm_type->value.IsString()) {
loc.osm_element_ = ppr::routing::osm_element{
osm_id->value.GetInt64(), parse_osm_namespace(osm_type->value)};
}

auto const& level = val.FindMember("level");
if (level != val.MemberEnd() && level->value.IsNumber()) {
loc.level_ = static_cast<int>(level->value.GetDouble() * 10.0);
}
}
}
}

inline void get_profile(ppr::routing::search_profile& profile,
rapidjson::Value const& doc, char const* key) {
if (doc.HasMember(key)) {
Expand Down
5 changes: 3 additions & 2 deletions include/ppr/backend/requests.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
#include <vector>

#include "ppr/common/location.h"
#include "ppr/routing/input_location.h"
#include "ppr/routing/search_profile.h"

namespace ppr::backend {

struct route_request {
location start_;
location destination_;
ppr::routing::input_location start_;
ppr::routing::input_location destination_;
ppr::routing::search_profile profile_;
bool include_infos_{};
bool include_full_path_{};
Expand Down
5 changes: 5 additions & 0 deletions include/ppr/common/area.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#pragma once

#include <cstdint>
#include <string>

#include "boost/geometry/algorithms/for_each.hpp"
#include "boost/geometry/geometries/register/point.hpp"

#include "ppr/common/data.h"
#include "ppr/common/edge.h"
#include "ppr/common/geometry/polygon.h"
#include "ppr/common/geometry/serializable_polygon.h"
#include "ppr/common/matrix.h"
Expand Down Expand Up @@ -86,14 +88,17 @@ struct area {
}

std::uint32_t id_{0};
edge_info_idx_t edge_info_{};
polygon_t polygon_;
names_idx_t name_{};
std::int64_t osm_id_{0};
bool from_way_{false};
std::int16_t level_{};
matrix<double, uint16_t> dist_matrix_;
matrix<uint16_t, uint16_t> next_matrix_;
data::vector<uint16_t> exit_nodes_;
data::vector<std::uint32_t> adjacent_areas_;
location center_{};
};

inline merc get_merc(area::point const& pt) { return to_merc(pt.location_); }
Expand Down
2 changes: 1 addition & 1 deletion include/ppr/common/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

namespace ppr {

namespace data = cista::offset;
namespace data = cista::offset; // NOLINT(misc-unused-alias-decls)

} // namespace ppr
2 changes: 2 additions & 0 deletions include/ppr/common/edge.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ struct edge_info {
wheelchair_type::wheelchair_type wheelchair_ : 2;
std::uint8_t step_count_{};
std::int32_t marked_crossing_detour_{};
std::int16_t level_{}; // stored as level * 10
};

inline edge_info make_edge_info(std::int64_t osm_way_id, edge_type type,
Expand All @@ -86,6 +87,7 @@ inline edge_info make_edge_info(std::int64_t osm_way_id, edge_type type,
tri_state::UNKNOWN,
wheelchair_type::UNKNOWN,
0,
0,
0};
}

Expand Down
8 changes: 2 additions & 6 deletions include/ppr/common/geometry/serializable_polygon.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ inline double distance(Location const& loc,

BOOST_GEOMETRY_REGISTER_RING_TEMPLATED(ppr::ring)

namespace boost {
namespace geometry {
namespace traits {
namespace boost::geometry::traits {

template <typename Point>
struct tag<ppr::serializable_polygon<Point>> {
Expand Down Expand Up @@ -120,6 +118,4 @@ struct closure<ppr::data::vector<Point>> {
static const closure_selector value = closed;
};

} // namespace traits
} // namespace geometry
} // namespace boost
} // namespace boost::geometry::traits
11 changes: 6 additions & 5 deletions include/ppr/common/mlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,21 @@ namespace ppr {

inline bool lock_memory(void* addr, std::size_t len) {
HANDLE proc = GetCurrentProcess();
SIZE_T min_size, max_size;
if (!GetProcessWorkingSetSize(proc, &min_size, &max_size)) {
SIZE_T min_size = 0;
SIZE_T max_size = 0;
if (GetProcessWorkingSetSize(proc, &min_size, &max_size) == FALSE) {
return false;
}
min_size += static_cast<SIZE_T>(len);
max_size += static_cast<SIZE_T>(len);
if (!SetProcessWorkingSetSize(proc, min_size, max_size)) {
if (SetProcessWorkingSetSize(proc, min_size, max_size) == FALSE) {
return false;
}
return VirtualLock(addr, len);
return VirtualLock(addr, len) != FALSE;
}

inline bool unlock_memory(void* addr, std::size_t len) {
return VirtualUnlock(addr, len);
return VirtualUnlock(addr, len) != FALSE;
}

} // namespace ppr
Expand Down
31 changes: 27 additions & 4 deletions include/ppr/common/routing_graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
#include <cstdint>
#include <functional>
#include <memory>
#include <utility>
#include <vector>

#include "ankerl/unordered_dense.h"

#include "boost/geometry/geometries/geometries.hpp"
#include "boost/geometry/geometries/point_xy.hpp"
#include "boost/geometry/geometry.hpp"
Expand Down Expand Up @@ -44,6 +47,11 @@ struct rg_edge {
std::uint32_t edge_index_;
};

struct osm_index {
ankerl::unordered_dense::map<std::int64_t, std::uint32_t> ways_to_areas_;
ankerl::unordered_dense::map<std::int64_t, std::uint32_t> relations_to_areas_;
};

enum class rtree_options { DEFAULT, PREFETCH, LOCK };

template <typename Value>
Expand Down Expand Up @@ -94,7 +102,7 @@ struct rtree_data {
for (std::size_t i = 0U; i < file_.get_size(); i += 4096) {
c += base[i];
}
volatile char cs = c;
volatile char cs = c; // NOLINT
(void)cs;
}
}
Expand All @@ -119,9 +127,8 @@ struct routing_graph {

routing_graph() : data_{cista::raw::make_unique<routing_graph_data>()} {}

routing_graph(cista::wrapped<routing_graph_data>&& data,
std::string const& filename)
: data_{std::move(data)}, filename_{filename} {}
routing_graph(cista::wrapped<routing_graph_data>&& data, std::string filename)
: data_{std::move(data)}, filename_{std::move(filename)} {}

void create_in_edges() {
for (auto& n : data_->nodes_) {
Expand All @@ -139,6 +146,7 @@ struct routing_graph {
rtree_options rtree_opt) {
create_edge_rtree(edge_rtree_file, edge_rtree_size, rtree_opt);
create_area_rtree(area_rtree_file, area_rtree_size, rtree_opt);
create_osm_index();
}

void prepare_for_routing(std::size_t edge_rtree_size = 1024UL * 1024 * 1024 *
Expand Down Expand Up @@ -212,13 +220,28 @@ struct routing_graph {
}
}

void create_osm_index() {
osm_index_ptr_ = std::make_unique<osm_index>();
osm_index_ = osm_index_ptr_.get();
for (auto const& a : data_->areas_) {
if (a.from_way_) {
osm_index_->ways_to_areas_[a.osm_id_] = a.id_;
} else {
osm_index_->relations_to_areas_[a.osm_id_] = a.id_;
}
}
}

public:
cista::wrapped<routing_graph_data> data_;

std::string filename_;

rtree_data<edge_rtree_value_type> edge_rtree_;
rtree_data<area_rtree_value_type> area_rtree_;

osm_index* osm_index_{};
std::unique_ptr<osm_index> osm_index_ptr_;
};

} // namespace ppr
2 changes: 1 addition & 1 deletion include/ppr/common/timing.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ inline double ms_since(
}

inline void print_timing(std::ostream& out, char const* name, double duration) {
boost::io::ios_all_saver all_saver(out);
boost::io::ios_all_saver const all_saver(out);
out << std::setfill('.') << std::setw(60) << std::left << name
<< std::setw(10) << std::right << duration << " ms" << std::endl;
}
Expand Down
3 changes: 3 additions & 0 deletions include/ppr/output/geojson/edge_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "rapidjson/rapidjson.h"

#include "ppr/common/routing_graph.h"
#include "ppr/output/json.h"

namespace ppr::output::geojson {

Expand Down Expand Up @@ -205,6 +206,8 @@ void write_edge_info(routing_graph_data const& rg, Writer& writer,

writer.String("marked_crossing_detour");
writer.Int(info->marked_crossing_detour_);

write_level(writer, info->level_);
}

} // namespace ppr::output::geojson
5 changes: 5 additions & 0 deletions include/ppr/output/geojson/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
#include "rapidjson/rapidjson.h"

#include "ppr/common/routing_graph.h"

#include "ppr/output/geojson/base.h"
#include "ppr/output/geojson/edge_info.h"
#include "ppr/output/json.h"

#include "ppr/preprocessing/osm_graph/osm_graph.h"

namespace ppr::output::geojson {
Expand Down Expand Up @@ -97,6 +100,8 @@ void write_area_properties(routing_graph_data const& rg, Writer& writer,
writer.String("");
}

write_level(writer, a.level_);

writer.String("from_way");
writer.Bool(a.from_way_);

Expand Down
8 changes: 8 additions & 0 deletions include/ppr/output/json.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <cstdint>

#include "ppr/common/tri_state.h"

namespace ppr::output {
Expand All @@ -21,4 +23,10 @@ void write_tri_state(Writer& writer, tri_state::tri_state tri) {
}
}

template <typename Writer>
void write_level(Writer& writer, std::int16_t level) {
writer.String("level");
writer.Double(static_cast<double>(level) / 10.0);
}

} // namespace ppr::output
Loading