Skip to content
Open
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ The current set of routing profiles can be found in the [`include/osr/routing/pr

- `node` struct: a node defines what is considered a node for this routing profile. The most basic definition of a node would basically be just what's considered a node in the data model (`node_idx_t`, see above). However, for many profiles, this is not succifient. Let's take the foot routing profile as an example: for indoor routing, it should be possible to distinguish the same OSM node on different levels. Therefore, the level has to be part of the foot profile's node definition. Another example is the car profile: to be able to detect u-turns (just changing the direction but staying on the same way), the node has to define the current direction. In order to properly handle turn restrictions, also the last used way has to be part of the node definition. The member function `node::get_key()` returns the key (see `key`).
- `label` struct: basically the same as the `node` struct but it should additionally carry the routing costs (currently tracked in seconds). The label has to provide `get_node()` and `cost()` member functions.
- `key`: The shortest path algorithm (e.g. Dijkstra) tracks minimal costs to each node in a hash map. In theory, it would be sufficient to use `node` as hash map key as we need to only track one shortest path to each profile `node`. To allow for a more efficient storage, multiple nodes can share the same hash map key, therefore reducing the hash map size (which can speedup the routing significantly). Therefore, a profile can define a `key` which can be the same as `node` but doesn't have to be. The key doesn't need any member functions and can therefore just be a typedef to `node_idx_t` (in the most simple case).
- `entry`: The entry is the hash map entry and is stored for each `key`. It has to store the costs and precessor. If `key` maps several `node`s to the same `entry`, then the `entry` has to store costs and predecessory for each of the `node`s. It has to provide the following member functions:
- `key`: The shortest path algorithm (e.g. Dijkstra) tracks minimal costs to each node in a hash map. In theory, it would be sufficient to use `node` as hash map key as we need to only track one shortest path to each profile `node`. To allow for a more efficient storage, multiple nodes can share the same hash map key, therefore reducing the hash map size (which can speed up the routing significantly). Therefore, a profile can define a `key` which can be the same as `node` but doesn't have to be. The key doesn't need any member functions and can therefore just be a typedef to `node_idx_t` (in the most simple case).
- `entry`: The entry is the hash map entry and is stored for each `key`. It has to store the costs and predecessor. If `key` maps several `node`s to the same `entry`, then the `entry` has to store costs and predecessors for each of the `node`s. It has to provide the following member functions:
- `std::optional<node> pred(node)`: returns the predecessor for the node, or `std::nullopt` if this `node` has never been visited.
- `cost_t cost(node)`: returns the shortest path costs to this `node`
- `bool update(label, node, cost_t, node pred)`: updates the costs for this node if they are better than the previously stored costs and returns `true` if the costs where updated and `false` otherwise.
Expand Down
42 changes: 24 additions & 18 deletions exe/backend/src/http_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,28 +140,34 @@ struct http_server::impl {
foot_speed_result.value()}
: get_parameters(profile);

auto const p = route(params, w_, l_, profile, from, to, max, dir, 100,
nullptr, nullptr, elevations_, routing_algo);
try {
auto const p = route(params, w_, l_, profile, from, to, max, dir, 100,
nullptr, nullptr, elevations_, routing_algo);

auto const p1 = route(params, w_, l_, profile, from, std::vector{to}, max,
dir, 100, nullptr, nullptr, elevations_);
auto const p1 = route(params, w_, l_, profile, from, std::vector{to}, max,
dir, 100, nullptr, nullptr, elevations_);

auto const print = [](char const* name, std::optional<path> const& p) {
if (p.has_value()) {
std::cout << name << " cost: " << p->cost_ << "\n";
} else {
std::cout << name << ": not found\n";
auto const print = [](char const* name, std::optional<path> const& p) {
if (p.has_value()) {
std::cout << name << " cost: " << p->cost_ << "\n";
} else {
std::cout << name << ": not found\n";
}
};
print("p", p);
print("p1", p1.at(0));

if (!p.has_value()) {
cb(json_response(req, "could not find a valid path",
http::status::not_found));
return;
}
};
print("p", p);
print("p1", p1.at(0));

if (!p.has_value()) {
cb(json_response(req, "could not find a valid path",
http::status::not_found));
return;
cb(json_response(req, to_featurecollection(w_, p)));
} catch (std::runtime_error const& e) {
cb(json_response(
req, boost::json::serialize(json::object{{"message", e.what()}}),
http::status::not_found));
}
cb(json_response(req, to_featurecollection(w_, p)));
}

void handle_levels(web_server::http_req_t const& req,
Expand Down
6 changes: 4 additions & 2 deletions exe/extract.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ struct config : public conf::configuration {
param(out_, "out,o", "output directory");
param(elevation_data_, "elevation_data,e", "directory with elevation data");
param(with_platforms_, "with_platforms,p", "extract platform info");
param(with_ch_, "with_contraction_hierarchies,ch",
"build CH during extraction");
}

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

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

extract(c.with_platforms_, c.in_, c.out_, c.elevation_data_);
extract(c.with_platforms_, c.in_, c.out_, c.elevation_data_, c.with_ch_);
}
3 changes: 2 additions & 1 deletion include/osr/extract/extract.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace osr {
void extract(bool with_platforms,
std::filesystem::path const& in,
std::filesystem::path const& out,
std::filesystem::path const& elevation_dir);
std::filesystem::path const& elevation_dir,
bool with_contraction_hierarchies = false);

} // namespace osr
2 changes: 2 additions & 0 deletions include/osr/geojson.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ inline std::string to_featurecollection(ways const& w,
bool const with_properties = true) {
return boost::json::serialize(boost::json::object{
{"type", "FeatureCollection"},
{"message", ""},
{"metadata", with_properties ? boost::json::value{{"duration", p->cost_},
{"distance", p->dist_}}
: boost::json::value{{}}},
Expand Down Expand Up @@ -179,6 +180,7 @@ struct geojson_writer {
{"car", p.is_car_accessible()},
{"bike", p.is_bike_accessible()},
{"foot", p.is_walk_accessible()},
{"importance", p.importance()},
{"is_restricted", w_.r_->node_is_restricted_[n]},
{"is_entrance", p.is_entrance()},
{"is_elevator", p.is_elevator()},
Expand Down
7 changes: 6 additions & 1 deletion include/osr/routing/algorithms.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
#pragma once

#include <cinttypes>

#include <string_view>

namespace osr {

enum class routing_algorithm : std::uint8_t { kDijkstra, kAStarBi };
enum class routing_algorithm : std::uint8_t {
kDijkstra,
kAStarBi,
kContractionHierarchies
};

routing_algorithm to_algorithm(std::string_view);

Expand Down
Loading
Loading