diff --git a/.github/workflows/osrm-backend.yml b/.github/workflows/osrm-backend.yml index bfd5ba520..20b7f9ab7 100644 --- a/.github/workflows/osrm-backend.yml +++ b/.github/workflows/osrm-backend.yml @@ -536,13 +536,6 @@ jobs: echo "PKG_CONFIG_PATH=${OSRM_INSTALL_DIR}/lib/pkgconfig" >> $GITHUB_ENV fi popd - - name: Build example - if: ${{ matrix.NODE_PACKAGE_TESTS_ONLY != 'ON' }} - run: | - mkdir example/build && pushd example/build - cmake .. -DCMAKE_BUILD_TYPE=${BUILD_TYPE} - make --jobs=${JOBS} - popd - name: Run all tests if: ${{ matrix.NODE_PACKAGE_TESTS_ONLY != 'ON' }} run: | @@ -550,7 +543,6 @@ jobs: # macOS SIP strips the linker path. Reset this inside the running shell export LD_LIBRARY_PATH=${{ env.LD_LIBRARY_PATH }} - ./example/build/osrm-example test/data/mld/monaco.osrm # All tests assume to be run from the build directory pushd ${OSRM_BUILD_DIR} diff --git a/.gitignore b/.gitignore index 9180d6fb5..a9dd4b9d4 100644 --- a/.gitignore +++ b/.gitignore @@ -43,7 +43,6 @@ Thumbs.db ####################### /_build* /build/ -/example/build/ /test/data/monaco.osrm* /test/data/ch /test/data/corech diff --git a/docs/libosrm.md b/docs/libosrm.md deleted file mode 100644 index 9b84180f1..000000000 --- a/docs/libosrm.md +++ /dev/null @@ -1,33 +0,0 @@ -## Introduction - -OSRM can be used as a library (libosrm) via C++ instead of using it through the HTTP interface and `osrm-routed`. This allows for fine-tuning OSRM and has much less overhead. Here is a quick introduction into how to use `libosrm` in the upcoming v5 release. - -Take a look at the example code that lives in the [example directory](https://github.com/Project-OSRM/osrm-backend/tree/master/example). Here is all you ever wanted to know about `libosrm`, that is a short description of what the types do and where to find documentation on it: - -## Important interface objects - -- [`EngineConfig`](https://github.com/Project-OSRM/osrm-backend/blob/master/include/engine/engine_config.hpp) - for initializing an OSRM instance we can configure certain properties and constraints. E.g. the storage config is the base path such as `france.osm.osrm` from which we derive and load `france.osm.osrm.*` auxiliary files. This also lets you set constraints such as the maximum number of locations allowed for specific services. - -- [`OSRM`](https://github.com/Project-OSRM/osrm-backend/blob/master/include/osrm/osrm.hpp) - this is the main Routing Machine type with functions such as `Route` and `Table`. You initialize it with a `EngineConfig`. It does all the heavy lifting for you. Each function takes its own parameters, e.g. the `Route` function takes `RouteParameters`, and a out-reference to a JSON result that gets filled. The return value is a `Status`, indicating error or success. - -- [`Status`](https://github.com/Project-OSRM/osrm-backend/blob/master/include/engine/status.hpp) - this is a type wrapping `Error` or `Ok` for indicating error or success, respectively. - -- [`TableParameters`](https://github.com/Project-OSRM/osrm-backend/blob/master/include/engine/api/table_parameters.hpp) - this is an example of parameter types the Routing Machine functions expect. In this case `Table` expects its own parameters as `TableParameters`. You can see it wrapping two vectors, sources and destinations --- these are indices into your coordinates for the table service to construct a matrix from (empty sources or destinations means: use all of them). If you ask yourself where coordinates come from, you can see `TableParameters` inheriting from `BaseParameters`. - -- [`BaseParameter`](https://github.com/Project-OSRM/osrm-backend/blob/master/include/engine/api/base_parameters.hpp) - this most importantly holds coordinates (and a few other optional properties that you don't need for basic usage); the specific parameter types inherit from `BaseParameters` to get these member attributes. That means your `TableParameters` type has `coordinates`, `sources` and `destination` member attributes (and a few other that we ignore for now). - -- [`Coordinate`](https://github.com/Project-OSRM/osrm-backend/blob/master/include/util/coordinate.hpp) - this is a wrapper around a (longitude, latitude) pair. We really don't care about (lon,lat) vs (lat, lon) but we don't want you to accidentally mix them up, so both latitude and longitude are strictly typed wrappers around integers (fixed notation such as `13423240`) and floating points (floating notation such as `13.42324`). - -- [Parameters for other services](https://github.com/Project-OSRM/osrm-backend/tree/master/include/engine/api) - here are all other `*Parameters` you need for other Routing Machine services. - -- [JSON](https://github.com/Project-OSRM/osrm-backend/blob/master/include/util/json_container.hpp) - this is a sum type resembling JSON. The Routing Machine service functions take a out-ref to a JSON result and fill it accordingly. It is currently implemented using [mapbox/variant](https://github.com/mapbox/variant) which is similar to [Boost.Variant](http://www.boost.org/doc/libs/1_55_0/doc/html/variant.html). There are two ways to work with this sum type: either provide a visitor that acts on each type on visitation or use the `get` function in case you're sure about the structure. The JSON structure is written down in the [HTTP API](#http-api). - -## Example - -See [the example folder](https://github.com/Project-OSRM/osrm-backend/tree/master/example) in the OSRM repository. - -## Workflow - - - Create an `OSRM` instance initialized with a `EngineConfig` - - Call the service function on the `OSRM` object providing service specific `*Parameters` - - Check the return code and use the JSON result diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt deleted file mode 100644 index 1ec0ff9cc..000000000 --- a/example/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -cmake_minimum_required(VERSION 3.18) - -if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR AND NOT MSVC_IDE) - message(FATAL_ERROR "In-source builds are not allowed. -Please create a directory and run cmake from there, passing the path to this source directory as the last argument. -This process created the file `CMakeCache.txt' and the directory `CMakeFiles'. Please delete them.") -endif() - -if(NOT CMAKE_BUILD_TYPE MATCHES Debug) - set(CMAKE_BUILD_TYPE Release) -endif() - -project(osrm-example C CXX) - -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_EXTENSIONS OFF) - -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") - -if(CMAKE_SIZEOF_VOID_P EQUAL 8) - message(STATUS "Building on a 64 bit system") -else() - message(STATUS "Building on a 32 bit system") -endif() - -link_directories(${LibOSRM_LIBRARY_DIRS}) -add_executable(osrm-example example.cpp) - -find_package(LibOSRM REQUIRED) - -target_link_libraries(osrm-example ${LibOSRM_LIBRARIES} ${LibOSRM_DEPENDENT_LIBRARIES}) -include_directories(SYSTEM ${LibOSRM_INCLUDE_DIRS}) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LibOSRM_CXXFLAGS}") diff --git a/example/cmake/FindLibOSRM.cmake b/example/cmake/FindLibOSRM.cmake deleted file mode 100644 index 50a5641a1..000000000 --- a/example/cmake/FindLibOSRM.cmake +++ /dev/null @@ -1,63 +0,0 @@ -# - Try to find LibOSRM -# Once done this will define -# LibOSRM_FOUND - System has LibOSRM -# LibOSRM_LIBRARIES - The libraries and ldflags needed to use LibOSRM -# LibOSRM_DEPENDENT_LIBRARIES - The libraries and ldflags need to link LibOSRM dependencies -# LibOSRM_LIBRARY_DIRS - The libraries paths needed to find LibOSRM -# LibOSRM_CXXFLAGS - Compiler switches required for using LibOSRM - -find_package(PkgConfig) -pkg_search_module(PC_LibOSRM QUIET libosrm) - -function(JOIN VALUES GLUE OUTPUT) - string (REPLACE ";" "${GLUE}" _TMP_STR "${VALUES}") - set (${OUTPUT} "${_TMP_STR}" PARENT_SCOPE) -endfunction() - -list(REMOVE_ITEM PC_LibOSRM_CFLAGS " ") -JOIN("${PC_LibOSRM_CFLAGS}" " " output) - -set(LibOSRM_CXXFLAGS ${output}) -set(LibOSRM_LIBRARY_DIRS ${PC_LibOSRM_LIBRARY_DIRS}) - -find_path(LibOSRM_INCLUDE_DIR osrm/osrm.hpp - PATH_SUFFIXES osrm include/osrm include - HINTS ${PC_LibOSRM_INCLUDEDIR} ${PC_LibOSRM_INCLUDE_DIRS} - ~/Library/Frameworks - /Library/Frameworks - /usr/local - /usr - /opt/local - /opt) - -find_library(TEST_LibOSRM_STATIC_LIBRARY Names osrm.lib libosrm.a - PATH_SUFFIXES osrm lib/osrm lib - HINTS ${PC_LibOSRM_LIBDIR} ${PC_LibOSRM_LIBRARY_DIRS} - ~/Library/Frameworks - /Library/Frameworks - /usr/local - /usr - /opt/local - /opt) -find_library(TEST_LibOSRM_DYNAMIC_LIBRARY Names libosrm.dylib libosrm.so - PATH_SUFFIXES osrm lib/osrm lib - HINTS ${PC_LibOSRM_LIBDIR} ${PC_LibOSRM_LIBRARY_DIRS} - ~/Library/Frameworks - /Library/Frameworks - /usr/local - /usr - /opt/local - /opt) - -set(LibOSRM_DEPENDENT_LIBRARIES ${PC_LibOSRM_STATIC_LDFLAGS}) -set(LibOSRM_LIBRARIES ${PC_LibOSRM_LDFLAGS}) - -include(FindPackageHandleStandardArgs) -# handle the QUIETLY and REQUIRED arguments and set LIBOSRM_FOUND to TRUE -# if all listed variables are TRUE -find_package_handle_standard_args(LibOSRM DEFAULT_MSG - LibOSRM_LIBRARY_DIRS - LibOSRM_CXXFLAGS - LibOSRM_LIBRARIES - LibOSRM_DEPENDENT_LIBRARIES - LibOSRM_INCLUDE_DIR) diff --git a/example/cmake/FindTBB.cmake b/example/cmake/FindTBB.cmake deleted file mode 120000 index f51bdf742..000000000 --- a/example/cmake/FindTBB.cmake +++ /dev/null @@ -1 +0,0 @@ -../../cmake/FindTBB.cmake \ No newline at end of file diff --git a/example/example.cpp b/example/example.cpp deleted file mode 100644 index 1d08eb9fc..000000000 --- a/example/example.cpp +++ /dev/null @@ -1,90 +0,0 @@ -#include "osrm/match_parameters.hpp" -#include "osrm/nearest_parameters.hpp" -#include "osrm/route_parameters.hpp" -#include "osrm/table_parameters.hpp" -#include "osrm/trip_parameters.hpp" - -#include "osrm/coordinate.hpp" -#include "osrm/engine_config.hpp" -#include "osrm/json_container.hpp" - -#include "osrm/osrm.hpp" -#include "osrm/status.hpp" - -#include -#include -#include -#include - -#include - -int main(int argc, const char *argv[]) -{ - if (argc < 2) - { - std::cerr << "Usage: " << argv[0] << " data.osrm\n"; - return EXIT_FAILURE; - } - - using namespace osrm; - - // Configure based on a .osrm base path, and no datasets in shared mem from osrm-datastore - EngineConfig config; - - config.storage_config = {argv[1]}; - config.use_shared_memory = false; - - // We support two routing speed up techniques: - // - Contraction Hierarchies (CH): requires extract+contract pre-processing - // - Multi-Level Dijkstra (MLD): requires extract+partition+customize pre-processing - // - // config.algorithm = EngineConfig::Algorithm::CH; - config.algorithm = EngineConfig::Algorithm::MLD; - - // Routing machine with several services (such as Route, Table, Nearest, Trip, Match) - const OSRM osrm{config}; - - // The following shows how to use the Route service; configure this service - RouteParameters params; - - // Route in monaco - params.coordinates.push_back({util::FloatLongitude{7.419758}, util::FloatLatitude{43.731142}}); - params.coordinates.push_back({util::FloatLongitude{7.419505}, util::FloatLatitude{43.736825}}); - - // Response is in JSON format - engine::api::ResultT result = json::Object(); - - // Execute routing request, this does the heavy lifting - const auto status = osrm.Route(params, result); - - auto &json_result = std::get(result); - if (status == Status::Ok) - { - auto &routes = std::get(json_result.values["routes"]); - - // Let's just use the first route - auto &route = std::get(routes.values.at(0)); - const auto distance = std::get(route.values["distance"]).value; - const auto duration = std::get(route.values["duration"]).value; - - // Warn users if extract does not contain the default coordinates from above - if (distance == 0 || duration == 0) - { - std::cout << "Note: distance or duration is zero. "; - std::cout << "You are probably doing a query outside of the OSM extract.\n\n"; - } - - std::cout << "Distance: " << distance << " meter\n"; - std::cout << "Duration: " << duration << " seconds\n"; - return EXIT_SUCCESS; - } - else if (status == Status::Error) - { - const auto code = std::get(json_result.values["code"]).value; - const auto message = std::get(json_result.values["message"]).value; - - std::cout << "Code: " << code << "\n"; - std::cout << "Message: " << code << "\n"; - return EXIT_FAILURE; - } -}