Open Source Routing Machine (OSRM)

repository·master·Indexed 27 days ago

https://github.com/project-osrm/osrm-backend

A high-performance routing engine written in C++ designed to run on OpenStreetMap data. OSRM provides routing services including shortest path, distance matrices, and GPS trace matching via HTTP APIs, C++ libraries, and language bindings for Node.js (@project-osrm/osrm) and Python (osrm-bindings). It supports multiple routing algorithms, including Multi-Level Dijkstra (MLD) and Contraction Hierarchies (CH).

Tokens
26.6K
Snippets
73
Records
155
Agent score
93%

What's inside OSRM

  1. Use OSRM profiles for different transport modes

    master

    OSRM uses profiles to define routing behavior for different transport modes (e.g., car, bicycle, foot) or specific preferences (e.g., fastest vs. shortest). Profiles are Lua scripts that determine which ways are routable, which nodes can be passed, and the travel speeds.

    Important: Profiles are applied during the preprocessing stage, not at query time. If you modify a profile, you must re-run the osrm-extract, osrm-contract, and reload the data to apply the changes.

  2. Quick Start with OSRM using Docker (CH Pipeline)

    master
    If you need to use the Contraction Hierarchies (CH) pipeline (e.g., for very large distance matrices), replace the osrm-partition and osrm-customize steps with a single osrm-contract command, and change the osrm-routed algorithm flag to --algorithm ch.
  3. Build a distribution wheel

    master

    Once an editable install has successfully compiled the project, you can produce a wheel without recompiling everything by using pip wheel with --no-build-isolation. The resulting wheel will be placed in the dist/ directory.

    # Linux / macOS
    pip wheel . --no-build-isolation -w dist
    
    # Windows (PowerShell)
    pip wheel . --no-build-isolation -w dist
  4. Set up osrm-bindings for development

    master

    To develop the Python bindings, clone the repository and install it in editable mode with development dependencies. You should also install pre-commit hooks to manage code quality.

    # Clone and install in editable mode
    git clone https://github.com/Project-OSRM/osrm-backend
    cd osrm-backend
    pip install -e ".[dev]"
    
    # Install pre-commit hooks
    pre-commit install
  5. Prepare OSRM test data for dataset-dependent tests

    master

    If you need to test features using a real dataset, OSRM provides a small extract in test/data. Note that this dataset is not necessarily in sync with current OSM maps or the demo server. To prepare the data, navigate to the directory and run make.

    cd test/data/
    make
  6. Use Flatbuffers format for high-performance serialization

    master

    OSRM supports a binary flatbuffers format which is significantly faster for serialization and deserialization than the default json format. It provides the same data as JSON but with an optimized layout to minimize transfer size.

    Message descriptors are located in the include/engine/api/flatbuffers directory and can be compiled for Go, JavaScript, TypeScript, Java, Dart, C#, Python, Lua, Rust, PHP, and Kotlin. A precompiled C++ parser is supplied with OSRM.

    To construct the root object from a raw flatbuffers buffer in C++:

    auto osrm = osrm::engine::api::fbresult::GetFBResult(some_input_buffer);
  7. Configure vcpkg for local source builds

    master

    Local source builds require vcpkg to manage C++ dependencies. You must bootstrap vcpkg, set the VCPKG_ROOT environment variable, and pass the toolchain file to CMake via CMAKE_ARGS.

    Linux and macOS

    git clone https://github.com/microsoft/vcpkg
    ./vcpkg/bootstrap-vcpkg.sh
    export VCPKG_ROOT=$PWD/vcpkg
    export CMAKE_ARGS="-DCMAKE_TOOLCHAIN_FILE=$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-linux-release"

    Windows (PowerShell)

    git clone https://github.com/microsoft/vcpkg
    .\vcpkg\bootstrap-vcpkg.bat
    $env:VCPKG_ROOT = "$PWD\vcpkg"
  8. Install and Build OSRM from Source

    master

    OSRM uses vcpkg in manifest mode for dependency management.

    Prerequisites (Linux): Requires a C++20 compiler, CMake ≥ 3.29, Ninja, and autotools packages.

    Steps:

    1. Install system dependencies via apt.
    2. Bootstrap vcpkg and set the VCPKG_ROOT environment variable.
    3. Use CMake presets to configure, build, and install.
    # Install dependencies
    sudo apt install build-essential git cmake ninja-build pkg-config \
      autoconf automake libtool curl zip unzip tar
    
    # Bootstrap vcpkg
    git clone https://github.com/microsoft/vcpkg.git ~/vcpkg
    ~/vcpkg/bootstrap-vcpkg.sh
    export VCPKG_ROOT=~/vcpkg
    
    # Compile and install
    cmake --preset ci-linux
    cmake --build --preset ci-linux
    sudo cmake --install build
  9. Quick Start with OSRM using Docker (MLD Pipeline)

    master

    The fastest way to set up OSRM is using Docker images. This guide uses the Multi-Level Dijkstra (MLD) pipeline, which is recommended by default.

    1. Download OSM data: Get an extract (e.g., from Geofabrik).
    2. Extract: Run osrm-extract with a profile (e.g., /opt/car.lua).
    3. Partition: Run osrm-partition on the extracted data.
    4. Customize: Run osrm-customize to finalize the graph.
    5. Serve: Run osrm-routed with the --algorithm mld flag to start the HTTP server.

    Note: The .osrm path refers to a set of files (e.g., berlin-latest.osrm.*).