Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
d17d7eb
node importance
traines-source Aug 26, 2025
14c0716
add new binary preprocessing file to cmake list
Sep 8, 2025
bfc984c
add contraction hierarchie files
Sep 8, 2025
8c7f756
create node order strategy
Sep 8, 2025
f79624e
add entry point for ch
Sep 8, 2025
439e867
add storage
Sep 8, 2025
db4fcf1
add contraction process
Sep 8, 2025
84356cc
add loop search
Sep 8, 2025
ae1979a
adapt adjacent signature and include shortcuts in car profile
Sep 8, 2025
788e973
add bidir routing algorithm
Sep 8, 2025
b656c75
add ch dijkstra routing and reconstruction
Sep 8, 2025
afef8a8
add suppport for contraction hierarchies to http server
Sep 8, 2025
0e4cc49
add contraction hierarchies algorithm option
Sep 8, 2025
141b814
set way_pos_t to 16 bit
Sep 8, 2025
596da55
fix directory bug
Sep 8, 2025
fee5ef9
add test for contraction hierarchies
Sep 8, 2025
7949394
add new node importance order as default
Sep 10, 2025
47db031
fix importance node order
Sep 16, 2025
7b4512f
replace data structures with std vector and add new info for shortcuts
Sep 16, 2025
74f8d39
replace maps with std vector
Sep 16, 2025
3a0b226
change car entry from array to vector
Sep 16, 2025
2526f3f
fix tests
Sep 16, 2025
107e452
add stall argument
Sep 21, 2025
6655869
adapt meetpoint evaluation
Sep 21, 2025
3747bd1
fix loop restrictions and add suboptimal shortcut check
Sep 21, 2025
2b2f874
clean up
Sep 21, 2025
4f6dd02
clean up
Sep 21, 2025
9dd1dee
resolve merge conflicts with master
Sep 21, 2025
0fcc236
format files
Sep 22, 2025
8d16610
ci fixes
Sep 22, 2025
d108347
ci fixes
Sep 22, 2025
a7ab7e0
ci fixes
Sep 22, 2025
7093c0e
ci-fixes
Sep 22, 2025
77396ca
ci fix
Sep 22, 2025
e5cf27f
disable switzerland test because it is infeasible
Sep 22, 2025
6b92bdd
remove prints
Sep 30, 2025
64d2ad1
formatting
Sep 30, 2025
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
/.pkg.mutex
/.clang-tidy
/.vs
/out
/out
/test/monaco*
/test/hamburg*
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ target_link_libraries(osr
add_executable(osr-extract exe/extract.cc)
target_link_libraries(osr-extract osr)

add_executable(osr-preprocessing exe/osr-preprocessing/main.cc)
target_link_libraries(osr-preprocessing osr)

add_executable(osr-benchmark exe/benchmark.cc)
target_link_libraries(osr-benchmark osr)

Expand Down
5 changes: 4 additions & 1 deletion exe/backend/include/osr/backend/http_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "osr/elevation_storage.h"
#include "osr/lookup.h"
#include "osr/platforms.h"
#include "osr/preprocessing/contraction_hierarchies/storage.h"
#include "osr/ways.h"

namespace osr::backend {
Expand All @@ -19,7 +20,9 @@ struct http_server {
lookup const&,
platforms const*,
elevation_storage const*,
std::string const& static_file_path);
std::string const& static_file_path,
ch::shortcut_storage const*,
ways const*); // ch ways when shortcuts are on
~http_server();
http_server(http_server const&) = delete;
http_server& operator=(http_server const&) = delete;
Expand Down
34 changes: 27 additions & 7 deletions exe/backend/src/http_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,18 @@ struct http_server::impl {
lookup const& l,
platforms const* pl,
elevation_storage const* elevations,
std::string const& static_file_path)
std::string const& static_file_path,
ch::shortcut_storage const* shortcuts,
ways const* shortcut_ways)
: ioc_{ios},
thread_pool_{thread_pool},
w_{g},
l_{l},
pl_{pl},
elevations_{elevations},
server_{ioc_} {
server_{ioc_},
shortcuts_{shortcuts},
shortcut_ways_{shortcut_ways} {
try {
if (!static_file_path.empty() && fs::is_directory(static_file_path)) {
static_file_path_ = fs::canonical(static_file_path).string();
Expand Down Expand Up @@ -140,15 +144,20 @@ 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);
auto const p =
route(params, w_, l_, profile, from, to, max, dir, 100, nullptr,
nullptr, elevations_, routing_algo, shortcuts_, shortcut_ways_);

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";
for (auto& segment : p->segments_) {
fmt::print(" {} -{}-> {}", segment.from_, segment.way_, segment.to_);
}
fmt::print("\n");
} else {
std::cout << name << ": not found\n";
}
Expand Down Expand Up @@ -358,6 +367,8 @@ struct http_server::impl {
web_server server_;
bool serve_static_files_{false};
std::string static_file_path_;
ch::shortcut_storage const* shortcuts_;
ways const* shortcut_ways_;
};

http_server::http_server(boost::asio::io_context& ioc,
Expand All @@ -366,9 +377,18 @@ http_server::http_server(boost::asio::io_context& ioc,
lookup const& l,
platforms const* pl,
elevation_storage const* elevation,
std::string const& static_file_path)
: impl_{new impl(ioc, thread_pool, w, l, pl, elevation, static_file_path)} {
}
std::string const& static_file_path,
ch::shortcut_storage const* shortcuts,
ways const* shortcut_ways)
: impl_{new impl(ioc,
thread_pool,
w,
l,
pl,
elevation,
static_file_path,
shortcuts,
shortcut_ways)} {}

http_server::~http_server() = default;

Expand Down
56 changes: 54 additions & 2 deletions exe/backend/src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ class settings : public conf::configuration {
param(static_file_path_, "static,s", "Path to static files (ui/web)");
param(threads_, "threads,t", "Number of routing threads");
param(lock_, "lock,l", "Lock to memory");
param(ch_dir_, "ch-dir,ch", "directory of contraction hierarchy");
}

fs::path data_dir_{"osr"};
std::string http_host_{"0.0.0.0"};
std::string http_port_{"8000"};
std::string static_file_path_;
bool lock_{true};
fs::path ch_dir_{""};
unsigned threads_{std::thread::hardware_concurrency()};
};

Expand Down Expand Up @@ -94,10 +96,60 @@ int main(int argc, char const* argv[]) {

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

bool use_ch = false;
if (!opt.ch_dir_.empty()) {
use_ch = true;
}

std::unique_ptr<ways> w_shortcuts =
use_ch
? std::make_unique<ways>(opt.ch_dir_, cista::mmap::protection::READ)
: nullptr;
auto const ch_check_path = opt.ch_dir_ / "shortcuts.bin";
bool const should_load = fs::exists(ch_check_path) && use_ch;
if (!fs::exists(ch_check_path) && use_ch) {
std::cout << ch_check_path << " does not exist\n";
}
auto shortcuts =
should_load ? std::make_unique<ch::shortcut_storage>() : nullptr;
if (shortcuts != nullptr) {
shortcuts->load(opt.ch_dir_);
shortcuts->load_all_shortcuts_in_graph(std::ref(*w_shortcuts));
fmt::print("loaded {} shortcuts\n", shortcuts->shortcuts_.size());
}
auto const ch_node_order_path = opt.ch_dir_ / "node_order.bin";
bool const should_load_node_order = fs::exists(ch_node_order_path) && use_ch;
if (!fs::exists(ch_node_order_path) && use_ch) {
std::cout << ch_node_order_path << " does not exist\n";
}
auto node_order = should_load_node_order
? std::make_unique<ch::node_order>(
opt.ch_dir_, cista::mmap::protection::READ)
: nullptr;
if (node_order != nullptr) {
fmt::print("loaded node order\n");
}
if ((shortcuts == nullptr || node_order == nullptr) && use_ch) {
fmt::print(
"no shortcuts or node order found, skipping contraction hierarchy\n");
shortcuts = nullptr;
node_order = nullptr;
} else if (use_ch) {
fmt::print("using contraction hierarchy\n");
shortcuts->node_order_ = std::move(node_order);
}

auto ioc = boost::asio::io_context{};
auto pool = boost::asio::io_context{};
auto server = http_server{
ioc, pool, w, l, pl.get(), elevations.get(), opt.static_file_path_};
auto server = http_server{ioc,
pool,
w,
l,
pl.get(),
elevations.get(),
opt.static_file_path_,
shortcuts.get(),
w_shortcuts.get()};

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 @@ -267,7 +267,7 @@ int main(int argc, char const* argv[]) {
auto const start_time = std::chrono::steady_clock::now();
d.template run<direction::kForward, false>(
params, w, *w.r_, opt.max_dist_, nullptr, nullptr,
elevations.get());
elevations.get(), nullptr);
auto const middle_time = std::chrono::steady_clock::now();
b.template run<direction::kForward, false>(
params, w, *w.r_, opt.max_dist_, nullptr, nullptr,
Expand Down
82 changes: 82 additions & 0 deletions exe/osr-preprocessing/main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#include <iostream>

#include "boost/filesystem.hpp"

#include <filesystem>

#include "conf/options_parser.h"
#include "fmt/ostream.h"
#include "osr/preprocessing/contraction_hierarchies/node_order_strategy.h"
#include "osr/preprocessing/contraction_hierarchies/preprocessor.h"

#include "utl/progress_tracker.h"

using namespace osr;
using namespace osr::ch;
namespace fs = std::filesystem;

struct config final : public conf::configuration {
explicit config(fs::path in) : configuration{"Options"}, in_{std::move(in)} {
param(in_, "in,i", "input directory for extracted Data");
param(out_, "out,o", "output directory for preprocessed Data");
param(order_, "order",
"Order which to use (default rand, predefined = pre)");
param(seed_, "seed", "Seed for any random order");
param(stall_, "stall",
"Percentage of the nodes that should be contracted [0-100] (default: "
"95)");
}

fs::path in_;
fs::path out_;
std::string order_{"importance"};
int seed_{-1};
size_t stall_{95};
};

std::unique_ptr<order_strategy> get_order_strategy(const config& c) {
if (c.order_ == "rand") {
return std::make_unique<random_order_strategy>(c.seed_);
}
return std::make_unique<node_importance_order_strategy>(
c.seed_); // importance
}

int main(int const argc, char const** argv) {
auto c = config{"osr-germany"};

conf::options_parser parser({&c});
parser.read_command_line_args(argc, argv);

parser.read_configuration_file();

parser.print_unrecognized(std::cout);
parser.print_used(std::cout);

if (!fs::is_directory(c.in_)) {
fmt::println("directory not found: {}", c.in_);
return 1;
}

if (fs::exists(c.out_)) {
fmt::println("Removing existing contraction hierarchy directory: {}",
c.out_);
fs::remove_all(c.out_);
}

fmt::println("Creating contraction hierarchy directory: {}", c.out_);
fs::create_directories(c.out_);
for (auto const& file : fs::directory_iterator(c.in_)) {
fs::copy(file.path(), c.out_ / file.path().filename(),
fs::copy_options::recursive);
}

utl::activate_progress_tracker("contraction-hierarchy");
auto const silencer = utl::global_progress_bars{false};

auto order = get_order_strategy(c);

process_ch(c.in_, c.out_, order, c.stall_);

return 0;
}
1 change: 1 addition & 0 deletions include/osr/geojson.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,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
Loading
Loading