Compare commits
122 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c3085d5dc7 | |||
| 3c0cec3a2c | |||
| 2b18954cb9 | |||
| cb5d596a5a | |||
| 49e09294bf | |||
| 4a4d7ac62f | |||
| 91a24bf537 | |||
| 01f050cebb | |||
| 7ff8428ad1 | |||
| ddb25cdf22 | |||
| 524f8cc312 | |||
| d9ecb8693f | |||
| 0bf0535a8a | |||
| 2cc32dcc88 | |||
| 8ba516c17e | |||
| 4e0c018dff | |||
| 6bd74c287b | |||
| 5597415f28 | |||
| 5476f6ab27 | |||
| 0971f06193 | |||
| 85515f063a | |||
| 69d7825542 | |||
| 9b779c704f | |||
| 5bd7d04fe3 | |||
| 0f78f7b2cc | |||
| 8473be69d2 | |||
| c0124f7d77 | |||
| b630b4e32a | |||
| 89fabc1b9c | |||
| a649a8a5cf | |||
| f928956584 | |||
| 7ff68792d7 | |||
| 3088dd0342 | |||
| d2590989f5 | |||
| 3a7b377586 | |||
| 82b5648c97 | |||
| 1628a3c4d5 | |||
| e5d8319c43 | |||
| 06699132eb | |||
| 918e794d6a | |||
| 8dd8ee1fc2 | |||
| c3d0efda93 | |||
| 3b4e2e83ef | |||
| c459530cb6 | |||
| 2a15e6dec8 | |||
| 1a1293608d | |||
| 318df9deaa | |||
| cacb162520 | |||
| 105709cb43 | |||
| 9695fa7941 | |||
| fd9bebbfa7 | |||
| db18e8669f | |||
| 9b4a4fdd82 | |||
| cdc7e5f021 | |||
| adc87149e2 | |||
| 8adbfe06ed | |||
| ae805f9ec8 | |||
| be24689b0f | |||
| 41c31a2388 | |||
| 8b866502d1 | |||
| 7837cd61df | |||
| b573485c31 | |||
| 4e68f3a7e1 | |||
| 5ba26d3d6d | |||
| a6cf2eee7e | |||
| 6843eb1479 | |||
| b331885d3c | |||
| 73716bd651 | |||
| 9edd161da3 | |||
| 1bc3ff6491 | |||
| b0f2ef287e | |||
| 16f53ff81a | |||
| 7a260dc2ba | |||
| 1c0d951f5e | |||
| 77a740c0fb | |||
| 61101db8cf | |||
| b51632a2fb | |||
| 9d10503a9c | |||
| 7d50e5afe0 | |||
| 549216c792 | |||
| 1990de7dcc | |||
| 89f6e2d55b | |||
| c628ecbf24 | |||
| b6f19cd544 | |||
| 14860b62e9 | |||
| 9970b7d580 | |||
| 7feb79ef91 | |||
| 6f84812903 | |||
| 8085e86170 | |||
| 35973576d9 | |||
| 7740d5d7c0 | |||
| c4eff6cd65 | |||
| 5c4353b46e | |||
| 05a5918909 | |||
| 80ad38bbc6 | |||
| 6bee8866de | |||
| ba92674c6e | |||
| 68019a1fb2 | |||
| 3a9acde2c3 | |||
| a3a7a822e1 | |||
| c7d22c2b92 | |||
| b2aeb47630 | |||
| 0a1d1901cc | |||
| 29db0c80d9 | |||
| 4654751872 | |||
| b5b18d8afc | |||
| 15139c934f | |||
| 7b8619e37c | |||
| f52b5c31b6 | |||
| e98859e4c0 | |||
| c5cc4c5a74 | |||
| e3b831364f | |||
| 730d2b5ef2 | |||
| 16abee1022 | |||
| 69fa52a010 | |||
| e1efa4c6ab | |||
| 17cd1575f6 | |||
| 3cd8e0fef8 | |||
| 397bb694fd | |||
| 473ebfcbf6 | |||
| a06171438e | |||
| ea0881553e |
+1
-1
@@ -365,7 +365,7 @@ install:
|
||||
script:
|
||||
- if [[ $TARGET_ARCH == armhf ]] ; then echo "Skip tests for $TARGET_ARCH" && exit 0 ; fi
|
||||
- make -C test/data benchmark
|
||||
- ./example/build/osrm-example test/data/mld/monaco.osrm
|
||||
# - ./example/build/osrm-example test/data/mld/monaco.osrm
|
||||
# All tests assume to be run from the build directory
|
||||
- pushd ${OSRM_BUILD_DIR}
|
||||
- ./unit_tests/library-tests
|
||||
|
||||
@@ -1,4 +1,37 @@
|
||||
# UNRELEASED
|
||||
- Changes from 5.19.0:
|
||||
- Features:
|
||||
- ADDED: direct mmapping of datafiles is now supported via the `-mmap` switch. [#5242](https://github.com/Project-OSRM/osrm-backend/pull/5242)
|
||||
- REMOVED: the previous `--memory_file` switch is now deprecated and will fallback to `--mmap` [#5242](https://github.com/Project-OSRM/osrm-backend/pull/5242)
|
||||
|
||||
# 5.19.0
|
||||
- Changes from 5.18.0:
|
||||
- Optimizations:
|
||||
- CHANGED: Use Grisu2 for serializing floating point numbers. [#5188](https://github.com/Project-OSRM/osrm-backend/pull/5188)
|
||||
- ADDED: Node bindings can return pre-rendered JSON buffer. [#5189](https://github.com/Project-OSRM/osrm-backend/pull/5189)
|
||||
- Bugfixes:
|
||||
- FIXED: collapsing of ExitRoundabout instructions [#5114](https://github.com/Project-OSRM/osrm-backend/issues/5114)
|
||||
- Misc:
|
||||
- CHANGED: Support up to 512 named shared memory regions [#5185](https://github.com/Project-OSRM/osrm-backend/pull/5185)
|
||||
|
||||
# 5.18.0
|
||||
- Changes from 5.17.0:
|
||||
- Features:
|
||||
- ADDED: `table` plugin now optionally returns `distance` matrix as part of response [#4990](https://github.com/Project-OSRM/osrm-backend/pull/4990)
|
||||
- ADDED: New optional parameter `annotations` for `table` that accepts `distance`, `duration`, or both `distance,duration` as values [#4990](https://github.com/Project-OSRM/osrm-backend/pull/4990)
|
||||
- Infrastructure:
|
||||
- ADDED: Updated libosmium and added protozero and vtzero libraries [#5037](https://github.com/Project-OSRM/osrm-backend/pull/5037)
|
||||
- CHANGED: Use vtzero library in tile plugin [#4686](https://github.com/Project-OSRM/osrm-backend/pull/4686)
|
||||
- Profile:
|
||||
- ADDED: Bicycle profile now returns classes for ferry and tunnel routes. [#5054](https://github.com/Project-OSRM/osrm-backend/pull/5054)
|
||||
- ADDED: Bicycle profile allows to exclude ferry routes (default to not enabled) [#5054](https://github.com/Project-OSRM/osrm-backend/pull/5054)
|
||||
|
||||
# 5.17.1
|
||||
- Changes from 5.17.0:
|
||||
- Bugfixes:
|
||||
- FIXED: Do not combine a segregated edge with a roundabout [#5039](https://github.com/Project-OSRM/osrm-backend/issues/5039)
|
||||
|
||||
# 5.17.0
|
||||
- Changes from 5.16.0:
|
||||
- Bugfixes:
|
||||
- FIXED: deduplication of route steps when waypoints are used [#4909](https://github.com/Project-OSRM/osrm-backend/issues/4909)
|
||||
@@ -6,9 +39,11 @@
|
||||
- FIXED: Remove the last short annotation segment in `trimShortSegments` [#4946](https://github.com/Project-OSRM/osrm-backend/pull/4946)
|
||||
- FIXED: Properly calculate annotations for speeds, durations and distances when waypoints are used with mapmatching [#4949](https://github.com/Project-OSRM/osrm-backend/pull/4949)
|
||||
- FIXED: Don't apply unimplemented SH and PH conditions in OpeningHours and add inversed date ranges [#4992](https://github.com/Project-OSRM/osrm-backend/issues/4992)
|
||||
- FIXED: integer overflow in `DynamicGraph::Renumber` [#5021](https://github.com/Project-OSRM/osrm-backend/pull/5021)
|
||||
- Profile:
|
||||
- CHANGED: Handle oneways in get_forward_backward_by_key [#4929](https://github.com/Project-OSRM/osrm-backend/pull/4929)
|
||||
- FIXED: Do not route against oneway road if there is a cycleway in the wrong direction; also review bike profile [#4943](https://github.com/Project-OSRM/osrm-backend/issues/4943)
|
||||
- CHANGED: Make cyclability weighting of the bike profile prefer safer routes more strongly [#5015](https://github.com/Project-OSRM/osrm-backend/issues/5015)
|
||||
- Guidance:
|
||||
- CHANGED: Don't use obviousness for links bifurcations [#4929](https://github.com/Project-OSRM/osrm-backend/pull/4929)
|
||||
- FIXED: Adjust Straight direction modifiers of side roads in driveway handler [#4929](https://github.com/Project-OSRM/osrm-backend/pull/4929)
|
||||
|
||||
+24
-13
@@ -167,7 +167,7 @@ add_executable(osrm-customize src/tools/customize.cpp)
|
||||
add_executable(osrm-contract src/tools/contract.cpp)
|
||||
add_executable(osrm-routed src/tools/routed.cpp $<TARGET_OBJECTS:SERVER> $<TARGET_OBJECTS:UTIL>)
|
||||
add_executable(osrm-datastore src/tools/store.cpp $<TARGET_OBJECTS:MICROTAR> $<TARGET_OBJECTS:UTIL>)
|
||||
add_library(osrm src/osrm/osrm.cpp $<TARGET_OBJECTS:ENGINE> $<TARGET_OBJECTS:STORAGE> $<TARGET_OBJECTS:MICROTAR> $<TARGET_OBJECTS:UTIL> )
|
||||
add_library(osrm src/osrm/osrm.cpp $<TARGET_OBJECTS:ENGINE> $<TARGET_OBJECTS:STORAGE> $<TARGET_OBJECTS:MICROTAR> $<TARGET_OBJECTS:UTIL>)
|
||||
add_library(osrm_contract src/osrm/contractor.cpp $<TARGET_OBJECTS:CONTRACTOR> $<TARGET_OBJECTS:UTIL>)
|
||||
add_library(osrm_extract src/osrm/extractor.cpp $<TARGET_OBJECTS:EXTRACTOR> $<TARGET_OBJECTS:MICROTAR> $<TARGET_OBJECTS:UTIL>)
|
||||
add_library(osrm_guidance $<TARGET_OBJECTS:GUIDANCE> $<TARGET_OBJECTS:UTIL>)
|
||||
@@ -416,11 +416,30 @@ if(UNIX AND NOT APPLE)
|
||||
set(MAYBE_RT_LIBRARY -lrt)
|
||||
endif()
|
||||
|
||||
# Disallow deprecated protozero APIs
|
||||
add_definitions(-DPROTOZERO_STRICT_API)
|
||||
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
# Third-party libraries
|
||||
set(RAPIDJSON_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/rapidjson/include")
|
||||
include_directories(SYSTEM ${RAPIDJSON_INCLUDE_DIR})
|
||||
|
||||
set(MICROTAR_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/microtar/src")
|
||||
include_directories(SYSTEM ${MICROTAR_INCLUDE_DIR})
|
||||
|
||||
set(MBXGEOM_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/geometry.hpp-0.9.2/include")
|
||||
include_directories(SYSTEM ${MBXGEOM_INCLUDE_DIR})
|
||||
set(CHEAPRULER_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/cheap-ruler-cpp-2.5.4/include")
|
||||
include_directories(SYSTEM ${CHEAPRULER_INCLUDE_DIR})
|
||||
|
||||
add_library(MICROTAR OBJECT "${CMAKE_CURRENT_SOURCE_DIR}/third_party/microtar/src/microtar.c")
|
||||
set_property(TARGET MICROTAR PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
set(PROTOZERO_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/protozero/include")
|
||||
include_directories(SYSTEM ${PROTOZERO_INCLUDE_DIR})
|
||||
|
||||
set(VTZERO_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/vtzero/include")
|
||||
include_directories(SYSTEM ${VTZERO_INCLUDE_DIR})
|
||||
|
||||
|
||||
# if mason is enabled no find_package calls are made
|
||||
# to ensure that we are only compiling and linking against
|
||||
# fully portable mason packages
|
||||
@@ -554,14 +573,6 @@ else()
|
||||
include_directories(SYSTEM ${OSMIUM_INCLUDE_DIR})
|
||||
endif()
|
||||
|
||||
set(RAPIDJSON_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/rapidjson/include")
|
||||
include_directories(SYSTEM ${RAPIDJSON_INCLUDE_DIR})
|
||||
|
||||
set(MICROTAR_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/microtar/src")
|
||||
include_directories(SYSTEM ${MICROTAR_INCLUDE_DIR})
|
||||
add_library(MICROTAR OBJECT "${CMAKE_CURRENT_SOURCE_DIR}/third_party/microtar/src/microtar.c")
|
||||
set_property(TARGET MICROTAR PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
# prefix compilation with ccache by default if available and on clang or gcc
|
||||
if(ENABLE_CCACHE AND (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU"))
|
||||
find_program(CCACHE_FOUND ccache)
|
||||
@@ -862,4 +873,4 @@ if (ENABLE_NODE_BINDINGS)
|
||||
endforeach()
|
||||
add_library(check-headers STATIC EXCLUDE_FROM_ALL ${sources})
|
||||
set_target_properties(check-headers PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${check_headers_dir})
|
||||
endif()
|
||||
endif()
|
||||
@@ -9,7 +9,7 @@ High performance routing engine written in C++14 designed to run on OpenStreetMa
|
||||
The following services are available via HTTP API, C++ library interface and NodeJs wrapper:
|
||||
- Nearest - Snaps coordinates to the street network and returns the nearest matches
|
||||
- Route - Finds the fastest route between coordinates
|
||||
- Table - Computes the duration of the fastest route between all pairs of supplied coordinates
|
||||
- Table - Computes the duration or distances of the fastest route between all pairs of supplied coordinates
|
||||
- Match - Snaps noisy GPS traces to the road network in the most plausible way
|
||||
- Trip - Solves the Traveling Salesman Problem using a greedy heuristic
|
||||
- Tile - Generates Mapbox Vector Tiles with internal routing metadata
|
||||
|
||||
+1
-1
@@ -3,5 +3,5 @@ module.exports = {
|
||||
verify: '--strict --tags ~@stress --tags ~@todo --tags ~@mld-only -f progress --require features/support --require features/step_definitions',
|
||||
todo: '--strict --tags @todo --require features/support --require features/step_definitions',
|
||||
all: '--strict --require features/support --require features/step_definitions',
|
||||
mld: '--strict --tags ~@stress --tags ~@todo --require features/support --require features/step_definitions -f progress'
|
||||
mld: '--strict --tags ~@stress --tags ~@todo --tags ~@ch --require features/support --require features/step_definitions -f progress'
|
||||
};
|
||||
|
||||
+117
-8
@@ -222,13 +222,13 @@ curl 'http://router.project-osrm.org/route/v1/driving/13.388860,52.517037;13.397
|
||||
|
||||
### Table service
|
||||
|
||||
Computes the duration of the fastest route between all pairs of supplied coordinates.
|
||||
Computes the duration of the fastest route between all pairs of supplied coordinates. Returns the durations or distances or both between the coordinate pairs. Note that the distances are not the shortest distance between two coordinates, but rather the distances of the fastest routes. Duration is in seconds and distances is in meters.
|
||||
|
||||
```endpoint
|
||||
GET /table/v1/{profile}/{coordinates}?{sources}=[{elem}...];&destinations=[{elem}...]
|
||||
GET /table/v1/{profile}/{coordinates}?{sources}=[{elem}...];&{destinations}=[{elem}...]&annotations={duration|distance|duration,distance}
|
||||
```
|
||||
|
||||
**Coordinates**
|
||||
**Options**
|
||||
|
||||
In addition to the [general options](#general-options) the following options are supported for this service:
|
||||
|
||||
@@ -236,6 +236,8 @@ In addition to the [general options](#general-options) the following options are
|
||||
|------------|--------------------------------------------------|---------------------------------------------|
|
||||
|sources |`{index};{index}[;{index} ...]` or `all` (default)|Use location with given index as source. |
|
||||
|destinations|`{index};{index}[;{index} ...]` or `all` (default)|Use location with given index as destination.|
|
||||
|annotations |`duration` (default), `distance`, or `duration,distance`|Return the requested table or tables in response. Note that computing the `distances` table is currently only implemented for CH. If `annotations=distance` or `annotations=duration,distance` is requested when running a MLD router, a `NotImplemented` error will be returned.
|
||||
|
|
||||
|
||||
Unlike other array encoded options, the length of `sources` and `destinations` can be **smaller or equal**
|
||||
to number of input locations;
|
||||
@@ -253,14 +255,23 @@ sources=0;5;7&destinations=5;1;4;2;3;6
|
||||
#### Example Request
|
||||
|
||||
```curl
|
||||
# Returns a 3x3 matrix:
|
||||
# Returns a 3x3 duration matrix:
|
||||
curl 'http://router.project-osrm.org/table/v1/driving/13.388860,52.517037;13.397634,52.529407;13.428555,52.523219'
|
||||
|
||||
# Returns a 1x3 matrix
|
||||
# Returns a 1x3 duration matrix
|
||||
curl 'http://router.project-osrm.org/table/v1/driving/13.388860,52.517037;13.397634,52.529407;13.428555,52.523219?sources=0'
|
||||
|
||||
# Returns a asymmetric 3x2 matrix with from the polyline encoded locations `qikdcB}~dpXkkHz`:
|
||||
# Returns a asymmetric 3x2 duration matrix with from the polyline encoded locations `qikdcB}~dpXkkHz`:
|
||||
curl 'http://router.project-osrm.org/table/v1/driving/polyline(egs_Iq_aqAppHzbHulFzeMe`EuvKpnCglA)?sources=0;1;3&destinations=2;4'
|
||||
|
||||
# Returns a 3x3 duration matrix:
|
||||
curl 'http://router.project-osrm.org/table/v1/driving/13.388860,52.517037;13.397634,52.529407;13.428555,52.523219?annotations=duration'
|
||||
|
||||
# Returns a 3x3 distance matrix for CH:
|
||||
curl 'http://router.project-osrm.org/table/v1/driving/13.388860,52.517037;13.397634,52.529407;13.428555,52.523219?annotations=distance'
|
||||
|
||||
# Returns a 3x3 duration matrix and a 3x3 distance matrix for CH:
|
||||
curl 'http://router.project-osrm.org/table/v1/driving/13.388860,52.517037;13.397634,52.529407;13.428555,52.523219?annotations=distance,duration'
|
||||
```
|
||||
|
||||
**Response**
|
||||
@@ -268,17 +279,115 @@ curl 'http://router.project-osrm.org/table/v1/driving/polyline(egs_Iq_aqAppHzbHu
|
||||
- `code` if the request was successful `Ok` otherwise see the service dependent and general status codes.
|
||||
- `durations` array of arrays that stores the matrix in row-major order. `durations[i][j]` gives the travel time from
|
||||
the i-th waypoint to the j-th waypoint. Values are given in seconds. Can be `null` if no route between `i` and `j` can be found.
|
||||
- `distances` array of arrays that stores the matrix in row-major order. `distances[i][j]` gives the travel distance from
|
||||
the i-th waypoint to the j-th waypoint. Values are given in meters. Can be `null` if no route between `i` and `j` can be found. Note that computing the `distances` table is currently only implemented for CH. If `annotations=distance` or `annotations=duration,distance` is requested when running a MLD router, a `NotImplemented` error will be returned.
|
||||
- `sources` array of `Waypoint` objects describing all sources in order
|
||||
- `destinations` array of `Waypoint` objects describing all destinations in order
|
||||
|
||||
In case of error the following `code`s are supported in addition to the general ones:
|
||||
|
||||
| Type | Description |
|
||||
|-------------------|-----------------|
|
||||
| Type | Description |
|
||||
|------------------|-----------------|
|
||||
| `NoTable` | No route found. |
|
||||
| `NotImplemented` | This request is not supported |
|
||||
|
||||
All other properties might be undefined.
|
||||
|
||||
#### Example Response
|
||||
|
||||
```json
|
||||
{
|
||||
"sources": [
|
||||
{
|
||||
"location": [
|
||||
13.3888,
|
||||
52.517033
|
||||
],
|
||||
"hint": "PAMAgEVJAoAUAAAAIAAAAAcAAAAAAAAArss0Qa7LNEHiVIRA4lSEQAoAAAAQAAAABAAAAAAAAADMAAAAAEzMAKlYIQM8TMwArVghAwEA3wps52D3",
|
||||
"name": "Friedrichstraße"
|
||||
},
|
||||
{
|
||||
"location": [
|
||||
13.397631,
|
||||
52.529432
|
||||
],
|
||||
"hint": "WIQBgL6mAoAEAAAABgAAAAAAAAA7AAAAhU6PQHvHj0IAAAAAQbyYQgQAAAAGAAAAAAAAADsAAADMAAAAf27MABiJIQOCbswA_4ghAwAAXwVs52D3",
|
||||
"name": "Torstraße"
|
||||
},
|
||||
{
|
||||
"location": [
|
||||
13.428554,
|
||||
52.523239
|
||||
],
|
||||
"hint": "7UcAgP___38fAAAAUQAAACYAAABTAAAAhSQKQrXq5kKRbiZCWJo_Qx8AAABRAAAAJgAAAFMAAADMAAAASufMAOdwIQNL58wA03AhAwMAvxBs52D3",
|
||||
"name": "Platz der Vereinten Nationen"
|
||||
}
|
||||
],
|
||||
"durations": [
|
||||
[
|
||||
0,
|
||||
192.6,
|
||||
382.8
|
||||
],
|
||||
[
|
||||
199,
|
||||
0,
|
||||
283.9
|
||||
],
|
||||
[
|
||||
344.7,
|
||||
222.3,
|
||||
0
|
||||
]
|
||||
],
|
||||
"destinations": [
|
||||
{
|
||||
"location": [
|
||||
13.3888,
|
||||
52.517033
|
||||
],
|
||||
"hint": "PAMAgEVJAoAUAAAAIAAAAAcAAAAAAAAArss0Qa7LNEHiVIRA4lSEQAoAAAAQAAAABAAAAAAAAADMAAAAAEzMAKlYIQM8TMwArVghAwEA3wps52D3",
|
||||
"name": "Friedrichstraße"
|
||||
},
|
||||
{
|
||||
"location": [
|
||||
13.397631,
|
||||
52.529432
|
||||
],
|
||||
"hint": "WIQBgL6mAoAEAAAABgAAAAAAAAA7AAAAhU6PQHvHj0IAAAAAQbyYQgQAAAAGAAAAAAAAADsAAADMAAAAf27MABiJIQOCbswA_4ghAwAAXwVs52D3",
|
||||
"name": "Torstraße"
|
||||
},
|
||||
{
|
||||
"location": [
|
||||
13.428554,
|
||||
52.523239
|
||||
],
|
||||
"hint": "7UcAgP___38fAAAAUQAAACYAAABTAAAAhSQKQrXq5kKRbiZCWJo_Qx8AAABRAAAAJgAAAFMAAADMAAAASufMAOdwIQNL58wA03AhAwMAvxBs52D3",
|
||||
"name": "Platz der Vereinten Nationen"
|
||||
}
|
||||
],
|
||||
"code": "Ok",
|
||||
"distances": [
|
||||
[
|
||||
0,
|
||||
1886.89,
|
||||
3791.3
|
||||
],
|
||||
[
|
||||
1824,
|
||||
0,
|
||||
2838.09
|
||||
],
|
||||
[
|
||||
3275.36,
|
||||
2361.73,
|
||||
0
|
||||
]
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### Match service
|
||||
|
||||
Map matching matches/snaps given GPS points to the road network in the most plausible way.
|
||||
|
||||
+25
-2
@@ -110,8 +110,8 @@ Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refer
|
||||
|
||||
### table
|
||||
|
||||
Computes duration tables for the given locations. Allows for both symmetric and asymmetric
|
||||
tables.
|
||||
Computes duration table for the given locations. Allows for both symmetric and asymmetric
|
||||
tables. Optionally returns distance table.
|
||||
|
||||
**Parameters**
|
||||
|
||||
@@ -297,6 +297,29 @@ Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refer
|
||||
2) `waypoint_index`: index of the point in the trip.
|
||||
**`trips`**: an array of [`Route`](#route) objects that assemble the trace.
|
||||
|
||||
## Plugin behaviour
|
||||
|
||||
All plugins support a second additional object that is available to configure some NodeJS specific behaviours.
|
||||
|
||||
- `plugin_config` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Object literal containing parameters for the trip query.
|
||||
- `plugin_config.format` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** The format of the result object to various API calls. Valid options are `object` (default), which returns a standard Javascript object, as described above, and `json_buffer`, which will return a NodeJS **[Buffer](https://nodejs.org/api/buffer.html)** object, containing a JSON string. The latter has the advantage that it can be immediately serialized to disk/sent over the network, and the generation of the string is performed outside the main NodeJS event loop. This option is ignored by the `tile` plugin.
|
||||
|
||||
**Examples**
|
||||
|
||||
```javascript
|
||||
var osrm = new OSRM('network.osrm');
|
||||
var options = {
|
||||
coordinates: [
|
||||
[13.36761474609375, 52.51663871100423],
|
||||
[13.374481201171875, 52.506191342034576]
|
||||
]
|
||||
};
|
||||
osrm.route(options, { format: "json_buffer" }, function(err, response) {
|
||||
if (err) throw err;
|
||||
console.log(response.toString("utf-8"));
|
||||
});
|
||||
```
|
||||
|
||||
## Responses
|
||||
|
||||
Responses
|
||||
|
||||
+5
-5
@@ -68,7 +68,7 @@ If you want to prioritize certain streets, increase the rate on these.
|
||||
|
||||
## Elements
|
||||
### api_version
|
||||
A profile should set `api_version` at the top of your profile. This is done to ensure that older profiles are still supported when the api changes. If `api_version` is not defined, 0 will be assumed. The current api version is 2.
|
||||
A profile should set `api_version` at the top of your profile. This is done to ensure that older profiles are still supported when the api changes. If `api_version` is not defined, 0 will be assumed. The current api version is 4.
|
||||
|
||||
### Library files
|
||||
The folder [profiles/lib/](../profiles/lib/) contains LUA library files for handling many common processing tasks.
|
||||
@@ -138,7 +138,7 @@ Given an OpenStreetMap way, the `process_way` function will either return nothin
|
||||
Argument | Description
|
||||
---------|-------------------------------------------------------
|
||||
profile | The configuration table you returned in `setup`.
|
||||
node | The input way to process (read-only).
|
||||
way | The input way to process (read-only).
|
||||
result | The output that you will modify.
|
||||
relations| Storage of relations to access relations, where `way` is a member.
|
||||
|
||||
@@ -199,7 +199,7 @@ source.lon | Read | Float | Co-ordinates of segment start
|
||||
source.lat | Read | Float | ""
|
||||
target.lon | Read | Float | Co-ordinates of segment end
|
||||
target.lat | Read | Float | ""
|
||||
target.distance | Read | Float | Length of segment
|
||||
distance | Read | Float | Length of segment
|
||||
weight | Read/write | Float | Routing weight for this segment
|
||||
duration | Read/write | Float | Duration for this segment
|
||||
|
||||
@@ -224,8 +224,8 @@ source_highway_turn_classification | Read | Integer |
|
||||
source_access_turn_classification | Read | Integer | Classification based on access tag defined by user during setup. (default when not set: 0, allowed classification values are: 0-15))
|
||||
source_speed | Read | Integer | Speed on this source road in km/h
|
||||
source_priority_class | Read | Enum | The type of road priority class of the source. Defined in `include/extractor/guidance/road_classification.hpp`
|
||||
target_restricted | Read | Boolean | Is it from a restricted access road? (See definition in `process_way`)
|
||||
target_mode | Read | Enum | Travel mode before the turn. Defined in `include/extractor/travel_mode.hpp`
|
||||
target_restricted | Read | Boolean | Is the target a restricted access road? (See definition in `process_way`)
|
||||
target_mode | Read | Enum | Travel mode after the turn. Defined in `include/extractor/travel_mode.hpp`
|
||||
target_is_motorway | Read | Boolean | Is the target road a motorway?
|
||||
target_is_link | Read | Boolean | Is the target road a link?
|
||||
target_number_of_lanes | Read | Integer | How many lanes does the target road have? (default when not tagged: 0)
|
||||
|
||||
+3
-3
@@ -43,9 +43,9 @@ We may introduce forward-compatible changes: query parameters and response prope
|
||||
|
||||
1. Check out the appropriate release branch `x.y`
|
||||
2. Make sure `CHANGELOG.md` is up to date.
|
||||
3. Make sure the `package.json` is up to date.
|
||||
4. Make sure all tests are passing (e.g. Travis CI gives you a :thumbs_up:)
|
||||
5. Use an annotated tag to mark the release: `git tag vx.y.z -a` Body of the tag description should be the changelog entries.
|
||||
3. Make sure the `package.json` on branch `x.y` has been committed.
|
||||
4. Make sure all tests are passing (e.g. Travis CI gives you a :green_apple:)
|
||||
5. Use an annotated tag to mark the release: `git tag vx.y.z -a` Body of the tag description should be the changelog entries. Commit should be one in which the `package.json` version matches the version you want to release.
|
||||
6. Use `npm run docs` to generate the API documentation. Copy `build/docs/*` to `https://github.com/Project-OSRM/project-osrm.github.com` in the `docs/vN.N.N/api` directory
|
||||
7. Push tags and commits: `git push; git push --tags`
|
||||
8. On https://github.com/Project-OSRM/osrm-backend/releases press `Draft a new release`,
|
||||
|
||||
@@ -19,7 +19,7 @@ Feature: Barriers
|
||||
| entrance | x |
|
||||
| wall | |
|
||||
| fence | |
|
||||
| some_tag | |
|
||||
| some_tag | x |
|
||||
| block | x |
|
||||
|
||||
Scenario: Bike - Access tag trumphs barriers
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
@routing @bicycle @mode
|
||||
Feature: Bicycle - Mode flag
|
||||
Background:
|
||||
Given the profile "bicycle"
|
||||
|
||||
Scenario: Bicycle - We tag ferries with a class
|
||||
Given the node map
|
||||
"""
|
||||
a b
|
||||
c d
|
||||
"""
|
||||
|
||||
And the ways
|
||||
| nodes | highway | route |
|
||||
| ab | primary | |
|
||||
| bc | | ferry |
|
||||
| cd | primary | |
|
||||
|
||||
When I route I should get
|
||||
| from | to | route | turns | classes |
|
||||
| a | d | ab,bc,cd,cd | depart,notification right,notification left,arrive | [()],[(ferry)],[()],[()] |
|
||||
| d | a | cd,bc,ab,ab | depart,notification right,notification left,arrive | [()],[(ferry)],[()],[()] |
|
||||
| c | a | bc,ab,ab | depart,notification left,arrive | [(ferry)],[()],[()] |
|
||||
| d | b | cd,bc,bc | depart,notification right,arrive | [()],[(ferry)],[()] |
|
||||
| a | c | ab,bc,bc | depart,notification right,arrive | [()],[(ferry)],[()] |
|
||||
| b | d | bc,cd,cd | depart,notification left,arrive | [(ferry)],[()],[()] |
|
||||
|
||||
Scenario: Bicycle - We tag tunnel with a class
|
||||
Background:
|
||||
Given a grid size of 200 meters
|
||||
|
||||
Given the node map
|
||||
"""
|
||||
a b
|
||||
c d
|
||||
"""
|
||||
|
||||
And the ways
|
||||
| nodes | tunnel |
|
||||
| ab | no |
|
||||
| bc | yes |
|
||||
| cd | |
|
||||
|
||||
When I route I should get
|
||||
| from | to | route | turns | classes |
|
||||
| a | d | ab,bc,cd,cd | depart,new name right,new name left,arrive | [()],[(tunnel)],[()],[()] |
|
||||
|
||||
Scenario: Bicycle - We tag classes without intersections
|
||||
Background:
|
||||
Given a grid size of 200 meters
|
||||
|
||||
Given the node map
|
||||
"""
|
||||
a b c d
|
||||
"""
|
||||
|
||||
And the ways
|
||||
| nodes | name | tunnel |
|
||||
| ab | road | |
|
||||
| bc | road | yes |
|
||||
| cd | road | |
|
||||
|
||||
When I route I should get
|
||||
| from | to | route | turns | classes |
|
||||
| a | d | road,road | depart,arrive | [(),(tunnel),()],[()] |
|
||||
|
||||
Scenario: Bicycle - From roundabout on ferry
|
||||
Given the node map
|
||||
"""
|
||||
c
|
||||
/ \
|
||||
a---b d---f--h
|
||||
\ /
|
||||
e
|
||||
|
|
||||
g
|
||||
"""
|
||||
|
||||
And the ways
|
||||
| nodes | oneway | highway | junction | route |
|
||||
| ab | yes | service | | |
|
||||
| cb | yes | service | roundabout | |
|
||||
| dc | yes | service | roundabout | |
|
||||
| be | yes | service | roundabout | |
|
||||
| ed | yes | service | roundabout | |
|
||||
| eg | yes | service | | |
|
||||
| df | | | | ferry |
|
||||
| fh | yes | service | | |
|
||||
|
||||
When I route I should get
|
||||
| from | to | route | turns | classes |
|
||||
| a | h | ab,df,df,fh,fh | depart,roundabout-exit-2,exit roundabout slight right,notification straight,arrive | [()],[(),()],[(ferry)],[()],[()] |
|
||||
@@ -0,0 +1,55 @@
|
||||
@routing @bicycle @exclude
|
||||
Feature: Bicycle - Exclude flags
|
||||
Background:
|
||||
Given the profile file "bicycle" initialized with
|
||||
"""
|
||||
profile.excludable = Sequence { Set { 'ferry' } }
|
||||
"""
|
||||
Given the node map
|
||||
"""
|
||||
a....b~~~~~c...f
|
||||
: :
|
||||
d.....e
|
||||
"""
|
||||
|
||||
And the ways
|
||||
| nodes | highway | route | duration | # |
|
||||
| ab | service | | | always drivable |
|
||||
| bc | | ferry | 00:00:01 | not drivable for exclude=ferry, but fast. |
|
||||
| bd | service | | | always drivable |
|
||||
| de | service | | | always drivable |
|
||||
| ec | service | | | always drivable |
|
||||
| cf | service | | | always drivable |
|
||||
|
||||
Scenario: Bicycle - exclude nothing
|
||||
When I route I should get
|
||||
| from | to | route |
|
||||
| a | f | ab,bc,cf,cf |
|
||||
|
||||
When I match I should get
|
||||
| trace | matchings | duration |
|
||||
| abcf | abcf | 109 |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | a | f |
|
||||
| a | 0 | 109 |
|
||||
| f | 109 | 0 |
|
||||
|
||||
Scenario: Bicycle - exclude ferry
|
||||
Given the query options
|
||||
| exclude | ferry |
|
||||
|
||||
When I route I should get
|
||||
| from | to | route |
|
||||
| a | f | ab,bd,de,ec,cf,cf |
|
||||
|
||||
When I match I should get
|
||||
| trace | matchings | duration |
|
||||
| abcf | abcf | 301.2 |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | a | f |
|
||||
| a | 0 | 301 +- 1 |
|
||||
| f | 301.2 +- 1 | 0 |
|
||||
|
||||
|
||||
@@ -11,11 +11,11 @@ Feature: Bicycle - Adds penalties to unsafe roads
|
||||
Then routability should be
|
||||
| highway | cycleway | forw | backw | forw_rate | backw_rate |
|
||||
| motorway | | | | | |
|
||||
| primary | | 15 km/h | 15 km/h | 2.9 | 2.9 |
|
||||
| secondary | | 15 km/h | 15 km/h | 3.1 | 3.1 |
|
||||
| primary | | 15 km/h | 15 km/h | 2.1 | 2.1 |
|
||||
| secondary | | 15 km/h | 15 km/h | 2.7 | 2.7 |
|
||||
| tertiary | | 15 km/h | 15 km/h | 3.3 | 3.3 |
|
||||
| primary_link | | 15 km/h | 15 km/h | 2.9 | 2.9 |
|
||||
| secondary_link | | 15 km/h | 15 km/h | 3.1 | 3.1 |
|
||||
| primary_link | | 15 km/h | 15 km/h | 2.1 | 2.1 |
|
||||
| secondary_link | | 15 km/h | 15 km/h | 2.7 | 2.7 |
|
||||
| tertiary_link | | 15 km/h | 15 km/h | 3.3 | 3.3 |
|
||||
| residential | | 15 km/h | 15 km/h | 4.2 | 4.2 |
|
||||
| cycleway | | 15 km/h | 15 km/h | 4.2 | 4.2 |
|
||||
@@ -51,49 +51,49 @@ Feature: Bicycle - Adds penalties to unsafe roads
|
||||
Then routability should be
|
||||
| highway | cycleway:right | cycleway:left | forw | backw | forw_rate | backw_rate |
|
||||
| motorway | track | | 15 km/h | | 4.2 | |
|
||||
| primary | track | | 15 km/h | 15 km/h | 4.2 | 2.9 |
|
||||
| secondary | track | | 15 km/h | 15 km/h | 4.2 | 3.1 |
|
||||
| primary | track | | 15 km/h | 15 km/h | 4.2 | 2.1 |
|
||||
| secondary | track | | 15 km/h | 15 km/h | 4.2 | 2.7 |
|
||||
| tertiary | track | | 15 km/h | 15 km/h | 4.2 | 3.3 |
|
||||
| primary_link | track | | 15 km/h | 15 km/h | 4.2 | 2.9 |
|
||||
| secondary_link | track | | 15 km/h | 15 km/h | 4.2 | 3.1 |
|
||||
| primary_link | track | | 15 km/h | 15 km/h | 4.2 | 2.1 |
|
||||
| secondary_link | track | | 15 km/h | 15 km/h | 4.2 | 2.7 |
|
||||
| tertiary_link | track | | 15 km/h | 15 km/h | 4.2 | 3.3 |
|
||||
| residential | track | | 15 km/h | 15 km/h | 4.2 | 4.2 |
|
||||
| cycleway | track | | 15 km/h | 15 km/h | 4.2 | 4.2 |
|
||||
| footway | track | | 15 km/h | 4 km/h +-1 | 4.2 | 1.1 |
|
||||
| motorway | | track | 15 km/h | | 4.2 | |
|
||||
| primary | | track | 15 km/h | 15 km/h | 2.9 | 4.2 |
|
||||
| secondary | | track | 15 km/h | 15 km/h | 3.1 | 4.2 |
|
||||
| primary | | track | 15 km/h | 15 km/h | 2.1 | 4.2 |
|
||||
| secondary | | track | 15 km/h | 15 km/h | 2.7 | 4.2 |
|
||||
| tertiary | | track | 15 km/h | 15 km/h | 3.3 | 4.2 |
|
||||
| primary_link | | track | 15 km/h | 15 km/h | 2.9 | 4.2 |
|
||||
| secondary_link | | track | 15 km/h | 15 km/h | 3.1 | 4.2 |
|
||||
| primary_link | | track | 15 km/h | 15 km/h | 2.1 | 4.2 |
|
||||
| secondary_link | | track | 15 km/h | 15 km/h | 2.7 | 4.2 |
|
||||
| tertiary_link | | track | 15 km/h | 15 km/h | 3.3 | 4.2 |
|
||||
| residential | | track | 15 km/h | 15 km/h | 4.2 | 4.2 |
|
||||
| cycleway | | track | 15 km/h | 15 km/h | 4.2 | 4.2 |
|
||||
| footway | | track | 4 km/h +-1 | 15 km/h | 1.1 | 4.2 |
|
||||
| motorway | lane | | 15 km/h | | 4.2 | |
|
||||
| primary | lane | | 15 km/h | 15 km/h | 4.2 | 2.9 |
|
||||
| secondary | lane | | 15 km/h | 15 km/h | 4.2 | 3.1 |
|
||||
| primary | lane | | 15 km/h | 15 km/h | 4.2 | 2.1 |
|
||||
| secondary | lane | | 15 km/h | 15 km/h | 4.2 | 2.7 |
|
||||
| tertiary | lane | | 15 km/h | 15 km/h | 4.2 | 3.3 |
|
||||
| primary_link | lane | | 15 km/h | 15 km/h | 4.2 | 2.9 |
|
||||
| secondary_link | lane | | 15 km/h | 15 km/h | 4.2 | 3.1 |
|
||||
| primary_link | lane | | 15 km/h | 15 km/h | 4.2 | 2.1 |
|
||||
| secondary_link | lane | | 15 km/h | 15 km/h | 4.2 | 2.7 |
|
||||
| tertiary_link | lane | | 15 km/h | 15 km/h | 4.2 | 3.3 |
|
||||
| residential | lane | | 15 km/h +-1 | 15 km/h +-1 | 4.2 | 4.2 |
|
||||
| cycleway | lane | | 15 km/h | 15 km/h | 4.2 | 4.2 |
|
||||
| footway | lane | | 15 km/h | 4 km/h +-1 | 4.2 | 1.1 |
|
||||
| motorway | | lane | 15 km/h | | 4.2 | |
|
||||
| primary | | lane | 15 km/h | 15 km/h | 2.9 | 4.2 |
|
||||
| secondary | | lane | 15 km/h +-1 | 15 km/h +-1 | 3.1 | 4.2 |
|
||||
| primary | | lane | 15 km/h | 15 km/h | 2.1 | 4.2 |
|
||||
| secondary | | lane | 15 km/h +-1 | 15 km/h +-1 | 2.7 | 4.2 |
|
||||
| tertiary | | lane | 15 km/h | 15 km/h | 3.3 | 4.2 |
|
||||
| primary_link | | lane | 15 km/h | 15 km/h | 2.9 | 4.2 |
|
||||
| secondary_link | | lane | 15 km/h | 15 km/h | 3.1 | 4.2 |
|
||||
| primary_link | | lane | 15 km/h | 15 km/h | 2.1 | 4.2 |
|
||||
| secondary_link | | lane | 15 km/h | 15 km/h | 2.7 | 4.2 |
|
||||
| tertiary_link | | lane | 15 km/h | 15 km/h | 3.3 | 4.2 |
|
||||
| residential | | lane | 15 km/h | 15 km/h | 4.2 | 4.2 |
|
||||
| cycleway | | lane | 15 km/h | 15 km/h | 4.2 | 4.2 |
|
||||
| footway | | lane | 4 km/h +-1 | 15 km/h | 1.1 | 4.2 |
|
||||
| motorway | shared_lane | | 15 km/h | | 4.2 | |
|
||||
| primary | shared_lane | | 15 km/h | 15 km/h | 4.2 | 2.9 |
|
||||
| primary | shared_lane | | 15 km/h | 15 km/h | 4.2 | 2.1 |
|
||||
| motorway | | shared_lane | 15 km/h | | 4.2 | |
|
||||
| primary | | shared_lane | 15 km/h | 15 km/h | 2.9 | 4.2 |
|
||||
| primary | | shared_lane | 15 km/h | 15 km/h | 2.1 | 4.2 |
|
||||
|
||||
|
||||
Scenario: Bike - Don't apply penalties for all kind of cycleways
|
||||
|
||||
@@ -48,3 +48,22 @@ Feature: Car - Handle physical limitation
|
||||
| primary | | none | x |
|
||||
| primary | | no-sign | x |
|
||||
| primary | | unsigned | x |
|
||||
|
||||
Scenario: Car - Limited by length
|
||||
Then routability should be
|
||||
| highway | maxlength | bothw |
|
||||
| primary | | x |
|
||||
| primary | 1 | |
|
||||
| primary | 5 | x |
|
||||
| primary | unsigned | x |
|
||||
|
||||
Scenario: Car - Limited by weight
|
||||
Then routability should be
|
||||
| highway | maxweight | bothw |
|
||||
| primary | | x |
|
||||
| primary | 1 | |
|
||||
| primary | 3.5 | x |
|
||||
| primary | 35000 kg | x |
|
||||
| primary | 8.9t | x |
|
||||
| primary | 0.1 lbs | |
|
||||
| primary | unsigned | x |
|
||||
|
||||
@@ -19,7 +19,7 @@ Feature: Barriers
|
||||
| entrance | x |
|
||||
| wall | |
|
||||
| fence | |
|
||||
| some_tag | |
|
||||
| some_tag | x |
|
||||
| block | x |
|
||||
|
||||
Scenario: Foot - Access tag trumphs barriers
|
||||
|
||||
@@ -1209,3 +1209,33 @@ Feature: Simple Turns
|
||||
| a | c | knob,knob | depart,arrive |
|
||||
| d | e | soph,soph | depart,arrive |
|
||||
| d | a | soph,knob,knob | depart,turn left,arrive |
|
||||
|
||||
|
||||
# https://www.openstreetmap.org/node/30797565
|
||||
Scenario: No turn instruction when turning from unnamed onto unnamed
|
||||
Given the node map
|
||||
"""
|
||||
a
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
b----------------c
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
d
|
||||
"""
|
||||
|
||||
And the ways
|
||||
| nodes | highway | name | ref |
|
||||
| ab | trunk_link | | |
|
||||
| db | secondary | | L 460 |
|
||||
| bc | secondary | | |
|
||||
|
||||
When I route I should get
|
||||
| from | to | route | turns |
|
||||
| d | c | ,, | depart,turn right,arrive |
|
||||
|
||||
@@ -84,7 +84,47 @@ class OSRMDirectLoader extends OSRMBaseLoader {
|
||||
throw new Error(util.format('osrm-routed %s: %s', errorReason(err), err.cmd));
|
||||
}
|
||||
});
|
||||
callback();
|
||||
|
||||
this.child.readyFunc = (data) => {
|
||||
if (/running and waiting for requests/.test(data)) {
|
||||
this.child.stdout.removeListener('data', this.child.readyFunc);
|
||||
callback();
|
||||
}
|
||||
};
|
||||
this.child.stdout.on('data',this.child.readyFunc);
|
||||
}
|
||||
};
|
||||
|
||||
class OSRMmmapLoader extends OSRMBaseLoader {
|
||||
constructor (scope) {
|
||||
super(scope);
|
||||
}
|
||||
|
||||
load (inputFile, callback) {
|
||||
this.inputFile = inputFile;
|
||||
this.shutdown(() => {
|
||||
this.launch(callback);
|
||||
});
|
||||
}
|
||||
|
||||
osrmUp (callback) {
|
||||
if (this.osrmIsRunning()) return callback(new Error("osrm-routed already running!"));
|
||||
|
||||
const command_arguments = util.format('%s -p %d -i %s -a %s --mmap', this.inputFile, this.scope.OSRM_PORT, this.scope.OSRM_IP, this.scope.ROUTING_ALGORITHM);
|
||||
this.child = this.scope.runBin('osrm-routed', command_arguments, this.scope.environment, (err) => {
|
||||
if (err && err.signal !== 'SIGINT') {
|
||||
this.child = null;
|
||||
throw new Error(util.format('osrm-routed %s: %s', errorReason(err), err.cmd));
|
||||
}
|
||||
});
|
||||
|
||||
this.child.readyFunc = (data) => {
|
||||
if (/running and waiting for requests/.test(data)) {
|
||||
this.child.stdout.removeListener('data', this.child.readyFunc);
|
||||
callback();
|
||||
}
|
||||
};
|
||||
this.child.stdout.on('data',this.child.readyFunc);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -135,22 +175,32 @@ class OSRMLoader {
|
||||
this.scope = scope;
|
||||
this.sharedLoader = new OSRMDatastoreLoader(this.scope);
|
||||
this.directLoader = new OSRMDirectLoader(this.scope);
|
||||
this.mmapLoader = new OSRMmmapLoader(this.scope);
|
||||
this.method = scope.DEFAULT_LOAD_METHOD;
|
||||
}
|
||||
|
||||
load (inputFile, callback) {
|
||||
if (!this.loader) {
|
||||
this.loader = {shutdown: (cb) => cb() };
|
||||
}
|
||||
if (this.method === 'datastore') {
|
||||
this.directLoader.shutdown((err) => {
|
||||
this.loader.shutdown((err) => {
|
||||
if (err) return callback(err);
|
||||
this.loader = this.sharedLoader;
|
||||
this.sharedLoader.load(inputFile, callback);
|
||||
});
|
||||
} else if (this.method === 'directly') {
|
||||
this.sharedLoader.shutdown((err) => {
|
||||
this.loader.shutdown((err) => {
|
||||
if (err) return callback(err);
|
||||
this.loader = this.directLoader;
|
||||
this.directLoader.load(inputFile, callback);
|
||||
});
|
||||
} else if (this.method === 'mmap') {
|
||||
this.loader.shutdown((err) => {
|
||||
if (err) return callback(err);
|
||||
this.loader = this.mmapLoader;
|
||||
this.mmapLoader.load(inputFile, callback);
|
||||
});
|
||||
} else {
|
||||
callback(new Error('*** Unknown load method ' + method));
|
||||
}
|
||||
|
||||
@@ -1,74 +1,88 @@
|
||||
var util = require('util');
|
||||
|
||||
module.exports = function () {
|
||||
this.When(/^I request a travel time matrix I should get$/, (table, callback) => {
|
||||
var NO_ROUTE = 2147483647; // MAX_INT
|
||||
const durationsRegex = new RegExp(/^I request a travel time matrix I should get$/);
|
||||
const distancesRegex = new RegExp(/^I request a travel distance matrix I should get$/);
|
||||
|
||||
var tableRows = table.raw();
|
||||
const DURATIONS_NO_ROUTE = 2147483647; // MAX_INT
|
||||
const DISTANCES_NO_ROUTE = 3.40282e+38; // MAX_FLOAT
|
||||
|
||||
if (tableRows[0][0] !== '') throw new Error('*** Top-left cell of matrix table must be empty');
|
||||
this.When(durationsRegex, function(table, callback) {tableParse.call(this, table, DURATIONS_NO_ROUTE, 'durations', callback);}.bind(this));
|
||||
this.When(distancesRegex, function(table, callback) {tableParse.call(this, table, DISTANCES_NO_ROUTE, 'distances', callback);}.bind(this));
|
||||
};
|
||||
|
||||
var waypoints = [],
|
||||
columnHeaders = tableRows[0].slice(1),
|
||||
rowHeaders = tableRows.map((h) => h[0]).slice(1),
|
||||
symmetric = columnHeaders.length == rowHeaders.length && columnHeaders.every((ele, i) => ele === rowHeaders[i]);
|
||||
const durationsParse = function(v) { return isNaN(parseInt(v)); };
|
||||
const distancesParse = function(v) { return isNaN(parseFloat(v)); };
|
||||
|
||||
if (symmetric) {
|
||||
columnHeaders.forEach((nodeName) => {
|
||||
var node = this.findNodeByName(nodeName);
|
||||
if (!node) throw new Error(util.format('*** unknown node "%s"', nodeName));
|
||||
waypoints.push({ coord: node, type: 'loc' });
|
||||
function tableParse(table, noRoute, annotation, callback) {
|
||||
|
||||
const parse = annotation == 'distances' ? distancesParse : durationsParse;
|
||||
const params = this.queryParams;
|
||||
params.annotations = annotation == 'distances' ? 'distance' : 'duration';
|
||||
|
||||
var tableRows = table.raw();
|
||||
|
||||
if (tableRows[0][0] !== '') throw new Error('*** Top-left cell of matrix table must be empty');
|
||||
|
||||
var waypoints = [],
|
||||
columnHeaders = tableRows[0].slice(1),
|
||||
rowHeaders = tableRows.map((h) => h[0]).slice(1),
|
||||
symmetric = columnHeaders.length == rowHeaders.length && columnHeaders.every((ele, i) => ele === rowHeaders[i]);
|
||||
|
||||
if (symmetric) {
|
||||
columnHeaders.forEach((nodeName) => {
|
||||
var node = this.findNodeByName(nodeName);
|
||||
if (!node) throw new Error(util.format('*** unknown node "%s"', nodeName));
|
||||
waypoints.push({ coord: node, type: 'loc' });
|
||||
});
|
||||
} else {
|
||||
columnHeaders.forEach((nodeName) => {
|
||||
var node = this.findNodeByName(nodeName);
|
||||
if (!node) throw new Error(util.format('*** unknown node "%s"', nodeName));
|
||||
waypoints.push({ coord: node, type: 'dst' });
|
||||
});
|
||||
rowHeaders.forEach((nodeName) => {
|
||||
var node = this.findNodeByName(nodeName);
|
||||
if (!node) throw new Error(util.format('*** unknown node "%s"', nodeName));
|
||||
waypoints.push({ coord: node, type: 'src' });
|
||||
});
|
||||
}
|
||||
|
||||
var actual = [];
|
||||
actual.push(table.headers);
|
||||
|
||||
this.reprocessAndLoadData((e) => {
|
||||
if (e) return callback(e);
|
||||
// compute matrix
|
||||
|
||||
this.requestTable(waypoints, params, (err, response) => {
|
||||
if (err) return callback(err);
|
||||
if (!response.body.length) return callback(new Error('Invalid response body'));
|
||||
|
||||
var json = JSON.parse(response.body);
|
||||
|
||||
var result = json[annotation].map(row => {
|
||||
var hashes = {};
|
||||
row.forEach((v, i) => { hashes[tableRows[0][i+1]] = parse(v) ? '' : v; });
|
||||
return hashes;
|
||||
});
|
||||
} else {
|
||||
columnHeaders.forEach((nodeName) => {
|
||||
var node = this.findNodeByName(nodeName);
|
||||
if (!node) throw new Error(util.format('*** unknown node "%s"', nodeName));
|
||||
waypoints.push({ coord: node, type: 'dst' });
|
||||
});
|
||||
rowHeaders.forEach((nodeName) => {
|
||||
var node = this.findNodeByName(nodeName);
|
||||
if (!node) throw new Error(util.format('*** unknown node "%s"', nodeName));
|
||||
waypoints.push({ coord: node, type: 'src' });
|
||||
});
|
||||
}
|
||||
|
||||
var actual = [];
|
||||
actual.push(table.headers);
|
||||
|
||||
this.reprocessAndLoadData((e) => {
|
||||
if (e) return callback(e);
|
||||
// compute matrix
|
||||
var params = this.queryParams;
|
||||
|
||||
this.requestTable(waypoints, params, (err, response) => {
|
||||
if (err) return callback(err);
|
||||
if (!response.body.length) return callback(new Error('Invalid response body'));
|
||||
|
||||
var json = JSON.parse(response.body);
|
||||
|
||||
var result = json['durations'].map(row => {
|
||||
var hashes = {};
|
||||
row.forEach((v, i) => { hashes[tableRows[0][i+1]] = isNaN(parseInt(v)) ? '' : v; });
|
||||
return hashes;
|
||||
});
|
||||
|
||||
var testRow = (row, ri, cb) => {
|
||||
for (var k in result[ri]) {
|
||||
if (this.FuzzyMatch.match(result[ri][k], row[k])) {
|
||||
result[ri][k] = row[k];
|
||||
} else if (row[k] === '' && result[ri][k] === NO_ROUTE) {
|
||||
result[ri][k] = '';
|
||||
} else {
|
||||
result[ri][k] = result[ri][k].toString();
|
||||
}
|
||||
var testRow = (row, ri, cb) => {
|
||||
for (var k in result[ri]) {
|
||||
if (this.FuzzyMatch.match(result[ri][k], row[k])) {
|
||||
result[ri][k] = row[k];
|
||||
} else if (row[k] === '' && result[ri][k] === noRoute) {
|
||||
result[ri][k] = '';
|
||||
} else {
|
||||
result[ri][k] = result[ri][k].toString();
|
||||
}
|
||||
}
|
||||
|
||||
result[ri][''] = row[''];
|
||||
cb(null, result[ri]);
|
||||
};
|
||||
result[ri][''] = row[''];
|
||||
cb(null, result[ri]);
|
||||
};
|
||||
|
||||
this.processRowsAndDiff(table, testRow, callback);
|
||||
});
|
||||
this.processRowsAndDiff(table, testRow, callback);
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
@@ -21,7 +21,8 @@ module.exports = {
|
||||
matchRe = want.match(/^\/(.*)\/$/),
|
||||
// we use this for matching before/after bearing
|
||||
matchBearingListAbs = want.match(/^((\d+)->(\d+))(,(\d+)->(\d+))*\s+\+\-(.+)$/),
|
||||
matchIntersectionListAbs = want.match(/^(((((true|false):\d+)\s{0,1})+,{0,1})+;{0,1})+\s+\+\-(.+)$/);
|
||||
matchIntersectionListAbs = want.match(/^(((((true|false):\d+)\s{0,1})+,{0,1})+;{0,1})+\s+\+\-(.+)$/),
|
||||
matchRangeNumbers = want.match(/\d+\+\-\d+/);
|
||||
|
||||
function inRange(margin, got, want) {
|
||||
var fromR = parseFloat(want) - margin,
|
||||
@@ -105,6 +106,11 @@ module.exports = {
|
||||
return inRange(margin, got, matchAbs[1]);
|
||||
} else if (matchRe) { // regex: /a,b,.*/
|
||||
return got.match(matchRe[1]);
|
||||
} else if (matchRangeNumbers) {
|
||||
let real_want_and_margin = want.split('+-'),
|
||||
margin = parseFloat(real_want_and_margin[1].trim()),
|
||||
real_want = parseFloat(real_want_and_margin[0].trim());
|
||||
return inRange(margin, got, real_want);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ module.exports = function () {
|
||||
this.DEFAULT_ENVIRONMENT = Object.assign({STXXLCFG: stxxl_config}, process.env);
|
||||
this.DEFAULT_PROFILE = 'bicycle';
|
||||
this.DEFAULT_INPUT_FORMAT = 'osm';
|
||||
this.DEFAULT_LOAD_METHOD = 'datastore';
|
||||
this.DEFAULT_LOAD_METHOD = process.argv[process.argv.indexOf('-m') +1].match('mmap') ? 'mmap' : 'datastore';
|
||||
this.DEFAULT_ORIGIN = [1,1];
|
||||
this.OSM_USER = 'osrm';
|
||||
this.OSM_UID = 1;
|
||||
|
||||
@@ -51,7 +51,7 @@ module.exports = function () {
|
||||
.defer(rimraf, this.scenarioLogFile)
|
||||
.awaitAll(callback);
|
||||
// uncomment to get path to logfile
|
||||
// console.log(" Writing logging output to " + this.scenarioLogFile)
|
||||
// console.log(' Writing logging output to ' + this.scenarioLogFile);
|
||||
});
|
||||
|
||||
this.After((scenario, callback) => {
|
||||
|
||||
@@ -226,3 +226,22 @@ Feature: Distance calculation
|
||||
| x | v | xv,xv | 424m +-1 |
|
||||
| x | w | xw,xw | 360m +-1 |
|
||||
| x | y | xy,xy | 316m +-1 |
|
||||
|
||||
|
||||
# Check rounding errors
|
||||
Scenario: Distances Long distances
|
||||
Given a grid size of 1000 meters
|
||||
Given the node map
|
||||
"""
|
||||
a b c d
|
||||
"""
|
||||
|
||||
And the ways
|
||||
| nodes |
|
||||
| abcd |
|
||||
|
||||
When I route I should get
|
||||
| from | to | distance |
|
||||
| a | b | 1000m +-3 |
|
||||
| a | c | 2000m +-3 |
|
||||
| a | d | 3000m +-3 |
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
@matrix @testbot
|
||||
Feature: Basic Distance Matrix
|
||||
# note that results are travel time, specified in 1/10th of seconds
|
||||
# since testbot uses a default speed of 100m/10s, the result matches
|
||||
# the number of meters as long as the way type is the default 'primary'
|
||||
# note that results of travel distance are in metres
|
||||
|
||||
Background:
|
||||
Given the profile "testbot"
|
||||
And the partition extra arguments "--small-component-size 1 --max-cell-sizes 2,4,8,16"
|
||||
|
||||
Scenario: Testbot - Travel time matrix of minimal network
|
||||
Scenario: Testbot - Travel distance matrix of minimal network
|
||||
Given the node map
|
||||
"""
|
||||
a b
|
||||
@@ -18,12 +16,99 @@ Feature: Basic Distance Matrix
|
||||
| nodes |
|
||||
| ab |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | a | b |
|
||||
| a | 0 | 10 |
|
||||
| b | 10 | 0 |
|
||||
When I request a travel distance matrix I should get
|
||||
| | a | b |
|
||||
| a | 0 | 100+-1 |
|
||||
| b | 100+-1 | 0 |
|
||||
|
||||
Scenario: Testbot - Travel time matrix with different way speeds
|
||||
Scenario: Testbot - Travel distance matrix of minimal network with toll exclude
|
||||
Given the query options
|
||||
| exclude | toll |
|
||||
|
||||
Given the node map
|
||||
"""
|
||||
a b
|
||||
c d
|
||||
"""
|
||||
|
||||
And the ways
|
||||
| nodes | highway | toll | # |
|
||||
| ab | motorway | | not drivable for exclude=motorway |
|
||||
| cd | primary | | always drivable |
|
||||
| ac | primary | yes | not drivable for exclude=toll and exclude=motorway,toll |
|
||||
| bd | motorway | yes | not drivable for exclude=toll and exclude=motorway,toll |
|
||||
|
||||
When I request a travel distance matrix I should get
|
||||
| | a | b | c | d |
|
||||
| a | 0 | 100+-1 | | |
|
||||
| b | 100+-1 | 0 | | |
|
||||
| c | | | 0 | 100+-1 |
|
||||
| d | | | 100+-1 | 0 |
|
||||
|
||||
Scenario: Testbot - Travel distance matrix of minimal network with motorway exclude
|
||||
Given the query options
|
||||
| exclude | motorway |
|
||||
|
||||
Given the node map
|
||||
"""
|
||||
a b
|
||||
c d
|
||||
"""
|
||||
|
||||
And the ways
|
||||
| nodes | highway | # |
|
||||
| ab | motorway | not drivable for exclude=motorway |
|
||||
| cd | residential | |
|
||||
| ac | residential | |
|
||||
| bd | residential | |
|
||||
|
||||
When I request a travel distance matrix I should get
|
||||
| | a | b | c | d |
|
||||
| a | 0 | 300+-2 | 100+-2 | 200+-2 |
|
||||
|
||||
Scenario: Testbot - Travel distance matrix of minimal network disconnected motorway exclude
|
||||
Given the query options
|
||||
| exclude | motorway |
|
||||
And the extract extra arguments "--small-component-size 4"
|
||||
|
||||
Given the node map
|
||||
"""
|
||||
ab efgh
|
||||
cd
|
||||
"""
|
||||
|
||||
And the ways
|
||||
| nodes | highway | # |
|
||||
| be | motorway | not drivable for exclude=motorway |
|
||||
| abcd | residential | |
|
||||
| efgh | residential | |
|
||||
|
||||
When I request a travel distance matrix I should get
|
||||
| | a | b | e |
|
||||
| a | 0 | 50+-1 | |
|
||||
|
||||
Scenario: Testbot - Travel distance matrix of minimal network with motorway and toll excludes
|
||||
Given the query options
|
||||
| exclude | motorway,toll |
|
||||
|
||||
Given the node map
|
||||
"""
|
||||
a b e f
|
||||
c d g h
|
||||
"""
|
||||
|
||||
And the ways
|
||||
| nodes | highway | toll | # |
|
||||
| be | motorway | | not drivable for exclude=motorway |
|
||||
| dg | primary | yes | not drivable for exclude=toll |
|
||||
| abcd | residential | | |
|
||||
| efgh | residential | | |
|
||||
|
||||
When I request a travel distance matrix I should get
|
||||
| | a | b | e | g |
|
||||
| a | 0 | 100+-1 | | |
|
||||
|
||||
Scenario: Testbot - Travel distance matrix with different way speeds
|
||||
Given the node map
|
||||
"""
|
||||
a b c d
|
||||
@@ -35,40 +120,25 @@ Feature: Basic Distance Matrix
|
||||
| bc | secondary |
|
||||
| cd | tertiary |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | a | b | c | d |
|
||||
| a | 0 | 10 | 30 | 60 |
|
||||
| b | 10 | 0 | 20 | 50 |
|
||||
| c | 30 | 20 | 0 | 30 |
|
||||
| d | 60 | 50 | 30 | 0 |
|
||||
When I request a travel distance matrix I should get
|
||||
| | a | b | c | d |
|
||||
| a | 0 | 100+-1 | 200+-1 | 300+-1 |
|
||||
| b | 100+-1 | 0 | 100+-1 | 200+-1 |
|
||||
| c | 200+-1 | 100+-1 | 0 | 100+-1 |
|
||||
| d | 300+-1 | 200+-1 | 100+-1 | 0 |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | a | b | c | d |
|
||||
| a | 0 | 10 | 30 | 60 |
|
||||
When I request a travel distance matrix I should get
|
||||
| | a | b | c | d |
|
||||
| a | 0 | 100+-1 | 200+-1 | 300+-1 |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | a |
|
||||
| a | 0 |
|
||||
| b | 10 |
|
||||
| c | 30 |
|
||||
| d | 60 |
|
||||
When I request a travel distance matrix I should get
|
||||
| | a |
|
||||
| a | 0 |
|
||||
| b | 100+-1 |
|
||||
| c | 200+-1 |
|
||||
| d | 300+-1 |
|
||||
|
||||
Scenario: Testbot - Travel time matrix with fuzzy match
|
||||
Given the node map
|
||||
"""
|
||||
a b
|
||||
"""
|
||||
|
||||
And the ways
|
||||
| nodes |
|
||||
| ab |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | a | b |
|
||||
| a | 0 | 10 |
|
||||
| b | 10 | 0 |
|
||||
|
||||
Scenario: Testbot - Travel time matrix of small grid
|
||||
Scenario: Testbot - Travel distance matrix of small grid
|
||||
Given the node map
|
||||
"""
|
||||
a b c
|
||||
@@ -83,14 +153,14 @@ Feature: Basic Distance Matrix
|
||||
| be |
|
||||
| cf |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | a | b | e | f |
|
||||
| a | 0 | 10 | 20 | 30 |
|
||||
| b | 10 | 0 | 10 | 20 |
|
||||
| e | 20 | 10 | 0 | 10 |
|
||||
| f | 30 | 20 | 10 | 0 |
|
||||
When I request a travel distance matrix I should get
|
||||
| | a | b | e | f |
|
||||
| a | 0 | 100+-1 | 200+-1 | 300+-1 |
|
||||
| b | 100+-1 | 0 | 100+-1 | 200+-1 |
|
||||
| e | 200+-1 | 100+-1 | 0 | 100+-1 |
|
||||
| f | 300+-1 | 200+-1 | 100+-1 | 0 |
|
||||
|
||||
Scenario: Testbot - Travel time matrix of network with unroutable parts
|
||||
Scenario: Testbot - Travel distance matrix of network with unroutable parts
|
||||
Given the node map
|
||||
"""
|
||||
a b
|
||||
@@ -100,12 +170,12 @@ Feature: Basic Distance Matrix
|
||||
| nodes | oneway |
|
||||
| ab | yes |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | a | b |
|
||||
| a | 0 | 10 |
|
||||
| b | | 0 |
|
||||
When I request a travel distance matrix I should get
|
||||
| | a | b |
|
||||
| a | 0 | 100+-1 |
|
||||
| b | | 0 |
|
||||
|
||||
Scenario: Testbot - Travel time matrix of network with oneways
|
||||
Scenario: Testbot - Travel distance matrix of network with oneways
|
||||
Given the node map
|
||||
"""
|
||||
x a b y
|
||||
@@ -118,14 +188,14 @@ Feature: Basic Distance Matrix
|
||||
| xa | |
|
||||
| by | |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | x | y | d | e |
|
||||
| x | 0 | 30 | 40 | 30 |
|
||||
| y | 50 | 0 | 30 | 20 |
|
||||
| d | 20 | 30 | 0 | 30 |
|
||||
| e | 30 | 40 | 10 | 0 |
|
||||
When I request a travel distance matrix I should get
|
||||
| | x | y | d | e |
|
||||
| x | 0 | 300+-2 | 400+-2 | 300+-2 |
|
||||
| y | 500+-2 | 0 | 300+-2 | 200+-2 |
|
||||
| d | 200+-2 | 300+-2 | 0 | 300+-2 |
|
||||
| e | 300+-2 | 400+-2 | 100+-2 | 0 |
|
||||
|
||||
Scenario: Testbot - Rectangular travel time matrix
|
||||
Scenario: Testbot - Rectangular travel distance matrix
|
||||
Given the node map
|
||||
"""
|
||||
a b c
|
||||
@@ -140,51 +210,57 @@ Feature: Basic Distance Matrix
|
||||
| be |
|
||||
| cf |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | a | b | e | f |
|
||||
| a | 0 | 10 | 20 | 30 |
|
||||
When I route I should get
|
||||
| from | to | distance |
|
||||
| e | a | 200m +- 1 |
|
||||
| e | b | 100m +- 1 |
|
||||
| f | a | 300m +- 1 |
|
||||
| f | b | 200m +- 1 |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | a |
|
||||
| a | 0 |
|
||||
| b | 10 |
|
||||
| e | 20 |
|
||||
| f | 30 |
|
||||
When I request a travel distance matrix I should get
|
||||
| | a | b | e | f |
|
||||
| a | 0 | 100+-1 | 200+-1 | 300+-1 |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | a | b | e | f |
|
||||
| a | 0 | 10 | 20 | 30 |
|
||||
| b | 10 | 0 | 10 | 20 |
|
||||
When I request a travel distance matrix I should get
|
||||
| | a |
|
||||
| a | 0 |
|
||||
| b | 100+-1 |
|
||||
| e | 200+-1 |
|
||||
| f | 300+-1 |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | a | b |
|
||||
| a | 0 | 10 |
|
||||
| b | 10 | 0 |
|
||||
| e | 20 | 10 |
|
||||
| f | 30 | 20 |
|
||||
When I request a travel distance matrix I should get
|
||||
| | a | b | e | f |
|
||||
| a | 0 | 100+-1 | 200+-1 | 300+-1 |
|
||||
| b | 100+-1 | 0 | 100+-1 | 200+-1 |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | a | b | e | f |
|
||||
| a | 0 | 10 | 20 | 30 |
|
||||
| b | 10 | 0 | 10 | 20 |
|
||||
| e | 20 | 10 | 0 | 10 |
|
||||
When I request a travel distance matrix I should get
|
||||
| | a | b |
|
||||
| a | 0 | 100+-1 |
|
||||
| b | 100+-1 | 0 |
|
||||
| e | 200+-1 | 100+-1 |
|
||||
| f | 300+-1 | 200+-1 |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | a | b | e |
|
||||
| a | 0 | 10 | 20 |
|
||||
| b | 10 | 0 | 10 |
|
||||
| e | 20 | 10 | 0 |
|
||||
| f | 30 | 20 | 10 |
|
||||
When I request a travel distance matrix I should get
|
||||
| | a | b | e | f |
|
||||
| a | 0 | 100+-1 | 200+-1 | 300+-1 |
|
||||
| b | 100+-1 | 0 | 100+-1 | 200+-1 |
|
||||
| e | 200+-1 | 100+-1 | 0 | 100+-1 |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | a | b | e | f |
|
||||
| a | 0 | 10 | 20 | 30 |
|
||||
| b | 10 | 0 | 10 | 20 |
|
||||
| e | 20 | 10 | 0 | 10 |
|
||||
| f | 30 | 20 | 10 | 0 |
|
||||
When I request a travel distance matrix I should get
|
||||
| | a | b | e |
|
||||
| a | 0 | 100+-1 | 200+-1 |
|
||||
| b | 100+-1 | 0 | 100+-1 |
|
||||
| e | 200+-1 | 100+-1 | 0 |
|
||||
| f | 300+-1 | 200+-1 | 100+-1 |
|
||||
|
||||
When I request a travel distance matrix I should get
|
||||
| | a | b | e | f |
|
||||
| a | 0 | 100+-1 | 200+-1 | 300+-1 |
|
||||
| b | 100+-1 | 0 | 100+-1 | 200+-1 |
|
||||
| e | 200+-1 | 100+-1 | 0 | 100+-1 |
|
||||
| f | 300+-1 | 200+-1 | 100+-1 | 0 |
|
||||
|
||||
Scenario: Testbot - Travel time 3x2 matrix
|
||||
Scenario: Testbot - Travel distance 3x2 matrix
|
||||
Given the node map
|
||||
"""
|
||||
a b c
|
||||
@@ -199,10 +275,11 @@ Feature: Basic Distance Matrix
|
||||
| be |
|
||||
| cf |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | b | e | f |
|
||||
| a | 10 | 20 | 30 |
|
||||
| b | 0 | 10 | 20 |
|
||||
|
||||
When I request a travel distance matrix I should get
|
||||
| | b | e | f |
|
||||
| a | 100+-1 | 200+-1 | 300+-1 |
|
||||
| b | 0 | 100+-1 | 200+-1 |
|
||||
|
||||
Scenario: Testbot - All coordinates are from same small component
|
||||
Given a grid size of 300 meters
|
||||
@@ -221,10 +298,10 @@ Feature: Basic Distance Matrix
|
||||
| da |
|
||||
| fg |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | f | g |
|
||||
| f | 0 | 30 |
|
||||
| g | 30 | 0 |
|
||||
When I request a travel distance matrix I should get
|
||||
| | f | g |
|
||||
| f | 0 | 300+-2 |
|
||||
| g | 300+-2 | 0 |
|
||||
|
||||
Scenario: Testbot - Coordinates are from different small component and snap to big CC
|
||||
Given a grid size of 300 meters
|
||||
@@ -244,14 +321,25 @@ Feature: Basic Distance Matrix
|
||||
| fg |
|
||||
| hi |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | f | g | h | i |
|
||||
| f | 0 | 30 | 0 | 30 |
|
||||
| g | 30 | 0 | 30 | 0 |
|
||||
| h | 0 | 30 | 0 | 30 |
|
||||
| i | 30 | 0 | 30 | 0 |
|
||||
When I route I should get
|
||||
| from | to | distance |
|
||||
| f | g | 300m |
|
||||
| f | i | 300m |
|
||||
| g | f | 300m |
|
||||
| g | h | 300m |
|
||||
| h | g | 300m |
|
||||
| h | i | 300m |
|
||||
| i | f | 300m |
|
||||
| i | h | 300m |
|
||||
|
||||
Scenario: Testbot - Travel time matrix with loops
|
||||
When I request a travel distance matrix I should get
|
||||
| | f | g | h | i |
|
||||
| f | 0 | 300+-2 | 0 | 300+-2 |
|
||||
| g | 300+-2 | 0 | 300+-2 | 0 |
|
||||
| h | 0 | 300+-2 | 0 | 300+-2 |
|
||||
| i | 300+-2 | 0 | 300+-2 | 0 |
|
||||
|
||||
Scenario: Testbot - Travel distance matrix with loops
|
||||
Given the node map
|
||||
"""
|
||||
a 1 2 b
|
||||
@@ -265,14 +353,15 @@ Feature: Basic Distance Matrix
|
||||
| cd | yes |
|
||||
| da | yes |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | 1 | 2 | 3 | 4 |
|
||||
| 1 | 0 | 10 +-1 | 40 +-1 | 50 +-1 |
|
||||
| 2 | 70 +-1 | 0 | 30 +-1 | 40 +-1 |
|
||||
| 3 | 40 +-1 | 50 +-1 | 0 | 10 +-1 |
|
||||
| 4 | 30 +-1 | 40 +-1 | 70 +-1 | 0 |
|
||||
When I request a travel distance matrix I should get
|
||||
| | 1 | 2 | 3 | 4 |
|
||||
| 1 | 0 | 100+-1 | 400+-1 | 500+-1 |
|
||||
| 2 | 700+-1 | 0 | 300+-1 | 400+-1 |
|
||||
| 3 | 400+-1 | 500+-1 | 0 | 100+-1 |
|
||||
| 4 | 300+-1 | 400+-1 | 700+-1 | 0 |
|
||||
|
||||
Scenario: Testbot - Travel time matrix based on segment durations
|
||||
|
||||
Scenario: Testbot - Travel distance matrix based on segment durations
|
||||
Given the profile file
|
||||
"""
|
||||
local functions = require('testbot')
|
||||
@@ -301,20 +390,19 @@ Feature: Basic Distance Matrix
|
||||
"""
|
||||
|
||||
And the ways
|
||||
| nodes |
|
||||
| abcd |
|
||||
| ce |
|
||||
| nodes |
|
||||
| abcd |
|
||||
| ce |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | a | b | c | d | e |
|
||||
| a | 0 | 11 | 22 | 33 | 33 |
|
||||
| b | 11 | 0 | 11 | 22 | 22 |
|
||||
| c | 22 | 11 | 0 | 11 | 11 |
|
||||
| d | 33 | 22 | 11 | 0 | 22 |
|
||||
| e | 33 | 22 | 11 | 22 | 0 |
|
||||
When I request a travel distance matrix I should get
|
||||
| | a | b | c | d | e |
|
||||
| a | 0 | 100+-2 | 200+-2 | 300+-2 | 400+-2 |
|
||||
| b | 100+-2 | 0 | 100+-2 | 200+-2 | 300+-2 |
|
||||
| c | 200+-2 | 100+-2 | 0 | 100+-2 | 200+-2 |
|
||||
| d | 300+-2 | 200+-2 | 100+-2 | 0 | 300+-2 |
|
||||
| e | 400+-2 | 300+-2 | 200+-2 | 300+-2 | 0 |
|
||||
|
||||
|
||||
Scenario: Testbot - Travel time matrix for alternative loop paths
|
||||
Scenario: Testbot - Travel distance matrix for alternative loop paths
|
||||
Given the profile file
|
||||
"""
|
||||
local functions = require('testbot')
|
||||
@@ -350,62 +438,132 @@ Feature: Basic Distance Matrix
|
||||
| dc | yes |
|
||||
| ca | yes |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|
||||
| 1 | 0 | 11 | 3 | 2 | 6 | 5 | 8.9 | 7.9 |
|
||||
| 2 | 1 | 0 | 4 | 3 | 7 | 6 | 9.9 | 8.9 |
|
||||
| 3 | 9 | 8 | 0 | 11 | 3 | 2 | 5.9 | 4.9 |
|
||||
| 4 | 10 | 9 | 1 | 0 | 4 | 3 | 6.9 | 5.9 |
|
||||
| 5 | 6 | 5 | 9 | 8 | 0 | 11 | 2.9 | 1.9 |
|
||||
| 6 | 7 | 6 | 10 | 9 | 1 | 0 | 3.9 | 2.9 |
|
||||
| 7 | 3.1 | 2.1 | 6.1 | 5.1 | 9.1 | 8.1 | 0 | 11 |
|
||||
| 8 | 4.1 | 3.1 | 7.1 | 6.1 | 10.1 | 9.1 | 1 | 0 |
|
||||
When I request a travel distance matrix I should get
|
||||
| | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|
||||
| 1 | 0 | 1100+-5 | 300+-5 | 200+-5 | 600+-5 | 500+-5 | 900+-5 | 800+-5 |
|
||||
| 2 | 100+-5 | 0 | 400+-5 | 300+-5 | 700+-5 | 600+-5 | 1000+-5 | 900+-5 |
|
||||
| 3 | 900+-5 | 800+-5 | 0 | 1100+-5 | 300+-5 | 200+-5 | 600+-5 | 500+-5 |
|
||||
| 4 | 1000+-5 | 900+-5 | 100+-5 | 0 | 400+-5 | 300+-5 | 700+-5 | 600+-5 |
|
||||
| 5 | 600+-5 | 500+-5 | 900+-5 | 800+-5 | 0 | 1100+-5 | 300+-5 | 200+-5 |
|
||||
| 6 | 700+-5 | 600+-5 | 1000+-5 | 900+-5 | 100+-5 | 0 | 400+-5 | 300+-5 |
|
||||
| 7 | 300+-5 | 200+-5 | 600+-5 | 500+-5 | 900+-5 | 800+-5 | 0 | 1100+-5 |
|
||||
| 8 | 400+-5 | 300+-5 | 700+-5 | 600+-5 | 1000+-5 | 900+-5 | 100+-5 | 0 |
|
||||
|
||||
When I request a travel distance matrix I should get
|
||||
| | 1 |
|
||||
| 1 | 0 |
|
||||
| 2 | 100+-5 |
|
||||
| 3 | 900+-5 |
|
||||
| 4 | 1000+-5 |
|
||||
| 5 | 600+-5 |
|
||||
| 6 | 700+-5 |
|
||||
| 7 | 300+-5 |
|
||||
| 8 | 400+-5 |
|
||||
|
||||
Scenario: Testbot - Travel time matrix with ties
|
||||
Given the profile file
|
||||
"""
|
||||
local functions = require('testbot')
|
||||
functions.process_segment = function(profile, segment)
|
||||
segment.weight = 1
|
||||
segment.duration = 1
|
||||
end
|
||||
functions.process_turn = function(profile, turn)
|
||||
if turn.angle >= 0 then
|
||||
turn.duration = 16
|
||||
else
|
||||
turn.duration = 4
|
||||
end
|
||||
turn.weight = 0
|
||||
end
|
||||
return functions
|
||||
"""
|
||||
And the node map
|
||||
Scenario: Testbot - Travel distance matrix with ties
|
||||
Given the node map
|
||||
"""
|
||||
a b
|
||||
a b
|
||||
|
||||
c d
|
||||
"""
|
||||
|
||||
And the ways
|
||||
| nodes |
|
||||
| ab |
|
||||
| ac |
|
||||
| bd |
|
||||
| dc |
|
||||
|
||||
| nodes |
|
||||
| ab |
|
||||
| ac |
|
||||
| bd |
|
||||
| dc |
|
||||
|
||||
When I route I should get
|
||||
| from | to | route | distance | time | weight |
|
||||
| a | c | ac,ac | 200m | 5s | 5 |
|
||||
| from | to | route | distance | time | weight |
|
||||
| a | c | ac,ac | 200m | 20s | 20 |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | a | b | c | d |
|
||||
| a | 0 | 1 | 5 | 10 |
|
||||
When I route I should get
|
||||
| from | to | route | distance |
|
||||
| a | b | ab,ab | 450m |
|
||||
| a | c | ac,ac | 200m |
|
||||
| a | d | ac,dc,dc | 500m +- 1 |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | a |
|
||||
| a | 0 |
|
||||
| b | 1 |
|
||||
| c | 15 |
|
||||
| d | 10 |
|
||||
When I request a travel distance matrix I should get
|
||||
| | a | b | c | d |
|
||||
| a | 0 | 450+-2 | 200+-2 | 500+-2 |
|
||||
|
||||
When I request a travel distance matrix I should get
|
||||
| | a |
|
||||
| a | 0 |
|
||||
| b | 450+-2 |
|
||||
| c | 200+-2 |
|
||||
| d | 500+-2 |
|
||||
|
||||
When I request a travel distance matrix I should get
|
||||
| | a | c |
|
||||
| a | 0 | 200+-2 |
|
||||
| c | 200+-2 | 0 |
|
||||
|
||||
|
||||
# Check rounding errors
|
||||
Scenario: Testbot - Long distances in tables
|
||||
Given a grid size of 1000 meters
|
||||
Given the node map
|
||||
"""
|
||||
a b c d
|
||||
"""
|
||||
|
||||
And the ways
|
||||
| nodes |
|
||||
| abcd |
|
||||
|
||||
When I request a travel distance matrix I should get
|
||||
| | a | b | c | d |
|
||||
| a | 0 | 1000+-3 | 2000+-3 | 3000+-3 |
|
||||
|
||||
|
||||
Scenario: Testbot - OneToMany vs ManyToOne
|
||||
Given the node map
|
||||
"""
|
||||
a b
|
||||
c
|
||||
"""
|
||||
|
||||
And the ways
|
||||
| nodes | oneway |
|
||||
| ab | yes |
|
||||
| ac | |
|
||||
| bc | |
|
||||
|
||||
When I request a travel distance matrix I should get
|
||||
| | a | b |
|
||||
| b | 240.4 | 0 |
|
||||
|
||||
When I request a travel distance matrix I should get
|
||||
| | a |
|
||||
| a | 0 |
|
||||
| b | 240.4 |
|
||||
|
||||
Scenario: Testbot - Varying distances between nodes
|
||||
Given the node map
|
||||
"""
|
||||
a b c d
|
||||
|
||||
e
|
||||
|
||||
|
||||
|
||||
f
|
||||
"""
|
||||
|
||||
And the ways
|
||||
| nodes | oneway |
|
||||
| feabcd | yes |
|
||||
| ec | |
|
||||
| fd | |
|
||||
|
||||
When I request a travel distance matrix I should get
|
||||
| | a | b | c | d | e | f |
|
||||
| a | 0 | 100+-1 | 300+-1 | 650+-1 | 1930+-1 | 1533+-1 |
|
||||
| b | 760+-1 | 0 | 200+-1 | 550+-1 | 1830+-1 | 1433+-1 |
|
||||
| c | 560+-2 | 660+-2 | 0 | 350+-1 | 1630+-1 | 1233+-1 |
|
||||
| d | 1480+-2 | 1580+-1 | 1780+-1 | 0 | 1280+-1 | 883+-1 |
|
||||
| e | 200+-2 | 300+-2 | 500+-1 | 710+-1 | 0 | 1593+-1 |
|
||||
| f | 597+-1 | 696+-1 | 896+-1 | 1108+-1 | 400+-3 | 0 |
|
||||
|
||||
@@ -0,0 +1,512 @@
|
||||
@matrix @testbot
|
||||
Feature: Basic Duration Matrix
|
||||
# note that results of travel time are in seconds
|
||||
|
||||
Background:
|
||||
Given the profile "testbot"
|
||||
And the partition extra arguments "--small-component-size 1 --max-cell-sizes 2,4,8,16"
|
||||
|
||||
Scenario: Testbot - Travel time matrix of minimal network
|
||||
Given the node map
|
||||
"""
|
||||
a b
|
||||
"""
|
||||
|
||||
And the ways
|
||||
| nodes |
|
||||
| ab |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | a | b |
|
||||
| a | 0 | 10 |
|
||||
| b | 10 | 0 |
|
||||
|
||||
@ch
|
||||
Scenario: Testbot - Travel time matrix of minimal network with toll exclude
|
||||
Given the query options
|
||||
| exclude | toll |
|
||||
|
||||
Given the node map
|
||||
"""
|
||||
a b
|
||||
c d
|
||||
"""
|
||||
|
||||
And the ways
|
||||
| nodes | highway | toll | # |
|
||||
| ab | motorway | | not drivable for exclude=motorway |
|
||||
| cd | primary | | always drivable |
|
||||
| ac | motorway | yes | not drivable for exclude=toll and exclude=motorway,toll |
|
||||
| bd | motorway | yes | not drivable for exclude=toll and exclude=motorway,toll |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | a | b | c | d |
|
||||
| a | 0 | 15 | | |
|
||||
| b | 15 | 0 | | |
|
||||
| c | | | 0 | 10 |
|
||||
| d | | | 10 | 0 |
|
||||
|
||||
@ch
|
||||
Scenario: Testbot - Travel time matrix of minimal network with motorway exclude
|
||||
Given the query options
|
||||
| exclude | motorway |
|
||||
|
||||
Given the node map
|
||||
"""
|
||||
a b
|
||||
c d
|
||||
"""
|
||||
|
||||
And the ways
|
||||
| nodes | highway | # |
|
||||
| ab | motorway | not drivable for exclude=motorway |
|
||||
| cd | residential | |
|
||||
| ac | residential | |
|
||||
| bd | residential | |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | a | b | c | d |
|
||||
| a | 0 | 45 | 15 | 30 |
|
||||
|
||||
@ch
|
||||
Scenario: Testbot - Travel time matrix of minimal network disconnected motorway exclude
|
||||
Given the query options
|
||||
| exclude | motorway |
|
||||
|
||||
Given the node map
|
||||
"""
|
||||
ab efgh
|
||||
cd
|
||||
"""
|
||||
|
||||
And the ways
|
||||
| nodes | highway | # |
|
||||
| be | motorway | not drivable for exclude=motorway |
|
||||
| abcd | residential | |
|
||||
| efgh | residential | |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | a | b | e |
|
||||
| a | 0 | 7.5 | |
|
||||
|
||||
@ch
|
||||
Scenario: Testbot - Travel time matrix of minimal network with motorway and toll excludes
|
||||
Given the query options
|
||||
| exclude | motorway,toll |
|
||||
|
||||
Given the node map
|
||||
"""
|
||||
a b e f
|
||||
c d g h
|
||||
"""
|
||||
|
||||
And the ways
|
||||
| nodes | highway | toll | # |
|
||||
| be | motorway | | not drivable for exclude=motorway |
|
||||
| dg | primary | yes | not drivable for exclude=toll |
|
||||
| abcd | residential | | |
|
||||
| efgh | residential | | |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | a | b | e | g |
|
||||
| a | 0 | 15 | | |
|
||||
|
||||
Scenario: Testbot - Travel time matrix with different way speeds
|
||||
Given the node map
|
||||
"""
|
||||
a b c d
|
||||
"""
|
||||
|
||||
And the ways
|
||||
| nodes | highway |
|
||||
| ab | primary |
|
||||
| bc | secondary |
|
||||
| cd | tertiary |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | a | b | c | d |
|
||||
| a | 0 | 10 | 30 | 60 |
|
||||
| b | 10 | 0 | 20 | 50 |
|
||||
| c | 30 | 20 | 0 | 30 |
|
||||
| d | 60 | 50 | 30 | 0 |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | a | b | c | d |
|
||||
| a | 0 | 10 | 30 | 60 |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | a |
|
||||
| a | 0 |
|
||||
| b | 10 |
|
||||
| c | 30 |
|
||||
| d | 60 |
|
||||
|
||||
|
||||
Scenario: Testbot - Travel time matrix of small grid
|
||||
Given the node map
|
||||
"""
|
||||
a b c
|
||||
d e f
|
||||
"""
|
||||
|
||||
And the ways
|
||||
| nodes |
|
||||
| abc |
|
||||
| def |
|
||||
| ad |
|
||||
| be |
|
||||
| cf |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | a | b | e | f |
|
||||
| a | 0 | 10 | 20 | 30 |
|
||||
| b | 10 | 0 | 10 | 20 |
|
||||
| e | 20 | 10 | 0 | 10 |
|
||||
| f | 30 | 20 | 10 | 0 |
|
||||
|
||||
|
||||
Scenario: Testbot - Travel time matrix of network with unroutable parts
|
||||
Given the node map
|
||||
"""
|
||||
a b
|
||||
"""
|
||||
|
||||
And the ways
|
||||
| nodes | oneway |
|
||||
| ab | yes |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | a | b |
|
||||
| a | 0 | 10 |
|
||||
| b | | 0 |
|
||||
|
||||
|
||||
Scenario: Testbot - Travel time matrix of network with oneways
|
||||
Given the node map
|
||||
"""
|
||||
x a b y
|
||||
d e
|
||||
"""
|
||||
|
||||
And the ways
|
||||
| nodes | oneway |
|
||||
| abeda | yes |
|
||||
| xa | |
|
||||
| by | |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | x | y | d | e |
|
||||
| x | 0 | 30 | 40 | 30 |
|
||||
| y | 50 | 0 | 30 | 20 |
|
||||
| d | 20 | 30 | 0 | 30 |
|
||||
| e | 30 | 40 | 10 | 0 |
|
||||
|
||||
|
||||
Scenario: Testbot - Rectangular travel time matrix
|
||||
Given the node map
|
||||
"""
|
||||
a b c
|
||||
d e f
|
||||
"""
|
||||
|
||||
And the ways
|
||||
| nodes |
|
||||
| abc |
|
||||
| def |
|
||||
| ad |
|
||||
| be |
|
||||
| cf |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | a | b | e | f |
|
||||
| a | 0 | 10 | 20 | 30 |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | a |
|
||||
| a | 0 |
|
||||
| b | 10 |
|
||||
| e | 20 |
|
||||
| f | 30 |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | a | b | e | f |
|
||||
| a | 0 | 10 | 20 | 30 |
|
||||
| b | 10 | 0 | 10 | 20 |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | a | b |
|
||||
| a | 0 | 10 |
|
||||
| b | 10 | 0 |
|
||||
| e | 20 | 10 |
|
||||
| f | 30 | 20 |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | a | b | e | f |
|
||||
| a | 0 | 10 | 20 | 30 |
|
||||
| b | 10 | 0 | 10 | 20 |
|
||||
| e | 20 | 10 | 0 | 10 |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | a | b | e |
|
||||
| a | 0 | 10 | 20 |
|
||||
| b | 10 | 0 | 10 |
|
||||
| e | 20 | 10 | 0 |
|
||||
| f | 30 | 20 | 10 |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | a | b | e | f |
|
||||
| a | 0 | 10 | 20 | 30 |
|
||||
| b | 10 | 0 | 10 | 20 |
|
||||
| e | 20 | 10 | 0 | 10 |
|
||||
| f | 30 | 20 | 10 | 0 |
|
||||
|
||||
Scenario: Testbot - Travel time 3x2 matrix
|
||||
Given the node map
|
||||
"""
|
||||
a b c
|
||||
d e f
|
||||
"""
|
||||
|
||||
And the ways
|
||||
| nodes |
|
||||
| abc |
|
||||
| def |
|
||||
| ad |
|
||||
| be |
|
||||
| cf |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | b | e | f |
|
||||
| a | 10 | 20 | 30 |
|
||||
| b | 0 | 10 | 20 |
|
||||
|
||||
|
||||
Scenario: Testbot - All coordinates are from same small component
|
||||
Given a grid size of 300 meters
|
||||
Given the extract extra arguments "--small-component-size 4"
|
||||
Given the node map
|
||||
"""
|
||||
a b f
|
||||
d e g
|
||||
"""
|
||||
|
||||
And the ways
|
||||
| nodes |
|
||||
| ab |
|
||||
| be |
|
||||
| ed |
|
||||
| da |
|
||||
| fg |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | f | g |
|
||||
| f | 0 | 30 |
|
||||
| g | 30 | 0 |
|
||||
|
||||
|
||||
Scenario: Testbot - Coordinates are from different small component and snap to big CC
|
||||
Given a grid size of 300 meters
|
||||
Given the extract extra arguments "--small-component-size 4"
|
||||
Given the node map
|
||||
"""
|
||||
a b f h
|
||||
d e g i
|
||||
"""
|
||||
|
||||
And the ways
|
||||
| nodes |
|
||||
| ab |
|
||||
| be |
|
||||
| ed |
|
||||
| da |
|
||||
| fg |
|
||||
| hi |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | f | g | h | i |
|
||||
| f | 0 | 30 | 0 | 30 |
|
||||
| g | 30 | 0 | 30 | 0 |
|
||||
| h | 0 | 30 | 0 | 30 |
|
||||
| i | 30 | 0 | 30 | 0 |
|
||||
|
||||
|
||||
Scenario: Testbot - Travel time matrix with loops
|
||||
Given the node map
|
||||
"""
|
||||
a 1 2 b
|
||||
d 4 3 c
|
||||
"""
|
||||
|
||||
And the ways
|
||||
| nodes | oneway |
|
||||
| ab | yes |
|
||||
| bc | yes |
|
||||
| cd | yes |
|
||||
| da | yes |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | 1 | 2 | 3 | 4 |
|
||||
| 1 | 0 | 10 +-1 | 40 +-1 | 50 +-1 |
|
||||
| 2 | 70 +-1 | 0 | 30 +-1 | 40 +-1 |
|
||||
| 3 | 40 +-1 | 50 +-1 | 0 | 10 +-1 |
|
||||
| 4 | 30 +-1 | 40 +-1 | 70 +-1 | 0 |
|
||||
|
||||
|
||||
Scenario: Testbot - Travel time matrix based on segment durations
|
||||
Given the profile file
|
||||
"""
|
||||
local functions = require('testbot')
|
||||
functions.setup_testbot = functions.setup
|
||||
|
||||
functions.setup = function()
|
||||
local profile = functions.setup_testbot()
|
||||
profile.traffic_signal_penalty = 0
|
||||
profile.u_turn_penalty = 0
|
||||
return profile
|
||||
end
|
||||
|
||||
functions.process_segment = function(profile, segment)
|
||||
segment.weight = 2
|
||||
segment.duration = 11
|
||||
end
|
||||
|
||||
return functions
|
||||
"""
|
||||
|
||||
And the node map
|
||||
"""
|
||||
a-b-c-d
|
||||
.
|
||||
e
|
||||
"""
|
||||
|
||||
And the ways
|
||||
| nodes |
|
||||
| abcd |
|
||||
| ce |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | a | b | c | d | e |
|
||||
| a | 0 | 11 | 22 | 33 | 33 |
|
||||
| b | 11 | 0 | 11 | 22 | 22 |
|
||||
| c | 22 | 11 | 0 | 11 | 11 |
|
||||
| d | 33 | 22 | 11 | 0 | 22 |
|
||||
| e | 33 | 22 | 11 | 22 | 0 |
|
||||
|
||||
|
||||
Scenario: Testbot - Travel time matrix for alternative loop paths
|
||||
Given the profile file
|
||||
"""
|
||||
local functions = require('testbot')
|
||||
functions.setup_testbot = functions.setup
|
||||
|
||||
functions.setup = function()
|
||||
local profile = functions.setup_testbot()
|
||||
profile.traffic_signal_penalty = 0
|
||||
profile.u_turn_penalty = 0
|
||||
profile.weight_precision = 3
|
||||
return profile
|
||||
end
|
||||
|
||||
functions.process_segment = function(profile, segment)
|
||||
segment.weight = 777
|
||||
segment.duration = 3
|
||||
end
|
||||
|
||||
return functions
|
||||
"""
|
||||
And the node map
|
||||
"""
|
||||
a 2 1 b
|
||||
7 4
|
||||
8 3
|
||||
c 5 6 d
|
||||
"""
|
||||
|
||||
And the ways
|
||||
| nodes | oneway |
|
||||
| ab | yes |
|
||||
| bd | yes |
|
||||
| dc | yes |
|
||||
| ca | yes |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|
||||
| 1 | 0 | 11 | 3 | 2 | 6 | 5 | 8.9 | 7.9 |
|
||||
| 2 | 1 | 0 | 4 | 3 | 7 | 6 | 9.9 | 8.9 |
|
||||
| 3 | 9 | 8 | 0 | 11 | 3 | 2 | 5.9 | 4.9 |
|
||||
| 4 | 10 | 9 | 1 | 0 | 4 | 3 | 6.9 | 5.9 |
|
||||
| 5 | 6 | 5 | 9 | 8 | 0 | 11 | 2.9 | 1.9 |
|
||||
| 6 | 7 | 6 | 10 | 9 | 1 | 0 | 3.9 | 2.9 |
|
||||
| 7 | 3.1 | 2.1 | 6.1 | 5.1 | 9.1 | 8.1 | 0 | 11 |
|
||||
| 8 | 4.1 | 3.1 | 7.1 | 6.1 | 10.1 | 9.1 | 1 | 0 |
|
||||
|
||||
|
||||
Scenario: Testbot - Travel time matrix with ties
|
||||
Given the profile file
|
||||
"""
|
||||
local functions = require('testbot')
|
||||
functions.process_segment = function(profile, segment)
|
||||
segment.weight = 1
|
||||
segment.duration = 1
|
||||
end
|
||||
functions.process_turn = function(profile, turn)
|
||||
if turn.angle >= 0 then
|
||||
turn.duration = 16
|
||||
else
|
||||
turn.duration = 4
|
||||
end
|
||||
turn.weight = 0
|
||||
end
|
||||
return functions
|
||||
"""
|
||||
And the node map
|
||||
"""
|
||||
a b
|
||||
|
||||
c d
|
||||
"""
|
||||
|
||||
And the ways
|
||||
| nodes |
|
||||
| ab |
|
||||
| ac |
|
||||
| bd |
|
||||
| dc |
|
||||
|
||||
When I route I should get
|
||||
| from | to | route | distance | time | weight |
|
||||
| a | c | ac,ac | 200m | 5s | 5 |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | a | b | c | d |
|
||||
| a | 0 | 1 | 5 | 10 |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | a |
|
||||
| a | 0 |
|
||||
| b | 1 |
|
||||
| c | 15 |
|
||||
| d | 10 |
|
||||
|
||||
Scenario: Testbot - OneToMany vs ManyToOne
|
||||
Given the node map
|
||||
"""
|
||||
a b
|
||||
c
|
||||
"""
|
||||
|
||||
And the ways
|
||||
| nodes | oneway |
|
||||
| ab | yes |
|
||||
| ac | |
|
||||
| bc | |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | a | b |
|
||||
| b | 24.1 | 0 |
|
||||
|
||||
When I request a travel time matrix I should get
|
||||
| | a |
|
||||
| a | 0 |
|
||||
| b | 24.1 |
|
||||
@@ -39,5 +39,64 @@ Feature: Fixed bugs, kept to check for regressions
|
||||
| de | yes |
|
||||
|
||||
When I route I should get
|
||||
| from | to | route |
|
||||
| 1 | 2 | bcd,bcd |
|
||||
| from | to | route |
|
||||
| 1 | 2 | bcd,bcd |
|
||||
|
||||
#############################
|
||||
# This test models the OSM map at the location for
|
||||
# https://github.com/Project-OSRM/osrm-backend/issues/5039
|
||||
#############################
|
||||
Scenario: Mixed Entry and Exit and segregated
|
||||
Given the profile file "car" initialized with
|
||||
"""
|
||||
profile.properties.left_hand_driving = true
|
||||
"""
|
||||
Given the node locations
|
||||
| node | lon | lat |
|
||||
| a | 171.12889297029 | -42.58425289548 |
|
||||
| b | 171.1299357 | -42.5849295 |
|
||||
| c | 171.1295427 | -42.5849385 |
|
||||
| d | 171.1297356 | -42.5852029 |
|
||||
| e | 171.1296909 | -42.5851986 |
|
||||
| f | 171.1295097 | -42.585007 |
|
||||
| g | 171.1298225 | -42.5851928 |
|
||||
| h | 171.1300262 | -42.5859122 |
|
||||
| i | 171.1292651 | -42.584698 |
|
||||
| j | 171.1297209 | -42.5848569 |
|
||||
| k | 171.1297188 | -42.5854056 |
|
||||
| l | 171.1298326 | -42.5857266 |
|
||||
| m | 171.1298871 | -42.5848922 |
|
||||
| n | 171.1296505 | -42.585189 |
|
||||
| o | 171.1295206 | -42.5850862 |
|
||||
| p | 171.1296106 | -42.5848862 |
|
||||
| q | 171.1299784 | -42.5850191 |
|
||||
| r | 171.1298867 | -42.5851671 |
|
||||
| s | 171.1306955 | -42.5845812 |
|
||||
| t | 171.129525 | -42.584807 |
|
||||
| u | 171.1299705 | -42.584984 |
|
||||
| v | 171.1299067 | -42.5849073 |
|
||||
| w | 171.1302061 | -42.5848173 |
|
||||
| x | 171.12975 | -42.5855753 |
|
||||
| y | 171.129969 | -42.585079 |
|
||||
| 1 | 171.131511926651| -42.584306746421966 |
|
||||
| 2 | 171.128743886947| -42.58414875714669 |
|
||||
And the ways
|
||||
| nodes | highway | maxspeed | name | ref | surface | junction | oneway |
|
||||
| ws | primary | 100 | Taramakau Highway | SH 6 | asphalt | | |
|
||||
| kxlh | trunk | | Otira Highway | SH 73 | | | |
|
||||
| ai | primary | 100 | Kumara Junction Highway | SH 6 | asphalt | | |
|
||||
| qyrgdenof | primary | 100 | Kumara Junction | | | roundabout | yes |
|
||||
| ke | trunk | | Otira Highway | SH 73 | | | yes |
|
||||
| itj | primary | 100 | Kumara Junction Highway | SH 6 | | | yes |
|
||||
| gk | trunk | | Otira Highway | SH 73 | | | yes |
|
||||
| fi | primary | 100 | Kumara Junction Highway | SH 6 | | | yes |
|
||||
| wq | primary | 100 | Taramakau Highway | SH 6 | | | yes |
|
||||
| vw | primary | 100 | Taramakau Highway | SH 6 | | | yes |
|
||||
| vbuq | primary | 100 | Kumara Junction | | | roundabout | yes |
|
||||
| jmv | primary | 100 | Kumara Junction | | | roundabout | yes |
|
||||
| fcpj | primary | 100 | Kumara Junction | | | roundabout | yes |
|
||||
|
||||
When I route I should get
|
||||
| waypoints | route | turns |
|
||||
| 1,2 | Taramakau Highway,Kumara Junction Highway,Kumara Junction Highway,Kumara Junction Highway | depart,Kumara Junction-exit-2,exit rotary slight left,arrive |
|
||||
|
||||
|
||||
@@ -106,6 +106,40 @@ Feature: Multi level routing
|
||||
| l | 144.7 | 60 |
|
||||
| o | 124.7 | 0 |
|
||||
|
||||
|
||||
When I request a travel distance matrix I should get
|
||||
| | a | f | l | o |
|
||||
| a | 0+-2 | 2287+-2 | 1443+-2 | 1243+-2 |
|
||||
| f | 2284+-2 | 0+-2 | 1241+-2 | 1443+-2 |
|
||||
| l | 1443+-2 | 1244+-2 | 0+-2 | 600+-2 |
|
||||
| o | 1243+-2 | 1444+-2 | 600+-2 | 0+-2 |
|
||||
|
||||
When I request a travel distance matrix I should get
|
||||
| | a | f | l | o |
|
||||
| a | 0 | 2287.2+-2 | 1443+-2 | 1243+-2 |
|
||||
|
||||
When I request a travel distance matrix I should get
|
||||
| | a |
|
||||
| a | 0 |
|
||||
| f | 2284.5+-2 |
|
||||
| l | 1443.1 |
|
||||
| o | 1243 |
|
||||
|
||||
When I request a travel distance matrix I should get
|
||||
| | a | f | l | o |
|
||||
| a | 0 | 2287+-2 | 1443+-2 | 1243+-2 |
|
||||
| o | 1243 | 1444+-2 | 600+-2 | 0+-2 |
|
||||
|
||||
|
||||
When I request a travel distance matrix I should get
|
||||
| | a | o |
|
||||
| a | 0+-2 | 1243+-2 |
|
||||
| f | 2284+-2 | 1443+-2 |
|
||||
| l | 1443+-2 | 600+-2 |
|
||||
| o | 1243+-2 | 0+-2 |
|
||||
|
||||
|
||||
|
||||
Scenario: Testbot - Multi level routing: horizontal road
|
||||
Given the node map
|
||||
"""
|
||||
|
||||
@@ -54,7 +54,7 @@ Feature: Traffic - speeds
|
||||
| a | d | ad,ad | 27 km/h | 1275.7,0 | 1 |
|
||||
| d | c | dc,dc | 36 km/h | 956.8,0 | 0 |
|
||||
| g | b | fb,fb | 36 km/h | 164.7,0 | 0 |
|
||||
| a | g | ad,df,fb,fb | 30 km/h | 1275.7,487.5,304.7,0 | 1:0:0 |
|
||||
| a | g | ad,df,fb,fb | 30 km/h | 1295.7,487.5,304.7,0 | 1:0:0 |
|
||||
|
||||
|
||||
Scenario: Weighting based on speed file weights, ETA based on file durations
|
||||
|
||||
@@ -72,8 +72,14 @@ struct ContractorConfig final : storage::IOConfig
|
||||
// The remaining vertices form the core of the hierarchy
|
||||
//(e.g. 0.8 contracts 80 percent of the hierarchy, leaving a core of 20%)
|
||||
double core_factor;
|
||||
|
||||
// Whether to store distances for CH edges in addition to duration/weight
|
||||
// Defaults to false. Setting to true will require more storage/memory,
|
||||
// but avoids the need for path unpacking to learn the distance of a CH
|
||||
// route (useful for faster distance results in table queries)
|
||||
bool cache_distances;
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace contractor
|
||||
} // namespace osrm
|
||||
|
||||
#endif // EXTRACTOR_OPTIONS_HPP
|
||||
|
||||
@@ -12,23 +12,26 @@ namespace contractor
|
||||
struct ContractorEdgeData
|
||||
{
|
||||
ContractorEdgeData()
|
||||
: weight(0), duration(0), id(0), originalEdges(0), shortcut(0), forward(0), backward(0)
|
||||
: weight(0), duration(0), distance(0), id(0), originalEdges(0), shortcut(0), forward(0),
|
||||
backward(0)
|
||||
{
|
||||
}
|
||||
ContractorEdgeData(EdgeWeight weight,
|
||||
EdgeWeight duration,
|
||||
EdgeDistance distance,
|
||||
unsigned original_edges,
|
||||
unsigned id,
|
||||
bool shortcut,
|
||||
bool forward,
|
||||
bool backward)
|
||||
: weight(weight), duration(duration), id(id),
|
||||
: weight(weight), duration(duration), distance(distance), id(id),
|
||||
originalEdges(std::min((1u << 29) - 1u, original_edges)), shortcut(shortcut),
|
||||
forward(forward), backward(backward)
|
||||
{
|
||||
}
|
||||
EdgeWeight weight;
|
||||
EdgeWeight duration;
|
||||
EdgeDistance distance;
|
||||
unsigned id;
|
||||
unsigned originalEdges : 29;
|
||||
bool shortcut : 1;
|
||||
|
||||
@@ -41,6 +41,7 @@ ContractorGraph toContractorGraph(NodeID number_of_nodes, InputEdgeContainer inp
|
||||
input_edge.target,
|
||||
std::max(input_edge.data.weight, 1),
|
||||
input_edge.data.duration,
|
||||
input_edge.data.distance,
|
||||
1,
|
||||
input_edge.data.turn_id,
|
||||
false,
|
||||
@@ -51,6 +52,7 @@ ContractorGraph toContractorGraph(NodeID number_of_nodes, InputEdgeContainer inp
|
||||
input_edge.source,
|
||||
std::max(input_edge.data.weight, 1),
|
||||
input_edge.data.duration,
|
||||
input_edge.data.distance,
|
||||
1,
|
||||
input_edge.data.turn_id,
|
||||
false,
|
||||
@@ -82,6 +84,7 @@ ContractorGraph toContractorGraph(NodeID number_of_nodes, InputEdgeContainer inp
|
||||
forward_edge.data.originalEdges = reverse_edge.data.originalEdges = 1;
|
||||
forward_edge.data.weight = reverse_edge.data.weight = INVALID_EDGE_WEIGHT;
|
||||
forward_edge.data.duration = reverse_edge.data.duration = MAXIMAL_EDGE_DURATION;
|
||||
forward_edge.data.distance = reverse_edge.data.distance = MAXIMAL_EDGE_DISTANCE;
|
||||
// remove parallel edges
|
||||
while (i < edges.size() && edges[i].source == source && edges[i].target == target)
|
||||
{
|
||||
@@ -90,12 +93,16 @@ ContractorGraph toContractorGraph(NodeID number_of_nodes, InputEdgeContainer inp
|
||||
forward_edge.data.weight = std::min(edges[i].data.weight, forward_edge.data.weight);
|
||||
forward_edge.data.duration =
|
||||
std::min(edges[i].data.duration, forward_edge.data.duration);
|
||||
forward_edge.data.distance =
|
||||
std::min(edges[i].data.distance, forward_edge.data.distance);
|
||||
}
|
||||
if (edges[i].data.backward)
|
||||
{
|
||||
reverse_edge.data.weight = std::min(edges[i].data.weight, reverse_edge.data.weight);
|
||||
reverse_edge.data.duration =
|
||||
std::min(edges[i].data.duration, reverse_edge.data.duration);
|
||||
reverse_edge.data.distance =
|
||||
std::min(edges[i].data.distance, reverse_edge.data.distance);
|
||||
}
|
||||
++i;
|
||||
}
|
||||
@@ -151,6 +158,7 @@ template <class Edge, typename GraphT> inline std::vector<Edge> toEdges(GraphT g
|
||||
BOOST_ASSERT_MSG(SPECIAL_NODEID != new_edge.target, "Target id invalid");
|
||||
new_edge.data.weight = data.weight;
|
||||
new_edge.data.duration = data.duration;
|
||||
new_edge.data.distance = data.distance;
|
||||
new_edge.data.shortcut = data.shortcut;
|
||||
new_edge.data.turn_id = data.id;
|
||||
BOOST_ASSERT_MSG(new_edge.data.turn_id != INT_MAX, // 2^31
|
||||
|
||||
@@ -17,7 +17,8 @@ struct QueryEdge
|
||||
struct EdgeData
|
||||
{
|
||||
explicit EdgeData()
|
||||
: turn_id(0), shortcut(false), weight(0), duration(0), forward(false), backward(false)
|
||||
: turn_id(0), shortcut(false), weight(0), duration(0), forward(false), backward(false),
|
||||
distance(0)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -25,10 +26,11 @@ struct QueryEdge
|
||||
const bool shortcut,
|
||||
const EdgeWeight weight,
|
||||
const EdgeWeight duration,
|
||||
const EdgeDistance distance,
|
||||
const bool forward,
|
||||
const bool backward)
|
||||
: turn_id(turn_id), shortcut(shortcut), weight(weight), duration(duration),
|
||||
forward(forward), backward(backward)
|
||||
forward(forward), backward(backward), distance(distance)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -40,6 +42,7 @@ struct QueryEdge
|
||||
turn_id = other.id;
|
||||
forward = other.forward;
|
||||
backward = other.backward;
|
||||
distance = other.distance;
|
||||
}
|
||||
// this ID is either the middle node of the shortcut, or the ID of the edge based node (node
|
||||
// based edge) storing the appropriate data. If `shortcut` is set to true, we get the middle
|
||||
@@ -50,6 +53,7 @@ struct QueryEdge
|
||||
EdgeWeight duration : 30;
|
||||
std::uint32_t forward : 1;
|
||||
std::uint32_t backward : 1;
|
||||
EdgeDistance distance;
|
||||
} data;
|
||||
|
||||
QueryEdge() : source(SPECIAL_NODEID), target(SPECIAL_NODEID) {}
|
||||
@@ -69,10 +73,11 @@ struct QueryEdge
|
||||
return (source == right.source && target == right.target &&
|
||||
data.weight == right.data.weight && data.duration == right.data.duration &&
|
||||
data.shortcut == right.data.shortcut && data.forward == right.data.forward &&
|
||||
data.backward == right.data.backward && data.turn_id == right.data.turn_id);
|
||||
data.backward == right.data.backward && data.turn_id == right.data.turn_id &&
|
||||
data.distance == right.data.distance);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace contractor
|
||||
} // namespace osrm
|
||||
|
||||
#endif // QUERYEDGE_HPP
|
||||
|
||||
@@ -21,7 +21,8 @@ struct CustomizationConfig final : storage::IOConfig
|
||||
".osrm.partition",
|
||||
".osrm.cells",
|
||||
".osrm.ebg_nodes",
|
||||
".osrm.properties"},
|
||||
".osrm.properties",
|
||||
".osrm.enw"},
|
||||
{},
|
||||
{".osrm.cell_metrics", ".osrm.mldgr"}),
|
||||
requested_num_threads(0)
|
||||
|
||||
@@ -16,28 +16,109 @@ namespace osrm
|
||||
namespace customizer
|
||||
{
|
||||
|
||||
using EdgeBasedGraphEdgeData = partitioner::EdgeBasedGraphEdgeData;
|
||||
|
||||
struct MultiLevelEdgeBasedGraph
|
||||
: public partitioner::MultiLevelGraph<EdgeBasedGraphEdgeData, storage::Ownership::Container>
|
||||
struct EdgeBasedGraphEdgeData
|
||||
{
|
||||
using Base =
|
||||
partitioner::MultiLevelGraph<EdgeBasedGraphEdgeData, storage::Ownership::Container>;
|
||||
using Base::Base;
|
||||
NodeID turn_id; // ID of the edge based node (node based edge)
|
||||
};
|
||||
|
||||
struct MultiLevelEdgeBasedGraphView
|
||||
: public partitioner::MultiLevelGraph<EdgeBasedGraphEdgeData, storage::Ownership::View>
|
||||
template <typename EdgeDataT, storage::Ownership Ownership> class MultiLevelGraph;
|
||||
|
||||
namespace serialization
|
||||
{
|
||||
using Base = partitioner::MultiLevelGraph<EdgeBasedGraphEdgeData, storage::Ownership::View>;
|
||||
using Base::Base;
|
||||
template <typename EdgeDataT, storage::Ownership Ownership>
|
||||
void read(storage::tar::FileReader &reader,
|
||||
const std::string &name,
|
||||
MultiLevelGraph<EdgeDataT, Ownership> &graph);
|
||||
|
||||
template <typename EdgeDataT, storage::Ownership Ownership>
|
||||
void write(storage::tar::FileWriter &writer,
|
||||
const std::string &name,
|
||||
const MultiLevelGraph<EdgeDataT, Ownership> &graph);
|
||||
}
|
||||
|
||||
template <typename EdgeDataT, storage::Ownership Ownership>
|
||||
class MultiLevelGraph : public partitioner::MultiLevelGraph<EdgeDataT, Ownership>
|
||||
{
|
||||
private:
|
||||
using SuperT = partitioner::MultiLevelGraph<EdgeDataT, Ownership>;
|
||||
using PartitionerGraphT = partitioner::MultiLevelGraph<partitioner::EdgeBasedGraphEdgeData,
|
||||
storage::Ownership::Container>;
|
||||
template <typename T> using Vector = util::ViewOrVector<T, Ownership>;
|
||||
|
||||
public:
|
||||
using NodeArrayEntry = typename SuperT::NodeArrayEntry;
|
||||
using EdgeArrayEntry = typename SuperT::EdgeArrayEntry;
|
||||
using EdgeOffset = typename SuperT::EdgeOffset;
|
||||
|
||||
MultiLevelGraph() = default;
|
||||
MultiLevelGraph(MultiLevelGraph &&) = default;
|
||||
MultiLevelGraph(const MultiLevelGraph &) = default;
|
||||
MultiLevelGraph &operator=(MultiLevelGraph &&) = default;
|
||||
MultiLevelGraph &operator=(const MultiLevelGraph &) = default;
|
||||
|
||||
MultiLevelGraph(PartitionerGraphT &&graph,
|
||||
Vector<EdgeWeight> node_weights_,
|
||||
Vector<EdgeDuration> node_durations_)
|
||||
: node_weights(std::move(node_weights_)), node_durations(std::move(node_durations_))
|
||||
{
|
||||
util::ViewOrVector<PartitionerGraphT::EdgeArrayEntry, storage::Ownership::Container>
|
||||
original_edge_array;
|
||||
|
||||
std::tie(SuperT::node_array,
|
||||
original_edge_array,
|
||||
SuperT::node_to_edge_offset,
|
||||
SuperT::connectivity_checksum) = std::move(graph).data();
|
||||
|
||||
SuperT::edge_array.reserve(original_edge_array.size());
|
||||
for (const auto &edge : original_edge_array)
|
||||
{
|
||||
SuperT::edge_array.push_back({edge.target, {edge.data.turn_id}});
|
||||
is_forward_edge.push_back(edge.data.forward);
|
||||
is_backward_edge.push_back(edge.data.backward);
|
||||
}
|
||||
}
|
||||
|
||||
MultiLevelGraph(Vector<NodeArrayEntry> node_array_,
|
||||
Vector<EdgeArrayEntry> edge_array_,
|
||||
Vector<EdgeOffset> node_to_edge_offset_,
|
||||
Vector<EdgeWeight> node_weights_,
|
||||
Vector<EdgeDuration> node_durations_,
|
||||
Vector<bool> is_forward_edge_,
|
||||
Vector<bool> is_backward_edge_)
|
||||
: SuperT(std::move(node_array_), std::move(edge_array_), std::move(node_to_edge_offset_)),
|
||||
node_weights(std::move(node_weights_)), node_durations(std::move(node_durations_)),
|
||||
is_forward_edge(is_forward_edge_), is_backward_edge(is_backward_edge_)
|
||||
{
|
||||
}
|
||||
|
||||
EdgeWeight GetNodeWeight(NodeID node) const { return node_weights[node]; }
|
||||
|
||||
EdgeWeight GetNodeDuration(NodeID node) const { return node_durations[node]; }
|
||||
|
||||
bool IsForwardEdge(EdgeID edge) const { return is_forward_edge[edge]; }
|
||||
|
||||
bool IsBackwardEdge(EdgeID edge) const { return is_backward_edge[edge]; }
|
||||
|
||||
friend void
|
||||
serialization::read<EdgeDataT, Ownership>(storage::tar::FileReader &reader,
|
||||
const std::string &name,
|
||||
MultiLevelGraph<EdgeDataT, Ownership> &graph);
|
||||
friend void
|
||||
serialization::write<EdgeDataT, Ownership>(storage::tar::FileWriter &writer,
|
||||
const std::string &name,
|
||||
const MultiLevelGraph<EdgeDataT, Ownership> &graph);
|
||||
|
||||
protected:
|
||||
Vector<EdgeWeight> node_weights;
|
||||
Vector<EdgeDuration> node_durations;
|
||||
Vector<bool> is_forward_edge;
|
||||
Vector<bool> is_backward_edge;
|
||||
};
|
||||
|
||||
struct StaticEdgeBasedGraphEdge : MultiLevelEdgeBasedGraph::InputEdge
|
||||
{
|
||||
using Base = MultiLevelEdgeBasedGraph::InputEdge;
|
||||
using Base::Base;
|
||||
};
|
||||
using MultiLevelEdgeBasedGraph =
|
||||
MultiLevelGraph<EdgeBasedGraphEdgeData, storage::Ownership::Container>;
|
||||
using MultiLevelEdgeBasedGraphView =
|
||||
MultiLevelGraph<EdgeBasedGraphEdgeData, storage::Ownership::View>;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -73,6 +73,39 @@ writeCellMetrics(const boost::filesystem::path &path,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// reads .osrm.mldgr file
|
||||
template <typename MultiLevelGraphT>
|
||||
inline void readGraph(const boost::filesystem::path &path,
|
||||
MultiLevelGraphT &graph,
|
||||
std::uint32_t &connectivity_checksum)
|
||||
{
|
||||
static_assert(std::is_same<customizer::MultiLevelEdgeBasedGraphView, MultiLevelGraphT>::value ||
|
||||
std::is_same<customizer::MultiLevelEdgeBasedGraph, MultiLevelGraphT>::value,
|
||||
"");
|
||||
|
||||
storage::tar::FileReader reader{path, storage::tar::FileReader::VerifyFingerprint};
|
||||
|
||||
reader.ReadInto("/mld/connectivity_checksum", connectivity_checksum);
|
||||
serialization::read(reader, "/mld/multilevelgraph", graph);
|
||||
}
|
||||
|
||||
// writes .osrm.mldgr file
|
||||
template <typename MultiLevelGraphT>
|
||||
inline void writeGraph(const boost::filesystem::path &path,
|
||||
const MultiLevelGraphT &graph,
|
||||
const std::uint32_t connectivity_checksum)
|
||||
{
|
||||
static_assert(std::is_same<customizer::MultiLevelEdgeBasedGraphView, MultiLevelGraphT>::value ||
|
||||
std::is_same<customizer::MultiLevelEdgeBasedGraph, MultiLevelGraphT>::value,
|
||||
"");
|
||||
|
||||
storage::tar::FileWriter writer{path, storage::tar::FileWriter::GenerateFingerprint};
|
||||
|
||||
writer.WriteElementCount64("/mld/connectivity_checksum", 1);
|
||||
writer.WriteFrom("/mld/connectivity_checksum", connectivity_checksum);
|
||||
serialization::write(writer, "/mld/multilevelgraph", graph);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef OSRM_CUSTOMIZER_SERIALIZATION_HPP
|
||||
#define OSRM_CUSTOMIZER_SERIALIZATION_HPP
|
||||
|
||||
#include "customizer/edge_based_graph.hpp"
|
||||
|
||||
#include "partitioner/cell_storage.hpp"
|
||||
|
||||
#include "storage/serialization.hpp"
|
||||
@@ -31,6 +33,34 @@ inline void write(storage::tar::FileWriter &writer,
|
||||
storage::serialization::write(writer, name + "/weights", metric.weights);
|
||||
storage::serialization::write(writer, name + "/durations", metric.durations);
|
||||
}
|
||||
|
||||
template <typename EdgeDataT, storage::Ownership Ownership>
|
||||
inline void read(storage::tar::FileReader &reader,
|
||||
const std::string &name,
|
||||
MultiLevelGraph<EdgeDataT, Ownership> &graph)
|
||||
{
|
||||
storage::serialization::read(reader, name + "/node_array", graph.node_array);
|
||||
storage::serialization::read(reader, name + "/node_weights", graph.node_weights);
|
||||
storage::serialization::read(reader, name + "/node_durations", graph.node_durations);
|
||||
storage::serialization::read(reader, name + "/edge_array", graph.edge_array);
|
||||
storage::serialization::read(reader, name + "/is_forward_edge", graph.is_forward_edge);
|
||||
storage::serialization::read(reader, name + "/is_backward_edge", graph.is_backward_edge);
|
||||
storage::serialization::read(reader, name + "/node_to_edge_offset", graph.node_to_edge_offset);
|
||||
}
|
||||
|
||||
template <typename EdgeDataT, storage::Ownership Ownership>
|
||||
inline void write(storage::tar::FileWriter &writer,
|
||||
const std::string &name,
|
||||
const MultiLevelGraph<EdgeDataT, Ownership> &graph)
|
||||
{
|
||||
storage::serialization::write(writer, name + "/node_array", graph.node_array);
|
||||
storage::serialization::write(writer, name + "/node_weights", graph.node_weights);
|
||||
storage::serialization::write(writer, name + "/node_durations", graph.node_durations);
|
||||
storage::serialization::write(writer, name + "/edge_array", graph.edge_array);
|
||||
storage::serialization::write(writer, name + "/is_forward_edge", graph.is_forward_edge);
|
||||
storage::serialization::write(writer, name + "/is_backward_edge", graph.is_backward_edge);
|
||||
storage::serialization::write(writer, name + "/node_to_edge_offset", graph.node_to_edge_offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,9 @@ template <typename AlgorithmT> struct HasMapMatching final : std::false_type
|
||||
template <typename AlgorithmT> struct HasManyToManySearch final : std::false_type
|
||||
{
|
||||
};
|
||||
template <typename AlgorithmT> struct SupportsDistanceAnnotationType final : std::false_type
|
||||
{
|
||||
};
|
||||
template <typename AlgorithmT> struct HasGetTileTurns final : std::false_type
|
||||
{
|
||||
};
|
||||
@@ -73,6 +76,9 @@ template <> struct HasMapMatching<ch::Algorithm> final : std::true_type
|
||||
template <> struct HasManyToManySearch<ch::Algorithm> final : std::true_type
|
||||
{
|
||||
};
|
||||
template <> struct SupportsDistanceAnnotationType<ch::Algorithm> final : std::true_type
|
||||
{
|
||||
};
|
||||
template <> struct HasGetTileTurns<ch::Algorithm> final : std::true_type
|
||||
{
|
||||
};
|
||||
@@ -96,6 +102,9 @@ template <> struct HasMapMatching<mld::Algorithm> final : std::true_type
|
||||
template <> struct HasManyToManySearch<mld::Algorithm> final : std::true_type
|
||||
{
|
||||
};
|
||||
template <> struct SupportsDistanceAnnotationType<mld::Algorithm> final : std::false_type
|
||||
{
|
||||
};
|
||||
template <> struct HasGetTileTurns<mld::Algorithm> final : std::true_type
|
||||
{
|
||||
};
|
||||
|
||||
@@ -36,9 +36,10 @@ class TableAPI final : public BaseAPI
|
||||
{
|
||||
}
|
||||
|
||||
virtual void MakeResponse(const std::vector<EdgeWeight> &durations,
|
||||
const std::vector<PhantomNode> &phantoms,
|
||||
util::json::Object &response) const
|
||||
virtual void
|
||||
MakeResponse(const std::pair<std::vector<EdgeDuration>, std::vector<EdgeDistance>> &tables,
|
||||
const std::vector<PhantomNode> &phantoms,
|
||||
util::json::Object &response) const
|
||||
{
|
||||
auto number_of_sources = parameters.sources.size();
|
||||
auto number_of_destinations = parameters.destinations.size();
|
||||
@@ -64,8 +65,18 @@ class TableAPI final : public BaseAPI
|
||||
response.values["destinations"] = MakeWaypoints(phantoms, parameters.destinations);
|
||||
}
|
||||
|
||||
response.values["durations"] =
|
||||
MakeTable(durations, number_of_sources, number_of_destinations);
|
||||
if (parameters.annotations & TableParameters::AnnotationsType::Duration)
|
||||
{
|
||||
response.values["durations"] =
|
||||
MakeDurationTable(tables.first, number_of_sources, number_of_destinations);
|
||||
}
|
||||
|
||||
if (parameters.annotations & TableParameters::AnnotationsType::Distance)
|
||||
{
|
||||
response.values["distances"] =
|
||||
MakeDistanceTable(tables.second, number_of_sources, number_of_destinations);
|
||||
}
|
||||
|
||||
response.values["code"] = "Ok";
|
||||
}
|
||||
|
||||
@@ -97,9 +108,9 @@ class TableAPI final : public BaseAPI
|
||||
return json_waypoints;
|
||||
}
|
||||
|
||||
virtual util::json::Array MakeTable(const std::vector<EdgeWeight> &values,
|
||||
std::size_t number_of_rows,
|
||||
std::size_t number_of_columns) const
|
||||
virtual util::json::Array MakeDurationTable(const std::vector<EdgeWeight> &values,
|
||||
std::size_t number_of_rows,
|
||||
std::size_t number_of_columns) const
|
||||
{
|
||||
util::json::Array json_table;
|
||||
for (const auto row : util::irange<std::size_t>(0UL, number_of_rows))
|
||||
@@ -116,6 +127,7 @@ class TableAPI final : public BaseAPI
|
||||
{
|
||||
return util::json::Value(util::json::Null());
|
||||
}
|
||||
// division by 10 because the duration is in deciseconds (10s)
|
||||
return util::json::Value(util::json::Number(duration / 10.));
|
||||
});
|
||||
json_table.values.push_back(std::move(json_row));
|
||||
@@ -123,6 +135,34 @@ class TableAPI final : public BaseAPI
|
||||
return json_table;
|
||||
}
|
||||
|
||||
virtual util::json::Array MakeDistanceTable(const std::vector<EdgeDistance> &values,
|
||||
std::size_t number_of_rows,
|
||||
std::size_t number_of_columns) const
|
||||
{
|
||||
util::json::Array json_table;
|
||||
for (const auto row : util::irange<std::size_t>(0UL, number_of_rows))
|
||||
{
|
||||
util::json::Array json_row;
|
||||
auto row_begin_iterator = values.begin() + (row * number_of_columns);
|
||||
auto row_end_iterator = values.begin() + ((row + 1) * number_of_columns);
|
||||
json_row.values.resize(number_of_columns);
|
||||
std::transform(row_begin_iterator,
|
||||
row_end_iterator,
|
||||
json_row.values.begin(),
|
||||
[](const EdgeDistance distance) {
|
||||
if (distance == INVALID_EDGE_DISTANCE)
|
||||
{
|
||||
return util::json::Value(util::json::Null());
|
||||
}
|
||||
// round to single decimal place
|
||||
return util::json::Value(
|
||||
util::json::Number(std::round(distance * 10) / 10.));
|
||||
});
|
||||
json_table.values.push_back(std::move(json_row));
|
||||
}
|
||||
return json_table;
|
||||
}
|
||||
|
||||
const TableParameters ¶meters;
|
||||
};
|
||||
|
||||
|
||||
@@ -60,6 +60,16 @@ struct TableParameters : public BaseParameters
|
||||
std::vector<std::size_t> sources;
|
||||
std::vector<std::size_t> destinations;
|
||||
|
||||
enum class AnnotationsType
|
||||
{
|
||||
None = 0,
|
||||
Duration = 0x01,
|
||||
Distance = 0x02,
|
||||
All = Duration | Distance
|
||||
};
|
||||
|
||||
AnnotationsType annotations = AnnotationsType::Duration;
|
||||
|
||||
TableParameters() = default;
|
||||
template <typename... Args>
|
||||
TableParameters(std::vector<std::size_t> sources_,
|
||||
@@ -70,6 +80,16 @@ struct TableParameters : public BaseParameters
|
||||
{
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
TableParameters(std::vector<std::size_t> sources_,
|
||||
std::vector<std::size_t> destinations_,
|
||||
const AnnotationsType annotations_,
|
||||
Args... args_)
|
||||
: BaseParameters{std::forward<Args>(args_)...}, sources{std::move(sources_)},
|
||||
destinations{std::move(destinations_)}, annotations{annotations_}
|
||||
{
|
||||
}
|
||||
|
||||
bool IsValid() const
|
||||
{
|
||||
if (!BaseParameters::IsValid())
|
||||
@@ -79,7 +99,7 @@ struct TableParameters : public BaseParameters
|
||||
if (coordinates.size() < 2)
|
||||
return false;
|
||||
|
||||
// 1/ The user is able to specify duplicates in srcs and dsts, in that case it's her fault
|
||||
// 1/ The user is able to specify duplicates in srcs and dsts, in that case it's their fault
|
||||
|
||||
// 2/ len(srcs) and len(dsts) smaller or equal to len(locations)
|
||||
if (sources.size() > coordinates.size())
|
||||
@@ -100,6 +120,26 @@ struct TableParameters : public BaseParameters
|
||||
return true;
|
||||
}
|
||||
};
|
||||
inline bool operator&(TableParameters::AnnotationsType lhs, TableParameters::AnnotationsType rhs)
|
||||
{
|
||||
return static_cast<bool>(
|
||||
static_cast<std::underlying_type_t<TableParameters::AnnotationsType>>(lhs) &
|
||||
static_cast<std::underlying_type_t<TableParameters::AnnotationsType>>(rhs));
|
||||
}
|
||||
|
||||
inline TableParameters::AnnotationsType operator|(TableParameters::AnnotationsType lhs,
|
||||
TableParameters::AnnotationsType rhs)
|
||||
{
|
||||
return (TableParameters::AnnotationsType)(
|
||||
static_cast<std::underlying_type_t<TableParameters::AnnotationsType>>(lhs) |
|
||||
static_cast<std::underlying_type_t<TableParameters::AnnotationsType>>(rhs));
|
||||
}
|
||||
|
||||
inline TableParameters::AnnotationsType &operator|=(TableParameters::AnnotationsType &lhs,
|
||||
TableParameters::AnnotationsType rhs)
|
||||
{
|
||||
return lhs = lhs | rhs;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define OSRM_ENGINE_DATAFACADE_ALGORITHM_DATAFACADE_HPP
|
||||
|
||||
#include "contractor/query_edge.hpp"
|
||||
#include "customizer/edge_based_graph.hpp"
|
||||
#include "extractor/edge_based_edge.hpp"
|
||||
#include "engine/algorithm.hpp"
|
||||
|
||||
@@ -59,7 +60,7 @@ template <> class AlgorithmDataFacade<CH>
|
||||
template <> class AlgorithmDataFacade<MLD>
|
||||
{
|
||||
public:
|
||||
using EdgeData = extractor::EdgeBasedEdge::EdgeData;
|
||||
using EdgeData = customizer::EdgeBasedGraphEdgeData;
|
||||
using EdgeRange = util::range<EdgeID>;
|
||||
|
||||
// search graph access
|
||||
@@ -71,12 +72,20 @@ template <> class AlgorithmDataFacade<MLD>
|
||||
|
||||
virtual unsigned GetOutDegree(const NodeID n) const = 0;
|
||||
|
||||
virtual EdgeRange GetAdjacentEdgeRange(const NodeID node) const = 0;
|
||||
|
||||
virtual EdgeWeight GetNodeWeight(const NodeID node) const = 0;
|
||||
|
||||
virtual EdgeWeight GetNodeDuration(const NodeID node) const = 0; // TODO: to be removed
|
||||
|
||||
virtual bool IsForwardEdge(EdgeID edge) const = 0;
|
||||
|
||||
virtual bool IsBackwardEdge(EdgeID edge) const = 0;
|
||||
|
||||
virtual NodeID GetTarget(const EdgeID e) const = 0;
|
||||
|
||||
virtual const EdgeData &GetEdgeData(const EdgeID e) const = 0;
|
||||
|
||||
virtual EdgeRange GetAdjacentEdgeRange(const NodeID node) const = 0;
|
||||
|
||||
virtual const partitioner::MultiLevelPartitionView &GetMultiLevelPartition() const = 0;
|
||||
|
||||
virtual const partitioner::CellStorageView &GetCellStorage() const = 0;
|
||||
|
||||
@@ -133,7 +133,6 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
|
||||
using RTreeNode = SharedRTree::TreeNode;
|
||||
|
||||
extractor::ClassData exclude_mask;
|
||||
std::string m_timestamp;
|
||||
extractor::ProfileProperties *m_profile_properties;
|
||||
extractor::Datasources *m_datasources;
|
||||
|
||||
@@ -283,13 +282,13 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
|
||||
return segment_data.GetReverseDatasources(id);
|
||||
}
|
||||
|
||||
TurnPenalty GetWeightPenaltyForEdgeID(const unsigned id) const override final
|
||||
TurnPenalty GetWeightPenaltyForEdgeID(const EdgeID id) const override final
|
||||
{
|
||||
BOOST_ASSERT(m_turn_weight_penalties.size() > id);
|
||||
return m_turn_weight_penalties[id];
|
||||
}
|
||||
|
||||
TurnPenalty GetDurationPenaltyForEdgeID(const unsigned id) const override final
|
||||
TurnPenalty GetDurationPenaltyForEdgeID(const EdgeID id) const override final
|
||||
{
|
||||
BOOST_ASSERT(m_turn_duration_penalties.size() > id);
|
||||
return m_turn_duration_penalties[id];
|
||||
@@ -622,7 +621,6 @@ class ContiguousInternalMemoryDataFacade<CH>
|
||||
const std::size_t exclude_index)
|
||||
: ContiguousInternalMemoryDataFacadeBase(allocator, metric_name, exclude_index),
|
||||
ContiguousInternalMemoryAlgorithmDataFacade<CH>(allocator, metric_name, exclude_index)
|
||||
|
||||
{
|
||||
}
|
||||
};
|
||||
@@ -684,6 +682,31 @@ template <> class ContiguousInternalMemoryAlgorithmDataFacade<MLD> : public Algo
|
||||
return query_graph.GetOutDegree(n);
|
||||
}
|
||||
|
||||
EdgeRange GetAdjacentEdgeRange(const NodeID node) const override final
|
||||
{
|
||||
return query_graph.GetAdjacentEdgeRange(node);
|
||||
}
|
||||
|
||||
EdgeWeight GetNodeWeight(const NodeID node) const override final
|
||||
{
|
||||
return query_graph.GetNodeWeight(node);
|
||||
}
|
||||
|
||||
EdgeDuration GetNodeDuration(const NodeID node) const override final
|
||||
{
|
||||
return query_graph.GetNodeDuration(node);
|
||||
}
|
||||
|
||||
bool IsForwardEdge(const NodeID node) const override final
|
||||
{
|
||||
return query_graph.IsForwardEdge(node);
|
||||
}
|
||||
|
||||
bool IsBackwardEdge(const NodeID node) const override final
|
||||
{
|
||||
return query_graph.IsBackwardEdge(node);
|
||||
}
|
||||
|
||||
NodeID GetTarget(const EdgeID e) const override final { return query_graph.GetTarget(e); }
|
||||
|
||||
const EdgeData &GetEdgeData(const EdgeID e) const override final
|
||||
@@ -691,11 +714,6 @@ template <> class ContiguousInternalMemoryAlgorithmDataFacade<MLD> : public Algo
|
||||
return query_graph.GetEdgeData(e);
|
||||
}
|
||||
|
||||
EdgeRange GetAdjacentEdgeRange(const NodeID node) const override final
|
||||
{
|
||||
return query_graph.GetAdjacentEdgeRange(node);
|
||||
}
|
||||
|
||||
EdgeRange GetBorderEdgeRange(const LevelID level, const NodeID node) const override final
|
||||
{
|
||||
return query_graph.GetBorderEdgeRange(level, node);
|
||||
@@ -720,7 +738,6 @@ class ContiguousInternalMemoryDataFacade<MLD> final
|
||||
const std::size_t exclude_index)
|
||||
: ContiguousInternalMemoryDataFacadeBase(allocator, metric_name, exclude_index),
|
||||
ContiguousInternalMemoryAlgorithmDataFacade<MLD>(allocator, metric_name, exclude_index)
|
||||
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
|
||||
#include <boost/range/adaptor/reversed.hpp>
|
||||
#include <boost/range/any_range.hpp>
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#include <string>
|
||||
@@ -87,9 +86,9 @@ class BaseDataFacade
|
||||
virtual NodeForwardRange GetUncompressedForwardGeometry(const EdgeID id) const = 0;
|
||||
virtual NodeReverseRange GetUncompressedReverseGeometry(const EdgeID id) const = 0;
|
||||
|
||||
virtual TurnPenalty GetWeightPenaltyForEdgeID(const unsigned id) const = 0;
|
||||
virtual TurnPenalty GetWeightPenaltyForEdgeID(const EdgeID id) const = 0;
|
||||
|
||||
virtual TurnPenalty GetDurationPenaltyForEdgeID(const unsigned id) const = 0;
|
||||
virtual TurnPenalty GetDurationPenaltyForEdgeID(const EdgeID id) const = 0;
|
||||
|
||||
// Gets the weight values for each segment in an uncompressed geometry.
|
||||
// Should always be 1 shorter than GetUncompressedGeometry
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <boost/iostreams/device/mapped_file.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
@@ -24,8 +25,7 @@ namespace datafacade
|
||||
class MMapMemoryAllocator : public ContiguousBlockAllocator
|
||||
{
|
||||
public:
|
||||
explicit MMapMemoryAllocator(const storage::StorageConfig &config,
|
||||
const boost::filesystem::path &memory_file);
|
||||
explicit MMapMemoryAllocator(const storage::StorageConfig &config);
|
||||
~MMapMemoryAllocator() override final;
|
||||
|
||||
// interface to give access to the datafacades
|
||||
@@ -33,8 +33,8 @@ class MMapMemoryAllocator : public ContiguousBlockAllocator
|
||||
|
||||
private:
|
||||
storage::SharedDataIndex index;
|
||||
util::vector_view<char> mapped_memory;
|
||||
boost::iostreams::mapped_file mapped_memory_file;
|
||||
std::vector<boost::iostreams::mapped_file> mapped_memory_files;
|
||||
std::string rtree_filename;
|
||||
};
|
||||
|
||||
} // namespace datafacade
|
||||
|
||||
@@ -32,9 +32,8 @@ class ExternalProvider final : public DataFacadeProvider<AlgorithmT, FacadeT>
|
||||
public:
|
||||
using Facade = typename DataFacadeProvider<AlgorithmT, FacadeT>::Facade;
|
||||
|
||||
ExternalProvider(const storage::StorageConfig &config,
|
||||
const boost::filesystem::path &memory_file)
|
||||
: facade_factory(std::make_shared<datafacade::MMapMemoryAllocator>(config, memory_file))
|
||||
ExternalProvider(const storage::StorageConfig &config)
|
||||
: facade_factory(std::make_shared<datafacade::MMapMemoryAllocator>(config))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -94,7 +93,7 @@ class WatchingProvider : public DataFacadeProvider<AlgorithmT, FacadeT>
|
||||
return watchdog.Get(params);
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
template <typename AlgorithmT>
|
||||
using DataFacadeProvider = detail::DataFacadeProvider<AlgorithmT, DataFacade>;
|
||||
@@ -104,7 +103,7 @@ template <typename AlgorithmT>
|
||||
using ImmutableProvider = detail::ImmutableProvider<AlgorithmT, DataFacade>;
|
||||
template <typename AlgorithmT>
|
||||
using ExternalProvider = detail::ExternalProvider<AlgorithmT, DataFacade>;
|
||||
}
|
||||
}
|
||||
} // namespace engine
|
||||
} // namespace osrm
|
||||
|
||||
#endif
|
||||
|
||||
@@ -63,12 +63,16 @@ template <typename Algorithm> class Engine final : public EngineInterface
|
||||
<< "\" with algorithm " << routing_algorithms::name<Algorithm>();
|
||||
facade_provider = std::make_unique<WatchingProvider<Algorithm>>(config.dataset_name);
|
||||
}
|
||||
else if (!config.memory_file.empty())
|
||||
else if (!config.memory_file.empty() || config.use_mmap)
|
||||
{
|
||||
util::Log(logDEBUG) << "Using memory mapped filed at " << config.memory_file
|
||||
<< " with algorithm " << routing_algorithms::name<Algorithm>();
|
||||
facade_provider = std::make_unique<ExternalProvider<Algorithm>>(config.storage_config,
|
||||
config.memory_file);
|
||||
if (!config.memory_file.empty())
|
||||
{
|
||||
util::Log(logWARNING)
|
||||
<< "The 'memory_file' option is DEPRECATED - using direct mmaping instead";
|
||||
}
|
||||
util::Log(logDEBUG) << "Using direct memory mapping with algorithm "
|
||||
<< routing_algorithms::name<Algorithm>();
|
||||
facade_provider = std::make_unique<ExternalProvider<Algorithm>>(config.storage_config);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -134,7 +138,7 @@ template <typename Algorithm> class Engine final : public EngineInterface
|
||||
const plugins::MatchPlugin match_plugin;
|
||||
const plugins::TilePlugin tile_plugin;
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace engine
|
||||
} // namespace osrm
|
||||
|
||||
#endif // OSRM_IMPL_HPP
|
||||
|
||||
@@ -89,11 +89,12 @@ struct EngineConfig final
|
||||
int max_alternatives = 3; // set an arbitrary upper bound; can be adjusted by user
|
||||
bool use_shared_memory = true;
|
||||
boost::filesystem::path memory_file;
|
||||
bool use_mmap = true;
|
||||
Algorithm algorithm = Algorithm::CH;
|
||||
std::string verbosity;
|
||||
std::string dataset_name;
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace engine
|
||||
} // namespace osrm
|
||||
|
||||
#endif // SERVER_CONFIG_HPP
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <iterator>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
@@ -447,6 +448,8 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
|
||||
const auto forward_durations = datafacade.GetUncompressedForwardDurations(geometry_id);
|
||||
const auto reverse_durations = datafacade.GetUncompressedReverseDurations(geometry_id);
|
||||
|
||||
const auto forward_geometry = datafacade.GetUncompressedForwardGeometry(geometry_id);
|
||||
|
||||
const auto forward_weight_offset =
|
||||
std::accumulate(forward_weights.begin(),
|
||||
forward_weights.begin() + data.fwd_segment_position,
|
||||
@@ -457,12 +460,25 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
|
||||
forward_durations.begin() + data.fwd_segment_position,
|
||||
EdgeDuration{0});
|
||||
|
||||
EdgeWeight forward_weight = forward_weights[data.fwd_segment_position];
|
||||
EdgeDuration forward_duration = forward_durations[data.fwd_segment_position];
|
||||
EdgeDistance forward_distance_offset = 0;
|
||||
for (auto current = forward_geometry.begin();
|
||||
current < forward_geometry.begin() + data.fwd_segment_position;
|
||||
++current)
|
||||
{
|
||||
forward_distance_offset += util::coordinate_calculation::fccApproximateDistance(
|
||||
datafacade.GetCoordinateOfNode(*current),
|
||||
datafacade.GetCoordinateOfNode(*std::next(current)));
|
||||
}
|
||||
|
||||
BOOST_ASSERT(data.fwd_segment_position <
|
||||
std::distance(forward_durations.begin(), forward_durations.end()));
|
||||
|
||||
EdgeWeight forward_weight = forward_weights[data.fwd_segment_position];
|
||||
EdgeDuration forward_duration = forward_durations[data.fwd_segment_position];
|
||||
EdgeDistance forward_distance = util::coordinate_calculation::fccApproximateDistance(
|
||||
datafacade.GetCoordinateOfNode(forward_geometry(data.fwd_segment_position)),
|
||||
point_on_segment);
|
||||
|
||||
const auto reverse_weight_offset =
|
||||
std::accumulate(reverse_weights.begin(),
|
||||
reverse_weights.end() - data.fwd_segment_position - 1,
|
||||
@@ -473,10 +489,23 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
|
||||
reverse_durations.end() - data.fwd_segment_position - 1,
|
||||
EdgeDuration{0});
|
||||
|
||||
EdgeDistance reverse_distance_offset = 0;
|
||||
for (auto current = forward_geometry.begin();
|
||||
current < forward_geometry.end() - data.fwd_segment_position - 2;
|
||||
++current)
|
||||
{
|
||||
reverse_distance_offset += util::coordinate_calculation::fccApproximateDistance(
|
||||
datafacade.GetCoordinateOfNode(*current),
|
||||
datafacade.GetCoordinateOfNode(*std::next(current)));
|
||||
}
|
||||
|
||||
EdgeWeight reverse_weight =
|
||||
reverse_weights[reverse_weights.size() - data.fwd_segment_position - 1];
|
||||
EdgeDuration reverse_duration =
|
||||
reverse_durations[reverse_durations.size() - data.fwd_segment_position - 1];
|
||||
EdgeDistance reverse_distance = util::coordinate_calculation::fccApproximateDistance(
|
||||
point_on_segment,
|
||||
datafacade.GetCoordinateOfNode(forward_geometry(data.fwd_segment_position + 1)));
|
||||
|
||||
ratio = std::min(1.0, std::max(0.0, ratio));
|
||||
if (data.forward_segment_id.id != SPECIAL_SEGMENTID)
|
||||
@@ -510,6 +539,10 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
|
||||
reverse_weight,
|
||||
forward_weight_offset,
|
||||
reverse_weight_offset,
|
||||
forward_distance,
|
||||
reverse_distance,
|
||||
forward_distance_offset,
|
||||
reverse_distance_offset,
|
||||
forward_duration,
|
||||
reverse_duration,
|
||||
forward_duration_offset,
|
||||
|
||||
@@ -63,8 +63,8 @@ struct Hint
|
||||
friend std::ostream &operator<<(std::ostream &, const Hint &);
|
||||
};
|
||||
|
||||
static_assert(sizeof(Hint) == 64 + 4, "Hint is bigger than expected");
|
||||
constexpr std::size_t ENCODED_HINT_SIZE = 92;
|
||||
static_assert(sizeof(Hint) == 80 + 4, "Hint is bigger than expected");
|
||||
constexpr std::size_t ENCODED_HINT_SIZE = 112;
|
||||
static_assert(ENCODED_HINT_SIZE / 4 * 3 >= sizeof(Hint),
|
||||
"ENCODED_HINT_SIZE does not match size of Hint");
|
||||
}
|
||||
|
||||
@@ -34,6 +34,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "util/coordinate.hpp"
|
||||
#include "util/typedefs.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
namespace osrm
|
||||
@@ -47,10 +49,13 @@ struct PhantomNode
|
||||
: forward_segment_id{SPECIAL_SEGMENTID, false},
|
||||
reverse_segment_id{SPECIAL_SEGMENTID, false}, forward_weight(INVALID_EDGE_WEIGHT),
|
||||
reverse_weight(INVALID_EDGE_WEIGHT), forward_weight_offset(0), reverse_weight_offset(0),
|
||||
forward_distance(INVALID_EDGE_DISTANCE), reverse_distance(INVALID_EDGE_DISTANCE),
|
||||
forward_distance_offset(0), reverse_distance_offset(0),
|
||||
forward_duration(MAXIMAL_EDGE_DURATION), reverse_duration(MAXIMAL_EDGE_DURATION),
|
||||
forward_duration_offset(0), reverse_duration_offset(0), fwd_segment_position(0),
|
||||
is_valid_forward_source{false}, is_valid_forward_target{false},
|
||||
is_valid_reverse_source{false}, is_valid_reverse_target{false}, bearing(0)
|
||||
|
||||
{
|
||||
}
|
||||
|
||||
@@ -78,6 +83,30 @@ struct PhantomNode
|
||||
return reverse_duration + reverse_duration_offset;
|
||||
}
|
||||
|
||||
// DO THIS FOR DISTANCE
|
||||
|
||||
EdgeDistance GetForwardDistance() const
|
||||
{
|
||||
// ..... <-- forward_distance
|
||||
// .... <-- offset
|
||||
// ......... <-- desired distance
|
||||
// x <-- this is PhantomNode.location
|
||||
// 0----1----2----3----4 <-- EdgeBasedGraph Node segments
|
||||
BOOST_ASSERT(forward_segment_id.enabled);
|
||||
return forward_distance + forward_distance_offset;
|
||||
}
|
||||
|
||||
EdgeDistance GetReverseDistance() const
|
||||
{
|
||||
// .......... <-- reverse_distance
|
||||
// ... <-- offset
|
||||
// ............. <-- desired distance
|
||||
// x <-- this is PhantomNode.location
|
||||
// 0----1----2----3----4 <-- EdgeBasedGraph Node segments
|
||||
BOOST_ASSERT(reverse_segment_id.enabled);
|
||||
return reverse_distance + reverse_distance_offset;
|
||||
}
|
||||
|
||||
bool IsBidirected() const { return forward_segment_id.enabled && reverse_segment_id.enabled; }
|
||||
|
||||
bool IsValid(const unsigned number_of_nodes) const
|
||||
@@ -88,6 +117,8 @@ struct PhantomNode
|
||||
(reverse_weight != INVALID_EDGE_WEIGHT)) &&
|
||||
((forward_duration != MAXIMAL_EDGE_DURATION) ||
|
||||
(reverse_duration != MAXIMAL_EDGE_DURATION)) &&
|
||||
((forward_distance != INVALID_EDGE_DISTANCE) ||
|
||||
(reverse_distance != INVALID_EDGE_DISTANCE)) &&
|
||||
(component.id != INVALID_COMPONENTID);
|
||||
}
|
||||
|
||||
@@ -130,6 +161,10 @@ struct PhantomNode
|
||||
EdgeWeight reverse_weight,
|
||||
EdgeWeight forward_weight_offset,
|
||||
EdgeWeight reverse_weight_offset,
|
||||
EdgeDistance forward_distance,
|
||||
EdgeDistance reverse_distance,
|
||||
EdgeDistance forward_distance_offset,
|
||||
EdgeDistance reverse_distance_offset,
|
||||
EdgeWeight forward_duration,
|
||||
EdgeWeight reverse_duration,
|
||||
EdgeWeight forward_duration_offset,
|
||||
@@ -144,7 +179,9 @@ struct PhantomNode
|
||||
: forward_segment_id{other.forward_segment_id},
|
||||
reverse_segment_id{other.reverse_segment_id}, forward_weight{forward_weight},
|
||||
reverse_weight{reverse_weight}, forward_weight_offset{forward_weight_offset},
|
||||
reverse_weight_offset{reverse_weight_offset}, forward_duration{forward_duration},
|
||||
reverse_weight_offset{reverse_weight_offset}, forward_distance{forward_distance},
|
||||
reverse_distance{reverse_distance}, forward_distance_offset{forward_distance_offset},
|
||||
reverse_distance_offset{reverse_distance_offset}, forward_duration{forward_duration},
|
||||
reverse_duration{reverse_duration}, forward_duration_offset{forward_duration_offset},
|
||||
reverse_duration_offset{reverse_duration_offset},
|
||||
component{component.id, component.is_tiny}, location{location},
|
||||
@@ -162,13 +199,17 @@ struct PhantomNode
|
||||
EdgeWeight reverse_weight;
|
||||
EdgeWeight forward_weight_offset; // TODO: try to remove -> requires path unpacking changes
|
||||
EdgeWeight reverse_weight_offset; // TODO: try to remove -> requires path unpacking changes
|
||||
EdgeDistance forward_distance;
|
||||
EdgeDistance reverse_distance;
|
||||
EdgeDistance forward_distance_offset; // TODO: try to remove -> requires path unpacking changes
|
||||
EdgeDistance reverse_distance_offset; // TODO: try to remove -> requires path unpacking changes
|
||||
EdgeWeight forward_duration;
|
||||
EdgeWeight reverse_duration;
|
||||
EdgeWeight forward_duration_offset; // TODO: try to remove -> requires path unpacking changes
|
||||
EdgeWeight reverse_duration_offset; // TODO: try to remove -> requires path unpacking changes
|
||||
ComponentID component;
|
||||
|
||||
util::Coordinate location;
|
||||
util::Coordinate location; // this is the coordinate of x
|
||||
util::Coordinate input_location;
|
||||
unsigned short fwd_segment_position;
|
||||
// is phantom node valid to be used as source or target
|
||||
@@ -180,7 +221,7 @@ struct PhantomNode
|
||||
unsigned short bearing : 12;
|
||||
};
|
||||
|
||||
static_assert(sizeof(PhantomNode) == 64, "PhantomNode has more padding then expected");
|
||||
static_assert(sizeof(PhantomNode) == 80, "PhantomNode has more padding then expected");
|
||||
|
||||
using PhantomNodePair = std::pair<PhantomNode, PhantomNode>;
|
||||
|
||||
@@ -195,7 +236,7 @@ struct PhantomNodes
|
||||
PhantomNode source_phantom;
|
||||
PhantomNode target_phantom;
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace engine
|
||||
} // namespace osrm
|
||||
|
||||
#endif // PHANTOM_NODES_H
|
||||
|
||||
@@ -30,10 +30,12 @@ class RoutingAlgorithmsInterface
|
||||
virtual InternalRouteResult
|
||||
DirectShortestPathSearch(const PhantomNodes &phantom_node_pair) const = 0;
|
||||
|
||||
virtual std::vector<EdgeDuration>
|
||||
virtual std::pair<std::vector<EdgeDuration>, std::vector<EdgeDistance>>
|
||||
ManyToManySearch(const std::vector<PhantomNode> &phantom_nodes,
|
||||
const std::vector<std::size_t> &source_indices,
|
||||
const std::vector<std::size_t> &target_indices) const = 0;
|
||||
const std::vector<std::size_t> &target_indices,
|
||||
const bool calculate_distance,
|
||||
const bool calculate_duration) const = 0;
|
||||
|
||||
virtual routing_algorithms::SubMatchingList
|
||||
MapMatching(const routing_algorithms::CandidateLists &candidates_list,
|
||||
@@ -53,6 +55,7 @@ class RoutingAlgorithmsInterface
|
||||
virtual bool HasDirectShortestPathSearch() const = 0;
|
||||
virtual bool HasMapMatching() const = 0;
|
||||
virtual bool HasManyToManySearch() const = 0;
|
||||
virtual bool SupportsDistanceAnnotationType() const = 0;
|
||||
virtual bool HasGetTileTurns() const = 0;
|
||||
virtual bool HasExcludeFlags() const = 0;
|
||||
virtual bool IsValid() const = 0;
|
||||
@@ -81,10 +84,12 @@ template <typename Algorithm> class RoutingAlgorithms final : public RoutingAlgo
|
||||
InternalRouteResult
|
||||
DirectShortestPathSearch(const PhantomNodes &phantom_nodes) const final override;
|
||||
|
||||
std::vector<EdgeDuration>
|
||||
virtual std::pair<std::vector<EdgeDuration>, std::vector<EdgeDistance>>
|
||||
ManyToManySearch(const std::vector<PhantomNode> &phantom_nodes,
|
||||
const std::vector<std::size_t> &source_indices,
|
||||
const std::vector<std::size_t> &target_indices) const final override;
|
||||
const std::vector<std::size_t> &target_indices,
|
||||
const bool calculate_distance,
|
||||
const bool calculate_duration) const final override;
|
||||
|
||||
routing_algorithms::SubMatchingList
|
||||
MapMatching(const routing_algorithms::CandidateLists &candidates_list,
|
||||
@@ -124,6 +129,11 @@ template <typename Algorithm> class RoutingAlgorithms final : public RoutingAlgo
|
||||
return routing_algorithms::HasManyToManySearch<Algorithm>::value;
|
||||
}
|
||||
|
||||
bool SupportsDistanceAnnotationType() const final override
|
||||
{
|
||||
return routing_algorithms::SupportsDistanceAnnotationType<Algorithm>::value;
|
||||
}
|
||||
|
||||
bool HasGetTileTurns() const final override
|
||||
{
|
||||
return routing_algorithms::HasGetTileTurns<Algorithm>::value;
|
||||
@@ -184,10 +194,12 @@ inline routing_algorithms::SubMatchingList RoutingAlgorithms<Algorithm>::MapMatc
|
||||
}
|
||||
|
||||
template <typename Algorithm>
|
||||
std::vector<EdgeDuration> RoutingAlgorithms<Algorithm>::ManyToManySearch(
|
||||
const std::vector<PhantomNode> &phantom_nodes,
|
||||
const std::vector<std::size_t> &_source_indices,
|
||||
const std::vector<std::size_t> &_target_indices) const
|
||||
std::pair<std::vector<EdgeDuration>, std::vector<EdgeDistance>>
|
||||
RoutingAlgorithms<Algorithm>::ManyToManySearch(const std::vector<PhantomNode> &phantom_nodes,
|
||||
const std::vector<std::size_t> &_source_indices,
|
||||
const std::vector<std::size_t> &_target_indices,
|
||||
const bool calculate_distance,
|
||||
const bool calculate_duration) const
|
||||
{
|
||||
BOOST_ASSERT(!phantom_nodes.empty());
|
||||
|
||||
@@ -205,8 +217,13 @@ std::vector<EdgeDuration> RoutingAlgorithms<Algorithm>::ManyToManySearch(
|
||||
std::iota(target_indices.begin(), target_indices.end(), 0);
|
||||
}
|
||||
|
||||
return routing_algorithms::manyToManySearch(
|
||||
heaps, *facade, phantom_nodes, std::move(source_indices), std::move(target_indices));
|
||||
return routing_algorithms::manyToManySearch(heaps,
|
||||
*facade,
|
||||
phantom_nodes,
|
||||
std::move(source_indices),
|
||||
std::move(target_indices),
|
||||
calculate_distance,
|
||||
calculate_duration);
|
||||
}
|
||||
|
||||
template <typename Algorithm>
|
||||
|
||||
@@ -15,23 +15,46 @@ namespace engine
|
||||
{
|
||||
namespace routing_algorithms
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
struct NodeBucket
|
||||
{
|
||||
NodeID middle_node;
|
||||
unsigned column_index; // a column in the weight/duration matrix
|
||||
NodeID parent_node;
|
||||
unsigned column_index : 31; // a column in the weight/duration matrix
|
||||
unsigned from_clique_arc : 1;
|
||||
EdgeWeight weight;
|
||||
EdgeDuration duration;
|
||||
EdgeDistance distance;
|
||||
|
||||
NodeBucket(NodeID middle_node, unsigned column_index, EdgeWeight weight, EdgeDuration duration)
|
||||
: middle_node(middle_node), column_index(column_index), weight(weight), duration(duration)
|
||||
NodeBucket(NodeID middle_node,
|
||||
NodeID parent_node,
|
||||
bool from_clique_arc,
|
||||
unsigned column_index,
|
||||
EdgeWeight weight,
|
||||
EdgeDuration duration,
|
||||
EdgeDistance distance)
|
||||
: middle_node(middle_node), parent_node(parent_node), column_index(column_index),
|
||||
from_clique_arc(from_clique_arc), weight(weight), duration(duration), distance(distance)
|
||||
{
|
||||
}
|
||||
|
||||
NodeBucket(NodeID middle_node,
|
||||
NodeID parent_node,
|
||||
unsigned column_index,
|
||||
EdgeWeight weight,
|
||||
EdgeDuration duration,
|
||||
EdgeDistance distance)
|
||||
: middle_node(middle_node), parent_node(parent_node), column_index(column_index),
|
||||
from_clique_arc(false), weight(weight), duration(duration), distance(distance)
|
||||
{
|
||||
}
|
||||
|
||||
// partial order comparison
|
||||
bool operator<(const NodeBucket &rhs) const { return middle_node < rhs.middle_node; }
|
||||
bool operator<(const NodeBucket &rhs) const
|
||||
{
|
||||
return std::tie(middle_node, column_index) < std::tie(rhs.middle_node, rhs.column_index);
|
||||
}
|
||||
|
||||
// functor for equal_range
|
||||
struct Compare
|
||||
@@ -46,15 +69,36 @@ struct NodeBucket
|
||||
return lhs < rhs.middle_node;
|
||||
}
|
||||
};
|
||||
|
||||
// functor for equal_range
|
||||
struct ColumnCompare
|
||||
{
|
||||
unsigned column_idx;
|
||||
|
||||
ColumnCompare(unsigned column_idx) : column_idx(column_idx){};
|
||||
|
||||
bool operator()(const NodeBucket &lhs, const NodeID &rhs) const // lowerbound
|
||||
{
|
||||
return std::tie(lhs.middle_node, lhs.column_index) < std::tie(rhs, column_idx);
|
||||
}
|
||||
|
||||
bool operator()(const NodeID &lhs, const NodeBucket &rhs) const // upperbound
|
||||
{
|
||||
return std::tie(lhs, column_idx) < std::tie(rhs.middle_node, rhs.column_index);
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
template <typename Algorithm>
|
||||
std::vector<EdgeDuration> manyToManySearch(SearchEngineData<Algorithm> &engine_working_data,
|
||||
const DataFacade<Algorithm> &facade,
|
||||
const std::vector<PhantomNode> &phantom_nodes,
|
||||
const std::vector<std::size_t> &source_indices,
|
||||
const std::vector<std::size_t> &target_indices);
|
||||
std::pair<std::vector<EdgeDuration>, std::vector<EdgeDistance>>
|
||||
manyToManySearch(SearchEngineData<Algorithm> &engine_working_data,
|
||||
const DataFacade<Algorithm> &facade,
|
||||
const std::vector<PhantomNode> &phantom_nodes,
|
||||
const std::vector<std::size_t> &source_indices,
|
||||
const std::vector<std::size_t> &target_indices,
|
||||
const bool calculate_distance,
|
||||
const bool calculate_duration);
|
||||
|
||||
} // namespace routing_algorithms
|
||||
} // namespace engine
|
||||
|
||||
@@ -85,13 +85,17 @@ void insertSourceInHeap(ManyToManyQueryHeap &heap, const PhantomNode &phantom_no
|
||||
{
|
||||
heap.Insert(phantom_node.forward_segment_id.id,
|
||||
-phantom_node.GetForwardWeightPlusOffset(),
|
||||
{phantom_node.forward_segment_id.id, -phantom_node.GetForwardDuration()});
|
||||
{phantom_node.forward_segment_id.id,
|
||||
-phantom_node.GetForwardDuration(),
|
||||
-phantom_node.GetForwardDistance()});
|
||||
}
|
||||
if (phantom_node.IsValidReverseSource())
|
||||
{
|
||||
heap.Insert(phantom_node.reverse_segment_id.id,
|
||||
-phantom_node.GetReverseWeightPlusOffset(),
|
||||
{phantom_node.reverse_segment_id.id, -phantom_node.GetReverseDuration()});
|
||||
{phantom_node.reverse_segment_id.id,
|
||||
-phantom_node.GetReverseDuration(),
|
||||
-phantom_node.GetReverseDistance()});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,13 +106,17 @@ void insertTargetInHeap(ManyToManyQueryHeap &heap, const PhantomNode &phantom_no
|
||||
{
|
||||
heap.Insert(phantom_node.forward_segment_id.id,
|
||||
phantom_node.GetForwardWeightPlusOffset(),
|
||||
{phantom_node.forward_segment_id.id, phantom_node.GetForwardDuration()});
|
||||
{phantom_node.forward_segment_id.id,
|
||||
phantom_node.GetForwardDuration(),
|
||||
phantom_node.GetForwardDistance()});
|
||||
}
|
||||
if (phantom_node.IsValidReverseTarget())
|
||||
{
|
||||
heap.Insert(phantom_node.reverse_segment_id.id,
|
||||
phantom_node.GetReverseWeightPlusOffset(),
|
||||
{phantom_node.reverse_segment_id.id, phantom_node.GetReverseDuration()});
|
||||
{phantom_node.reverse_segment_id.id,
|
||||
phantom_node.GetReverseDuration(),
|
||||
phantom_node.GetReverseDistance()});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,6 +189,7 @@ void annotatePath(const FacadeT &facade,
|
||||
BOOST_ASSERT(datasource_vector.size() > 0);
|
||||
BOOST_ASSERT(weight_vector.size() + 1 == id_vector.size());
|
||||
BOOST_ASSERT(duration_vector.size() + 1 == id_vector.size());
|
||||
|
||||
const bool is_first_segment = unpacked_path.empty();
|
||||
|
||||
const std::size_t start_index =
|
||||
@@ -405,6 +414,22 @@ InternalRouteResult extractRoute(const DataFacade<AlgorithmT> &facade,
|
||||
return raw_route_data;
|
||||
}
|
||||
|
||||
template <typename FacadeT> EdgeDistance computeEdgeDistance(const FacadeT &facade, NodeID node_id)
|
||||
{
|
||||
const auto geometry_index = facade.GetGeometryIndex(node_id);
|
||||
|
||||
EdgeDistance total_distance = 0.0;
|
||||
|
||||
auto geometry_range = facade.GetUncompressedForwardGeometry(geometry_index.id);
|
||||
for (auto current = geometry_range.begin(); current < geometry_range.end() - 1; ++current)
|
||||
{
|
||||
total_distance += util::coordinate_calculation::fccApproximateDistance(
|
||||
facade.GetCoordinateOfNode(*current), facade.GetCoordinateOfNode(*std::next(current)));
|
||||
}
|
||||
|
||||
return total_distance;
|
||||
}
|
||||
|
||||
} // namespace routing_algorithms
|
||||
} // namespace engine
|
||||
} // namespace osrm
|
||||
|
||||
@@ -186,9 +186,10 @@ void routingStep(const DataFacade<Algorithm> &facade,
|
||||
}
|
||||
|
||||
template <bool UseDuration>
|
||||
EdgeWeight getLoopWeight(const DataFacade<Algorithm> &facade, NodeID node)
|
||||
std::tuple<EdgeWeight, EdgeDistance> getLoopWeight(const DataFacade<Algorithm> &facade, NodeID node)
|
||||
{
|
||||
EdgeWeight loop_weight = UseDuration ? MAXIMAL_EDGE_DURATION : INVALID_EDGE_WEIGHT;
|
||||
EdgeDistance loop_distance = MAXIMAL_EDGE_DISTANCE;
|
||||
for (auto edge : facade.GetAdjacentEdgeRange(node))
|
||||
{
|
||||
const auto &data = facade.GetEdgeData(edge);
|
||||
@@ -198,11 +199,15 @@ EdgeWeight getLoopWeight(const DataFacade<Algorithm> &facade, NodeID node)
|
||||
if (to == node)
|
||||
{
|
||||
const auto value = UseDuration ? data.duration : data.weight;
|
||||
loop_weight = std::min(loop_weight, value);
|
||||
if (value < loop_weight)
|
||||
{
|
||||
loop_weight = value;
|
||||
loop_distance = data.distance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return loop_weight;
|
||||
return std::make_tuple(loop_weight, loop_distance);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -288,6 +293,106 @@ void unpackPath(const DataFacade<Algorithm> &facade,
|
||||
}
|
||||
}
|
||||
|
||||
template <typename BidirectionalIterator>
|
||||
EdgeDistance calculateEBGNodeAnnotations(const DataFacade<Algorithm> &facade,
|
||||
BidirectionalIterator packed_path_begin,
|
||||
BidirectionalIterator packed_path_end)
|
||||
{
|
||||
// Make sure we have at least something to unpack
|
||||
if (packed_path_begin == packed_path_end ||
|
||||
std::distance(packed_path_begin, packed_path_end) <= 1)
|
||||
return 0;
|
||||
|
||||
std::stack<std::tuple<NodeID, NodeID, bool>> recursion_stack;
|
||||
std::stack<EdgeDistance> distance_stack;
|
||||
// We have to push the path in reverse order onto the stack because it's LIFO.
|
||||
for (auto current = std::prev(packed_path_end); current > packed_path_begin;
|
||||
current = std::prev(current))
|
||||
{
|
||||
recursion_stack.emplace(*std::prev(current), *current, false);
|
||||
}
|
||||
|
||||
std::tuple<NodeID, NodeID, bool> edge;
|
||||
while (!recursion_stack.empty())
|
||||
{
|
||||
edge = recursion_stack.top();
|
||||
recursion_stack.pop();
|
||||
|
||||
// Have we processed the edge before? tells us if we have values in the durations stack that
|
||||
// we can add up
|
||||
if (!std::get<2>(edge))
|
||||
{ // haven't processed edge before, so process it in the body!
|
||||
|
||||
std::get<2>(edge) = true; // mark that this edge will now be processed
|
||||
|
||||
// Look for an edge on the forward CH graph (.forward)
|
||||
EdgeID smaller_edge_id =
|
||||
facade.FindSmallestEdge(std::get<0>(edge), std::get<1>(edge), [](const auto &data) {
|
||||
return data.forward;
|
||||
});
|
||||
|
||||
// If we didn't find one there, the we might be looking at a part of the path that
|
||||
// was found using the backward search. Here, we flip the node order (.second,
|
||||
// .first) and only consider edges with the `.backward` flag.
|
||||
if (SPECIAL_EDGEID == smaller_edge_id)
|
||||
{
|
||||
smaller_edge_id =
|
||||
facade.FindSmallestEdge(std::get<1>(edge),
|
||||
std::get<0>(edge),
|
||||
[](const auto &data) { return data.backward; });
|
||||
}
|
||||
|
||||
// If we didn't find anything *still*, then something is broken and someone has
|
||||
// called this function with bad values.
|
||||
BOOST_ASSERT_MSG(smaller_edge_id != SPECIAL_EDGEID, "Invalid smaller edge ID");
|
||||
|
||||
const auto &data = facade.GetEdgeData(smaller_edge_id);
|
||||
BOOST_ASSERT_MSG(data.weight != std::numeric_limits<EdgeWeight>::max(),
|
||||
"edge weight invalid");
|
||||
|
||||
// If the edge is a shortcut, we need to add the two halfs to the stack.
|
||||
if (data.shortcut)
|
||||
{ // unpack
|
||||
const NodeID middle_node_id = data.turn_id;
|
||||
// Note the order here - we're adding these to a stack, so we
|
||||
// want the first->middle to get visited before middle->second
|
||||
recursion_stack.emplace(edge);
|
||||
recursion_stack.emplace(middle_node_id, std::get<1>(edge), false);
|
||||
recursion_stack.emplace(std::get<0>(edge), middle_node_id, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
// compute the duration here and put it onto the duration stack using method
|
||||
// similar to annotatePath but smaller
|
||||
EdgeDistance distance = computeEdgeDistance(facade, std::get<0>(edge));
|
||||
distance_stack.emplace(distance);
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // the edge has already been processed. this means that there are enough values in the
|
||||
// distances stack
|
||||
|
||||
BOOST_ASSERT_MSG(distance_stack.size() >= 2,
|
||||
"There are not enough (at least 2) values on the distance stack");
|
||||
EdgeDistance distance1 = distance_stack.top();
|
||||
distance_stack.pop();
|
||||
EdgeDistance distance2 = distance_stack.top();
|
||||
distance_stack.pop();
|
||||
EdgeDistance distance = distance1 + distance2;
|
||||
distance_stack.emplace(distance);
|
||||
}
|
||||
}
|
||||
|
||||
EdgeDistance total_distance = 0;
|
||||
while (!distance_stack.empty())
|
||||
{
|
||||
total_distance += distance_stack.top();
|
||||
distance_stack.pop();
|
||||
}
|
||||
|
||||
return total_distance;
|
||||
}
|
||||
|
||||
template <typename RandomIter, typename FacadeT>
|
||||
void unpackPath(const FacadeT &facade,
|
||||
RandomIter packed_path_begin,
|
||||
@@ -340,6 +445,11 @@ void retrievePackedPathFromSingleHeap(const SearchEngineData<Algorithm>::QueryHe
|
||||
const NodeID middle_node_id,
|
||||
std::vector<NodeID> &packed_path);
|
||||
|
||||
void retrievePackedPathFromSingleManyToManyHeap(
|
||||
const SearchEngineData<Algorithm>::ManyToManyQueryHeap &search_heap,
|
||||
const NodeID middle_node_id,
|
||||
std::vector<NodeID> &packed_path);
|
||||
|
||||
// assumes that heaps are already setup correctly.
|
||||
// ATTENTION: This only works if no additional offset is supplied next to the Phantom Node
|
||||
// Offsets.
|
||||
|
||||
@@ -54,7 +54,7 @@ inline bool checkParentCellRestriction(CellID, const PhantomNodes &) { return tr
|
||||
|
||||
// Restricted search (Args is LevelID, CellID):
|
||||
// * use the fixed level for queries
|
||||
// * check if the node cell is the same as the specified parent onr
|
||||
// * check if the node cell is the same as the specified parent
|
||||
template <typename MultiLevelPartition>
|
||||
inline LevelID getNodeQueryLevel(const MultiLevelPartition &, NodeID, LevelID level, CellID)
|
||||
{
|
||||
@@ -65,6 +65,61 @@ inline bool checkParentCellRestriction(CellID cell, LevelID, CellID parent)
|
||||
{
|
||||
return cell == parent;
|
||||
}
|
||||
|
||||
// Unrestricted search with a single phantom node (Args is const PhantomNode &):
|
||||
// * use partition.GetQueryLevel to find the node query level
|
||||
// * allow to traverse all cells
|
||||
template <typename MultiLevelPartition>
|
||||
inline LevelID getNodeQueryLevel(const MultiLevelPartition &partition,
|
||||
const NodeID node,
|
||||
const PhantomNode &phantom_node)
|
||||
{
|
||||
auto highest_diffrent_level = [&partition, node](const SegmentID &phantom_node) {
|
||||
if (phantom_node.enabled)
|
||||
return partition.GetHighestDifferentLevel(phantom_node.id, node);
|
||||
return INVALID_LEVEL_ID;
|
||||
};
|
||||
|
||||
const auto node_level = std::min(highest_diffrent_level(phantom_node.forward_segment_id),
|
||||
highest_diffrent_level(phantom_node.reverse_segment_id));
|
||||
|
||||
return node_level;
|
||||
}
|
||||
|
||||
// Unrestricted search with a single phantom node and a vector of phantom nodes:
|
||||
// * use partition.GetQueryLevel to find the node query level
|
||||
// * allow to traverse all cells
|
||||
template <typename MultiLevelPartition>
|
||||
inline LevelID getNodeQueryLevel(const MultiLevelPartition &partition,
|
||||
NodeID node,
|
||||
const std::vector<PhantomNode> &phantom_nodes,
|
||||
const std::size_t phantom_index,
|
||||
const std::vector<std::size_t> &phantom_indices)
|
||||
{
|
||||
auto min_level = [&partition, node](const PhantomNode &phantom_node) {
|
||||
|
||||
const auto &forward_segment = phantom_node.forward_segment_id;
|
||||
const auto forward_level =
|
||||
forward_segment.enabled ? partition.GetHighestDifferentLevel(node, forward_segment.id)
|
||||
: INVALID_LEVEL_ID;
|
||||
|
||||
const auto &reverse_segment = phantom_node.reverse_segment_id;
|
||||
const auto reverse_level =
|
||||
reverse_segment.enabled ? partition.GetHighestDifferentLevel(node, reverse_segment.id)
|
||||
: INVALID_LEVEL_ID;
|
||||
|
||||
return std::min(forward_level, reverse_level);
|
||||
};
|
||||
|
||||
// Get minimum level over all phantoms of the highest different level with respect to node
|
||||
// This is equivalent to min_{∀ source, target} partition.GetQueryLevel(source, node, target)
|
||||
auto result = min_level(phantom_nodes[phantom_index]);
|
||||
for (const auto &index : phantom_indices)
|
||||
{
|
||||
result = std::min(result, min_level(phantom_nodes[index]));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
// Heaps only record for each node its predecessor ("parent") on the shortest path.
|
||||
@@ -74,6 +129,46 @@ inline bool checkParentCellRestriction(CellID cell, LevelID, CellID parent)
|
||||
using PackedEdge = std::tuple</*from*/ NodeID, /*to*/ NodeID, /*from_clique_arc*/ bool>;
|
||||
using PackedPath = std::vector<PackedEdge>;
|
||||
|
||||
template <bool DIRECTION, typename OutIter>
|
||||
inline void retrievePackedPathFromSingleManyToManyHeap(
|
||||
const SearchEngineData<Algorithm>::ManyToManyQueryHeap &heap, const NodeID middle, OutIter out)
|
||||
{
|
||||
|
||||
NodeID current = middle;
|
||||
NodeID parent = heap.GetData(current).parent;
|
||||
|
||||
while (current != parent)
|
||||
{
|
||||
const auto &data = heap.GetData(current);
|
||||
|
||||
if (DIRECTION == FORWARD_DIRECTION)
|
||||
{
|
||||
*out = std::make_tuple(parent, current, data.from_clique_arc);
|
||||
++out;
|
||||
}
|
||||
else if (DIRECTION == REVERSE_DIRECTION)
|
||||
{
|
||||
*out = std::make_tuple(current, parent, data.from_clique_arc);
|
||||
++out;
|
||||
}
|
||||
|
||||
current = parent;
|
||||
parent = heap.GetData(parent).parent;
|
||||
}
|
||||
}
|
||||
|
||||
template <bool DIRECTION>
|
||||
inline PackedPath retrievePackedPathFromSingleManyToManyHeap(
|
||||
const SearchEngineData<Algorithm>::ManyToManyQueryHeap &heap, const NodeID middle)
|
||||
{
|
||||
|
||||
PackedPath packed_path;
|
||||
retrievePackedPathFromSingleManyToManyHeap<DIRECTION>(
|
||||
heap, middle, std::back_inserter(packed_path));
|
||||
|
||||
return packed_path;
|
||||
}
|
||||
|
||||
template <bool DIRECTION, typename OutIter>
|
||||
inline void retrievePackedPathFromSingleHeap(const SearchEngineData<Algorithm>::QueryHeap &heap,
|
||||
const NodeID middle,
|
||||
@@ -206,15 +301,22 @@ void relaxOutgoingEdges(const DataFacade<Algorithm> &facade,
|
||||
for (const auto edge : facade.GetBorderEdgeRange(level, node))
|
||||
{
|
||||
const auto &edge_data = facade.GetEdgeData(edge);
|
||||
if (DIRECTION == FORWARD_DIRECTION ? edge_data.forward : edge_data.backward)
|
||||
|
||||
if ((DIRECTION == FORWARD_DIRECTION) ? facade.IsForwardEdge(edge)
|
||||
: facade.IsBackwardEdge(edge))
|
||||
{
|
||||
const NodeID to = facade.GetTarget(edge);
|
||||
|
||||
if (!facade.ExcludeNode(to) &&
|
||||
checkParentCellRestriction(partition.GetCell(level + 1, to), args...))
|
||||
{
|
||||
BOOST_ASSERT_MSG(edge_data.weight > 0, "edge_weight invalid");
|
||||
const EdgeWeight to_weight = weight + edge_data.weight;
|
||||
const auto node_weight =
|
||||
facade.GetNodeWeight(DIRECTION == FORWARD_DIRECTION ? node : to);
|
||||
const auto turn_penalty = facade.GetWeightPenaltyForEdgeID(edge_data.turn_id);
|
||||
|
||||
// TODO: BOOST_ASSERT(edge_data.weight == node_weight + turn_penalty);
|
||||
|
||||
const EdgeWeight to_weight = weight + node_weight + turn_penalty;
|
||||
|
||||
if (!forward_heap.WasInserted(to))
|
||||
{
|
||||
@@ -407,6 +509,90 @@ UnpackedPath search(SearchEngineData<Algorithm> &engine_working_data,
|
||||
return std::make_tuple(weight, std::move(unpacked_nodes), std::move(unpacked_edges));
|
||||
}
|
||||
|
||||
// With (s, middle, t) we trace back the paths middle -> s and middle -> t.
|
||||
// This gives us a packed path (node ids) from the base graph around s and t,
|
||||
// and overlay node ids otherwise. We then have to unpack the overlay clique
|
||||
// edges by recursively descending unpacking the path down to the base graph.
|
||||
|
||||
using UnpackedNodes = std::vector<NodeID>;
|
||||
using UnpackedEdges = std::vector<EdgeID>;
|
||||
using UnpackedPath = std::tuple<EdgeWeight, UnpackedNodes, UnpackedEdges>;
|
||||
|
||||
template <typename Algorithm, typename... Args>
|
||||
UnpackedPath
|
||||
unpackPathAndCalculateDistance(SearchEngineData<Algorithm> &engine_working_data,
|
||||
const DataFacade<Algorithm> &facade,
|
||||
typename SearchEngineData<Algorithm>::QueryHeap &forward_heap,
|
||||
typename SearchEngineData<Algorithm>::QueryHeap &reverse_heap,
|
||||
const bool force_loop_forward,
|
||||
const bool force_loop_reverse,
|
||||
EdgeWeight weight_upper_bound,
|
||||
PackedPath packed_path,
|
||||
NodeID middle,
|
||||
Args... args)
|
||||
{
|
||||
EdgeWeight weight = weight_upper_bound;
|
||||
const auto &partition = facade.GetMultiLevelPartition();
|
||||
const NodeID source_node = !packed_path.empty() ? std::get<0>(packed_path.front()) : middle;
|
||||
|
||||
// Unpack path
|
||||
std::vector<NodeID> unpacked_nodes;
|
||||
std::vector<EdgeID> unpacked_edges;
|
||||
unpacked_nodes.reserve(packed_path.size());
|
||||
unpacked_edges.reserve(packed_path.size());
|
||||
|
||||
unpacked_nodes.push_back(source_node);
|
||||
|
||||
for (auto const &packed_edge : packed_path)
|
||||
{
|
||||
NodeID source, target;
|
||||
bool overlay_edge;
|
||||
std::tie(source, target, overlay_edge) = packed_edge;
|
||||
if (!overlay_edge)
|
||||
{ // a base graph edge
|
||||
unpacked_nodes.push_back(target);
|
||||
unpacked_edges.push_back(facade.FindEdge(source, target));
|
||||
}
|
||||
else
|
||||
{ // an overlay graph edge
|
||||
LevelID level = getNodeQueryLevel(partition, source, args...);
|
||||
CellID parent_cell_id = partition.GetCell(level, source);
|
||||
BOOST_ASSERT(parent_cell_id == partition.GetCell(level, target));
|
||||
|
||||
LevelID sublevel = level - 1;
|
||||
|
||||
// Here heaps can be reused, let's go deeper!
|
||||
forward_heap.Clear();
|
||||
reverse_heap.Clear();
|
||||
forward_heap.Insert(source, 0, {source});
|
||||
reverse_heap.Insert(target, 0, {target});
|
||||
|
||||
// TODO: when structured bindings will be allowed change to
|
||||
// auto [subpath_weight, subpath_source, subpath_target, subpath] = ...
|
||||
EdgeWeight subpath_weight;
|
||||
std::vector<NodeID> subpath_nodes;
|
||||
std::vector<EdgeID> subpath_edges;
|
||||
std::tie(subpath_weight, subpath_nodes, subpath_edges) = search(engine_working_data,
|
||||
facade,
|
||||
forward_heap,
|
||||
reverse_heap,
|
||||
force_loop_forward,
|
||||
force_loop_reverse,
|
||||
weight_upper_bound,
|
||||
sublevel,
|
||||
parent_cell_id);
|
||||
BOOST_ASSERT(!subpath_edges.empty());
|
||||
BOOST_ASSERT(subpath_nodes.size() > 1);
|
||||
BOOST_ASSERT(subpath_nodes.front() == source);
|
||||
BOOST_ASSERT(subpath_nodes.back() == target);
|
||||
unpacked_nodes.insert(
|
||||
unpacked_nodes.end(), std::next(subpath_nodes.begin()), subpath_nodes.end());
|
||||
unpacked_edges.insert(unpacked_edges.end(), subpath_edges.begin(), subpath_edges.end());
|
||||
}
|
||||
}
|
||||
return std::make_tuple(weight, std::move(unpacked_nodes), std::move(unpacked_edges));
|
||||
}
|
||||
|
||||
// Alias to be compatible with the CH-based search
|
||||
template <typename Algorithm>
|
||||
inline void search(SearchEngineData<Algorithm> &engine_working_data,
|
||||
|
||||
@@ -30,7 +30,11 @@ struct HeapData
|
||||
struct ManyToManyHeapData : HeapData
|
||||
{
|
||||
EdgeWeight duration;
|
||||
ManyToManyHeapData(NodeID p, EdgeWeight duration) : HeapData(p), duration(duration) {}
|
||||
EdgeDistance distance;
|
||||
ManyToManyHeapData(NodeID p, EdgeWeight duration, EdgeDistance distance)
|
||||
: HeapData(p), duration(duration), distance(distance)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
template <> struct SearchEngineData<routing_algorithms::ch::Algorithm>
|
||||
@@ -75,12 +79,16 @@ struct MultiLayerDijkstraHeapData
|
||||
struct ManyToManyMultiLayerDijkstraHeapData : MultiLayerDijkstraHeapData
|
||||
{
|
||||
EdgeWeight duration;
|
||||
ManyToManyMultiLayerDijkstraHeapData(NodeID p, EdgeWeight duration)
|
||||
: MultiLayerDijkstraHeapData(p), duration(duration)
|
||||
EdgeDistance distance;
|
||||
ManyToManyMultiLayerDijkstraHeapData(NodeID p, EdgeWeight duration, EdgeDistance distance)
|
||||
: MultiLayerDijkstraHeapData(p), duration(duration), distance(distance)
|
||||
{
|
||||
}
|
||||
ManyToManyMultiLayerDijkstraHeapData(NodeID p, bool from, EdgeWeight duration)
|
||||
: MultiLayerDijkstraHeapData(p, from), duration(duration)
|
||||
ManyToManyMultiLayerDijkstraHeapData(NodeID p,
|
||||
bool from,
|
||||
EdgeWeight duration,
|
||||
EdgeDistance distance)
|
||||
: MultiLayerDijkstraHeapData(p, from), duration(duration), distance(distance)
|
||||
{
|
||||
}
|
||||
};
|
||||
@@ -112,7 +120,7 @@ template <> struct SearchEngineData<routing_algorithms::mld::Algorithm>
|
||||
void InitializeOrClearManyToManyThreadLocalStorage(unsigned number_of_nodes,
|
||||
unsigned number_of_boundary_nodes);
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace engine
|
||||
} // namespace osrm
|
||||
|
||||
#endif // SEARCH_ENGINE_DATA_HPP
|
||||
|
||||
@@ -82,7 +82,7 @@ class CompressedEdgeContainer
|
||||
std::unordered_map<EdgeID, unsigned> m_reverse_edge_id_to_zipped_index_map;
|
||||
std::unique_ptr<SegmentDataContainer> segment_data;
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace extractor
|
||||
} // namespace osrm
|
||||
|
||||
#endif // GEOMETRY_COMPRESSOR_HPP_
|
||||
|
||||
@@ -15,20 +15,25 @@ struct EdgeBasedEdge
|
||||
public:
|
||||
struct EdgeData
|
||||
{
|
||||
EdgeData() : turn_id(0), weight(0), duration(0), forward(false), backward(false) {}
|
||||
EdgeData()
|
||||
: turn_id(0), weight(0), distance(0), duration(0), forward(false), backward(false)
|
||||
{
|
||||
}
|
||||
|
||||
EdgeData(const NodeID turn_id,
|
||||
const EdgeWeight weight,
|
||||
const EdgeDistance distance,
|
||||
const EdgeWeight duration,
|
||||
const bool forward,
|
||||
const bool backward)
|
||||
: turn_id(turn_id), weight(weight), duration(duration), forward(forward),
|
||||
backward(backward)
|
||||
: turn_id(turn_id), weight(weight), distance(distance), duration(duration),
|
||||
forward(forward), backward(backward)
|
||||
{
|
||||
}
|
||||
|
||||
NodeID turn_id; // ID of the edge based node (node based edge)
|
||||
EdgeWeight weight;
|
||||
EdgeDistance distance;
|
||||
EdgeWeight duration : 30;
|
||||
std::uint32_t forward : 1;
|
||||
std::uint32_t backward : 1;
|
||||
@@ -43,6 +48,7 @@ struct EdgeBasedEdge
|
||||
const NodeID edge_id,
|
||||
const EdgeWeight weight,
|
||||
const EdgeWeight duration,
|
||||
const EdgeDistance distance,
|
||||
const bool forward,
|
||||
const bool backward);
|
||||
EdgeBasedEdge(const NodeID source, const NodeID target, const EdgeBasedEdge::EdgeData &data);
|
||||
@@ -53,7 +59,7 @@ struct EdgeBasedEdge
|
||||
NodeID target;
|
||||
EdgeData data;
|
||||
};
|
||||
static_assert(sizeof(extractor::EdgeBasedEdge) == 20,
|
||||
static_assert(sizeof(extractor::EdgeBasedEdge) == 24,
|
||||
"Size of extractor::EdgeBasedEdge type is "
|
||||
"bigger than expected. This will influence "
|
||||
"memory consumption.");
|
||||
@@ -67,9 +73,10 @@ inline EdgeBasedEdge::EdgeBasedEdge(const NodeID source,
|
||||
const NodeID turn_id,
|
||||
const EdgeWeight weight,
|
||||
const EdgeWeight duration,
|
||||
const EdgeDistance distance,
|
||||
const bool forward,
|
||||
const bool backward)
|
||||
: source(source), target(target), data{turn_id, weight, duration, forward, backward}
|
||||
: source(source), target(target), data{turn_id, weight, distance, duration, forward, backward}
|
||||
{
|
||||
}
|
||||
|
||||
@@ -89,7 +96,7 @@ inline bool EdgeBasedEdge::operator<(const EdgeBasedEdge &other) const
|
||||
return std::tie(source, target, data.weight, unidirectional) <
|
||||
std::tie(other.source, other.target, other.data.weight, other_is_unidirectional);
|
||||
}
|
||||
} // ns extractor
|
||||
} // ns osrm
|
||||
} // namespace extractor
|
||||
} // namespace osrm
|
||||
|
||||
#endif /* EDGE_BASED_EDGE_HPP */
|
||||
|
||||
@@ -91,6 +91,7 @@ class EdgeBasedGraphFactory
|
||||
void GetEdgeBasedNodeSegments(std::vector<EdgeBasedNodeSegment> &nodes);
|
||||
void GetStartPointMarkers(std::vector<bool> &node_is_startpoint);
|
||||
void GetEdgeBasedNodeWeights(std::vector<EdgeWeight> &output_node_weights);
|
||||
void GetEdgeBasedNodeDurations(std::vector<EdgeWeight> &output_node_durations);
|
||||
std::uint32_t GetConnectivityChecksum() const;
|
||||
|
||||
std::uint64_t GetNumberOfEdgeBasedNodes() const;
|
||||
@@ -117,6 +118,7 @@ class EdgeBasedGraphFactory
|
||||
//! node weights that indicate the length of the segment (node based) represented by the
|
||||
//! edge-based node
|
||||
std::vector<EdgeWeight> m_edge_based_node_weights;
|
||||
std::vector<EdgeDuration> m_edge_based_node_durations;
|
||||
|
||||
//! list of edge based nodes (compressed segments)
|
||||
std::vector<EdgeBasedNodeSegment> m_edge_based_node_segments;
|
||||
|
||||
@@ -87,6 +87,7 @@ class Extractor
|
||||
std::vector<EdgeBasedNodeSegment> &edge_based_node_segments,
|
||||
std::vector<bool> &node_is_startpoint,
|
||||
std::vector<EdgeWeight> &edge_based_node_weights,
|
||||
std::vector<EdgeDuration> &edge_based_node_durations,
|
||||
util::DeallocatingVector<EdgeBasedEdge> &edge_based_edge_list,
|
||||
std::uint32_t &connectivity_checksum);
|
||||
|
||||
|
||||
@@ -462,14 +462,28 @@ void readEdgeBasedNodeWeights(const boost::filesystem::path &path, NodeWeigtsVec
|
||||
storage::serialization::read(reader, "/extractor/edge_based_node_weights", weights);
|
||||
}
|
||||
|
||||
template <typename NodeWeigtsVectorT>
|
||||
void writeEdgeBasedNodeWeights(const boost::filesystem::path &path,
|
||||
const NodeWeigtsVectorT &weights)
|
||||
template <typename NodeWeigtsVectorT, typename NodeDurationsVectorT>
|
||||
void readEdgeBasedNodeWeightsDurations(const boost::filesystem::path &path,
|
||||
NodeWeigtsVectorT &weights,
|
||||
NodeDurationsVectorT &durations)
|
||||
{
|
||||
const auto fingerprint = storage::tar::FileReader::VerifyFingerprint;
|
||||
storage::tar::FileReader reader{path, fingerprint};
|
||||
|
||||
storage::serialization::read(reader, "/extractor/edge_based_node_weights", weights);
|
||||
storage::serialization::read(reader, "/extractor/edge_based_node_durations", durations);
|
||||
}
|
||||
|
||||
template <typename NodeWeigtsVectorT, typename NodeDurationsVectorT>
|
||||
void writeEdgeBasedNodeWeightsDurations(const boost::filesystem::path &path,
|
||||
const NodeWeigtsVectorT &weights,
|
||||
const NodeDurationsVectorT &durations)
|
||||
{
|
||||
const auto fingerprint = storage::tar::FileWriter::GenerateFingerprint;
|
||||
storage::tar::FileWriter writer{path, fingerprint};
|
||||
|
||||
storage::serialization::write(writer, "/extractor/edge_based_node_weights", weights);
|
||||
storage::serialization::write(writer, "/extractor/edge_based_node_durations", durations);
|
||||
}
|
||||
|
||||
template <typename RTreeT>
|
||||
|
||||
@@ -49,7 +49,7 @@ struct ByEdgeOrByMeterValue
|
||||
using value_type = float;
|
||||
value_type value;
|
||||
};
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
struct InternalExtractorEdge
|
||||
{
|
||||
@@ -63,7 +63,7 @@ struct InternalExtractorEdge
|
||||
WeightData weight_data,
|
||||
DurationData duration_data,
|
||||
util::Coordinate source_coordinate)
|
||||
: result(source, target, 0, 0, {}, -1, {}), weight_data(std::move(weight_data)),
|
||||
: result(source, target, 0, 0, 0, {}, -1, {}), weight_data(std::move(weight_data)),
|
||||
duration_data(std::move(duration_data)), source_coordinate(std::move(source_coordinate))
|
||||
{
|
||||
}
|
||||
@@ -113,7 +113,7 @@ struct InternalExtractorEdge
|
||||
return v;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace extractor
|
||||
} // namespace osrm
|
||||
|
||||
#endif // INTERNAL_EXTRACTOR_EDGE_HPP
|
||||
|
||||
@@ -97,6 +97,7 @@ struct NodeBasedEdge
|
||||
NodeID target,
|
||||
EdgeWeight weight,
|
||||
EdgeDuration duration,
|
||||
EdgeDistance distance,
|
||||
GeometryID geometry_id,
|
||||
AnnotationID annotation_data,
|
||||
NodeBasedEdgeClassification flags);
|
||||
@@ -107,6 +108,7 @@ struct NodeBasedEdge
|
||||
NodeID target; // 32 4
|
||||
EdgeWeight weight; // 32 4
|
||||
EdgeDuration duration; // 32 4
|
||||
EdgeDistance distance; // 32 4
|
||||
GeometryID geometry_id; // 32 4
|
||||
AnnotationID annotation_data; // 32 4
|
||||
NodeBasedEdgeClassification flags; // 32 4
|
||||
@@ -120,6 +122,7 @@ struct NodeBasedEdgeWithOSM : NodeBasedEdge
|
||||
OSMNodeID target,
|
||||
EdgeWeight weight,
|
||||
EdgeDuration duration,
|
||||
EdgeDistance distance,
|
||||
GeometryID geometry_id,
|
||||
AnnotationID annotation_data,
|
||||
NodeBasedEdgeClassification flags);
|
||||
@@ -137,7 +140,8 @@ inline NodeBasedEdgeClassification::NodeBasedEdgeClassification()
|
||||
}
|
||||
|
||||
inline NodeBasedEdge::NodeBasedEdge()
|
||||
: source(SPECIAL_NODEID), target(SPECIAL_NODEID), weight(0), duration(0), annotation_data(-1)
|
||||
: source(SPECIAL_NODEID), target(SPECIAL_NODEID), weight(0), duration(0), distance(0),
|
||||
annotation_data(-1)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -145,11 +149,12 @@ inline NodeBasedEdge::NodeBasedEdge(NodeID source,
|
||||
NodeID target,
|
||||
EdgeWeight weight,
|
||||
EdgeDuration duration,
|
||||
EdgeDistance distance,
|
||||
GeometryID geometry_id,
|
||||
AnnotationID annotation_data,
|
||||
NodeBasedEdgeClassification flags)
|
||||
: source(source), target(target), weight(weight), duration(duration), geometry_id(geometry_id),
|
||||
annotation_data(annotation_data), flags(flags)
|
||||
: source(source), target(target), weight(weight), duration(duration), distance(distance),
|
||||
geometry_id(geometry_id), annotation_data(annotation_data), flags(flags)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -175,11 +180,18 @@ inline NodeBasedEdgeWithOSM::NodeBasedEdgeWithOSM(OSMNodeID source,
|
||||
OSMNodeID target,
|
||||
EdgeWeight weight,
|
||||
EdgeDuration duration,
|
||||
EdgeDistance distance,
|
||||
GeometryID geometry_id,
|
||||
AnnotationID annotation_data,
|
||||
NodeBasedEdgeClassification flags)
|
||||
: NodeBasedEdge(
|
||||
SPECIAL_NODEID, SPECIAL_NODEID, weight, duration, geometry_id, annotation_data, flags),
|
||||
: NodeBasedEdge(SPECIAL_NODEID,
|
||||
SPECIAL_NODEID,
|
||||
weight,
|
||||
duration,
|
||||
distance,
|
||||
geometry_id,
|
||||
annotation_data,
|
||||
flags),
|
||||
osm_source_id(std::move(source)), osm_target_id(std::move(target))
|
||||
{
|
||||
}
|
||||
@@ -189,12 +201,12 @@ inline NodeBasedEdgeWithOSM::NodeBasedEdgeWithOSM()
|
||||
{
|
||||
}
|
||||
|
||||
static_assert(sizeof(extractor::NodeBasedEdge) == 28,
|
||||
static_assert(sizeof(extractor::NodeBasedEdge) == 32,
|
||||
"Size of extractor::NodeBasedEdge type is "
|
||||
"bigger than expected. This will influence "
|
||||
"memory consumption.");
|
||||
|
||||
} // ns extractor
|
||||
} // ns osrm
|
||||
} // namespace extractor
|
||||
} // namespace osrm
|
||||
|
||||
#endif /* NODE_BASED_EDGE_HPP */
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define OSRM_BINDINGS_NODE_SUPPORT_HPP
|
||||
|
||||
#include "nodejs/json_v8_renderer.hpp"
|
||||
#include "util/json_renderer.hpp"
|
||||
|
||||
#include "osrm/approach.hpp"
|
||||
#include "osrm/bearing.hpp"
|
||||
@@ -24,6 +25,7 @@
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -42,6 +44,13 @@ using match_parameters_ptr = std::unique_ptr<osrm::MatchParameters>;
|
||||
using nearest_parameters_ptr = std::unique_ptr<osrm::NearestParameters>;
|
||||
using table_parameters_ptr = std::unique_ptr<osrm::TableParameters>;
|
||||
|
||||
struct PluginParameters
|
||||
{
|
||||
bool renderJSONToBuffer = false;
|
||||
};
|
||||
|
||||
using ObjectOrString = typename mapbox::util::variant<osrm::json::Object, std::string>;
|
||||
|
||||
template <typename ResultT> inline v8::Local<v8::Value> render(const ResultT &result);
|
||||
|
||||
template <> v8::Local<v8::Value> inline render(const std::string &result)
|
||||
@@ -49,11 +58,21 @@ template <> v8::Local<v8::Value> inline render(const std::string &result)
|
||||
return Nan::CopyBuffer(result.data(), result.size()).ToLocalChecked();
|
||||
}
|
||||
|
||||
template <> v8::Local<v8::Value> inline render(const osrm::json::Object &result)
|
||||
template <> v8::Local<v8::Value> inline render(const ObjectOrString &result)
|
||||
{
|
||||
v8::Local<v8::Value> value;
|
||||
renderToV8(value, result);
|
||||
return value;
|
||||
if (result.is<osrm::json::Object>())
|
||||
{
|
||||
// Convert osrm::json object tree into matching v8 object tree
|
||||
v8::Local<v8::Value> value;
|
||||
renderToV8(value, result.get<osrm::json::Object>());
|
||||
return value;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Return the string object as a node Buffer
|
||||
return Nan::CopyBuffer(result.get<std::string>().data(), result.get<std::string>().size())
|
||||
.ToLocalChecked();
|
||||
}
|
||||
}
|
||||
|
||||
inline void ParseResult(const osrm::Status &result_status, osrm::json::Object &result)
|
||||
@@ -123,6 +142,10 @@ inline engine_config_ptr argumentsToEngineConfig(const Nan::FunctionCallbackInfo
|
||||
if (shared_memory.IsEmpty())
|
||||
return engine_config_ptr();
|
||||
|
||||
auto mmap_memory = params->Get(Nan::New("mmap_memory").ToLocalChecked());
|
||||
if (mmap_memory.IsEmpty())
|
||||
return engine_config_ptr();
|
||||
|
||||
if (!memory_file->IsUndefined())
|
||||
{
|
||||
if (path->IsUndefined())
|
||||
@@ -171,6 +194,18 @@ inline engine_config_ptr argumentsToEngineConfig(const Nan::FunctionCallbackInfo
|
||||
return engine_config_ptr();
|
||||
}
|
||||
}
|
||||
if (!mmap_memory->IsUndefined())
|
||||
{
|
||||
if (mmap_memory->IsBoolean())
|
||||
{
|
||||
engine_config->use_mmap = Nan::To<bool>(mmap_memory).FromJust();
|
||||
}
|
||||
else
|
||||
{
|
||||
Nan::ThrowError("mmap_memory option must be a boolean");
|
||||
return engine_config_ptr();
|
||||
}
|
||||
}
|
||||
|
||||
if (path->IsUndefined() && !engine_config->use_shared_memory)
|
||||
{
|
||||
@@ -814,6 +849,50 @@ inline bool parseCommonParameters(const v8::Local<v8::Object> &obj, ParamType &p
|
||||
return true;
|
||||
}
|
||||
|
||||
inline PluginParameters
|
||||
argumentsToPluginParameters(const Nan::FunctionCallbackInfo<v8::Value> &args)
|
||||
{
|
||||
if (args.Length() < 3 || !args[1]->IsObject())
|
||||
{
|
||||
return {};
|
||||
}
|
||||
v8::Local<v8::Object> obj = Nan::To<v8::Object>(args[1]).ToLocalChecked();
|
||||
if (obj->Has(Nan::New("format").ToLocalChecked()))
|
||||
{
|
||||
|
||||
v8::Local<v8::Value> format = obj->Get(Nan::New("format").ToLocalChecked());
|
||||
if (format.IsEmpty())
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
if (!format->IsString())
|
||||
{
|
||||
Nan::ThrowError("format must be a string: \"object\" or \"json_buffer\"");
|
||||
return {};
|
||||
}
|
||||
|
||||
const Nan::Utf8String format_utf8str(format);
|
||||
std::string format_str{*format_utf8str, *format_utf8str + format_utf8str.length()};
|
||||
|
||||
if (format_str == "object")
|
||||
{
|
||||
return {false};
|
||||
}
|
||||
else if (format_str == "json_buffer")
|
||||
{
|
||||
return {true};
|
||||
}
|
||||
else
|
||||
{
|
||||
Nan::ThrowError("format must be a string: \"object\" or \"json_buffer\"");
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
inline route_parameters_ptr
|
||||
argumentsToRouteParameter(const Nan::FunctionCallbackInfo<v8::Value> &args,
|
||||
bool requires_multiple_coordinates)
|
||||
@@ -1064,6 +1143,46 @@ argumentsToTableParameter(const Nan::FunctionCallbackInfo<v8::Value> &args,
|
||||
}
|
||||
}
|
||||
|
||||
if (obj->Has(Nan::New("annotations").ToLocalChecked()))
|
||||
{
|
||||
v8::Local<v8::Value> annotations = obj->Get(Nan::New("annotations").ToLocalChecked());
|
||||
if (annotations.IsEmpty())
|
||||
return table_parameters_ptr();
|
||||
|
||||
if (!annotations->IsArray())
|
||||
{
|
||||
Nan::ThrowError(
|
||||
"Annotations must an array containing 'duration' or 'distance', or both");
|
||||
return table_parameters_ptr();
|
||||
}
|
||||
|
||||
params->annotations = osrm::TableParameters::AnnotationsType::None;
|
||||
|
||||
v8::Local<v8::Array> annotations_array = v8::Local<v8::Array>::Cast(annotations);
|
||||
for (std::size_t i = 0; i < annotations_array->Length(); ++i)
|
||||
{
|
||||
const Nan::Utf8String annotations_utf8str(annotations_array->Get(i));
|
||||
std::string annotations_str{*annotations_utf8str,
|
||||
*annotations_utf8str + annotations_utf8str.length()};
|
||||
|
||||
if (annotations_str == "duration")
|
||||
{
|
||||
params->annotations =
|
||||
params->annotations | osrm::TableParameters::AnnotationsType::Duration;
|
||||
}
|
||||
else if (annotations_str == "distance")
|
||||
{
|
||||
params->annotations =
|
||||
params->annotations | osrm::TableParameters::AnnotationsType::Distance;
|
||||
}
|
||||
else
|
||||
{
|
||||
Nan::ThrowError("this 'annotations' param is not supported");
|
||||
return table_parameters_ptr();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
@@ -1317,6 +1436,6 @@ argumentsToMatchParameter(const Nan::FunctionCallbackInfo<v8::Value> &args,
|
||||
return params;
|
||||
}
|
||||
|
||||
} // ns node_osrm
|
||||
} // namespace node_osrm
|
||||
|
||||
#endif
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#include <tbb/parallel_for.h>
|
||||
#include <tbb/parallel_reduce.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include <algorithm>
|
||||
@@ -43,6 +45,7 @@ splitBidirectionalEdges(const std::vector<extractor::EdgeBasedEdge> &edges)
|
||||
edge.data.turn_id,
|
||||
std::max(edge.data.weight, 1),
|
||||
edge.data.duration,
|
||||
edge.data.distance,
|
||||
edge.data.forward,
|
||||
edge.data.backward);
|
||||
|
||||
@@ -51,6 +54,7 @@ splitBidirectionalEdges(const std::vector<extractor::EdgeBasedEdge> &edges)
|
||||
edge.data.turn_id,
|
||||
std::max(edge.data.weight, 1),
|
||||
edge.data.duration,
|
||||
edge.data.distance,
|
||||
edge.data.backward,
|
||||
edge.data.forward);
|
||||
}
|
||||
@@ -196,7 +200,7 @@ inline DynamicEdgeBasedGraph LoadEdgeBasedGraph(const boost::filesystem::path &p
|
||||
return DynamicEdgeBasedGraph(number_of_edge_based_nodes, std::move(tidied), checksum);
|
||||
}
|
||||
|
||||
} // ns partition
|
||||
} // ns osrm
|
||||
} // namespace partitioner
|
||||
} // namespace osrm
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
#ifndef OSRM_PARTITIONER_SERILIZATION_HPP
|
||||
#define OSRM_PARTITIONER_SERILIZATION_HPP
|
||||
|
||||
#include "customizer/edge_based_graph.hpp"
|
||||
|
||||
#include "partitioner/serialization.hpp"
|
||||
|
||||
#include "storage/io.hpp"
|
||||
@@ -14,39 +12,6 @@ namespace partitioner
|
||||
namespace files
|
||||
{
|
||||
|
||||
// reads .osrm.mldgr file
|
||||
template <typename MultiLevelGraphT>
|
||||
inline void readGraph(const boost::filesystem::path &path,
|
||||
MultiLevelGraphT &graph,
|
||||
std::uint32_t &connectivity_checksum)
|
||||
{
|
||||
static_assert(std::is_same<customizer::MultiLevelEdgeBasedGraphView, MultiLevelGraphT>::value ||
|
||||
std::is_same<customizer::MultiLevelEdgeBasedGraph, MultiLevelGraphT>::value,
|
||||
"");
|
||||
|
||||
storage::tar::FileReader reader{path, storage::tar::FileReader::VerifyFingerprint};
|
||||
|
||||
reader.ReadInto("/mld/connectivity_checksum", connectivity_checksum);
|
||||
serialization::read(reader, "/mld/multilevelgraph", graph);
|
||||
}
|
||||
|
||||
// writes .osrm.mldgr file
|
||||
template <typename MultiLevelGraphT>
|
||||
inline void writeGraph(const boost::filesystem::path &path,
|
||||
const MultiLevelGraphT &graph,
|
||||
const std::uint32_t connectivity_checksum)
|
||||
{
|
||||
static_assert(std::is_same<customizer::MultiLevelEdgeBasedGraphView, MultiLevelGraphT>::value ||
|
||||
std::is_same<customizer::MultiLevelEdgeBasedGraph, MultiLevelGraphT>::value,
|
||||
"");
|
||||
|
||||
storage::tar::FileWriter writer{path, storage::tar::FileWriter::GenerateFingerprint};
|
||||
|
||||
writer.WriteElementCount64("/mld/connectivity_checksum", 1);
|
||||
writer.WriteFrom("/mld/connectivity_checksum", connectivity_checksum);
|
||||
serialization::write(writer, "/mld/multilevelgraph", graph);
|
||||
}
|
||||
|
||||
// read .osrm.partition file
|
||||
template <typename MultiLevelPartitionT>
|
||||
inline void readPartition(const boost::filesystem::path &path, MultiLevelPartitionT &mlp)
|
||||
@@ -102,6 +67,35 @@ inline void writeCells(const boost::filesystem::path &path, CellStorageT &storag
|
||||
|
||||
serialization::write(writer, "/mld/cellstorage", storage);
|
||||
}
|
||||
|
||||
// reads .osrm.mldgr file
|
||||
template <typename MultiLevelGraphT>
|
||||
inline void readGraph(const boost::filesystem::path &path,
|
||||
MultiLevelGraphT &graph,
|
||||
std::uint32_t &connectivity_checksum)
|
||||
{
|
||||
static_assert(std::is_same<partitioner::MultiLevelEdgeBasedGraph, MultiLevelGraphT>::value, "");
|
||||
|
||||
storage::tar::FileReader reader{path, storage::tar::FileReader::VerifyFingerprint};
|
||||
|
||||
reader.ReadInto("/mld/connectivity_checksum", connectivity_checksum);
|
||||
serialization::read(reader, "/mld/multilevelgraph", graph);
|
||||
}
|
||||
|
||||
// writes .osrm.mldgr file
|
||||
template <typename MultiLevelGraphT>
|
||||
inline void writeGraph(const boost::filesystem::path &path,
|
||||
const MultiLevelGraphT &graph,
|
||||
const std::uint32_t connectivity_checksum)
|
||||
{
|
||||
static_assert(std::is_same<partitioner::MultiLevelEdgeBasedGraph, MultiLevelGraphT>::value, "");
|
||||
|
||||
storage::tar::FileWriter writer{path, storage::tar::FileWriter::GenerateFingerprint};
|
||||
|
||||
writer.WriteElementCount64("/mld/connectivity_checksum", 1);
|
||||
writer.WriteFrom("/mld/connectivity_checksum", connectivity_checksum);
|
||||
serialization::write(writer, "/mld/multilevelgraph", graph);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef OSRM_PARTITIONER_MULTI_LEVEL_GRAPH_HPP
|
||||
#define OSRM_PARTITIONER_MULTI_LEVEL_GRAPH_HPP
|
||||
|
||||
#include "partitioner/edge_based_graph.hpp"
|
||||
#include "partitioner/multi_level_partition.hpp"
|
||||
|
||||
#include "storage/shared_memory_ownership.hpp"
|
||||
@@ -42,6 +43,8 @@ class MultiLevelGraph : public util::StaticGraph<EdgeDataT, Ownership>
|
||||
template <typename T> using Vector = util::ViewOrVector<T, Ownership>;
|
||||
|
||||
public:
|
||||
using SuperT::SuperT;
|
||||
|
||||
// We limit each node to have 255 edges
|
||||
// this is very generous, we could probably pack this
|
||||
using EdgeOffset = std::uint8_t;
|
||||
@@ -146,6 +149,14 @@ class MultiLevelGraph : public util::StaticGraph<EdgeDataT, Ownership>
|
||||
return max_border_node_id;
|
||||
}
|
||||
|
||||
auto data() && // rvalue ref-qualifier is a safety-belt
|
||||
{
|
||||
return std::make_tuple(std::move(SuperT::node_array),
|
||||
std::move(SuperT::edge_array),
|
||||
std::move(node_to_edge_offset),
|
||||
connectivity_checksum);
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename ContainerT>
|
||||
auto GetHighestBorderLevel(const MultiLevelPartition &mlp, const ContainerT &edges) const
|
||||
@@ -218,9 +229,13 @@ class MultiLevelGraph : public util::StaticGraph<EdgeDataT, Ownership>
|
||||
const std::string &name,
|
||||
const MultiLevelGraph<EdgeDataT, Ownership> &graph);
|
||||
|
||||
protected:
|
||||
Vector<EdgeOffset> node_to_edge_offset;
|
||||
std::uint32_t connectivity_checksum;
|
||||
};
|
||||
|
||||
using MultiLevelEdgeBasedGraph =
|
||||
MultiLevelGraph<EdgeBasedGraphEdgeData, storage::Ownership::Container>;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace partitioner
|
||||
struct PartitionerConfig final : storage::IOConfig
|
||||
{
|
||||
PartitionerConfig()
|
||||
: IOConfig({".osrm", ".osrm.fileIndex", ".osrm.ebg_nodes"},
|
||||
: IOConfig({".osrm", ".osrm.fileIndex", ".osrm.ebg_nodes", ".osrm.enw"},
|
||||
{".osrm.hsgr", ".osrm.cnbg"},
|
||||
{".osrm.ebg",
|
||||
".osrm.cnbg",
|
||||
|
||||
@@ -19,26 +19,6 @@ namespace partitioner
|
||||
namespace serialization
|
||||
{
|
||||
|
||||
template <typename EdgeDataT, storage::Ownership Ownership>
|
||||
inline void read(storage::tar::FileReader &reader,
|
||||
const std::string &name,
|
||||
MultiLevelGraph<EdgeDataT, Ownership> &graph)
|
||||
{
|
||||
storage::serialization::read(reader, name + "/node_array", graph.node_array);
|
||||
storage::serialization::read(reader, name + "/edge_array", graph.edge_array);
|
||||
storage::serialization::read(reader, name + "/node_to_edge_offset", graph.node_to_edge_offset);
|
||||
}
|
||||
|
||||
template <typename EdgeDataT, storage::Ownership Ownership>
|
||||
inline void write(storage::tar::FileWriter &writer,
|
||||
const std::string &name,
|
||||
const MultiLevelGraph<EdgeDataT, Ownership> &graph)
|
||||
{
|
||||
storage::serialization::write(writer, name + "/node_array", graph.node_array);
|
||||
storage::serialization::write(writer, name + "/edge_array", graph.edge_array);
|
||||
storage::serialization::write(writer, name + "/node_to_edge_offset", graph.node_to_edge_offset);
|
||||
}
|
||||
|
||||
template <storage::Ownership Ownership>
|
||||
inline void read(storage::tar::FileReader &reader,
|
||||
const std::string &name,
|
||||
|
||||
@@ -22,11 +22,11 @@ namespace qi = boost::spirit::qi;
|
||||
|
||||
template <typename Iterator = std::string::iterator,
|
||||
typename Signature = void(engine::api::TableParameters &)>
|
||||
struct TableParametersGrammar final : public BaseParametersGrammar<Iterator, Signature>
|
||||
struct TableParametersGrammar : public BaseParametersGrammar<Iterator, Signature>
|
||||
{
|
||||
using BaseGrammar = BaseParametersGrammar<Iterator, Signature>;
|
||||
|
||||
TableParametersGrammar() : BaseGrammar(root_rule)
|
||||
TableParametersGrammar() : TableParametersGrammar(root_rule)
|
||||
{
|
||||
#ifdef BOOST_HAS_LONG_LONG
|
||||
if (std::is_same<std::size_t, unsigned long long>::value)
|
||||
@@ -51,15 +51,35 @@ struct TableParametersGrammar final : public BaseParametersGrammar<Iterator, Sig
|
||||
table_rule = destinations_rule(qi::_r1) | sources_rule(qi::_r1);
|
||||
|
||||
root_rule = BaseGrammar::query_rule(qi::_r1) > -qi::lit(".json") >
|
||||
-('?' > (table_rule(qi::_r1) | BaseGrammar::base_rule(qi::_r1)) % '&');
|
||||
-('?' > (table_rule(qi::_r1) | base_rule(qi::_r1)) % '&');
|
||||
}
|
||||
|
||||
TableParametersGrammar(qi::rule<Iterator, Signature> &root_rule_) : BaseGrammar(root_rule_)
|
||||
{
|
||||
using AnnotationsType = engine::api::TableParameters::AnnotationsType;
|
||||
|
||||
annotations.add("duration", AnnotationsType::Duration)("distance",
|
||||
AnnotationsType::Distance);
|
||||
|
||||
annotations_list = annotations[qi::_val |= qi::_1] % ',';
|
||||
|
||||
base_rule = BaseGrammar::base_rule(qi::_r1) |
|
||||
(qi::lit("annotations=") >
|
||||
annotations_list[ph::bind(&engine::api::TableParameters::annotations,
|
||||
qi::_r1) = qi::_1]);
|
||||
}
|
||||
|
||||
protected:
|
||||
qi::rule<Iterator, Signature> base_rule;
|
||||
|
||||
private:
|
||||
qi::rule<Iterator, Signature> root_rule;
|
||||
qi::rule<Iterator, Signature> table_rule;
|
||||
qi::rule<Iterator, Signature> sources_rule;
|
||||
qi::rule<Iterator, Signature> destinations_rule;
|
||||
qi::rule<Iterator, std::size_t()> size_t_;
|
||||
qi::symbols<char, engine::api::TableParameters::AnnotationsType> annotations;
|
||||
qi::rule<Iterator, engine::api::TableParameters::AnnotationsType()> annotations_list;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,10 +16,15 @@ struct Block
|
||||
{
|
||||
std::uint64_t num_entries;
|
||||
std::uint64_t byte_size;
|
||||
std::uint64_t offset;
|
||||
|
||||
Block() : num_entries(0), byte_size(0) {}
|
||||
Block() : num_entries(0), byte_size(0), offset(0) {}
|
||||
Block(std::uint64_t num_entries, std::uint64_t byte_size, std::uint64_t offset)
|
||||
: num_entries(num_entries), byte_size(byte_size), offset(offset)
|
||||
{
|
||||
}
|
||||
Block(std::uint64_t num_entries, std::uint64_t byte_size)
|
||||
: num_entries(num_entries), byte_size(byte_size)
|
||||
: num_entries(num_entries), byte_size(byte_size), offset(0)
|
||||
{
|
||||
}
|
||||
};
|
||||
@@ -29,7 +34,7 @@ using NamedBlock = std::tuple<std::string, Block>;
|
||||
template <typename T> Block make_block(uint64_t num_entries)
|
||||
{
|
||||
static_assert(sizeof(T) % alignof(T) == 0, "aligned T* can't be used as an array pointer");
|
||||
return Block{num_entries, sizeof(T) * num_entries};
|
||||
return Block{num_entries, sizeof(T) * num_entries, 0};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,22 +30,29 @@ namespace serialization
|
||||
namespace detail
|
||||
{
|
||||
template <typename T, typename BlockT = unsigned char>
|
||||
inline BlockT packBits(const T &data, std::size_t index, std::size_t count)
|
||||
inline BlockT packBits(const T &data, std::size_t base_index, const std::size_t count)
|
||||
{
|
||||
static_assert(std::is_same<typename T::value_type, bool>::value, "value_type is not bool");
|
||||
|
||||
// Note: if this packing is changed, be sure to update vector_view<bool>
|
||||
// as well, so that on-disk and in-memory layouts match.
|
||||
BlockT value = 0;
|
||||
for (std::size_t bit = 0; bit < count; ++bit, ++index)
|
||||
value = (value << 1) | data[index];
|
||||
for (std::size_t bit = 0; bit < count; ++bit)
|
||||
{
|
||||
value |= (data[base_index + bit] ? BlockT{1} : BlockT{0}) << bit;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
template <typename T, typename BlockT = unsigned char>
|
||||
inline void unpackBits(T &data, std::size_t index, std::size_t count, BlockT value)
|
||||
inline void
|
||||
unpackBits(T &data, const std::size_t base_index, const std::size_t count, const BlockT value)
|
||||
{
|
||||
static_assert(std::is_same<typename T::value_type, bool>::value, "value_type is not bool");
|
||||
const BlockT mask = BlockT{1} << (count - 1);
|
||||
for (std::size_t bit = 0; bit < count; value <<= 1, ++bit, ++index)
|
||||
data[index] = value & mask;
|
||||
for (std::size_t bit = 0; bit < count; ++bit)
|
||||
{
|
||||
data[base_index + bit] = value & (BlockT{1} << bit);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename VectorT>
|
||||
@@ -90,7 +97,7 @@ void writeBoolVector(tar::FileWriter &writer, const std::string &name, const Vec
|
||||
boost::make_function_input_iterator(encode_function, boost::infinite()),
|
||||
number_of_blocks);
|
||||
}
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
/* All vector formats here use the same on-disk format.
|
||||
* This is important because we want to be able to write from a vector
|
||||
@@ -266,14 +273,17 @@ template <typename K, typename V> void write(io::BufferWriter &writer, const std
|
||||
}
|
||||
}
|
||||
|
||||
inline void read(io::BufferReader &reader, DataLayout &layout) { read(reader, layout.blocks); }
|
||||
|
||||
inline void write(io::BufferWriter &writer, const DataLayout &layout)
|
||||
inline void read(io::BufferReader &reader, std::unique_ptr<BaseDataLayout> &layout)
|
||||
{
|
||||
write(writer, layout.blocks);
|
||||
}
|
||||
}
|
||||
read(reader, layout->blocks);
|
||||
}
|
||||
|
||||
inline void write(io::BufferWriter &writer, const std::unique_ptr<BaseDataLayout> &layout)
|
||||
{
|
||||
write(writer, layout->blocks);
|
||||
}
|
||||
} // namespace serialization
|
||||
} // namespace storage
|
||||
} // namespace osrm
|
||||
|
||||
#endif
|
||||
|
||||
@@ -20,7 +20,7 @@ class SharedDataIndex
|
||||
struct AllocatedRegion
|
||||
{
|
||||
char *memory_ptr;
|
||||
DataLayout layout;
|
||||
std::unique_ptr<BaseDataLayout> layout;
|
||||
};
|
||||
|
||||
SharedDataIndex() = default;
|
||||
@@ -29,10 +29,10 @@ class SharedDataIndex
|
||||
// Build mapping from block name to region
|
||||
for (auto index : util::irange<std::uint32_t>(0, regions.size()))
|
||||
{
|
||||
regions[index].layout.List("",
|
||||
boost::make_function_output_iterator([&](const auto &name) {
|
||||
block_to_region[name] = index;
|
||||
}));
|
||||
regions[index].layout->List("",
|
||||
boost::make_function_output_iterator([&](const auto &name) {
|
||||
block_to_region[name] = index;
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,39 +40,45 @@ class SharedDataIndex
|
||||
{
|
||||
for (const auto ®ion : regions)
|
||||
{
|
||||
region.layout.List(name_prefix, out);
|
||||
region.layout->List(name_prefix, out);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T> auto GetBlockPtr(const std::string &name) const
|
||||
{
|
||||
const auto index_iter = block_to_region.find(name);
|
||||
const auto ®ion = regions[index_iter->second];
|
||||
return region.layout.GetBlockPtr<T>(region.memory_ptr, name);
|
||||
const auto ®ion = GetBlockRegion(name);
|
||||
return reinterpret_cast<T *>(region.layout->GetBlockPtr(region.memory_ptr, name));
|
||||
}
|
||||
|
||||
template <typename T> auto GetBlockPtr(const std::string &name)
|
||||
{
|
||||
const auto index_iter = block_to_region.find(name);
|
||||
const auto ®ion = regions[index_iter->second];
|
||||
return region.layout.GetBlockPtr<T>(region.memory_ptr, name);
|
||||
const auto ®ion = GetBlockRegion(name);
|
||||
return reinterpret_cast<T *>(region.layout->GetBlockPtr(region.memory_ptr, name));
|
||||
}
|
||||
|
||||
std::size_t GetBlockEntries(const std::string &name) const
|
||||
{
|
||||
const auto index_iter = block_to_region.find(name);
|
||||
const auto ®ion = regions[index_iter->second];
|
||||
return region.layout.GetBlockEntries(name);
|
||||
const auto ®ion = GetBlockRegion(name);
|
||||
return region.layout->GetBlockEntries(name);
|
||||
}
|
||||
|
||||
std::size_t GetBlockSize(const std::string &name) const
|
||||
{
|
||||
const auto index_iter = block_to_region.find(name);
|
||||
const auto ®ion = regions[index_iter->second];
|
||||
return region.layout.GetBlockSize(name);
|
||||
const auto ®ion = GetBlockRegion(name);
|
||||
return region.layout->GetBlockSize(name);
|
||||
}
|
||||
|
||||
private:
|
||||
const AllocatedRegion &GetBlockRegion(const std::string &name) const
|
||||
{
|
||||
const auto index_iter = block_to_region.find(name);
|
||||
if (index_iter == block_to_region.end())
|
||||
{
|
||||
throw util::exception("data block " + name + " not found " + SOURCE_REF);
|
||||
}
|
||||
return regions[index_iter->second];
|
||||
}
|
||||
|
||||
std::vector<AllocatedRegion> regions;
|
||||
std::unordered_map<std::string, std::uint32_t> block_to_region;
|
||||
};
|
||||
|
||||
@@ -20,13 +20,13 @@ namespace osrm
|
||||
namespace storage
|
||||
{
|
||||
|
||||
class DataLayout;
|
||||
class BaseDataLayout;
|
||||
namespace serialization
|
||||
{
|
||||
inline void read(io::BufferReader &reader, DataLayout &layout);
|
||||
inline void read(io::BufferReader &reader, std::unique_ptr<BaseDataLayout> &layout);
|
||||
|
||||
inline void write(io::BufferWriter &writer, const DataLayout &layout);
|
||||
}
|
||||
inline void write(io::BufferWriter &writer, const std::unique_ptr<BaseDataLayout> &layout);
|
||||
} // namespace serialization
|
||||
|
||||
namespace detail
|
||||
{
|
||||
@@ -52,45 +52,22 @@ inline std::string trimName(const std::string &name_prefix, const std::string &n
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
class DataLayout
|
||||
class BaseDataLayout
|
||||
{
|
||||
public:
|
||||
DataLayout() : blocks{} {}
|
||||
virtual ~BaseDataLayout() = default;
|
||||
|
||||
inline void SetBlock(const std::string &name, Block block) { blocks[name] = std::move(block); }
|
||||
virtual inline void SetBlock(const std::string &name, Block block) = 0;
|
||||
|
||||
inline uint64_t GetBlockEntries(const std::string &name) const
|
||||
{
|
||||
return GetBlock(name).num_entries;
|
||||
}
|
||||
virtual inline uint64_t GetBlockEntries(const std::string &name) const = 0;
|
||||
|
||||
inline uint64_t GetBlockSize(const std::string &name) const { return GetBlock(name).byte_size; }
|
||||
virtual inline uint64_t GetBlockSize(const std::string &name) const = 0;
|
||||
|
||||
inline bool HasBlock(const std::string &name) const
|
||||
{
|
||||
return blocks.find(name) != blocks.end();
|
||||
}
|
||||
virtual inline bool HasBlock(const std::string &name) const = 0;
|
||||
|
||||
inline uint64_t GetSizeOfLayout() const
|
||||
{
|
||||
uint64_t result = 0;
|
||||
for (const auto &name_and_block : blocks)
|
||||
{
|
||||
result += GetBlockSize(name_and_block.first) + BLOCK_ALIGNMENT;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T> inline T *GetBlockPtr(char *shared_memory, const std::string &name) const
|
||||
{
|
||||
static_assert(BLOCK_ALIGNMENT % std::alignment_of<T>::value == 0,
|
||||
"Datatype does not fit alignment constraints.");
|
||||
|
||||
char *ptr = (char *)GetAlignedBlockPtr(shared_memory, name);
|
||||
return (T *)ptr;
|
||||
}
|
||||
virtual inline uint64_t GetSizeOfLayout() const = 0;
|
||||
|
||||
// Depending on the name prefix this function either lists all blocks with the same prefix
|
||||
// or all entries in the sub-directory.
|
||||
@@ -115,9 +92,59 @@ class DataLayout
|
||||
}
|
||||
}
|
||||
|
||||
virtual inline void *GetBlockPtr(char *shared_memory, const std::string &name) const = 0;
|
||||
|
||||
std::map<std::string, Block> blocks;
|
||||
};
|
||||
|
||||
class DataLayout final : public BaseDataLayout
|
||||
{
|
||||
public:
|
||||
inline void SetBlock(const std::string &name, Block block) override final
|
||||
{
|
||||
blocks[name] = std::move(block);
|
||||
}
|
||||
|
||||
inline uint64_t GetBlockEntries(const std::string &name) const override final
|
||||
{
|
||||
return GetBlock(name).num_entries;
|
||||
}
|
||||
|
||||
inline uint64_t GetBlockSize(const std::string &name) const override final
|
||||
{
|
||||
return GetBlock(name).byte_size;
|
||||
}
|
||||
|
||||
inline bool HasBlock(const std::string &name) const override final
|
||||
{
|
||||
return blocks.find(name) != blocks.end();
|
||||
}
|
||||
|
||||
inline uint64_t GetSizeOfLayout() const override final
|
||||
{
|
||||
uint64_t result = 0;
|
||||
for (const auto &name_and_block : blocks)
|
||||
{
|
||||
result += GetBlockSize(name_and_block.first) + BLOCK_ALIGNMENT;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
inline void *GetBlockPtr(char *shared_memory, const std::string &name) const override final
|
||||
{
|
||||
// TODO: re-enable this alignment checking somehow
|
||||
// static_assert(BLOCK_ALIGNMENT % std::alignment_of<T>::value == 0,
|
||||
// "Datatype does not fit alignment constraints.");
|
||||
|
||||
char *ptr = (char *)GetAlignedBlockPtr(shared_memory, name);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
private:
|
||||
friend void serialization::read(io::BufferReader &reader, DataLayout &layout);
|
||||
friend void serialization::write(io::BufferWriter &writer, const DataLayout &layout);
|
||||
friend void serialization::read(io::BufferReader &reader,
|
||||
std::unique_ptr<BaseDataLayout> &layout);
|
||||
friend void serialization::write(io::BufferWriter &writer,
|
||||
const std::unique_ptr<BaseDataLayout> &layout);
|
||||
|
||||
const Block &GetBlock(const std::string &name) const
|
||||
{
|
||||
@@ -157,7 +184,64 @@ class DataLayout
|
||||
}
|
||||
|
||||
static constexpr std::size_t BLOCK_ALIGNMENT = 64;
|
||||
std::map<std::string, Block> blocks;
|
||||
};
|
||||
|
||||
class TarDataLayout final : public BaseDataLayout
|
||||
{
|
||||
public:
|
||||
inline void SetBlock(const std::string &name, Block block) override final
|
||||
{
|
||||
blocks[name] = std::move(block);
|
||||
}
|
||||
|
||||
inline uint64_t GetBlockEntries(const std::string &name) const override final
|
||||
{
|
||||
return GetBlock(name).num_entries;
|
||||
}
|
||||
|
||||
inline uint64_t GetBlockSize(const std::string &name) const override final
|
||||
{
|
||||
return GetBlock(name).byte_size;
|
||||
}
|
||||
|
||||
inline bool HasBlock(const std::string &name) const override final
|
||||
{
|
||||
return blocks.find(name) != blocks.end();
|
||||
}
|
||||
|
||||
inline uint64_t GetSizeOfLayout() const override final
|
||||
{
|
||||
uint64_t result = 0;
|
||||
for (const auto &name_and_block : blocks)
|
||||
{
|
||||
result += GetBlockSize(name_and_block.first);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
inline void *GetBlockPtr(char *memory_ptr, const std::string &name) const override final
|
||||
{
|
||||
auto offset = GetBlock(name).offset;
|
||||
const auto offset_memory = memory_ptr + offset;
|
||||
return offset_memory;
|
||||
}
|
||||
|
||||
private:
|
||||
friend void serialization::read(io::BufferReader &reader,
|
||||
std::unique_ptr<BaseDataLayout> &layout);
|
||||
friend void serialization::write(io::BufferWriter &writer,
|
||||
const std::unique_ptr<BaseDataLayout> &layout);
|
||||
|
||||
const Block &GetBlock(const std::string &name) const
|
||||
{
|
||||
auto iter = blocks.find(name);
|
||||
if (iter == blocks.end())
|
||||
{
|
||||
throw util::exception("Could not find block " + name);
|
||||
}
|
||||
|
||||
return iter->second;
|
||||
}
|
||||
};
|
||||
|
||||
struct SharedRegion
|
||||
@@ -165,7 +249,7 @@ struct SharedRegion
|
||||
static constexpr const int MAX_NAME_LENGTH = 254;
|
||||
|
||||
SharedRegion() : name{0}, timestamp{0} {}
|
||||
SharedRegion(const std::string &name_, std::uint64_t timestamp, std::uint8_t shm_key)
|
||||
SharedRegion(const std::string &name_, std::uint64_t timestamp, std::uint16_t shm_key)
|
||||
: name{0}, timestamp{timestamp}, shm_key{shm_key}
|
||||
{
|
||||
std::copy_n(name_.begin(), std::min<std::size_t>(MAX_NAME_LENGTH, name_.size()), name);
|
||||
@@ -175,14 +259,14 @@ struct SharedRegion
|
||||
|
||||
char name[MAX_NAME_LENGTH + 1];
|
||||
std::uint64_t timestamp;
|
||||
std::uint8_t shm_key;
|
||||
std::uint16_t shm_key;
|
||||
};
|
||||
|
||||
// Keeps a list of all shared regions in a fixed-sized struct
|
||||
// for fast access and deserialization.
|
||||
struct SharedRegionRegister
|
||||
{
|
||||
using RegionID = std::uint8_t;
|
||||
using RegionID = std::uint16_t;
|
||||
static constexpr const RegionID INVALID_REGION_ID = std::numeric_limits<RegionID>::max();
|
||||
using ShmKey = decltype(SharedRegion::shm_key);
|
||||
|
||||
@@ -250,12 +334,11 @@ struct SharedRegionRegister
|
||||
|
||||
void ReleaseKey(ShmKey key) { shm_key_in_use[key] = false; }
|
||||
|
||||
static constexpr const std::uint8_t MAX_SHARED_REGIONS =
|
||||
std::numeric_limits<RegionID>::max() - 1;
|
||||
static constexpr const std::size_t MAX_SHARED_REGIONS = 512;
|
||||
static_assert(MAX_SHARED_REGIONS < std::numeric_limits<RegionID>::max(),
|
||||
"Number of shared memory regions needs to be less than the region id size.");
|
||||
|
||||
static constexpr const std::uint8_t MAX_SHM_KEYS = std::numeric_limits<std::uint8_t>::max() - 1;
|
||||
static constexpr const std::size_t MAX_SHM_KEYS = MAX_SHARED_REGIONS * 2;
|
||||
|
||||
static constexpr const char *name = "osrm-region";
|
||||
|
||||
@@ -263,7 +346,7 @@ struct SharedRegionRegister
|
||||
std::array<SharedRegion, MAX_SHARED_REGIONS> regions;
|
||||
std::array<bool, MAX_SHM_KEYS> shm_key_in_use;
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace storage
|
||||
} // namespace osrm
|
||||
|
||||
#endif /* SHARED_DATA_TYPE_HPP */
|
||||
|
||||
@@ -34,10 +34,10 @@ namespace storage
|
||||
|
||||
struct OSRMLockFile
|
||||
{
|
||||
boost::filesystem::path operator()()
|
||||
template <typename IdentifierT> boost::filesystem::path operator()(const IdentifierT &id)
|
||||
{
|
||||
boost::filesystem::path temp_dir = boost::filesystem::temp_directory_path();
|
||||
boost::filesystem::path lock_file = temp_dir / "osrm.lock";
|
||||
boost::filesystem::path lock_file = temp_dir / ("osrm-" + std::to_string(id) + ".lock");
|
||||
return lock_file;
|
||||
}
|
||||
};
|
||||
@@ -93,7 +93,7 @@ class SharedMemory
|
||||
try
|
||||
{
|
||||
OSRMLockFile lock_file;
|
||||
boost::interprocess::xsi_key key(lock_file().string().c_str(), id);
|
||||
boost::interprocess::xsi_key key(lock_file(id).string().c_str(), id);
|
||||
result = RegionExists(key);
|
||||
}
|
||||
catch (...)
|
||||
@@ -106,7 +106,7 @@ class SharedMemory
|
||||
template <typename IdentifierT> static bool Remove(const IdentifierT id)
|
||||
{
|
||||
OSRMLockFile lock_file;
|
||||
boost::interprocess::xsi_key key(lock_file().string().c_str(), id);
|
||||
boost::interprocess::xsi_key key(lock_file(id).string().c_str(), id);
|
||||
return Remove(key);
|
||||
}
|
||||
|
||||
@@ -287,10 +287,11 @@ class SharedMemory
|
||||
template <typename IdentifierT, typename LockFileT = OSRMLockFile>
|
||||
std::unique_ptr<SharedMemory> makeSharedMemory(const IdentifierT &id, const uint64_t size = 0)
|
||||
{
|
||||
static_assert(sizeof(id) == sizeof(std::uint16_t), "Key type is not 16 bits");
|
||||
try
|
||||
{
|
||||
LockFileT lock_file;
|
||||
if (!boost::filesystem::exists(lock_file()))
|
||||
if (!boost::filesystem::exists(lock_file(id)))
|
||||
{
|
||||
if (0 == size)
|
||||
{
|
||||
@@ -298,10 +299,10 @@ std::unique_ptr<SharedMemory> makeSharedMemory(const IdentifierT &id, const uint
|
||||
}
|
||||
else
|
||||
{
|
||||
boost::filesystem::ofstream ofs(lock_file());
|
||||
boost::filesystem::ofstream ofs(lock_file(id));
|
||||
}
|
||||
}
|
||||
return std::make_unique<SharedMemory>(lock_file(), id, size);
|
||||
return std::make_unique<SharedMemory>(lock_file(id), id, size);
|
||||
}
|
||||
catch (const boost::interprocess::interprocess_exception &e)
|
||||
{
|
||||
@@ -310,7 +311,7 @@ std::unique_ptr<SharedMemory> makeSharedMemory(const IdentifierT &id, const uint
|
||||
throw util::exception(e.what() + SOURCE_REF);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace storage
|
||||
} // namespace osrm
|
||||
|
||||
#endif // SHARED_MEMORY_HPP
|
||||
|
||||
@@ -33,7 +33,7 @@ template <class Lock> class InvertedLock
|
||||
InvertedLock(Lock &lock) : lock(lock) { lock.unlock(); }
|
||||
~InvertedLock() { lock.lock(); }
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
// The shared monitor implementation based on a semaphore and mutex
|
||||
template <typename Data> struct SharedMonitor
|
||||
@@ -117,6 +117,19 @@ template <typename Data> struct SharedMonitor
|
||||
#endif
|
||||
|
||||
static void remove() { bi::shared_memory_object::remove(Data::name); }
|
||||
static bool exists()
|
||||
{
|
||||
try
|
||||
{
|
||||
bi::shared_memory_object shmem_open =
|
||||
bi::shared_memory_object(bi::open_only, Data::name, bi::read_only);
|
||||
}
|
||||
catch (const bi::interprocess_exception &exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
#if USE_BOOST_INTERPROCESS_CONDITION
|
||||
@@ -133,7 +146,9 @@ template <typename Data> struct SharedMonitor
|
||||
// like two-turnstile reusable barrier or boost/interprocess/sync/spin/condition.hpp
|
||||
// fail if a waiter is killed.
|
||||
|
||||
static constexpr int buffer_size = 256;
|
||||
// Buffer size needs to be large enough to hold all the semaphores for every
|
||||
// listener you want to support.
|
||||
static constexpr int buffer_size = 4096 * 4;
|
||||
|
||||
struct InternalData
|
||||
{
|
||||
@@ -219,8 +234,8 @@ template <typename Data> struct SharedMonitor
|
||||
bi::shared_memory_object shmem;
|
||||
bi::mapped_region region;
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace storage
|
||||
} // namespace osrm
|
||||
|
||||
#undef USE_BOOST_INTERPROCESS_CONDITION
|
||||
|
||||
|
||||
@@ -46,11 +46,15 @@ class Storage
|
||||
Storage(StorageConfig config);
|
||||
|
||||
int Run(int max_wait, const std::string &name, bool only_metric);
|
||||
|
||||
void PopulateStaticLayout(DataLayout &layout);
|
||||
void PopulateUpdatableLayout(DataLayout &layout);
|
||||
void PopulateStaticData(const SharedDataIndex &index);
|
||||
void PopulateUpdatableData(const SharedDataIndex &index);
|
||||
void PopulateLayout(std::unique_ptr<storage::BaseDataLayout> &layout,
|
||||
std::vector<std::pair<bool, boost::filesystem::path>> files);
|
||||
std::string PopulateLayoutWithRTree(std::unique_ptr<storage::BaseDataLayout> &layout);
|
||||
void readBlocks(const boost::filesystem::path &path,
|
||||
std::unique_ptr<storage::BaseDataLayout> &layout);
|
||||
std::vector<std::pair<bool, boost::filesystem::path>> GetUpdatableFiles();
|
||||
std::vector<std::pair<bool, boost::filesystem::path>> GetStaticFiles();
|
||||
|
||||
private:
|
||||
StorageConfig config;
|
||||
|
||||
@@ -29,10 +29,8 @@ checkMTarError(int error_code, const boost::filesystem::path &filepath, const st
|
||||
case MTAR_ESUCCESS:
|
||||
return;
|
||||
case MTAR_EFAILURE:
|
||||
throw util::RuntimeError(filepath.string() + " : " + name,
|
||||
ErrorCode::FileIOError,
|
||||
SOURCE_REF,
|
||||
std::strerror(errno));
|
||||
throw util::RuntimeError(
|
||||
filepath.string() + " : " + name, ErrorCode::FileIOError, SOURCE_REF);
|
||||
case MTAR_EOPENFAIL:
|
||||
throw util::RuntimeError(filepath.string() + " : " + name,
|
||||
ErrorCode::FileOpenError,
|
||||
|
||||
@@ -330,9 +330,18 @@ inline auto make_multi_level_graph_view(const SharedDataIndex &index, const std:
|
||||
index, name + "/edge_array");
|
||||
auto node_to_offset = make_vector_view<customizer::MultiLevelEdgeBasedGraphView::EdgeOffset>(
|
||||
index, name + "/node_to_edge_offset");
|
||||
auto node_weights = make_vector_view<EdgeWeight>(index, name + "/node_weights");
|
||||
auto node_durations = make_vector_view<EdgeDuration>(index, name + "/node_durations");
|
||||
auto is_forward_edge = make_vector_view<bool>(index, name + "/is_forward_edge");
|
||||
auto is_backward_edge = make_vector_view<bool>(index, name + "/is_backward_edge");
|
||||
|
||||
return customizer::MultiLevelEdgeBasedGraphView(
|
||||
std::move(node_list), std::move(edge_list), std::move(node_to_offset));
|
||||
return customizer::MultiLevelEdgeBasedGraphView(std::move(node_list),
|
||||
std::move(edge_list),
|
||||
std::move(node_to_offset),
|
||||
std::move(node_weights),
|
||||
std::move(node_durations),
|
||||
std::move(is_forward_edge),
|
||||
std::move(is_backward_edge));
|
||||
}
|
||||
|
||||
inline auto make_maneuver_overrides_views(const SharedDataIndex &index, const std::string &name)
|
||||
|
||||
@@ -17,13 +17,15 @@ class Updater
|
||||
public:
|
||||
Updater(UpdaterConfig config_) : config(std::move(config_)) {}
|
||||
|
||||
using NumNodesAndEdges =
|
||||
std::tuple<EdgeID, std::vector<extractor::EdgeBasedEdge>, std::uint32_t>;
|
||||
NumNodesAndEdges LoadAndUpdateEdgeExpandedGraph() const;
|
||||
EdgeID
|
||||
LoadAndUpdateEdgeExpandedGraph(std::vector<extractor::EdgeBasedEdge> &edge_based_edge_list,
|
||||
std::vector<EdgeWeight> &node_weights,
|
||||
std::uint32_t &connectivity_checksum) const;
|
||||
|
||||
EdgeID
|
||||
LoadAndUpdateEdgeExpandedGraph(std::vector<extractor::EdgeBasedEdge> &edge_based_edge_list,
|
||||
std::vector<EdgeWeight> &node_weights,
|
||||
std::vector<EdgeDuration> &node_durations, // TODO: to be deleted
|
||||
std::uint32_t &connectivity_checksum) const;
|
||||
|
||||
private:
|
||||
|
||||
@@ -53,7 +53,8 @@ struct UpdaterConfig final : storage::IOConfig
|
||||
".osrm.geometry",
|
||||
".osrm.fileIndex",
|
||||
".osrm.properties",
|
||||
".osrm.restrictions"},
|
||||
".osrm.restrictions",
|
||||
".osrm.enw"},
|
||||
{},
|
||||
{".osrm.datasource_names"}),
|
||||
valid_now(0)
|
||||
|
||||
@@ -43,6 +43,9 @@ inline double radToDeg(const double radian)
|
||||
//! Takes the squared euclidean distance of the input coordinates. Does not return meters!
|
||||
std::uint64_t squaredEuclideanDistance(const Coordinate lhs, const Coordinate rhs);
|
||||
|
||||
double fccApproximateDistance(const Coordinate first_coordinate,
|
||||
const Coordinate second_coordinate);
|
||||
|
||||
double haversineDistance(const Coordinate first_coordinate, const Coordinate second_coordinate);
|
||||
|
||||
double greatCircleDistance(const Coordinate first_coordinate, const Coordinate second_coordinate);
|
||||
|
||||
+32
-12
@@ -1,9 +1,11 @@
|
||||
#ifndef OSRM_UTIL_DEBUG_HPP_
|
||||
#define OSRM_UTIL_DEBUG_HPP_
|
||||
|
||||
#include "extractor/edge_based_edge.hpp"
|
||||
#include "extractor/node_data_container.hpp"
|
||||
#include "extractor/query_node.hpp"
|
||||
#include "guidance/intersection.hpp"
|
||||
#include "guidance/turn_instruction.hpp"
|
||||
#include "guidance/turn_lane_data.hpp"
|
||||
#include "engine/guidance/route_step.hpp"
|
||||
#include "util/node_based_graph.hpp"
|
||||
@@ -22,10 +24,10 @@ namespace util
|
||||
inline std::ostream &operator<<(std::ostream &out, const Coordinate &coordinate)
|
||||
{
|
||||
out << std::setprecision(12) << "{" << toFloating(coordinate.lon) << ", "
|
||||
<< toFloating(coordinate.lon) << "}";
|
||||
<< toFloating(coordinate.lat) << "}";
|
||||
return out;
|
||||
}
|
||||
}
|
||||
} // namespace util
|
||||
|
||||
namespace engine
|
||||
{
|
||||
@@ -60,8 +62,8 @@ inline std::ostream &operator<<(std::ostream &out, const RouteStep &step)
|
||||
|
||||
return out;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace guidance
|
||||
} // namespace engine
|
||||
|
||||
namespace guidance
|
||||
{
|
||||
@@ -74,7 +76,7 @@ inline std::ostream &operator<<(std::ostream &out, const ConnectedRoad &road)
|
||||
<< static_cast<std::int32_t>(road.lane_data_id) << "}";
|
||||
return out;
|
||||
}
|
||||
}
|
||||
} // namespace guidance
|
||||
|
||||
namespace extractor
|
||||
{
|
||||
@@ -93,7 +95,7 @@ inline std::ostream &operator<<(std::ostream &out, const IntersectionViewData &v
|
||||
<< " angle: " << view.angle << " bearing: " << view.perceived_bearing << "}";
|
||||
return out;
|
||||
}
|
||||
}
|
||||
} // namespace intersection
|
||||
|
||||
namespace TurnLaneType
|
||||
{
|
||||
@@ -123,9 +125,9 @@ inline std::ostream &operator<<(std::ostream &out, const Mask lane_type)
|
||||
|
||||
return out;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace TurnLaneType
|
||||
} // namespace extractor
|
||||
} // namespace osrm
|
||||
|
||||
namespace std
|
||||
{
|
||||
@@ -145,7 +147,7 @@ inline std::ostream &operator<<(std::ostream &out,
|
||||
|
||||
return out;
|
||||
}
|
||||
}
|
||||
} // namespace std
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
@@ -184,8 +186,26 @@ inline std::ostream &operator<<(std::ostream &out, const LaneDataVector &turn_la
|
||||
|
||||
return out;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace lanes
|
||||
} // namespace guidance
|
||||
|
||||
namespace extractor
|
||||
{
|
||||
inline std::ostream &operator<<(std::ostream &out, const EdgeBasedEdge &edge)
|
||||
{
|
||||
out << " EdgeBasedEdge {";
|
||||
out << " source " << edge.source << ", target: " << edge.target;
|
||||
out << " EdgeBasedEdgeData data {";
|
||||
out << " turn_id: " << edge.data.turn_id << ", weight: " << edge.data.weight;
|
||||
out << " distance: " << edge.data.distance << ", duration: " << edge.data.duration;
|
||||
out << " forward: " << (edge.data.forward == 0 ? "false" : "true")
|
||||
<< ", backward: " << (edge.data.backward == 0 ? "false" : "true");
|
||||
out << " }";
|
||||
out << "}";
|
||||
return out;
|
||||
}
|
||||
|
||||
} // namespace extractor
|
||||
} // namespace osrm
|
||||
|
||||
#endif /*OSRM_ENGINE_GUIDANCE_DEBUG_HPP_*/
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
#define DYNAMICGRAPH_HPP
|
||||
|
||||
#include "util/deallocating_vector.hpp"
|
||||
#include "util/exception.hpp"
|
||||
#include "util/exception_utils.hpp"
|
||||
#include "util/integer_range.hpp"
|
||||
#include "util/permutation.hpp"
|
||||
#include "util/typedefs.hpp"
|
||||
@@ -411,7 +413,12 @@ template <typename EdgeDataT> class DynamicGraph
|
||||
util::inplacePermutation(node_array.begin(), node_array.end(), old_to_new_node);
|
||||
|
||||
// Build up edge permutation
|
||||
auto new_edge_index = 0;
|
||||
if (edge_list.size() >= std::numeric_limits<EdgeID>::max())
|
||||
{
|
||||
throw util::exception("There are too many edges, OSRM only supports 2^32" + SOURCE_REF);
|
||||
}
|
||||
|
||||
EdgeID new_edge_index = 0;
|
||||
std::vector<EdgeID> old_to_new_edge(edge_list.size(), SPECIAL_EDGEID);
|
||||
for (auto node : util::irange<NodeID>(0, number_of_nodes))
|
||||
{
|
||||
|
||||
@@ -0,0 +1,517 @@
|
||||
#ifndef IEEE754_HPP
|
||||
#define IEEE754_HPP
|
||||
/**
|
||||
Copyright (C) 2014 Milo Yip
|
||||
|
||||
Imported from:
|
||||
https://github.com/miloyip/dtoa-benchmark/blob/c4020c62754950d38a1aaaed2975b05b441d1e7d/src/milo/dtoa_milo.h
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
**/
|
||||
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#include "msinttypes/stdint.h"
|
||||
#include <intrin.h>
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
#define UINT64_C2(h, l) ((static_cast<uint64_t>(h) << 32) | static_cast<uint64_t>(l))
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace util
|
||||
{
|
||||
namespace ieee754
|
||||
{
|
||||
|
||||
struct DiyFp
|
||||
{
|
||||
DiyFp() {}
|
||||
|
||||
DiyFp(uint64_t f, int e) : f(f), e(e) {}
|
||||
|
||||
DiyFp(double d)
|
||||
{
|
||||
union {
|
||||
double d;
|
||||
uint64_t u64;
|
||||
} u = {d};
|
||||
|
||||
int biased_e = (u.u64 & kDpExponentMask) >> kDpSignificandSize;
|
||||
uint64_t significand = (u.u64 & kDpSignificandMask);
|
||||
if (biased_e != 0)
|
||||
{
|
||||
f = significand + kDpHiddenBit;
|
||||
e = biased_e - kDpExponentBias;
|
||||
}
|
||||
else
|
||||
{
|
||||
f = significand;
|
||||
e = kDpMinExponent + 1;
|
||||
}
|
||||
}
|
||||
|
||||
DiyFp operator-(const DiyFp &rhs) const
|
||||
{
|
||||
assert(e == rhs.e);
|
||||
assert(f >= rhs.f);
|
||||
return DiyFp(f - rhs.f, e);
|
||||
}
|
||||
|
||||
DiyFp operator*(const DiyFp &rhs) const
|
||||
{
|
||||
#if defined(_MSC_VER) && defined(_M_AMD64)
|
||||
uint64_t h;
|
||||
uint64_t l = _umul128(f, rhs.f, &h);
|
||||
if (l & (uint64_t(1) << 63)) // rounding
|
||||
h++;
|
||||
return DiyFp(h, e + rhs.e + 64);
|
||||
#elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && defined(__x86_64__)
|
||||
unsigned __int128 p =
|
||||
static_cast<unsigned __int128>(f) * static_cast<unsigned __int128>(rhs.f);
|
||||
uint64_t h = p >> 64;
|
||||
uint64_t l = static_cast<uint64_t>(p);
|
||||
if (l & (uint64_t(1) << 63)) // rounding
|
||||
h++;
|
||||
return DiyFp(h, e + rhs.e + 64);
|
||||
#else
|
||||
const uint64_t M32 = 0xFFFFFFFF;
|
||||
const uint64_t a = f >> 32;
|
||||
const uint64_t b = f & M32;
|
||||
const uint64_t c = rhs.f >> 32;
|
||||
const uint64_t d = rhs.f & M32;
|
||||
const uint64_t ac = a * c;
|
||||
const uint64_t bc = b * c;
|
||||
const uint64_t ad = a * d;
|
||||
const uint64_t bd = b * d;
|
||||
uint64_t tmp = (bd >> 32) + (ad & M32) + (bc & M32);
|
||||
tmp += 1U << 31; /// mult_round
|
||||
return DiyFp(ac + (ad >> 32) + (bc >> 32) + (tmp >> 32), e + rhs.e + 64);
|
||||
#endif
|
||||
}
|
||||
|
||||
DiyFp Normalize() const
|
||||
{
|
||||
#if defined(_MSC_VER) && defined(_M_AMD64)
|
||||
unsigned long index;
|
||||
_BitScanReverse64(&index, f);
|
||||
return DiyFp(f << (63 - index), e - (63 - index));
|
||||
#elif defined(__GNUC__)
|
||||
int s = __builtin_clzll(f);
|
||||
return DiyFp(f << s, e - s);
|
||||
#else
|
||||
DiyFp res = *this;
|
||||
while (!(res.f & kDpHiddenBit))
|
||||
{
|
||||
res.f <<= 1;
|
||||
res.e--;
|
||||
}
|
||||
res.f <<= (kDiySignificandSize - kDpSignificandSize - 1);
|
||||
res.e = res.e - (kDiySignificandSize - kDpSignificandSize - 1);
|
||||
return res;
|
||||
#endif
|
||||
}
|
||||
|
||||
DiyFp NormalizeBoundary() const
|
||||
{
|
||||
#if defined(_MSC_VER) && defined(_M_AMD64)
|
||||
unsigned long index;
|
||||
_BitScanReverse64(&index, f);
|
||||
return DiyFp(f << (63 - index), e - (63 - index));
|
||||
#else
|
||||
DiyFp res = *this;
|
||||
while (!(res.f & (kDpHiddenBit << 1)))
|
||||
{
|
||||
res.f <<= 1;
|
||||
res.e--;
|
||||
}
|
||||
res.f <<= (kDiySignificandSize - kDpSignificandSize - 2);
|
||||
res.e = res.e - (kDiySignificandSize - kDpSignificandSize - 2);
|
||||
return res;
|
||||
#endif
|
||||
}
|
||||
|
||||
void NormalizedBoundaries(DiyFp *minus, DiyFp *plus) const
|
||||
{
|
||||
DiyFp pl = DiyFp((f << 1) + 1, e - 1).NormalizeBoundary();
|
||||
DiyFp mi = (f == kDpHiddenBit) ? DiyFp((f << 2) - 1, e - 2) : DiyFp((f << 1) - 1, e - 1);
|
||||
mi.f <<= mi.e - pl.e;
|
||||
mi.e = pl.e;
|
||||
*plus = pl;
|
||||
*minus = mi;
|
||||
}
|
||||
|
||||
static const int kDiySignificandSize = 64;
|
||||
static const int kDpSignificandSize = 52;
|
||||
static const int kDpExponentBias = 0x3FF + kDpSignificandSize;
|
||||
static const int kDpMinExponent = -kDpExponentBias;
|
||||
static const uint64_t kDpExponentMask = UINT64_C2(0x7FF00000, 0x00000000);
|
||||
static const uint64_t kDpSignificandMask = UINT64_C2(0x000FFFFF, 0xFFFFFFFF);
|
||||
static const uint64_t kDpHiddenBit = UINT64_C2(0x00100000, 0x00000000);
|
||||
|
||||
uint64_t f;
|
||||
int e;
|
||||
};
|
||||
|
||||
inline DiyFp GetCachedPower(int e, int *K)
|
||||
{
|
||||
// 10^-348, 10^-340, ..., 10^340
|
||||
static const uint64_t kCachedPowers_F[] = {
|
||||
UINT64_C2(0xfa8fd5a0, 0x081c0288), UINT64_C2(0xbaaee17f, 0xa23ebf76),
|
||||
UINT64_C2(0x8b16fb20, 0x3055ac76), UINT64_C2(0xcf42894a, 0x5dce35ea),
|
||||
UINT64_C2(0x9a6bb0aa, 0x55653b2d), UINT64_C2(0xe61acf03, 0x3d1a45df),
|
||||
UINT64_C2(0xab70fe17, 0xc79ac6ca), UINT64_C2(0xff77b1fc, 0xbebcdc4f),
|
||||
UINT64_C2(0xbe5691ef, 0x416bd60c), UINT64_C2(0x8dd01fad, 0x907ffc3c),
|
||||
UINT64_C2(0xd3515c28, 0x31559a83), UINT64_C2(0x9d71ac8f, 0xada6c9b5),
|
||||
UINT64_C2(0xea9c2277, 0x23ee8bcb), UINT64_C2(0xaecc4991, 0x4078536d),
|
||||
UINT64_C2(0x823c1279, 0x5db6ce57), UINT64_C2(0xc2109436, 0x4dfb5637),
|
||||
UINT64_C2(0x9096ea6f, 0x3848984f), UINT64_C2(0xd77485cb, 0x25823ac7),
|
||||
UINT64_C2(0xa086cfcd, 0x97bf97f4), UINT64_C2(0xef340a98, 0x172aace5),
|
||||
UINT64_C2(0xb23867fb, 0x2a35b28e), UINT64_C2(0x84c8d4df, 0xd2c63f3b),
|
||||
UINT64_C2(0xc5dd4427, 0x1ad3cdba), UINT64_C2(0x936b9fce, 0xbb25c996),
|
||||
UINT64_C2(0xdbac6c24, 0x7d62a584), UINT64_C2(0xa3ab6658, 0x0d5fdaf6),
|
||||
UINT64_C2(0xf3e2f893, 0xdec3f126), UINT64_C2(0xb5b5ada8, 0xaaff80b8),
|
||||
UINT64_C2(0x87625f05, 0x6c7c4a8b), UINT64_C2(0xc9bcff60, 0x34c13053),
|
||||
UINT64_C2(0x964e858c, 0x91ba2655), UINT64_C2(0xdff97724, 0x70297ebd),
|
||||
UINT64_C2(0xa6dfbd9f, 0xb8e5b88f), UINT64_C2(0xf8a95fcf, 0x88747d94),
|
||||
UINT64_C2(0xb9447093, 0x8fa89bcf), UINT64_C2(0x8a08f0f8, 0xbf0f156b),
|
||||
UINT64_C2(0xcdb02555, 0x653131b6), UINT64_C2(0x993fe2c6, 0xd07b7fac),
|
||||
UINT64_C2(0xe45c10c4, 0x2a2b3b06), UINT64_C2(0xaa242499, 0x697392d3),
|
||||
UINT64_C2(0xfd87b5f2, 0x8300ca0e), UINT64_C2(0xbce50864, 0x92111aeb),
|
||||
UINT64_C2(0x8cbccc09, 0x6f5088cc), UINT64_C2(0xd1b71758, 0xe219652c),
|
||||
UINT64_C2(0x9c400000, 0x00000000), UINT64_C2(0xe8d4a510, 0x00000000),
|
||||
UINT64_C2(0xad78ebc5, 0xac620000), UINT64_C2(0x813f3978, 0xf8940984),
|
||||
UINT64_C2(0xc097ce7b, 0xc90715b3), UINT64_C2(0x8f7e32ce, 0x7bea5c70),
|
||||
UINT64_C2(0xd5d238a4, 0xabe98068), UINT64_C2(0x9f4f2726, 0x179a2245),
|
||||
UINT64_C2(0xed63a231, 0xd4c4fb27), UINT64_C2(0xb0de6538, 0x8cc8ada8),
|
||||
UINT64_C2(0x83c7088e, 0x1aab65db), UINT64_C2(0xc45d1df9, 0x42711d9a),
|
||||
UINT64_C2(0x924d692c, 0xa61be758), UINT64_C2(0xda01ee64, 0x1a708dea),
|
||||
UINT64_C2(0xa26da399, 0x9aef774a), UINT64_C2(0xf209787b, 0xb47d6b85),
|
||||
UINT64_C2(0xb454e4a1, 0x79dd1877), UINT64_C2(0x865b8692, 0x5b9bc5c2),
|
||||
UINT64_C2(0xc83553c5, 0xc8965d3d), UINT64_C2(0x952ab45c, 0xfa97a0b3),
|
||||
UINT64_C2(0xde469fbd, 0x99a05fe3), UINT64_C2(0xa59bc234, 0xdb398c25),
|
||||
UINT64_C2(0xf6c69a72, 0xa3989f5c), UINT64_C2(0xb7dcbf53, 0x54e9bece),
|
||||
UINT64_C2(0x88fcf317, 0xf22241e2), UINT64_C2(0xcc20ce9b, 0xd35c78a5),
|
||||
UINT64_C2(0x98165af3, 0x7b2153df), UINT64_C2(0xe2a0b5dc, 0x971f303a),
|
||||
UINT64_C2(0xa8d9d153, 0x5ce3b396), UINT64_C2(0xfb9b7cd9, 0xa4a7443c),
|
||||
UINT64_C2(0xbb764c4c, 0xa7a44410), UINT64_C2(0x8bab8eef, 0xb6409c1a),
|
||||
UINT64_C2(0xd01fef10, 0xa657842c), UINT64_C2(0x9b10a4e5, 0xe9913129),
|
||||
UINT64_C2(0xe7109bfb, 0xa19c0c9d), UINT64_C2(0xac2820d9, 0x623bf429),
|
||||
UINT64_C2(0x80444b5e, 0x7aa7cf85), UINT64_C2(0xbf21e440, 0x03acdd2d),
|
||||
UINT64_C2(0x8e679c2f, 0x5e44ff8f), UINT64_C2(0xd433179d, 0x9c8cb841),
|
||||
UINT64_C2(0x9e19db92, 0xb4e31ba9), UINT64_C2(0xeb96bf6e, 0xbadf77d9),
|
||||
UINT64_C2(0xaf87023b, 0x9bf0ee6b)};
|
||||
static const int16_t kCachedPowers_E[] = {
|
||||
-1220, -1193, -1166, -1140, -1113, -1087, -1060, -1034, -1007, -980, -954, -927, -901,
|
||||
-874, -847, -821, -794, -768, -741, -715, -688, -661, -635, -608, -582, -555,
|
||||
-529, -502, -475, -449, -422, -396, -369, -343, -316, -289, -263, -236, -210,
|
||||
-183, -157, -130, -103, -77, -50, -24, 3, 30, 56, 83, 109, 136,
|
||||
162, 189, 216, 242, 269, 295, 322, 348, 375, 402, 428, 455, 481,
|
||||
508, 534, 561, 588, 614, 641, 667, 694, 720, 747, 774, 800, 827,
|
||||
853, 880, 907, 933, 960, 986, 1013, 1039, 1066};
|
||||
|
||||
// int k = static_cast<int>(ceil((-61 - e) * 0.30102999566398114)) + 374;
|
||||
double dk =
|
||||
(-61 - e) * 0.30102999566398114 + 347; // dk must be positive, so can do ceiling in positive
|
||||
int k = static_cast<int>(dk);
|
||||
if (k != dk)
|
||||
k++;
|
||||
|
||||
unsigned index = static_cast<unsigned>((k >> 3) + 1);
|
||||
*K = -(-348 + static_cast<int>(index << 3)); // decimal exponent no need lookup table
|
||||
|
||||
assert(index < sizeof(kCachedPowers_F) / sizeof(kCachedPowers_F[0]));
|
||||
return DiyFp(kCachedPowers_F[index], kCachedPowers_E[index]);
|
||||
}
|
||||
|
||||
inline void
|
||||
GrisuRound(char *buffer, int len, uint64_t delta, uint64_t rest, uint64_t ten_kappa, uint64_t wp_w)
|
||||
{
|
||||
while (rest < wp_w && delta - rest >= ten_kappa && (rest + ten_kappa < wp_w || /// closer
|
||||
wp_w - rest > rest + ten_kappa - wp_w))
|
||||
{
|
||||
buffer[len - 1]--;
|
||||
rest += ten_kappa;
|
||||
}
|
||||
}
|
||||
|
||||
inline unsigned CountDecimalDigit32(uint32_t n)
|
||||
{
|
||||
// Simple pure C++ implementation was faster than __builtin_clz version in this situation.
|
||||
if (n < 10)
|
||||
return 1;
|
||||
if (n < 100)
|
||||
return 2;
|
||||
if (n < 1000)
|
||||
return 3;
|
||||
if (n < 10000)
|
||||
return 4;
|
||||
if (n < 100000)
|
||||
return 5;
|
||||
if (n < 1000000)
|
||||
return 6;
|
||||
if (n < 10000000)
|
||||
return 7;
|
||||
if (n < 100000000)
|
||||
return 8;
|
||||
if (n < 1000000000)
|
||||
return 9;
|
||||
return 10;
|
||||
}
|
||||
|
||||
inline void
|
||||
DigitGen(const DiyFp &W, const DiyFp &Mp, uint64_t delta, char *buffer, int *len, int *K)
|
||||
{
|
||||
static const uint32_t kPow10[] = {
|
||||
1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000};
|
||||
const DiyFp one(uint64_t(1) << -Mp.e, Mp.e);
|
||||
const DiyFp wp_w = Mp - W;
|
||||
uint32_t p1 = static_cast<uint32_t>(Mp.f >> -one.e);
|
||||
uint64_t p2 = Mp.f & (one.f - 1);
|
||||
int kappa = static_cast<int>(CountDecimalDigit32(p1));
|
||||
*len = 0;
|
||||
|
||||
while (kappa > 0)
|
||||
{
|
||||
uint32_t d;
|
||||
switch (kappa)
|
||||
{
|
||||
case 10:
|
||||
d = p1 / 1000000000;
|
||||
p1 %= 1000000000;
|
||||
break;
|
||||
case 9:
|
||||
d = p1 / 100000000;
|
||||
p1 %= 100000000;
|
||||
break;
|
||||
case 8:
|
||||
d = p1 / 10000000;
|
||||
p1 %= 10000000;
|
||||
break;
|
||||
case 7:
|
||||
d = p1 / 1000000;
|
||||
p1 %= 1000000;
|
||||
break;
|
||||
case 6:
|
||||
d = p1 / 100000;
|
||||
p1 %= 100000;
|
||||
break;
|
||||
case 5:
|
||||
d = p1 / 10000;
|
||||
p1 %= 10000;
|
||||
break;
|
||||
case 4:
|
||||
d = p1 / 1000;
|
||||
p1 %= 1000;
|
||||
break;
|
||||
case 3:
|
||||
d = p1 / 100;
|
||||
p1 %= 100;
|
||||
break;
|
||||
case 2:
|
||||
d = p1 / 10;
|
||||
p1 %= 10;
|
||||
break;
|
||||
case 1:
|
||||
d = p1;
|
||||
p1 = 0;
|
||||
break;
|
||||
default:
|
||||
#if defined(_MSC_VER)
|
||||
__assume(0);
|
||||
#elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
|
||||
__builtin_unreachable();
|
||||
#else
|
||||
d = 0;
|
||||
#endif
|
||||
}
|
||||
if (d || *len)
|
||||
buffer[(*len)++] = '0' + static_cast<char>(d);
|
||||
kappa--;
|
||||
uint64_t tmp = (static_cast<uint64_t>(p1) << -one.e) + p2;
|
||||
if (tmp <= delta)
|
||||
{
|
||||
*K += kappa;
|
||||
GrisuRound(
|
||||
buffer, *len, delta, tmp, static_cast<uint64_t>(kPow10[kappa]) << -one.e, wp_w.f);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// kappa = 0
|
||||
for (;;)
|
||||
{
|
||||
p2 *= 10;
|
||||
delta *= 10;
|
||||
char d = static_cast<char>(p2 >> -one.e);
|
||||
if (d || *len)
|
||||
buffer[(*len)++] = '0' + d;
|
||||
p2 &= one.f - 1;
|
||||
kappa--;
|
||||
if (p2 < delta)
|
||||
{
|
||||
*K += kappa;
|
||||
GrisuRound(buffer, *len, delta, p2, one.f, wp_w.f * kPow10[-kappa]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void Grisu2(double value, char *buffer, int *length, int *K)
|
||||
{
|
||||
const DiyFp v(value);
|
||||
DiyFp w_m, w_p;
|
||||
v.NormalizedBoundaries(&w_m, &w_p);
|
||||
|
||||
const DiyFp c_mk = GetCachedPower(w_p.e, K);
|
||||
const DiyFp W = v.Normalize() * c_mk;
|
||||
DiyFp Wp = w_p * c_mk;
|
||||
DiyFp Wm = w_m * c_mk;
|
||||
Wm.f++;
|
||||
Wp.f--;
|
||||
DigitGen(W, Wp, Wp.f - Wm.f, buffer, length, K);
|
||||
}
|
||||
|
||||
inline const char *GetDigitsLut()
|
||||
{
|
||||
static const char cDigitsLut[200] = {
|
||||
'0', '0', '0', '1', '0', '2', '0', '3', '0', '4', '0', '5', '0', '6', '0', '7', '0',
|
||||
'8', '0', '9', '1', '0', '1', '1', '1', '2', '1', '3', '1', '4', '1', '5', '1', '6',
|
||||
'1', '7', '1', '8', '1', '9', '2', '0', '2', '1', '2', '2', '2', '3', '2', '4', '2',
|
||||
'5', '2', '6', '2', '7', '2', '8', '2', '9', '3', '0', '3', '1', '3', '2', '3', '3',
|
||||
'3', '4', '3', '5', '3', '6', '3', '7', '3', '8', '3', '9', '4', '0', '4', '1', '4',
|
||||
'2', '4', '3', '4', '4', '4', '5', '4', '6', '4', '7', '4', '8', '4', '9', '5', '0',
|
||||
'5', '1', '5', '2', '5', '3', '5', '4', '5', '5', '5', '6', '5', '7', '5', '8', '5',
|
||||
'9', '6', '0', '6', '1', '6', '2', '6', '3', '6', '4', '6', '5', '6', '6', '6', '7',
|
||||
'6', '8', '6', '9', '7', '0', '7', '1', '7', '2', '7', '3', '7', '4', '7', '5', '7',
|
||||
'6', '7', '7', '7', '8', '7', '9', '8', '0', '8', '1', '8', '2', '8', '3', '8', '4',
|
||||
'8', '5', '8', '6', '8', '7', '8', '8', '8', '9', '9', '0', '9', '1', '9', '2', '9',
|
||||
'3', '9', '4', '9', '5', '9', '6', '9', '7', '9', '8', '9', '9'};
|
||||
return cDigitsLut;
|
||||
}
|
||||
|
||||
inline void WriteExponent(int K, char *buffer)
|
||||
{
|
||||
if (K < 0)
|
||||
{
|
||||
*buffer++ = '-';
|
||||
K = -K;
|
||||
}
|
||||
|
||||
if (K >= 100)
|
||||
{
|
||||
*buffer++ = '0' + static_cast<char>(K / 100);
|
||||
K %= 100;
|
||||
const char *d = GetDigitsLut() + K * 2;
|
||||
*buffer++ = d[0];
|
||||
*buffer++ = d[1];
|
||||
}
|
||||
else if (K >= 10)
|
||||
{
|
||||
const char *d = GetDigitsLut() + K * 2;
|
||||
*buffer++ = d[0];
|
||||
*buffer++ = d[1];
|
||||
}
|
||||
else
|
||||
*buffer++ = '0' + static_cast<char>(K);
|
||||
|
||||
*buffer = '\0';
|
||||
}
|
||||
|
||||
inline void Prettify(char *buffer, int length, int k)
|
||||
{
|
||||
const int kk = length + k; // 10^(kk-1) <= v < 10^kk
|
||||
|
||||
if (length <= kk && kk <= 21)
|
||||
{
|
||||
// 1234e7 -> 12340000000
|
||||
for (int i = length; i < kk; i++)
|
||||
buffer[i] = '0';
|
||||
buffer[kk] = '.';
|
||||
buffer[kk + 1] = '0';
|
||||
buffer[kk + 2] = '\0';
|
||||
}
|
||||
else if (0 < kk && kk <= 21)
|
||||
{
|
||||
// 1234e-2 -> 12.34
|
||||
memmove(&buffer[kk + 1], &buffer[kk], length - kk);
|
||||
buffer[kk] = '.';
|
||||
buffer[length + 1] = '\0';
|
||||
}
|
||||
else if (-6 < kk && kk <= 0)
|
||||
{
|
||||
// 1234e-6 -> 0.001234
|
||||
const int offset = 2 - kk;
|
||||
memmove(&buffer[offset], &buffer[0], length);
|
||||
buffer[0] = '0';
|
||||
buffer[1] = '.';
|
||||
for (int i = 2; i < offset; i++)
|
||||
buffer[i] = '0';
|
||||
buffer[length + offset] = '\0';
|
||||
}
|
||||
else if (length == 1)
|
||||
{
|
||||
// 1e30
|
||||
buffer[1] = 'e';
|
||||
WriteExponent(kk - 1, &buffer[2]);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 1234e30 -> 1.234e33
|
||||
memmove(&buffer[2], &buffer[1], length - 1);
|
||||
buffer[1] = '.';
|
||||
buffer[length + 1] = 'e';
|
||||
WriteExponent(kk - 1, &buffer[0 + length + 2]);
|
||||
}
|
||||
}
|
||||
|
||||
inline void dtoa_milo(double value, char *buffer)
|
||||
{
|
||||
// Not handling NaN and inf
|
||||
assert(!isnan(value));
|
||||
assert(!isinf(value));
|
||||
|
||||
if (value == 0)
|
||||
{
|
||||
buffer[0] = '0';
|
||||
buffer[1] = '.';
|
||||
buffer[2] = '0';
|
||||
buffer[3] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
if (value < 0)
|
||||
{
|
||||
*buffer++ = '-';
|
||||
value = -value;
|
||||
}
|
||||
int length, K;
|
||||
Grisu2(value, buffer, &length, &K);
|
||||
Prettify(buffer, length, K);
|
||||
}
|
||||
}
|
||||
} // namespace ieee754
|
||||
} // namespace util
|
||||
} // namespace osrm
|
||||
|
||||
#endif // IEEE754_HPP
|
||||
@@ -5,6 +5,7 @@
|
||||
#define JSON_RENDERER_HPP
|
||||
|
||||
#include "util/cast.hpp"
|
||||
#include "util/ieee754.hpp"
|
||||
#include "util/string_util.hpp"
|
||||
|
||||
#include "osrm/json_container.hpp"
|
||||
@@ -21,6 +22,11 @@ namespace util
|
||||
namespace json
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
constexpr int MAX_FLOAT_STRING_LENGTH = 256;
|
||||
}
|
||||
|
||||
struct Renderer
|
||||
{
|
||||
explicit Renderer(std::ostream &_out) : out(_out) {}
|
||||
@@ -34,8 +40,31 @@ struct Renderer
|
||||
|
||||
void operator()(const Number &number) const
|
||||
{
|
||||
out.precision(10);
|
||||
out << number.value;
|
||||
char buffer[MAX_FLOAT_STRING_LENGTH] = {'\0'};
|
||||
ieee754::dtoa_milo(number.value, buffer);
|
||||
|
||||
// Trucate to 10 decimal places
|
||||
int pos = 0;
|
||||
int decimalpos = 0;
|
||||
while (decimalpos == 0 && pos < MAX_FLOAT_STRING_LENGTH && buffer[pos] != 0)
|
||||
{
|
||||
if (buffer[pos] == '.')
|
||||
{
|
||||
decimalpos = pos;
|
||||
break;
|
||||
}
|
||||
++pos;
|
||||
}
|
||||
while (pos < MAX_FLOAT_STRING_LENGTH && buffer[pos] != 0)
|
||||
{
|
||||
if (pos - decimalpos == 10)
|
||||
{
|
||||
buffer[pos] = '\0';
|
||||
break;
|
||||
}
|
||||
++pos;
|
||||
}
|
||||
out << buffer;
|
||||
}
|
||||
|
||||
void operator()(const Object &object) const
|
||||
|
||||
+17
-16
@@ -15,14 +15,14 @@ namespace util
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <typename T, typename RegionT>
|
||||
util::vector_view<T> mmapFile(const boost::filesystem::path &file, RegionT ®ion)
|
||||
template <typename T, typename MmapContainerT>
|
||||
util::vector_view<T> mmapFile(const boost::filesystem::path &file, MmapContainerT &mmap_container)
|
||||
{
|
||||
try
|
||||
{
|
||||
region.open(file);
|
||||
std::size_t num_objects = region.size() / sizeof(T);
|
||||
auto data_ptr = region.data();
|
||||
mmap_container.open(file);
|
||||
std::size_t num_objects = mmap_container.size() / sizeof(T);
|
||||
auto data_ptr = mmap_container.data();
|
||||
BOOST_ASSERT(reinterpret_cast<uintptr_t>(data_ptr) % alignof(T) == 0);
|
||||
return util::vector_view<T>(reinterpret_cast<T *>(data_ptr), num_objects);
|
||||
}
|
||||
@@ -34,9 +34,10 @@ util::vector_view<T> mmapFile(const boost::filesystem::path &file, RegionT ®i
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, typename RegionT>
|
||||
util::vector_view<T>
|
||||
mmapFile(const boost::filesystem::path &file, RegionT ®ion, const std::size_t size)
|
||||
template <typename T, typename MmapContainerT>
|
||||
util::vector_view<T> mmapFile(const boost::filesystem::path &file,
|
||||
MmapContainerT &mmap_container,
|
||||
const std::size_t size)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -45,10 +46,10 @@ mmapFile(const boost::filesystem::path &file, RegionT ®ion, const std::size_t
|
||||
params.path = file.string();
|
||||
params.flags = boost::iostreams::mapped_file::readwrite;
|
||||
params.new_file_size = size;
|
||||
region.open(params);
|
||||
mmap_container.open(params);
|
||||
|
||||
std::size_t num_objects = size / sizeof(T);
|
||||
auto data_ptr = region.data();
|
||||
auto data_ptr = mmap_container.data();
|
||||
BOOST_ASSERT(reinterpret_cast<uintptr_t>(data_ptr) % alignof(T) == 0);
|
||||
return util::vector_view<T>(reinterpret_cast<T *>(data_ptr), num_objects);
|
||||
}
|
||||
@@ -63,24 +64,24 @@ mmapFile(const boost::filesystem::path &file, RegionT ®ion, const std::size_t
|
||||
|
||||
template <typename T>
|
||||
util::vector_view<const T> mmapFile(const boost::filesystem::path &file,
|
||||
boost::iostreams::mapped_file_source ®ion)
|
||||
boost::iostreams::mapped_file_source &mmap_container)
|
||||
{
|
||||
return detail::mmapFile<const T>(file, region);
|
||||
return detail::mmapFile<const T>(file, mmap_container);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
util::vector_view<T> mmapFile(const boost::filesystem::path &file,
|
||||
boost::iostreams::mapped_file ®ion)
|
||||
boost::iostreams::mapped_file &mmap_container)
|
||||
{
|
||||
return detail::mmapFile<T>(file, region);
|
||||
return detail::mmapFile<T>(file, mmap_container);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
util::vector_view<T> mmapFile(const boost::filesystem::path &file,
|
||||
boost::iostreams::mapped_file ®ion,
|
||||
boost::iostreams::mapped_file &mmap_container,
|
||||
std::size_t size)
|
||||
{
|
||||
return detail::mmapFile<T>(file, region, size);
|
||||
return detail::mmapFile<T>(file, mmap_container, size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <tbb/parallel_sort.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
@@ -20,24 +21,27 @@ namespace util
|
||||
struct NodeBasedEdgeData
|
||||
{
|
||||
NodeBasedEdgeData()
|
||||
: weight(INVALID_EDGE_WEIGHT), duration(INVALID_EDGE_WEIGHT), geometry_id({0, false}),
|
||||
reversed(false), annotation_data(-1)
|
||||
: weight(INVALID_EDGE_WEIGHT), duration(INVALID_EDGE_WEIGHT),
|
||||
distance(INVALID_EDGE_DISTANCE), geometry_id({0, false}), reversed(false),
|
||||
annotation_data(-1)
|
||||
{
|
||||
}
|
||||
|
||||
NodeBasedEdgeData(EdgeWeight weight,
|
||||
EdgeWeight duration,
|
||||
EdgeDistance distance,
|
||||
GeometryID geometry_id,
|
||||
bool reversed,
|
||||
extractor::NodeBasedEdgeClassification flags,
|
||||
AnnotationID annotation_data)
|
||||
: weight(weight), duration(duration), geometry_id(geometry_id), reversed(reversed),
|
||||
flags(flags), annotation_data(annotation_data)
|
||||
: weight(weight), duration(duration), distance(distance), geometry_id(geometry_id),
|
||||
reversed(reversed), flags(flags), annotation_data(annotation_data)
|
||||
{
|
||||
}
|
||||
|
||||
EdgeWeight weight;
|
||||
EdgeWeight duration;
|
||||
EdgeDistance distance;
|
||||
GeometryID geometry_id;
|
||||
bool reversed : 1;
|
||||
extractor::NodeBasedEdgeClassification flags;
|
||||
@@ -80,18 +84,24 @@ NodeBasedDynamicGraphFromEdges(NodeID number_of_nodes,
|
||||
const extractor::NodeBasedEdge &input_edge) {
|
||||
output_edge.data.weight = input_edge.weight;
|
||||
output_edge.data.duration = input_edge.duration;
|
||||
output_edge.data.distance = input_edge.distance;
|
||||
output_edge.data.flags = input_edge.flags;
|
||||
output_edge.data.annotation_data = input_edge.annotation_data;
|
||||
|
||||
BOOST_ASSERT(output_edge.data.weight > 0);
|
||||
BOOST_ASSERT(output_edge.data.duration > 0);
|
||||
BOOST_ASSERT(output_edge.data.weight >= 0);
|
||||
BOOST_ASSERT(output_edge.data.duration >= 0);
|
||||
if (output_edge.data.distance <= 0)
|
||||
{
|
||||
std::cout << "output_edge.data.distance " << output_edge.data.distance << std::endl;
|
||||
}
|
||||
BOOST_ASSERT(output_edge.data.distance >= 0);
|
||||
});
|
||||
|
||||
tbb::parallel_sort(edges_list.begin(), edges_list.end());
|
||||
|
||||
return NodeBasedDynamicGraph(number_of_nodes, edges_list);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace util
|
||||
} // namespace osrm
|
||||
|
||||
#endif // NODE_BASED_GRAPH_HPP
|
||||
|
||||
@@ -226,12 +226,14 @@ class QueryHeap
|
||||
Data &GetData(NodeID node)
|
||||
{
|
||||
const auto index = node_index.peek_index(node);
|
||||
BOOST_ASSERT((int)index >= 0 && (int)index < (int)inserted_nodes.size());
|
||||
return inserted_nodes[index].data;
|
||||
}
|
||||
|
||||
Data const &GetData(NodeID node) const
|
||||
{
|
||||
const auto index = node_index.peek_index(node);
|
||||
BOOST_ASSERT((int)index >= 0 && (int)index < (int)inserted_nodes.size());
|
||||
return inserted_nodes[index].data;
|
||||
}
|
||||
|
||||
|
||||
@@ -312,7 +312,7 @@ class StaticGraph
|
||||
});
|
||||
}
|
||||
|
||||
// private:
|
||||
protected:
|
||||
NodeIterator number_of_nodes;
|
||||
EdgeIterator number_of_edges;
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ struct osm_way_id
|
||||
struct duplicated_node
|
||||
{
|
||||
};
|
||||
}
|
||||
} // namespace tag
|
||||
using OSMNodeID = osrm::Alias<std::uint64_t, tag::osm_node_id>;
|
||||
static_assert(std::is_pod<OSMNodeID>(), "OSMNodeID is not a valid alias");
|
||||
using OSMWayID = osrm::Alias<std::uint64_t, tag::osm_way_id>;
|
||||
@@ -75,6 +75,7 @@ using NameID = std::uint32_t;
|
||||
using AnnotationID = std::uint32_t;
|
||||
using EdgeWeight = std::int32_t;
|
||||
using EdgeDuration = std::int32_t;
|
||||
using EdgeDistance = float;
|
||||
using SegmentWeight = std::uint32_t;
|
||||
using SegmentDuration = std::uint32_t;
|
||||
using TurnPenalty = std::int16_t; // turn penalty in 100ms units
|
||||
@@ -112,7 +113,9 @@ static const SegmentWeight MAX_SEGMENT_WEIGHT = INVALID_SEGMENT_WEIGHT - 1;
|
||||
static const SegmentDuration MAX_SEGMENT_DURATION = INVALID_SEGMENT_DURATION - 1;
|
||||
static const EdgeWeight INVALID_EDGE_WEIGHT = std::numeric_limits<EdgeWeight>::max();
|
||||
static const EdgeDuration MAXIMAL_EDGE_DURATION = std::numeric_limits<EdgeDuration>::max();
|
||||
static const EdgeDistance MAXIMAL_EDGE_DISTANCE = std::numeric_limits<EdgeDistance>::max();
|
||||
static const TurnPenalty INVALID_TURN_PENALTY = std::numeric_limits<TurnPenalty>::max();
|
||||
static const EdgeDistance INVALID_EDGE_DISTANCE = std::numeric_limits<EdgeDistance>::max();
|
||||
|
||||
// FIXME the bitfields we use require a reduced maximal duration, this should be kept consistent
|
||||
// within the code base. For now we have to ensure that we don't case 30 bit to -1 and break any
|
||||
|
||||
@@ -9,31 +9,6 @@ namespace util
|
||||
{
|
||||
namespace vector_tile
|
||||
{
|
||||
|
||||
const constexpr std::uint32_t ID_TAG = 1;
|
||||
const constexpr std::uint32_t NAME_TAG = 1;
|
||||
const constexpr std::uint32_t FEATURE_TAG = 2;
|
||||
const constexpr std::uint32_t LAYER_TAG = 3;
|
||||
const constexpr std::uint32_t GEOMETRY_TAG = 3;
|
||||
const constexpr std::uint32_t KEY_TAG = 3;
|
||||
const constexpr std::uint32_t VARIANT_TAG = 4;
|
||||
const constexpr std::uint32_t EXTENT_TAG = 5;
|
||||
const constexpr std::uint32_t VERSION_TAG = 15;
|
||||
|
||||
const constexpr std::uint32_t FEATURE_ATTRIBUTES_TAG = 2;
|
||||
const constexpr std::uint32_t FEATURE_GEOMETRIES_TAG = 4;
|
||||
|
||||
const constexpr std::uint32_t GEOMETRY_TYPE_POINT = 1;
|
||||
const constexpr std::uint32_t GEOMETRY_TYPE_LINE = 2;
|
||||
|
||||
const constexpr std::uint32_t VARIANT_TYPE_STRING = 1;
|
||||
const constexpr std::uint32_t VARIANT_TYPE_FLOAT = 2;
|
||||
const constexpr std::uint32_t VARIANT_TYPE_DOUBLE = 3;
|
||||
|
||||
const constexpr std::uint32_t VARIANT_TYPE_UINT64 = 5;
|
||||
const constexpr std::uint32_t VARIANT_TYPE_SINT64 = 6;
|
||||
const constexpr std::uint32_t VARIANT_TYPE_BOOL = 7;
|
||||
|
||||
// Vector tiles are 4096 virtual pixels on each side
|
||||
const constexpr double EXTENT = 4096.0;
|
||||
const constexpr double BUFFER = 128.0;
|
||||
|
||||
@@ -195,6 +195,8 @@ template <> class vector_view<bool>
|
||||
{
|
||||
BOOST_ASSERT_MSG(index < m_size, "invalid size");
|
||||
const std::size_t bucket = index / WORD_BITS;
|
||||
// Note: ordering of bits here should match packBits in storage/serialization.hpp
|
||||
// so that directly mmap-ing data is possible
|
||||
const auto offset = index % WORD_BITS;
|
||||
return m_ptr[bucket] & (static_cast<Word>(1) << offset);
|
||||
}
|
||||
@@ -224,11 +226,22 @@ template <> class vector_view<bool>
|
||||
{
|
||||
BOOST_ASSERT(index < m_size);
|
||||
const auto bucket = index / WORD_BITS;
|
||||
// Note: ordering of bits here should match packBits in storage/serialization.hpp
|
||||
// so that directly mmap-ing data is possible
|
||||
const auto offset = index % WORD_BITS;
|
||||
return reference{m_ptr + bucket, static_cast<Word>(1) << offset};
|
||||
}
|
||||
|
||||
template <typename T> friend void swap(vector_view<T> &, vector_view<T> &) noexcept;
|
||||
|
||||
friend std::ostream &operator<<(std::ostream &os, const vector_view<bool> &rhs)
|
||||
{
|
||||
for (std::size_t i = 0; i < rhs.size(); ++i)
|
||||
{
|
||||
os << (i > 0 ? " " : "") << rhs.at(i);
|
||||
}
|
||||
return os;
|
||||
}
|
||||
};
|
||||
|
||||
// Both vector_view<T> and the vector_view<bool> specializations share this impl.
|
||||
|
||||
+8
-2
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "osrm",
|
||||
"version": "5.17.0-latest.1",
|
||||
"version": "5.20.0-alpha.3",
|
||||
"private": false,
|
||||
"description": "The Open Source Routing Machine is a high performance routing engine written in C++14 designed to run on OpenStreetMap data.",
|
||||
"dependencies": {
|
||||
@@ -18,7 +18,7 @@
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "node ./node_modules/eslint/bin/eslint.js -c ./.eslintrc features/step_definitions/ features/support/",
|
||||
"test": "npm run lint && node ./node_modules/cucumber/bin/cucumber.js features/ -p verify && node ./node_modules/cucumber/bin/cucumber.js features/ -p mld",
|
||||
"test": "npm run lint && node ./node_modules/cucumber/bin/cucumber.js features/ -p verify && node ./node_modules/cucumber/bin/cucumber.js features/ -p verify -m mmap && node ./node_modules/cucumber/bin/cucumber.js features/ -p mld && node ./node_modules/cucumber/bin/cucumber.js features/ -p mld -m mmap",
|
||||
"clean": "rm -rf test/cache",
|
||||
"docs": "./scripts/build_api_docs.sh",
|
||||
"install": "node-pre-gyp install --fallback-to-build=false || ./scripts/node_install.sh",
|
||||
@@ -38,19 +38,25 @@
|
||||
"node": ">=4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ansi-escape-sequences": "^4.0.0",
|
||||
"aws-sdk": "~2.0.31",
|
||||
"babel-plugin-transform-class-properties": "^6.24.1",
|
||||
"chalk": "^1.1.3",
|
||||
"command-line-args": "^5.0.2",
|
||||
"command-line-usage": "^5.0.4",
|
||||
"csv-stringify": "^3.0.0",
|
||||
"cucumber": "^1.2.1",
|
||||
"d3-queue": "^2.0.3",
|
||||
"docbox": "^1.0.6",
|
||||
"documentation": "^4.0.0-rc.1",
|
||||
"eslint": "^2.4.0",
|
||||
"faucet": "^0.0.1",
|
||||
"jsonpath": "^1.0.0",
|
||||
"node-timeout": "0.0.4",
|
||||
"polyline": "^0.2.0",
|
||||
"request": "^2.69.0",
|
||||
"tape": "^4.7.0",
|
||||
"turf": "^3.0.14",
|
||||
"xmlbuilder": "^4.2.1"
|
||||
},
|
||||
"bundleDependencies": [
|
||||
|
||||
+242
-161
@@ -38,20 +38,10 @@ function setup()
|
||||
mode.pushing_bike
|
||||
},
|
||||
|
||||
barrier_whitelist = Set {
|
||||
'sump_buster',
|
||||
'bus_trap',
|
||||
'cycle_barrier',
|
||||
'bollard',
|
||||
'entrance',
|
||||
'cattle_grid',
|
||||
'border_control',
|
||||
'toll_booth',
|
||||
'sally_port',
|
||||
'gate',
|
||||
'lift_gate',
|
||||
'no',
|
||||
'block'
|
||||
barrier_blacklist = Set {
|
||||
'yes',
|
||||
'wall',
|
||||
'fence'
|
||||
},
|
||||
|
||||
access_tag_whitelist = Set {
|
||||
@@ -109,11 +99,11 @@ function setup()
|
||||
-- reduce the driving speed by 30% for unsafe roads
|
||||
-- only used for cyclability metric
|
||||
unsafe_highway_list = {
|
||||
primary = 0.7,
|
||||
secondary = 0.75,
|
||||
primary = 0.5,
|
||||
secondary = 0.65,
|
||||
tertiary = 0.8,
|
||||
primary_link = 0.7,
|
||||
secondary_link = 0.75,
|
||||
primary_link = 0.5,
|
||||
secondary_link = 0.65,
|
||||
tertiary_link = 0.8,
|
||||
},
|
||||
|
||||
@@ -193,6 +183,16 @@ function setup()
|
||||
sett = 10
|
||||
},
|
||||
|
||||
classes = Sequence {
|
||||
'ferry', 'tunnel'
|
||||
},
|
||||
|
||||
-- Which classes should be excludable
|
||||
-- This increases memory usage so its disabled by default.
|
||||
excludable = Sequence {
|
||||
-- Set {'ferry'}
|
||||
},
|
||||
|
||||
tracktype_speeds = {
|
||||
},
|
||||
|
||||
@@ -235,7 +235,7 @@ function process_node(profile, node, result)
|
||||
else
|
||||
local barrier = node:get_value_by_key("barrier")
|
||||
if barrier and "" ~= barrier then
|
||||
if not profile.barrier_whitelist[barrier] then
|
||||
if profile.barrier_blacklist[barrier] then
|
||||
result.barrier = true
|
||||
end
|
||||
end
|
||||
@@ -250,204 +250,237 @@ end
|
||||
|
||||
function handle_bicycle_tags(profile,way,result,data)
|
||||
-- initial routability check, filters out buildings, boundaries, etc
|
||||
local route = way:get_value_by_key("route")
|
||||
local man_made = way:get_value_by_key("man_made")
|
||||
local railway = way:get_value_by_key("railway")
|
||||
local amenity = way:get_value_by_key("amenity")
|
||||
local public_transport = way:get_value_by_key("public_transport")
|
||||
local bridge = way:get_value_by_key("bridge")
|
||||
data.route = way:get_value_by_key("route")
|
||||
data.man_made = way:get_value_by_key("man_made")
|
||||
data.railway = way:get_value_by_key("railway")
|
||||
data.amenity = way:get_value_by_key("amenity")
|
||||
data.public_transport = way:get_value_by_key("public_transport")
|
||||
data.bridge = way:get_value_by_key("bridge")
|
||||
|
||||
if (not data.highway or data.highway == '') and
|
||||
(not route or route == '') and
|
||||
(not profile.use_public_transport or not railway or railway=='') and
|
||||
(not amenity or amenity=='') and
|
||||
(not man_made or man_made=='') and
|
||||
(not public_transport or public_transport=='') and
|
||||
(not bridge or bridge=='')
|
||||
(not data.route or data.route == '') and
|
||||
(not profile.use_public_transport or not data.railway or data.railway=='') and
|
||||
(not data.amenity or data.amenity=='') and
|
||||
(not data.man_made or data.man_made=='') and
|
||||
(not data.public_transport or data.public_transport=='') and
|
||||
(not data.bridge or data.bridge=='')
|
||||
then
|
||||
return false
|
||||
end
|
||||
|
||||
-- access
|
||||
local access = find_access_tag(way, profile.access_tags_hierarchy)
|
||||
if access and profile.access_tag_blacklist[access] then
|
||||
data.access = find_access_tag(way, profile.access_tags_hierarchy)
|
||||
if data.access and profile.access_tag_blacklist[data.access] then
|
||||
return false
|
||||
end
|
||||
|
||||
-- other tags
|
||||
local junction = way:get_value_by_key("junction")
|
||||
local maxspeed = parse_maxspeed(way:get_value_by_key ( "maxspeed") )
|
||||
local maxspeed_forward = parse_maxspeed(way:get_value_by_key( "maxspeed:forward"))
|
||||
local maxspeed_backward = parse_maxspeed(way:get_value_by_key( "maxspeed:backward"))
|
||||
local barrier = way:get_value_by_key("barrier")
|
||||
local oneway = way:get_value_by_key("oneway")
|
||||
local oneway_bicycle = way:get_value_by_key("oneway:bicycle")
|
||||
local cycleway = way:get_value_by_key("cycleway")
|
||||
local cycleway_left = way:get_value_by_key("cycleway:left")
|
||||
local cycleway_right = way:get_value_by_key("cycleway:right")
|
||||
local duration = way:get_value_by_key("duration")
|
||||
local service = way:get_value_by_key("service")
|
||||
local foot = way:get_value_by_key("foot")
|
||||
local foot_forward = way:get_value_by_key("foot:forward")
|
||||
local foot_backward = way:get_value_by_key("foot:backward")
|
||||
local bicycle = way:get_value_by_key("bicycle")
|
||||
data.junction = way:get_value_by_key("junction")
|
||||
data.maxspeed = parse_maxspeed(way:get_value_by_key ( "maxspeed") )
|
||||
data.maxspeed_forward = parse_maxspeed(way:get_value_by_key( "maxspeed:forward"))
|
||||
data.maxspeed_backward = parse_maxspeed(way:get_value_by_key( "maxspeed:backward"))
|
||||
data.barrier = way:get_value_by_key("barrier")
|
||||
data.oneway = way:get_value_by_key("oneway")
|
||||
data.oneway_bicycle = way:get_value_by_key("oneway:bicycle")
|
||||
data.cycleway = way:get_value_by_key("cycleway")
|
||||
data.cycleway_left = way:get_value_by_key("cycleway:left")
|
||||
data.cycleway_right = way:get_value_by_key("cycleway:right")
|
||||
data.duration = way:get_value_by_key("duration")
|
||||
data.service = way:get_value_by_key("service")
|
||||
data.foot = way:get_value_by_key("foot")
|
||||
data.foot_forward = way:get_value_by_key("foot:forward")
|
||||
data.foot_backward = way:get_value_by_key("foot:backward")
|
||||
data.bicycle = way:get_value_by_key("bicycle")
|
||||
|
||||
speed_handler(profile,way,result,data)
|
||||
|
||||
oneway_handler(profile,way,result,data)
|
||||
|
||||
cycleway_handler(profile,way,result,data)
|
||||
|
||||
bike_push_handler(profile,way,result,data)
|
||||
|
||||
|
||||
local way_type_allows_pushing = false
|
||||
-- maxspeed
|
||||
limit( result, data.maxspeed, data.maxspeed_forward, data.maxspeed_backward )
|
||||
|
||||
-- not routable if no speed assigned
|
||||
-- this avoid assertions in debug builds
|
||||
if result.forward_speed <= 0 and result.duration <= 0 then
|
||||
result.forward_mode = mode.inaccessible
|
||||
end
|
||||
if result.backward_speed <= 0 and result.duration <= 0 then
|
||||
result.backward_mode = mode.inaccessible
|
||||
end
|
||||
|
||||
safety_handler(profile,way,result,data)
|
||||
end
|
||||
|
||||
|
||||
|
||||
function speed_handler(profile,way,result,data)
|
||||
|
||||
data.way_type_allows_pushing = false
|
||||
|
||||
-- speed
|
||||
local bridge_speed = profile.bridge_speeds[bridge]
|
||||
local bridge_speed = profile.bridge_speeds[data.bridge]
|
||||
if (bridge_speed and bridge_speed > 0) then
|
||||
data.highway = bridge
|
||||
if duration and durationIsValid(duration) then
|
||||
result.duration = math.max( parseDuration(duration), 1 )
|
||||
data.highway = data.bridge
|
||||
if data.duration and durationIsValid(data.duration) then
|
||||
result.duration = math.max( parseDuration(data.duration), 1 )
|
||||
end
|
||||
result.forward_speed = bridge_speed
|
||||
result.backward_speed = bridge_speed
|
||||
way_type_allows_pushing = true
|
||||
elseif profile.route_speeds[route] then
|
||||
data.way_type_allows_pushing = true
|
||||
elseif profile.route_speeds[data.route] then
|
||||
-- ferries (doesn't cover routes tagged using relations)
|
||||
result.forward_mode = mode.ferry
|
||||
result.backward_mode = mode.ferry
|
||||
if duration and durationIsValid(duration) then
|
||||
result.duration = math.max( 1, parseDuration(duration) )
|
||||
if data.duration and durationIsValid(data.duration) then
|
||||
result.duration = math.max( 1, parseDuration(data.duration) )
|
||||
else
|
||||
result.forward_speed = profile.route_speeds[route]
|
||||
result.backward_speed = profile.route_speeds[route]
|
||||
result.forward_speed = profile.route_speeds[data.route]
|
||||
result.backward_speed = profile.route_speeds[data.route]
|
||||
end
|
||||
-- railway platforms (old tagging scheme)
|
||||
elseif railway and profile.platform_speeds[railway] then
|
||||
result.forward_speed = profile.platform_speeds[railway]
|
||||
result.backward_speed = profile.platform_speeds[railway]
|
||||
way_type_allows_pushing = true
|
||||
elseif data.railway and profile.platform_speeds[data.railway] then
|
||||
result.forward_speed = profile.platform_speeds[data.railway]
|
||||
result.backward_speed = profile.platform_speeds[data.railway]
|
||||
data.way_type_allows_pushing = true
|
||||
-- public_transport platforms (new tagging platform)
|
||||
elseif public_transport and profile.platform_speeds[public_transport] then
|
||||
result.forward_speed = profile.platform_speeds[public_transport]
|
||||
result.backward_speed = profile.platform_speeds[public_transport]
|
||||
way_type_allows_pushing = true
|
||||
elseif data.public_transport and profile.platform_speeds[data.public_transport] then
|
||||
result.forward_speed = profile.platform_speeds[data.public_transport]
|
||||
result.backward_speed = profile.platform_speeds[data.public_transport]
|
||||
data.way_type_allows_pushing = true
|
||||
-- railways
|
||||
elseif profile.use_public_transport and railway and profile.railway_speeds[railway] and profile.access_tag_whitelist[access] then
|
||||
elseif profile.use_public_transport and data.railway and profile.railway_speeds[data.railway] and profile.access_tag_whitelist[data.access] then
|
||||
result.forward_mode = mode.train
|
||||
result.backward_mode = mode.train
|
||||
result.forward_speed = profile.railway_speeds[railway]
|
||||
result.backward_speed = profile.railway_speeds[railway]
|
||||
elseif amenity and profile.amenity_speeds[amenity] then
|
||||
result.forward_speed = profile.railway_speeds[data.railway]
|
||||
result.backward_speed = profile.railway_speeds[data.railway]
|
||||
elseif data.amenity and profile.amenity_speeds[data.amenity] then
|
||||
-- parking areas
|
||||
result.forward_speed = profile.amenity_speeds[amenity]
|
||||
result.backward_speed = profile.amenity_speeds[amenity]
|
||||
way_type_allows_pushing = true
|
||||
result.forward_speed = profile.amenity_speeds[data.amenity]
|
||||
result.backward_speed = profile.amenity_speeds[data.amenity]
|
||||
data.way_type_allows_pushing = true
|
||||
elseif profile.bicycle_speeds[data.highway] then
|
||||
-- regular ways
|
||||
result.forward_speed = profile.bicycle_speeds[data.highway]
|
||||
result.backward_speed = profile.bicycle_speeds[data.highway]
|
||||
way_type_allows_pushing = true
|
||||
elseif access and profile.access_tag_whitelist[access] then
|
||||
data.way_type_allows_pushing = true
|
||||
elseif data.access and profile.access_tag_whitelist[data.access] then
|
||||
-- unknown way, but valid access tag
|
||||
result.forward_speed = profile.default_speed
|
||||
result.backward_speed = profile.default_speed
|
||||
way_type_allows_pushing = true
|
||||
data.way_type_allows_pushing = true
|
||||
end
|
||||
end
|
||||
|
||||
function oneway_handler(profile,way,result,data)
|
||||
-- oneway
|
||||
local implied_oneway = junction == "roundabout" or junction == "circular" or data.highway == "motorway"
|
||||
local reverse = false
|
||||
data.implied_oneway = data.junction == "roundabout" or data.junction == "circular" or data.highway == "motorway"
|
||||
data.reverse = false
|
||||
|
||||
if oneway_bicycle == "yes" or oneway_bicycle == "1" or oneway_bicycle == "true" then
|
||||
if data.oneway_bicycle == "yes" or data.oneway_bicycle == "1" or data.oneway_bicycle == "true" then
|
||||
result.backward_mode = mode.inaccessible
|
||||
elseif oneway_bicycle == "no" or oneway_bicycle == "0" or oneway_bicycle == "false" then
|
||||
elseif data.oneway_bicycle == "no" or data.oneway_bicycle == "0" or data.oneway_bicycle == "false" then
|
||||
-- prevent other cases
|
||||
elseif oneway_bicycle == "-1" then
|
||||
elseif data.oneway_bicycle == "-1" then
|
||||
result.forward_mode = mode.inaccessible
|
||||
reverse = true
|
||||
elseif oneway == "yes" or oneway == "1" or oneway == "true" then
|
||||
data.reverse = true
|
||||
elseif data.oneway == "yes" or data.oneway == "1" or data.oneway == "true" then
|
||||
result.backward_mode = mode.inaccessible
|
||||
elseif oneway == "no" or oneway == "0" or oneway == "false" then
|
||||
elseif data.oneway == "no" or data.oneway == "0" or data.oneway == "false" then
|
||||
-- prevent other cases
|
||||
elseif oneway == "-1" then
|
||||
elseif data.oneway == "-1" then
|
||||
result.forward_mode = mode.inaccessible
|
||||
reverse = true
|
||||
elseif implied_oneway then
|
||||
data.reverse = true
|
||||
elseif data.implied_oneway then
|
||||
result.backward_mode = mode.inaccessible
|
||||
end
|
||||
end
|
||||
|
||||
function cycleway_handler(profile,way,result,data)
|
||||
-- cycleway
|
||||
local has_cycleway_forward = false
|
||||
local has_cycleway_backward = false
|
||||
local is_oneway = result.forward_mode ~= mode.inaccessible and result.backward_mode ~= mode.inaccessible and not implied_oneway
|
||||
data.has_cycleway_forward = false
|
||||
data.has_cycleway_backward = false
|
||||
data.is_twoway = result.forward_mode ~= mode.inaccessible and result.backward_mode ~= mode.inaccessible and not data.implied_oneway
|
||||
|
||||
-- cycleways on normal roads
|
||||
if is_oneway then
|
||||
if cycleway and profile.cycleway_tags[cycleway] then
|
||||
has_cycleway_backward = true
|
||||
has_cycleway_forward = true
|
||||
if data.is_twoway then
|
||||
if data.cycleway and profile.cycleway_tags[data.cycleway] then
|
||||
data.has_cycleway_backward = true
|
||||
data.has_cycleway_forward = true
|
||||
end
|
||||
if (cycleway_right and profile.cycleway_tags[cycleway_right]) or (cycleway_left and profile.opposite_cycleway_tags[cycleway_left]) then
|
||||
has_cycleway_forward = true
|
||||
if (data.cycleway_right and profile.cycleway_tags[data.cycleway_right]) or (data.cycleway_left and profile.opposite_cycleway_tags[data.cycleway_left]) then
|
||||
data.has_cycleway_forward = true
|
||||
end
|
||||
if (cycleway_left and profile.cycleway_tags[cycleway_left]) or (cycleway_right and profile.opposite_cycleway_tags[cycleway_right]) then
|
||||
has_cycleway_backward = true
|
||||
if (data.cycleway_left and profile.cycleway_tags[data.cycleway_left]) or (data.cycleway_right and profile.opposite_cycleway_tags[data.cycleway_right]) then
|
||||
data.has_cycleway_backward = true
|
||||
end
|
||||
else
|
||||
local has_twoway_cycleway = (cycleway and profile.opposite_cycleway_tags[cycleway]) or (cycleway_right and profile.opposite_cycleway_tags[cycleway_right]) or (cycleway_left and profile.opposite_cycleway_tags[cycleway_left])
|
||||
local has_opposite_cycleway = (cycleway_left and profile.opposite_cycleway_tags[cycleway_left]) or (cycleway_right and profile.opposite_cycleway_tags[cycleway_right])
|
||||
local has_oneway_cycleway = (cycleway and profile.cycleway_tags[cycleway]) or (cycleway_right and profile.cycleway_tags[cycleway_right]) or (cycleway_left and profile.cycleway_tags[cycleway_left])
|
||||
local has_twoway_cycleway = (data.cycleway and profile.opposite_cycleway_tags[data.cycleway]) or (data.cycleway_right and profile.opposite_cycleway_tags[data.cycleway_right]) or (data.cycleway_left and profile.opposite_cycleway_tags[data.cycleway_left])
|
||||
local has_opposite_cycleway = (data.cycleway_left and profile.opposite_cycleway_tags[data.cycleway_left]) or (data.cycleway_right and profile.opposite_cycleway_tags[data.cycleway_right])
|
||||
local has_oneway_cycleway = (data.cycleway and profile.cycleway_tags[data.cycleway]) or (data.cycleway_right and profile.cycleway_tags[data.cycleway_right]) or (data.cycleway_left and profile.cycleway_tags[data.cycleway_left])
|
||||
|
||||
-- set cycleway even though it is an one-way if opposite is tagged
|
||||
if has_twoway_cycleway then
|
||||
has_cycleway_backward = true
|
||||
has_cycleway_forward = true
|
||||
data.has_cycleway_backward = true
|
||||
data.has_cycleway_forward = true
|
||||
elseif has_opposite_cycleway then
|
||||
if not reverse then
|
||||
has_cycleway_backward = true
|
||||
if not data.reverse then
|
||||
data.has_cycleway_backward = true
|
||||
else
|
||||
has_cycleway_forward = true
|
||||
data.has_cycleway_forward = true
|
||||
end
|
||||
elseif has_oneway_cycleway then
|
||||
if not reverse then
|
||||
has_cycleway_forward = true
|
||||
if not data.reverse then
|
||||
data.has_cycleway_forward = true
|
||||
else
|
||||
has_cycleway_backward = true
|
||||
data.has_cycleway_backward = true
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
if has_cycleway_backward then
|
||||
if data.has_cycleway_backward then
|
||||
result.backward_mode = mode.cycling
|
||||
result.backward_speed = profile.bicycle_speeds["cycleway"]
|
||||
end
|
||||
|
||||
if has_cycleway_forward then
|
||||
if data.has_cycleway_forward then
|
||||
result.forward_mode = mode.cycling
|
||||
result.forward_speed = profile.bicycle_speeds["cycleway"]
|
||||
end
|
||||
end
|
||||
|
||||
function bike_push_handler(profile,way,result,data)
|
||||
-- pushing bikes - if no other mode found
|
||||
if result.forward_mode == mode.inaccessible or result.backward_mode == mode.inaccessible or
|
||||
result.forward_speed == -1 or result.backward_speed == -1 then
|
||||
if foot ~= 'no' then
|
||||
if data.foot ~= 'no' then
|
||||
local push_forward_speed = nil
|
||||
local push_backward_speed = nil
|
||||
|
||||
if profile.pedestrian_speeds[data.highway] then
|
||||
push_forward_speed = profile.pedestrian_speeds[data.highway]
|
||||
push_backward_speed = profile.pedestrian_speeds[data.highway]
|
||||
elseif man_made and profile.man_made_speeds[man_made] then
|
||||
push_forward_speed = profile.man_made_speeds[man_made]
|
||||
push_backward_speed = profile.man_made_speeds[man_made]
|
||||
elseif data.man_made and profile.man_made_speeds[data.man_made] then
|
||||
push_forward_speed = profile.man_made_speeds[data.man_made]
|
||||
push_backward_speed = profile.man_made_speeds[data.man_made]
|
||||
else
|
||||
if foot == 'yes' then
|
||||
if data.foot == 'yes' then
|
||||
push_forward_speed = profile.walking_speed
|
||||
if not implied_oneway then
|
||||
if not data.implied_oneway then
|
||||
push_backward_speed = profile.walking_speed
|
||||
end
|
||||
elseif foot_forward == 'yes' then
|
||||
elseif data.foot_forward == 'yes' then
|
||||
push_forward_speed = profile.walking_speed
|
||||
elseif foot_backward == 'yes' then
|
||||
elseif data.foot_backward == 'yes' then
|
||||
push_backward_speed = profile.walking_speed
|
||||
elseif way_type_allows_pushing then
|
||||
elseif data.way_type_allows_pushing then
|
||||
push_forward_speed = profile.walking_speed
|
||||
if not implied_oneway then
|
||||
if not data.implied_oneway then
|
||||
push_backward_speed = profile.walking_speed
|
||||
end
|
||||
end
|
||||
@@ -466,65 +499,77 @@ function handle_bicycle_tags(profile,way,result,data)
|
||||
|
||||
end
|
||||
|
||||
|
||||
-- dismount
|
||||
if bicycle == "dismount" then
|
||||
if data.bicycle == "dismount" then
|
||||
result.forward_mode = mode.pushing_bike
|
||||
result.backward_mode = mode.pushing_bike
|
||||
result.forward_speed = profile.walking_speed
|
||||
result.backward_speed = profile.walking_speed
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- maxspeed
|
||||
limit( result, maxspeed, maxspeed_forward, maxspeed_backward )
|
||||
|
||||
|
||||
-- not routable if no speed assigned
|
||||
-- this avoid assertions in debug builds
|
||||
if result.forward_speed <= 0 and result.duration <= 0 then
|
||||
result.forward_mode = mode.inaccessible
|
||||
end
|
||||
if result.backward_speed <= 0 and result.duration <= 0 then
|
||||
result.backward_mode = mode.inaccessible
|
||||
end
|
||||
|
||||
|
||||
function safety_handler(profile,way,result,data)
|
||||
-- convert duration into cyclability
|
||||
if profile.properties.weight_name == 'cyclability' then
|
||||
local safety_penalty = profile.unsafe_highway_list[data.highway] or 1.
|
||||
local is_unsafe = safety_penalty < 1
|
||||
local forward_is_unsafe = is_unsafe and not has_cycleway_forward
|
||||
local backward_is_unsafe = is_unsafe and not has_cycleway_backward
|
||||
local is_undesireable = data.highway == "service" and profile.service_penalties[service]
|
||||
local forward_penalty = 1.
|
||||
local backward_penalty = 1.
|
||||
if forward_is_unsafe then
|
||||
forward_penalty = math.min(forward_penalty, safety_penalty)
|
||||
end
|
||||
if backward_is_unsafe then
|
||||
backward_penalty = math.min(backward_penalty, safety_penalty)
|
||||
end
|
||||
local safety_penalty = profile.unsafe_highway_list[data.highway] or 1.
|
||||
local is_unsafe = safety_penalty < 1
|
||||
|
||||
if is_undesireable then
|
||||
forward_penalty = math.min(forward_penalty, profile.service_penalties[service])
|
||||
backward_penalty = math.min(backward_penalty, profile.service_penalties[service])
|
||||
end
|
||||
-- primaries that are one ways are probably huge primaries where the lanes need to be separated
|
||||
if is_unsafe and data.highway == 'primary' and not data.is_twoway then
|
||||
safety_penalty = safety_penalty * 0.5
|
||||
end
|
||||
if is_unsafe and data.highway == 'secondary' and not data.is_twoway then
|
||||
safety_penalty = safety_penalty * 0.6
|
||||
end
|
||||
|
||||
local forward_is_unsafe = is_unsafe and not data.has_cycleway_forward
|
||||
local backward_is_unsafe = is_unsafe and not data.has_cycleway_backward
|
||||
local is_undesireable = data.highway == "service" and profile.service_penalties[data.service]
|
||||
local forward_penalty = 1.
|
||||
local backward_penalty = 1.
|
||||
if forward_is_unsafe then
|
||||
forward_penalty = math.min(forward_penalty, safety_penalty)
|
||||
end
|
||||
if backward_is_unsafe then
|
||||
backward_penalty = math.min(backward_penalty, safety_penalty)
|
||||
end
|
||||
|
||||
if is_undesireable then
|
||||
forward_penalty = math.min(forward_penalty, profile.service_penalties[data.service])
|
||||
backward_penalty = math.min(backward_penalty, profile.service_penalties[data.service])
|
||||
end
|
||||
|
||||
if result.forward_speed > 0 then
|
||||
-- convert from km/h to m/s
|
||||
result.forward_rate = result.forward_speed / 3.6 * forward_penalty
|
||||
end
|
||||
if result.backward_speed > 0 then
|
||||
-- convert from km/h to m/s
|
||||
result.backward_rate = result.backward_speed / 3.6 * backward_penalty
|
||||
end
|
||||
if result.duration > 0 then
|
||||
result.weight = result.duration / forward_penalty
|
||||
end
|
||||
|
||||
if data.highway == "bicycle" then
|
||||
safety_bonus = safety_bonus + 0.2
|
||||
if result.forward_speed > 0 then
|
||||
-- convert from km/h to m/s
|
||||
result.forward_rate = result.forward_speed / 3.6 * forward_penalty
|
||||
result.forward_rate = result.forward_speed / 3.6 * safety_bonus
|
||||
end
|
||||
if result.backward_speed > 0 then
|
||||
-- convert from km/h to m/s
|
||||
result.backward_rate = result.backward_speed / 3.6 * backward_penalty
|
||||
result.backward_rate = result.backward_speed / 3.6 * safety_bonus
|
||||
end
|
||||
if result.duration > 0 then
|
||||
result.weight = result.duration / forward_penalty
|
||||
result.weight = result.duration / safety_bonus
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
function process_way(profile, way, result)
|
||||
-- the initial filtering of ways based on presence of tags
|
||||
-- affects processing times significantly, because all ways
|
||||
@@ -542,6 +587,39 @@ function process_way(profile, way, result)
|
||||
local data = {
|
||||
-- prefetch tags
|
||||
highway = way:get_value_by_key('highway'),
|
||||
|
||||
route = nil,
|
||||
man_made = nil,
|
||||
railway = nil,
|
||||
amenity = nil,
|
||||
public_transport = nil,
|
||||
bridge = nil,
|
||||
|
||||
access = nil,
|
||||
|
||||
junction = nil,
|
||||
maxspeed = nil,
|
||||
maxspeed_forward = nil,
|
||||
maxspeed_backward = nil,
|
||||
barrier = nil,
|
||||
oneway = nil,
|
||||
oneway_bicycle = nil,
|
||||
cycleway = nil,
|
||||
cycleway_left = nil,
|
||||
cycleway_right = nil,
|
||||
duration = nil,
|
||||
service = nil,
|
||||
foot = nil,
|
||||
foot_forward = nil,
|
||||
foot_backward = nil,
|
||||
bicycle = nil,
|
||||
|
||||
way_type_allows_pushing = false,
|
||||
has_cycleway_forward = false,
|
||||
has_cycleway_backward = false,
|
||||
is_twoway = true,
|
||||
reverse = false,
|
||||
implied_oneway = false
|
||||
}
|
||||
|
||||
local handlers = Sequence {
|
||||
@@ -572,6 +650,9 @@ function process_way(profile, way, result)
|
||||
-- set name, ref and pronunciation
|
||||
WayHandlers.names,
|
||||
|
||||
-- set classes
|
||||
WayHandlers.classes,
|
||||
|
||||
-- set weight properties of the way
|
||||
WayHandlers.weights
|
||||
}
|
||||
|
||||
+7
-3
@@ -42,6 +42,10 @@ function setup()
|
||||
vehicle_height = 2.5, -- in meters, 2.5m is the height of van
|
||||
vehicle_width = 1.9, -- in meters, ways with narrow tag are considered narrower than 2.2m
|
||||
|
||||
-- Size of the vehicle, to be limited mostly by legal restriction of the way
|
||||
vehicle_length = 4.8, -- in meters, 4.8m is the length of large or familly car
|
||||
vehicle_weight = 3500, -- in kilograms
|
||||
|
||||
-- a list of suffixes to suppress in name change instructions. The suffixes also include common substrings of each other
|
||||
suffix_list = {
|
||||
'N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW', 'North', 'South', 'West', 'East', 'Nor', 'Sou', 'We', 'Ea'
|
||||
@@ -116,9 +120,6 @@ function setup()
|
||||
|
||||
-- classes to support for exclude flags
|
||||
excludable = Sequence {
|
||||
Set {'toll'},
|
||||
Set {'motorway'},
|
||||
Set {'ferry'}
|
||||
},
|
||||
|
||||
avoid = Set {
|
||||
@@ -276,6 +277,7 @@ function setup()
|
||||
["de:rural"] = 100,
|
||||
["de:motorway"] = 0,
|
||||
["dk:rural"] = 80,
|
||||
["fr:rural"] = 80,
|
||||
["gb:nsl_single"] = (60*1609)/1000,
|
||||
["gb:nsl_dual"] = (70*1609)/1000,
|
||||
["gb:motorway"] = (70*1609)/1000,
|
||||
@@ -387,6 +389,8 @@ function process_way(profile, way, result, relations)
|
||||
WayHandlers.avoid_ways,
|
||||
WayHandlers.handle_height,
|
||||
WayHandlers.handle_width,
|
||||
WayHandlers.handle_length,
|
||||
WayHandlers.handle_weight,
|
||||
|
||||
-- determine access status by checking our hierarchy of
|
||||
-- access tags, e.g: motorcar, motor_vehicle, vehicle
|
||||
|
||||
+5
-14
@@ -24,19 +24,10 @@ function setup()
|
||||
default_speed = walking_speed,
|
||||
oneway_handling = 'specific', -- respect 'oneway:foot' but not 'oneway'
|
||||
|
||||
barrier_whitelist = Set {
|
||||
'cycle_barrier',
|
||||
'bollard',
|
||||
'entrance',
|
||||
'cattle_grid',
|
||||
'border_control',
|
||||
'toll_booth',
|
||||
'sally_port',
|
||||
'gate',
|
||||
'lift_gate',
|
||||
'no',
|
||||
'kerb',
|
||||
'block'
|
||||
barrier_blacklist = Set {
|
||||
'yes',
|
||||
'wall',
|
||||
'fence'
|
||||
},
|
||||
|
||||
access_tag_whitelist = Set {
|
||||
@@ -157,7 +148,7 @@ function process_node(profile, node, result)
|
||||
local bollard = node:get_value_by_key("bollard")
|
||||
local rising_bollard = bollard and "rising" == bollard
|
||||
|
||||
if not profile.barrier_whitelist[barrier] and not rising_bollard then
|
||||
if profile.barrier_blacklist[barrier] and not rising_bollard then
|
||||
result.barrier = true
|
||||
end
|
||||
end
|
||||
|
||||
+20
-26
@@ -5,6 +5,7 @@ Measure = {}
|
||||
-- measurements conversion constants
|
||||
local inch_to_meters = 0.0254
|
||||
local feet_to_inches = 12
|
||||
local pound_to_kilograms = 0.45359237
|
||||
|
||||
--- Parse string as a height in meters.
|
||||
--- according to http://wiki.openstreetmap.org/wiki/Key:maxheight
|
||||
@@ -25,33 +26,19 @@ function Measure.parse_value_meters(value)
|
||||
end
|
||||
end
|
||||
|
||||
--- according to http://wiki.openstreetmap.org/wiki/Map_Features/Units#Explicit_specifications
|
||||
local tonns_parse_patterns = Sequence {
|
||||
"%d+",
|
||||
"%d+.%d+",
|
||||
"%d+.%d+ ?t"
|
||||
}
|
||||
|
||||
local kg_parse_patterns = Sequence {
|
||||
"%d+ ?kg"
|
||||
}
|
||||
|
||||
--- Parse weight value in kilograms
|
||||
--- Parse weight value in kilograms.
|
||||
--- according to https://wiki.openstreetmap.org/wiki/Key:maxweight
|
||||
function Measure.parse_value_kilograms(value)
|
||||
-- try to parse kilograms
|
||||
for i, templ in ipairs(kg_parse_patterns) do
|
||||
m = string.match(value, templ)
|
||||
if m then
|
||||
return tonumber(m)
|
||||
end
|
||||
end
|
||||
|
||||
-- try to parse tonns
|
||||
for i, templ in ipairs(tonns_parse_patterns) do
|
||||
m = string.match(value, templ)
|
||||
if m then
|
||||
return tonumber(m) * 1000
|
||||
local n = tonumber(value:gsub(",", "."):match("%d+%.?%d*"))
|
||||
if n then
|
||||
if string.match(value, "lbs") then
|
||||
n = n * pound_to_kilograms
|
||||
elseif string.match(value, "kg") then
|
||||
-- n = n
|
||||
else -- Default, metric tons
|
||||
n = n * 1000
|
||||
end
|
||||
return n
|
||||
end
|
||||
end
|
||||
|
||||
@@ -83,7 +70,14 @@ function Measure.get_max_width(raw_value)
|
||||
end
|
||||
end
|
||||
|
||||
--- Get maxweight of specified way in kilogramms
|
||||
--- Get maxlength of specified way in meters.
|
||||
function Measure.get_max_length(raw_value)
|
||||
if raw_value then
|
||||
return Measure.parse_value_meters(raw_value)
|
||||
end
|
||||
end
|
||||
|
||||
--- Get maxweight of specified way in kilogramms.
|
||||
function Measure.get_max_weight(raw_value)
|
||||
if raw_value then
|
||||
return Measure.parse_value_kilograms(raw_value)
|
||||
|
||||
@@ -306,37 +306,46 @@ end
|
||||
|
||||
-- add class information
|
||||
function WayHandlers.classes(profile,way,result,data)
|
||||
if not profile.classes then
|
||||
return
|
||||
end
|
||||
|
||||
local allowed_classes = Set {}
|
||||
for k, v in pairs(profile.classes) do
|
||||
allowed_classes[v] = true
|
||||
end
|
||||
|
||||
local forward_toll, backward_toll = Tags.get_forward_backward_by_key(way, data, "toll")
|
||||
local forward_route, backward_route = Tags.get_forward_backward_by_key(way, data, "route")
|
||||
local tunnel = way:get_value_by_key("tunnel")
|
||||
|
||||
if tunnel and tunnel ~= "no" then
|
||||
if allowed_classes["tunnel"] and tunnel and tunnel ~= "no" then
|
||||
result.forward_classes["tunnel"] = true
|
||||
result.backward_classes["tunnel"] = true
|
||||
end
|
||||
|
||||
if forward_toll == "yes" then
|
||||
if allowed_classes["toll"] and forward_toll == "yes" then
|
||||
result.forward_classes["toll"] = true
|
||||
end
|
||||
if backward_toll == "yes" then
|
||||
if allowed_classes["toll"] and backward_toll == "yes" then
|
||||
result.backward_classes["toll"] = true
|
||||
end
|
||||
|
||||
if forward_route == "ferry" then
|
||||
if allowed_classes["ferry"] and forward_route == "ferry" then
|
||||
result.forward_classes["ferry"] = true
|
||||
end
|
||||
if backward_route == "ferry" then
|
||||
if allowed_classes["ferry"] and backward_route == "ferry" then
|
||||
result.backward_classes["ferry"] = true
|
||||
end
|
||||
|
||||
if result.forward_restricted then
|
||||
if allowed_classes["restricted"] and result.forward_restricted then
|
||||
result.forward_classes["restricted"] = true
|
||||
end
|
||||
if result.backward_restricted then
|
||||
if allowed_classes["restricted"] and result.backward_restricted then
|
||||
result.backward_classes["restricted"] = true
|
||||
end
|
||||
|
||||
if data.highway == "motorway" or data.highway == "motorway_link" then
|
||||
if allowed_classes["motorway"] and (data.highway == "motorway" or data.highway == "motorway_link") then
|
||||
result.forward_classes["motorway"] = true
|
||||
result.backward_classes["motorway"] = true
|
||||
end
|
||||
@@ -502,6 +511,38 @@ function WayHandlers.handle_width(profile,way,result,data)
|
||||
end
|
||||
end
|
||||
|
||||
-- handle maxweight tags
|
||||
function WayHandlers.handle_weight(profile,way,result,data)
|
||||
local keys = Sequence { 'maxweight' }
|
||||
local forward, backward = Tags.get_forward_backward_by_set(way,data,keys)
|
||||
forward = Measure.get_max_weight(forward)
|
||||
backward = Measure.get_max_weight(backward)
|
||||
|
||||
if forward and forward < profile.vehicle_weight then
|
||||
result.forward_mode = mode.inaccessible
|
||||
end
|
||||
|
||||
if backward and backward < profile.vehicle_weight then
|
||||
result.backward_mode = mode.inaccessible
|
||||
end
|
||||
end
|
||||
|
||||
-- handle maxlength tags
|
||||
function WayHandlers.handle_length(profile,way,result,data)
|
||||
local keys = Sequence { 'maxlength' }
|
||||
local forward, backward = Tags.get_forward_backward_by_set(way,data,keys)
|
||||
forward = Measure.get_max_length(forward)
|
||||
backward = Measure.get_max_length(backward)
|
||||
|
||||
if forward and forward < profile.vehicle_length then
|
||||
result.forward_mode = mode.inaccessible
|
||||
end
|
||||
|
||||
if backward and backward < profile.vehicle_length then
|
||||
result.backward_mode = mode.inaccessible
|
||||
end
|
||||
end
|
||||
|
||||
-- handle oneways tags
|
||||
function WayHandlers.oneway(profile,way,result,data)
|
||||
if not profile.oneway_handling then
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
-- Secondary road: 18km/h = 18000m/3600s = 100m/20s
|
||||
-- Tertiary road: 12km/h = 12000m/3600s = 100m/30s
|
||||
|
||||
api_version = 3
|
||||
api_version = 4
|
||||
|
||||
function setup()
|
||||
return {
|
||||
@@ -14,7 +14,7 @@ function setup()
|
||||
max_speed_for_map_matching = 30/3.6, --km -> m/s
|
||||
weight_name = 'duration',
|
||||
process_call_tagless_node = false,
|
||||
uturn_penalty = 20,
|
||||
u_turn_penalty = 20,
|
||||
traffic_light_penalty = 7, -- seconds
|
||||
use_turn_restrictions = true
|
||||
},
|
||||
@@ -32,7 +32,7 @@ function setup()
|
||||
primary = 36,
|
||||
secondary = 18,
|
||||
tertiary = 12,
|
||||
steps = 6,
|
||||
steps = 6
|
||||
}
|
||||
}
|
||||
end
|
||||
@@ -128,9 +128,9 @@ function process_way (profile, way, result)
|
||||
end
|
||||
|
||||
function process_turn (profile, turn)
|
||||
if turn.direction_modifier == direction_modifier.uturn then
|
||||
turn.duration = profile.properties.uturn_penalty
|
||||
turn.weight = profile.properties.uturn_penalty
|
||||
if turn.is_u_turn then
|
||||
turn.duration = turn.duration + profile.properties.u_turn_penalty
|
||||
turn.weight = turn.weight + profile.properties.u_turn_penalty
|
||||
end
|
||||
if turn.has_traffic_light then
|
||||
turn.duration = turn.duration + profile.properties.traffic_light_penalty
|
||||
|
||||
@@ -9,6 +9,8 @@ lonlat = lambda x: (coord2float(x['lon']['__value']), coord2float(x['lat']['__va
|
||||
|
||||
def call(this, method, *args):
|
||||
"""Call this.method(args)"""
|
||||
if (str(this) == '<optimized out>'):
|
||||
raise BaseException('"this" is optimized out')
|
||||
command = '(*({})({})).{}({})'.format(this.type.target().pointer(), this.address, method, ','.join((str(x) for x in args)))
|
||||
return gdb.parse_and_eval(command)
|
||||
|
||||
@@ -234,7 +236,6 @@ class SVGPrinter (gdb.Command):
|
||||
mld_facade = facade.cast(gdb.lookup_type('osrm::engine::datafacade::ContiguousInternalMemoryAlgorithmDataFacade<osrm::engine::routing_algorithms::mld::Algorithm>'))
|
||||
mld_partition = mld_facade['mld_partition']
|
||||
mld_levels = call(mld_partition, 'GetNumberOfLevels')
|
||||
print (mld_level, mld_levels)
|
||||
if mld_level < mld_levels:
|
||||
sentinel_node = call(mld_partition['partition'], 'size') - 1 # GetSentinelNode
|
||||
number_of_cells = call(mld_partition, 'GetCell', mld_level, sentinel_node) # GetNumberOfCells
|
||||
@@ -272,6 +273,7 @@ class SVGPrinter (gdb.Command):
|
||||
for node in nodes:
|
||||
geometry_id = call(facade, 'GetGeometryIndex', node)
|
||||
direction = 'forward' if geometry_id['forward'] else 'reverse'
|
||||
print (geometry_id, direction)
|
||||
geometry = SVGPrinter.getByGeometryId(facade, geometry_id, 'Geometry')
|
||||
weights = SVGPrinter.getByGeometryId(facade, geometry_id, 'Weights')
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/*********************************
|
||||
* Takes an XML `.osm` file and converts it into a cucumber scenario definition like
|
||||
* Given the node locations
|
||||
* | node | lon | lat |
|
||||
* .....
|
||||
* Given the ways
|
||||
* | nodes | tag1 | tag2 | tag3 |
|
||||
* .....
|
||||
*
|
||||
* Note that cucumber tests are limited to 26 nodes (labelled a-z), so
|
||||
* you'll need to use pretty small OSM extracts to get this to work.
|
||||
*****************************************/
|
||||
var fs = require('fs');
|
||||
var parseString = require('xml2js').parseString;
|
||||
|
||||
var data = fs.readFileSync('filename.osm', 'utf8');
|
||||
|
||||
const items = parseString(data, (err, result) => {
|
||||
var idmap = {};
|
||||
|
||||
console.log('Given the node locations');
|
||||
console.log(' | node | lon | lat |');
|
||||
result.osm.node.filter(n => !n.$.action || n.$.action !== 'delete').forEach(i => {
|
||||
var code = String.fromCharCode(97 + Object.keys(idmap).length)
|
||||
idmap[i.$.id] = code;
|
||||
console.log(` | ${code} | ${i.$.lon} | ${i.$.lat} |`);
|
||||
});
|
||||
|
||||
var allkeys = {};
|
||||
var waytags = {};
|
||||
|
||||
result.osm.way.filter(n => !n.$.action || n.$.action !== 'delete').forEach(w => {
|
||||
if (!waytags[w.$.id]) waytags[w.$.id] = {};
|
||||
w.tag.forEach(t => { allkeys[t.$.k] = t.$.v; waytags[w.$.id][t.$.k] = t.$.v; });
|
||||
});
|
||||
|
||||
console.log('And the ways');
|
||||
console.log(` | nodes | ${Object.keys(allkeys).join(' | ')} |`);
|
||||
|
||||
result.osm.way.filter(n => !n.$.action || n.$.action !== 'delete').forEach(w => {
|
||||
console.log(` | ${w.nd.map(n => idmap[n.$.ref]).join('')} | ${Object.keys(allkeys).map(k => waytags[w.$.id][k] || '').join(' | ')} |`);
|
||||
});
|
||||
});
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user