Compare commits

..

12 Commits

Author SHA1 Message Date
Patrick Niklaus 1869840f0e [publish binary] Test building node binaries with MLD 2017-03-22 00:51:07 +00:00
Patrick Niklaus 8532b5460b Disable doc builds because they are broken 2017-03-22 00:30:42 +00:00
Patrick Niklaus 1fdbaf4a39 Upgrade docbox 2017-03-22 00:04:46 +00:00
Patrick Niklaus 08527175b5 Fresh lock file 2017-03-21 23:44:08 +00:00
Patrick Niklaus d792572ece Install yarn on OSX by hand and update lock file 2017-03-21 23:26:32 +00:00
Patrick Niklaus 2a691ac5be Integrate documentation JS and make travis file slightly more readable 2017-03-21 22:50:08 +00:00
Patrick Niklaus 2221a34529 Switch to yarn 2017-03-21 22:37:16 +00:00
Patrick Niklaus a8fd4050a2 Integrate node-osrm docs 2017-03-21 22:29:00 +00:00
Patrick Niklaus 85ee03dfde Also copy osrm-partition and osrm-customize 2017-03-21 20:15:08 +00:00
Patrick Niklaus 694e3854d7 Test routing on CH, MLD, CoreCH via node bindings 2017-03-21 20:15:08 +00:00
Patrick Niklaus 90ed027711 Integrate MLD into node-bindings 2017-03-21 20:15:06 +00:00
Patrick Niklaus ac0c5c27e7 First steps towards integrating MLD in node bindings 2017-03-21 20:12:56 +00:00
164 changed files with 3957 additions and 4931 deletions
+1 -10
View File
@@ -16,8 +16,6 @@ notifications:
branches:
only:
- master
# enable building tags
- /^v\d+\.\d+(\.\d+)?(-\S*)?$/
cache:
yarn: true
@@ -28,8 +26,6 @@ cache:
env:
global:
- secure: "hk+32aXXF5t1ApaM2Wjqooz3dx1si907L87WRMkO47WlpJmUUU/Ye+MJk9sViH8MdhOcceocVAmdYl5/WFWOIbDWNlBya9QvXDZyIu2KIre/0QyOCTZbrsif8paBXKIO5O/R4OTvIZ8rvWZsadBdmAT9GSbDhih6FzqXAEgeIYQ="
- secure: "VE+cFkseFwW4jK6XwkP0yW3h4DixPJ8+Eb3yKcchGZ5iIJxlZ/8i1vKHYxadgPRwSYwPSB14tF70xj2OmiT2keGzZUfphmPXinBaLEhYk+Bde+GZZkoSl5ND109I/LcyNr0nG9dDgtV6pkvFchgchpyP9JnVOOS0+crEZlAz0RE="
- CCACHE_TEMPDIR=/tmp/.ccache-temp
- CCACHE_COMPRESS=1
- CASHER_TIME_OUT=599 # one second less than 10m to avoid 10m timeout error: https://github.com/Project-OSRM/osrm-backend/issues/2742
@@ -148,8 +144,6 @@ before_install:
sudo mdutil -i off /
npm install -g yarn
fi
- export PACKAGE_JSON_VERSION=$(node -e "console.log(require('./package.json').version)")
- export PUBLISH=$([[ "${TRAVIS_TAG:-}" == "v${PACKAGE_JSON_VERSION}" ]] && echo "On" || echo "Off")
- echo "Using ${JOBS} jobs"
- yarn install --ignore-scripts
# Bootstrap cmake to be able to run mason
@@ -223,10 +217,6 @@ script:
- ./unit_tests/util-tests
- ./unit_tests/server-tests
- ./unit_tests/partition-tests
- |
if [ -n "${ENABLE_NODE_BINDINGS}" ] && [ -z "${ENABLE_SANITIZER}" ]; then
npm run nodejs-tests
fi
- popd
- yarn test
@@ -238,5 +228,6 @@ after_success:
- |
if [ -n "${ENABLE_NODE_BINDINGS}" ]; then
source ./scripts/travis/build.sh
./scripts/travis/publish.sh
fi
-4
View File
@@ -1,5 +1,3 @@
- Track preprocessing flag in the map matching plugin.
# 5.7.0
- Changes from 5.6
- NodeJs Bindings
@@ -10,8 +8,6 @@
- .osrm.datasource_index file was removed. Data is now part of .osrm.geometries.
- .osrm.edge_lookup was removed. The option `--generate-edge-lookup` does nothing now.
- `osrm-contract` does not depend on the `.osrm.fileIndex` file anymore
- Profiles
- Added `force_split_edges` flag to global properties. True value guarantees that segment_function will be called for all segments, but also could double memory consumption
# 5.6.3
- Changes from 5.6.0
-2
View File
@@ -303,8 +303,6 @@ endif()
if (ENABLE_SANITIZER)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
set(OSRM_CXXFLAGS "${OSRM_CXXFLAGS} -fsanitize=address")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address")
endif()
# Configuring compilers
+6 -14
View File
@@ -41,27 +41,19 @@ The easiest and quickest way to setup your own routing engine backend is to use
### Using Docker
We base [our Docker images](https://hub.docker.com/r/osrm/osrm-backend/) on Alpine Linux and make sure they are as lightweight as possible.
We base the Docker images on Alpine Linux and make sure they are as lightweight as possible (around 10-15 MB).
In the following, replace `X.Y.Z` with the current stable release version.
```
wget http://download.geofabrik.de/europe/germany/berlin-latest.osm.pbf
docker run -t -v $(pwd):/data osrm/osrm-backend osrm-extract -p /opt/car.lua /data/berlin-latest.osm.pbf
docker run -t -v $(pwd):/data osrm/osrm-backend osrm-contract /data/berlin-latest.osrm
docker run -t -i -p 5000:5000 -v $(pwd):/data osrm/osrm-backend osrm-routed /data/berlin-latest.osrm
docker run -t -v $(pwd):/data osrm/osrm-backend:vX.Y.Z osrm-extract -p /opt/car.lua /data/berlin-latest.osm.pbf
docker run -t -v $(pwd):/data osrm/osrm-backend:vX.Y.Z osrm-contract /data/berlin-latest.osrm
docker run -t -i -p 5000:5000 -v $(pwd):/data osrm/osrm-backend:vX.Y.Z osrm-routed /data/berlin-latest.osrm
curl "http://127.0.0.1:5000/route/v1/driving/13.388860,52.517037;13.385983,52.496891?steps=true"
curl http://127.0.0.1:5000/route/v1/driving/13.388860,52.517037;13.385983,52.496891?steps=true
```
In case Docker complains about not being able to connect to the Docker daemon make sure you are in the `docker` group.
```
sudo usermod -aG docker $USER
```
After adding yourself to the `docker` group make sure to log out and back in again with your terminal.
### Building from Source
The following targets Ubuntu 16.04.
+3 -9
View File
@@ -141,21 +141,15 @@ SET test_osm=%test_region%.osm.pbf
IF NOT EXIST %test_osm% powershell Invoke-WebRequest https://s3.amazonaws.com/mapbox/osrm/testing/monaco.osm.pbf -OutFile %test_osm%
%Configuration%\osrm-extract.exe -p ../profiles/car.lua %test_osm%
MKDIR ch
XCOPY %test_region%.osrm.* ch\
XCOPY %test_region%.osrm ch\
XCOPY %test_region%.osrm %test_region%.osrm.* ch\
MKDIR corech
XCOPY %test_region%.osrm.* corech\
XCOPY %test_region%.osrm corech\
XCOPY %test_region%.osrm %test_region%.osrm.* corech\
MKDIR mld
XCOPY %test_region%.osrm.* mld\
XCOPY %test_region%.osrm mld\
XCOPY %test_region%.osrm %test_region%.osrm.* mld\
%Configuration%\osrm-contract.exe %test_region_ch%.osrm
%Configuration%\osrm-contract.exe --core 0.8 %test_region_corech%.osrm
%Configuration%\osrm-partition.exe %test_region_mld%.osrm
%Configuration%\osrm-customize.exe %test_region_mld%.osrm
XCOPY /Y ch\*.* ..\test\data\ch\
XCOPY /Y corech\*.* ..\test\data\corech\
XCOPY /Y mld\*.* ..\test\data\mld\
unit_tests\%Configuration%\library-tests.exe
IF NOT "%APPVEYOR_REPO_BRANCH%"=="master" GOTO DONE
-75
View File
@@ -1,75 +0,0 @@
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "user for publishing to s3://mapbox-node-binary/osrm",
"Resources": {
"User": {
"Type": "AWS::IAM::User",
"Properties": {
"Policies": [
{
"PolicyName": "list",
"PolicyDocument": {
"Statement": [
{
"Action": [
"s3:ListBucket"
],
"Effect": "Allow",
"Resource": "arn:aws:s3:::mapbox-node-binary",
"Condition": {
"StringLike": {
"s3:prefix": [
"osrm/*"
]
}
}
}
]
}
},
{
"PolicyName": "publish",
"PolicyDocument": {
"Statement": [
{
"Action": [
"s3:DeleteObject",
"s3:GetObject",
"s3:GetObjectAcl",
"s3:PutObject",
"s3:PutObjectAcl"
],
"Effect": "Allow",
"Resource": "arn:aws:s3:::mapbox-node-binary/osrm/*"
}
]
}
}
]
}
},
"AccessKey": {
"Type": "AWS::IAM::AccessKey",
"Properties": {
"UserName": {
"Ref": "User"
}
}
}
},
"Outputs": {
"AccessKeyId": {
"Value": {
"Ref": "AccessKey"
}
},
"SecretAccessKey": {
"Value": {
"Fn::GetAtt": [
"AccessKey",
"SecretAccessKey"
]
}
}
}
}
-59
View File
@@ -1,59 +0,0 @@
var cf = require('@mapbox/cloudfriend');
var package_json = require('../package.json')
module.exports = {
AWSTemplateFormatVersion: '2010-09-09',
Description: 'user for publishing to s3://mapbox-node-binary/' + package_json.name,
Resources: {
User: {
Type: 'AWS::IAM::User',
Properties: {
Policies: [
{
PolicyName: 'list',
PolicyDocument: {
Statement: [
{
Action: ['s3:ListBucket'],
Effect: 'Allow',
Resource: 'arn:aws:s3:::mapbox-node-binary',
Condition : {
StringLike : {
"s3:prefix": [ package_json.name + "/*"]
}
}
}
]
}
},
{
PolicyName: 'publish',
PolicyDocument: {
Statement: [
{
Action: ['s3:DeleteObject', 's3:GetObject', 's3:GetObjectAcl', 's3:PutObject', 's3:PutObjectAcl'],
Effect: 'Allow',
Resource: 'arn:aws:s3:::mapbox-node-binary/' + package_json.name + '/*'
}
]
}
}
]
}
},
AccessKey: {
Type: 'AWS::IAM::AccessKey',
Properties: {
UserName: cf.ref('User')
}
}
},
Outputs: {
AccessKeyId: {
Value: cf.ref('AccessKey')
},
SecretAccessKey: {
Value: cf.getAtt('AccessKey', 'SecretAccessKey')
}
}
};
-627
View File
@@ -1,627 +0,0 @@
# Vendored NodeJs.cmake to bootstrap our C++ build without
# having the user to install Node modules via `npm install`.
#
# Update via: ../node_modules/.bin/ncmake update
# Defaults for standard Node.js builds
set(NODEJS_DEFAULT_URL https://nodejs.org/download/release)
set(NODEJS_DEFAULT_VERSION installed)
set(NODEJS_VERSION_FALLBACK latest)
set(NODEJS_DEFAULT_NAME node)
set(NODEJS_DEFAULT_CHECKSUM SHASUMS256.txt)
set(NODEJS_DEFAULT_CHECKTYPE SHA256)
include(CMakeParseArguments)
# Find a path by walking upward from a base directory until the path is
# found. Sets the variable ${PATH} to False if the path can't
# be determined
function(find_path_parent NAME BASE PATH)
set(ROOT ${BASE})
set(${PATH} ${ROOT}/${NAME} PARENT_SCOPE)
set(DRIVE "^[A-Za-z]?:?/$")
while(NOT ROOT MATCHES ${DRIVE} AND NOT EXISTS ${ROOT}/${NAME})
get_filename_component(ROOT ${ROOT} DIRECTORY)
set(${PATH} ${ROOT}/${NAME} PARENT_SCOPE)
endwhile()
if(ROOT MATCHES ${DRIVE})
set(${PATH} False PARENT_SCOPE)
endif()
endfunction()
# Shortcut for finding standard node module locations
macro(find_nodejs_module NAME BASE PATH)
find_path_parent(node_modules/${NAME} ${BASE} ${PATH})
endmacro()
# Download with a bit of nice output (without spewing progress)
function(download_file URL)
message(STATUS "Downloading: ${URL}")
file(DOWNLOAD
${URL}
${ARGN}
)
endfunction()
# Embedded win_delay_load_hook file so that this file can be copied
# into projects directly (recommended practice)
function(nodejs_generate_delayload_hook OUTPUT)
file(WRITE ${OUTPUT} "")
file(APPEND ${OUTPUT} "/*\n")
file(APPEND ${OUTPUT} " * When this file is linked to a DLL, it sets up a delay-load hook that\n")
file(APPEND ${OUTPUT} " * intervenes when the DLL is trying to load 'node.exe' or 'iojs.exe'\n")
file(APPEND ${OUTPUT} " * dynamically. Instead of trying to locate the .exe file it'll just return\n")
file(APPEND ${OUTPUT} " * a handle to the process image.\n")
file(APPEND ${OUTPUT} " *\n")
file(APPEND ${OUTPUT} " * This allows compiled addons to work when node.exe or iojs.exe is renamed.\n")
file(APPEND ${OUTPUT} " */\n")
file(APPEND ${OUTPUT} "\n")
file(APPEND ${OUTPUT} "#ifdef _MSC_VER\n")
file(APPEND ${OUTPUT} "\n")
file(APPEND ${OUTPUT} "#ifndef DELAYIMP_INSECURE_WRITABLE_HOOKS\n")
file(APPEND ${OUTPUT} "#define DELAYIMP_INSECURE_WRITABLE_HOOKS\n")
file(APPEND ${OUTPUT} "#endif\n")
file(APPEND ${OUTPUT} "\n")
file(APPEND ${OUTPUT} "#ifndef WIN32_LEAN_AND_MEAN\n")
file(APPEND ${OUTPUT} "#define WIN32_LEAN_AND_MEAN\n")
file(APPEND ${OUTPUT} "#endif\n")
file(APPEND ${OUTPUT} "\n")
file(APPEND ${OUTPUT} "#include <windows.h>\n")
file(APPEND ${OUTPUT} "#include <Shlwapi.h>\n")
file(APPEND ${OUTPUT} "#include <delayimp.h>\n")
file(APPEND ${OUTPUT} "#include <string.h>\n")
file(APPEND ${OUTPUT} "\n")
file(APPEND ${OUTPUT} "static FARPROC WINAPI load_exe_hook(unsigned int event, DelayLoadInfo* info) {\n")
file(APPEND ${OUTPUT} " if (event != dliNotePreLoadLibrary) return NULL;\n")
file(APPEND ${OUTPUT} "\n")
file(APPEND ${OUTPUT} " if (_stricmp(info->szDll, \"iojs.exe\") != 0 &&\n")
file(APPEND ${OUTPUT} " _stricmp(info->szDll, \"node.exe\") != 0 &&\n")
file(APPEND ${OUTPUT} " _stricmp(info->szDll, \"node.dll\") != 0)\n")
file(APPEND ${OUTPUT} " return NULL;\n")
file(APPEND ${OUTPUT} "\n")
file(APPEND ${OUTPUT} " // Get a handle to the current process executable.\n")
file(APPEND ${OUTPUT} " HMODULE processModule = GetModuleHandle(NULL);\n")
file(APPEND ${OUTPUT} "\n")
file(APPEND ${OUTPUT} " // Get the path to the executable.\n")
file(APPEND ${OUTPUT} " TCHAR processPath[_MAX_PATH];\n")
file(APPEND ${OUTPUT} " GetModuleFileName(processModule, processPath, _MAX_PATH);\n")
file(APPEND ${OUTPUT} "\n")
file(APPEND ${OUTPUT} " // Get the name of the current executable.\n")
file(APPEND ${OUTPUT} " LPSTR processName = PathFindFileName(processPath);\n")
file(APPEND ${OUTPUT} "\n")
file(APPEND ${OUTPUT} " // If the current process is node or iojs, then just return the proccess \n")
file(APPEND ${OUTPUT} " // module.\n")
file(APPEND ${OUTPUT} " if (_stricmp(processName, \"node.exe\") == 0 ||\n")
file(APPEND ${OUTPUT} " _stricmp(processName, \"iojs.exe\") == 0) {\n")
file(APPEND ${OUTPUT} " return (FARPROC) processModule;\n")
file(APPEND ${OUTPUT} " }\n")
file(APPEND ${OUTPUT} "\n")
file(APPEND ${OUTPUT} " // If it is another process, attempt to load 'node.dll' from the same \n")
file(APPEND ${OUTPUT} " // directory.\n")
file(APPEND ${OUTPUT} " PathRemoveFileSpec(processPath);\n")
file(APPEND ${OUTPUT} " PathAppend(processPath, \"node.dll\");\n")
file(APPEND ${OUTPUT} "\n")
file(APPEND ${OUTPUT} " HMODULE nodeDllModule = GetModuleHandle(processPath);\n")
file(APPEND ${OUTPUT} " if(nodeDllModule != NULL) {\n")
file(APPEND ${OUTPUT} " // This application has a node.dll in the same directory as the executable,\n")
file(APPEND ${OUTPUT} " // use that.\n")
file(APPEND ${OUTPUT} " return (FARPROC) nodeDllModule;\n")
file(APPEND ${OUTPUT} " }\n")
file(APPEND ${OUTPUT} "\n")
file(APPEND ${OUTPUT} " // Fallback to the current executable, which must statically link to \n")
file(APPEND ${OUTPUT} " // node.lib\n")
file(APPEND ${OUTPUT} " return (FARPROC) processModule;\n")
file(APPEND ${OUTPUT} "}\n")
file(APPEND ${OUTPUT} "\n")
file(APPEND ${OUTPUT} "PfnDliHook __pfnDliNotifyHook2 = load_exe_hook;\n")
file(APPEND ${OUTPUT} "\n")
file(APPEND ${OUTPUT} "#endif\n")
endfunction()
# Sets up a project to build Node.js native modules
# - Downloads required dependencies and unpacks them to the build directory.
# Internet access is required the first invocation but not after (
# provided the download is successful)
# - Sets up several variables for building against the downloaded
# dependencies
# - Guarded to prevent multiple executions, so a single project hierarchy
# will only call this once
function(nodejs_init)
# Prevents this function from executing more than once
if(NODEJS_INIT)
return()
endif()
# Regex patterns used by the init function for component extraction
set(HEADERS_MATCH "^([A-Fa-f0-9]+)[ \t]+([^-]+)-(headers|v?[0-9.]+)-(headers|v?[0-9.]+)([.]tar[.]gz)$")
set(LIB32_MATCH "(^[0-9A-Fa-f]+)[\t ]+(win-x86)?(/)?([^/]*)(.lib)$")
set(LIB64_MATCH "(^[0-9A-Fa-f]+)[\t ]+(win-)?(x64/)(.*)(.lib)$")
# Parse function arguments
cmake_parse_arguments(nodejs_init
"" "URL;NAME;VERSION;CHECKSUM;CHECKTYPE" "" ${ARGN}
)
# Allow the download URL to be overridden by command line argument
# NODEJS_URL
if(NODEJS_URL)
set(URL ${NODEJS_URL})
else()
# Use the argument if specified, falling back to the default
set(URL ${NODEJS_DEFAULT_URL})
if(nodejs_init_URL)
set(URL ${nodejs_init_URL})
endif()
endif()
# Allow name to be overridden by command line argument NODEJS_NAME
if(NODEJS_NAME)
set(NAME ${NODEJS_NAME})
else()
# Use the argument if specified, falling back to the default
set(NAME ${NODEJS_DEFAULT_NAME})
if(nodejs_init_NAME)
set(NAME ${nodejs_init_NAME})
endif()
endif()
# Allow the checksum file to be overridden by command line argument
# NODEJS_CHECKSUM
if(NODEJS_CHECKSUM)
set(CHECKSUM ${NODEJS_CHECKSUM})
else()
# Use the argument if specified, falling back to the default
set(CHECKSUM ${NODEJS_DEFAULT_CHECKSUM})
if(nodejs_init_CHECKSUM)
set(CHECKSUM ${nodejs_init_CHECKSUM})
endif()
endif()
# Allow the checksum type to be overriden by the command line argument
# NODEJS_CHECKTYPE
if(NODEJS_CHECKTYPE)
set(CHECKTYPE ${NODEJS_CHECKTYPE})
else()
# Use the argument if specified, falling back to the default
set(CHECKTYPE ${NODEJS_DEFAULT_CHECKTYPE})
if(nodejs_init_CHECKTYPE)
set(CHECKTYPE ${nodejs_init_CHECKTYPE})
endif()
endif()
# Allow the version to be overridden by the command line argument
# NODEJS_VERSION
if(NODEJS_VERSION)
set(VERSION ${NODEJS_VERSION})
else()
# Use the argument if specified, falling back to the default
set(VERSION ${NODEJS_DEFAULT_VERSION})
if(nodejs_init_VERSION)
set(VERSION ${nodejs_init_VERSION})
endif()
endif()
# "installed" is a special version that tries to use the currently
# installed version (determined by running node)
set(NODEJS_INSTALLED False CACHE BOOL "Node.js install status" FORCE)
if(VERSION STREQUAL "installed")
if(NOT NAME STREQUAL ${NODEJS_DEFAULT_NAME})
message(FATAL_ERROR
"'Installed' version identifier can only be used with"
"the core Node.js library"
)
endif()
# Fall back to the "latest" version if node isn't installed
set(VERSION ${NODEJS_VERSION_FALLBACK})
find_program(NODEJS_BINARY NAMES node nodejs)
if(NODEJS_BINARY)
execute_process(
COMMAND ${NODEJS_BINARY} --version
RESULT_VARIABLE INSTALLED_VERSION_RESULT
OUTPUT_VARIABLE INSTALLED_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(INSTALLED_VERSION_RESULT STREQUAL "0")
set(NODEJS_INSTALLED True CACHE BOOL
"Node.js install status" FORCE
)
set(VERSION ${INSTALLED_VERSION})
endif()
endif()
endif()
# Create a temporary download directory
set(TEMP ${CMAKE_CURRENT_BINARY_DIR}/temp)
if(EXISTS ${TEMP})
file(REMOVE_RECURSE ${TEMP})
endif()
file(MAKE_DIRECTORY ${TEMP})
# Unless the target is special version "latest", the parameters
# necessary to construct the root path are known
if(NOT VERSION STREQUAL "latest")
set(ROOT ${CMAKE_CURRENT_BINARY_DIR}/${NAME}/${VERSION})
# Extract checksums from the existing checksum file
set(CHECKSUM_TARGET ${ROOT}/CHECKSUM)
endif()
# If we're trying to determine the version or we haven't saved the
# checksum file for this version, download it from the specified server
if(VERSION STREQUAL "latest" OR
(DEFINED ROOT AND NOT EXISTS ${ROOT}/CHECKSUM))
if(DEFINED ROOT)
# Clear away the old checksum in case the new one is different
# and/or it fails to download
file(REMOVE ${ROOT}/CHECKSUM)
endif()
file(REMOVE ${TEMP}/CHECKSUM)
download_file(
${URL}/${VERSION}/${CHECKSUM}
${TEMP}/CHECKSUM
INACTIVITY_TIMEOUT 10
STATUS CHECKSUM_STATUS
)
list(GET CHECKSUM_STATUS 0 CHECKSUM_STATUS)
if(CHECKSUM_STATUS GREATER 0)
file(REMOVE ${TEMP}/CHECKSUM)
message(FATAL_ERROR
"Unable to download checksum file"
)
endif()
# Extract checksums from the temporary file
set(CHECKSUM_TARGET ${TEMP}/CHECKSUM)
endif()
# Extract the version, name, header archive and archive checksum
# from the file. This first extract is what defines / specifies the
# actual version number and name.
file(STRINGS
${CHECKSUM_TARGET} HEADERS_CHECKSUM
REGEX ${HEADERS_MATCH}
LIMIT_COUNT 1
)
if(NOT HEADERS_CHECKSUM)
file(REMOVE ${TEMP}/CHECKSUM)
if(DEFINED ROOT)
file(REMOVE ${ROOT}/CHECKSUM)
endif()
message(FATAL_ERROR "Unable to extract header archive checksum")
endif()
string(REGEX MATCH ${HEADERS_MATCH} HEADERS_CHECKSUM ${HEADERS_CHECKSUM})
set(HEADERS_CHECKSUM ${CMAKE_MATCH_1})
set(NAME ${CMAKE_MATCH_2})
if(CMAKE_MATCH_3 STREQUAL "headers")
set(VERSION ${CMAKE_MATCH_4})
else()
set(VERSION ${CMAKE_MATCH_3})
endif()
set(HEADERS_ARCHIVE
${CMAKE_MATCH_2}-${CMAKE_MATCH_3}-${CMAKE_MATCH_4}${CMAKE_MATCH_5}
)
# Make sure that the root directory exists, and that the checksum
# file has been moved over from temp
if(DEFINED ROOT)
set(OLD_ROOT ${ROOT})
endif()
set(ROOT ${CMAKE_CURRENT_BINARY_DIR}/${NAME}/${VERSION})
if(DEFINED OLD_ROOT AND NOT ROOT STREQUAL "${OLD_ROOT}")
file(REMOVE ${TEMP}/CHECKSUM)
file(REMOVE ${ROOT}/CHECKSUM)
message(FATAL_ERROR "Version/Name mismatch")
endif()
file(MAKE_DIRECTORY ${ROOT})
if(EXISTS ${TEMP}/CHECKSUM)
file(REMOVE ${ROOT}/CHECKSUM)
file(RENAME ${TEMP}/CHECKSUM ${ROOT}/CHECKSUM)
endif()
# Now that its fully resolved, report the name and version of Node.js being
# used
message(STATUS "NodeJS: Using ${NAME}, version ${VERSION}")
# Download the headers for the version being used
# Theoretically, these could be found by searching the installed
# system, but in practice, this can be error prone. They're provided
# on the download servers, so just use the ones there.
if(NOT EXISTS ${ROOT}/include)
file(REMOVE ${TEMP}/${HEADERS_ARCHIVE})
download_file(
${URL}/${VERSION}/${HEADERS_ARCHIVE}
${TEMP}/${HEADERS_ARCHIVE}
INACTIVITY_TIMEOUT 10
EXPECTED_HASH ${CHECKTYPE}=${HEADERS_CHECKSUM}
STATUS HEADERS_STATUS
)
list(GET HEADERS_STATUS 0 HEADERS_STATUS)
if(HEADER_STATUS GREATER 0)
file(REMOVE ${TEMP}/${HEADERS_ARCHIVE})
message(FATAL_ERROR "Unable to download Node.js headers")
endif()
execute_process(
COMMAND ${CMAKE_COMMAND} -E tar xfz ${TEMP}/${HEADERS_ARCHIVE}
WORKING_DIRECTORY ${TEMP}
)
# This adapts the header extraction to support a number of different
# header archive contents in addition to the one used by the
# default Node.js library
unset(NODEJS_HEADERS_PATH CACHE)
find_path(NODEJS_HEADERS_PATH
NAMES src include
PATHS
${TEMP}/${NAME}-${VERSION}-headers
${TEMP}/${NAME}-${VERSION}
${TEMP}/${NODEJS_DEFAULT_NAME}-${VERSION}-headers
${TEMP}/${NODEJS_DEFAULT_NAME}-${VERSION}
${TEMP}/${NODEJS_DEFAULT_NAME}
${TEMP}
NO_DEFAULT_PATH
)
if(NOT NODEJS_HEADERS_PATH)
message(FATAL_ERROR "Unable to find extracted headers folder")
endif()
# Move the headers into a standard location with a standard layout
file(REMOVE ${TEMP}/${HEADERS_ARCHIVE})
file(REMOVE_RECURSE ${ROOT}/include)
if(EXISTS ${NODEJS_HEADERS_PATH}/include/node)
file(RENAME ${NODEJS_HEADERS_PATH}/include/node ${ROOT}/include)
elseif(EXISTS ${NODEJS_HEADERS_PATH}/src)
file(MAKE_DIRECTORY ${ROOT}/include)
if(NOT EXISTS ${NODEJS_HEADERS_PATH}/src)
file(REMOVE_RECURSE ${ROOT}/include)
message(FATAL_ERROR "Unable to find core headers")
endif()
file(COPY ${NODEJS_HEADERS_PATH}/src/
DESTINATION ${ROOT}/include
)
if(NOT EXISTS ${NODEJS_HEADERS_PATH}/deps/uv/include)
file(REMOVE_RECURSE ${ROOT}/include)
message(FATAL_ERROR "Unable to find libuv headers")
endif()
file(COPY ${NODEJS_HEADERS_PATH}/deps/uv/include/
DESTINATION ${ROOT}/include
)
if(NOT EXISTS ${NODEJS_HEADERS_PATH}/deps/v8/include)
file(REMOVE_RECURSE ${ROOT}/include)
message(FATAL_ERROR "Unable to find v8 headers")
endif()
file(COPY ${NODEJS_HEADERS_PATH}/deps/v8/include/
DESTINATION ${ROOT}/include
)
if(NOT EXISTS ${NODEJS_HEADERS_PATH}/deps/zlib)
file(REMOVE_RECURSE ${ROOT}/include)
message(FATAL_ERROR "Unable to find zlib headers")
endif()
file(COPY ${NODEJS_HEADERS_PATH}/deps/zlib/
DESTINATION ${ROOT}/include
)
endif()
file(REMOVE_RECURSE ${NODEJS_HEADERS_PATH})
unset(NODEJS_HEADERS_PATH CACHE)
endif()
# Only download the libraries on windows, since its the only place
# its necessary. Note, this requires rerunning CMake if moving
# a module from one platform to another (should happen automatically
# with most generators)
if(WIN32)
# Download the win32 library for linking
file(STRINGS
${ROOT}/CHECKSUM LIB32_CHECKSUM
LIMIT_COUNT 1
REGEX ${LIB32_MATCH}
)
if(NOT LIB32_CHECKSUM)
message(FATAL_ERROR "Unable to extract x86 library checksum")
endif()
string(REGEX MATCH ${LIB32_MATCH} LIB32_CHECKSUM ${LIB32_CHECKSUM})
set(LIB32_CHECKSUM ${CMAKE_MATCH_1})
set(LIB32_PATH win-x86)
set(LIB32_NAME ${CMAKE_MATCH_4}${CMAKE_MATCH_5})
set(LIB32_TARGET ${CMAKE_MATCH_2}${CMAKE_MATCH_3}${LIB32_NAME})
if(NOT EXISTS ${ROOT}/${LIB32_PATH})
file(REMOVE_RECURSE ${TEMP}/${LIB32_PATH})
download_file(
${URL}/${VERSION}/${LIB32_TARGET}
${TEMP}/${LIB32_PATH}/${LIB32_NAME}
INACTIVITY_TIMEOUT 10
EXPECTED_HASH ${CHECKTYPE}=${LIB32_CHECKSUM}
STATUS LIB32_STATUS
)
list(GET LIB32_STATUS 0 LIB32_STATUS)
if(LIB32_STATUS GREATER 0)
message(FATAL_ERROR
"Unable to download Node.js windows library (32-bit)"
)
endif()
file(REMOVE_RECURSE ${ROOT}/${LIB32_PATH})
file(MAKE_DIRECTORY ${ROOT}/${LIB32_PATH})
file(RENAME
${TEMP}/${LIB32_PATH}/${LIB32_NAME}
${ROOT}/${LIB32_PATH}/${LIB32_NAME}
)
file(REMOVE_RECURSE ${TEMP}/${LIB32_PATH})
endif()
# Download the win64 library for linking
file(STRINGS
${ROOT}/CHECKSUM LIB64_CHECKSUM
LIMIT_COUNT 1
REGEX ${LIB64_MATCH}
)
if(NOT LIB64_CHECKSUM)
message(FATAL_ERROR "Unable to extract x64 library checksum")
endif()
string(REGEX MATCH ${LIB64_MATCH} LIB64_CHECKSUM ${LIB64_CHECKSUM})
set(LIB64_CHECKSUM ${CMAKE_MATCH_1})
set(LIB64_PATH win-x64)
set(LIB64_NAME ${CMAKE_MATCH_4}${CMAKE_MATCH_5})
set(LIB64_TARGET ${CMAKE_MATCH_2}${CMAKE_MATCH_3}${LIB64_NAME})
if(NOT EXISTS ${ROOT}/${LIB64_PATH})
file(REMOVE_RECURSE ${TEMP}/${LIB64_PATH})
download_file(
${URL}/${VERSION}/${LIB64_TARGET}
${TEMP}/${LIB64_PATH}/${LIB64_NAME}
INACTIVITY_TIMEOUT 10
EXPECTED_HASH ${CHECKTYPE}=${LIB64_CHECKSUM}
STATUS LIB64_STATUS
)
list(GET LIB64_STATUS 0 LIB64_STATUS)
if(LIB64_STATUS GREATER 0)
message(FATAL_ERROR
"Unable to download Node.js windows library (64-bit)"
)
endif()
file(REMOVE_RECURSE ${ROOT}/${LIB64_PATH})
file(MAKE_DIRECTORY ${ROOT}/${LIB64_PATH})
file(RENAME
${TEMP}/${LIB64_PATH}/${LIB64_NAME}
${ROOT}/${LIB64_PATH}/${LIB64_NAME}
)
file(REMOVE_RECURSE ${TEMP}/${LIB64_PATH})
endif()
endif()
# The downloaded headers should always be set for inclusion
list(APPEND INCLUDE_DIRS ${ROOT}/include)
# Look for the NAN module, and add it to the includes
find_nodejs_module(
nan
${CMAKE_CURRENT_SOURCE_DIR}
NODEJS_NAN_DIR
)
if(NODEJS_NAN_DIR)
list(APPEND INCLUDE_DIRS ${NODEJS_NAN_DIR})
endif()
# Under windows, we need a bunch of libraries (due to the way
# dynamic linking works)
if(WIN32)
# Generate and use a delay load hook to allow the node binary
# name to be changed while still loading native modules
set(DELAY_LOAD_HOOK ${CMAKE_CURRENT_BINARY_DIR}/win_delay_load_hook.c)
nodejs_generate_delayload_hook(${DELAY_LOAD_HOOK})
set(SOURCES ${DELAY_LOAD_HOOK})
# Necessary flags to get delayload working correctly
list(APPEND LINK_FLAGS
"-IGNORE:4199"
"-DELAYLOAD:iojs.exe"
"-DELAYLOAD:node.exe"
"-DELAYLOAD:node.dll"
)
# Core system libraries used by node
list(APPEND LIBRARIES
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib
advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib
odbc32.lib Shlwapi.lib DelayImp.lib
)
# Also link to the node stub itself (downloaded above)
if(CMAKE_CL_64)
list(APPEND LIBRARIES ${ROOT}/${LIB64_PATH}/${LIB64_NAME})
else()
list(APPEND LIBRARIES ${ROOT}/${LIB32_PATH}/${LIB32_NAME})
endif()
else()
# Non-windows platforms should use these flags
list(APPEND DEFINITIONS _LARGEFILE_SOURCE _FILE_OFFSET_BITS=64)
endif()
# Special handling for OSX / clang to allow undefined symbols
# Define is required by node on OSX
if(APPLE)
list(APPEND LINK_FLAGS "-undefined dynamic_lookup")
list(APPEND DEFINITIONS _DARWIN_USE_64_BIT_INODE=1)
endif()
# Export all settings for use as arguments in the rest of the build
set(NODEJS_VERSION ${VERSION} PARENT_SCOPE)
set(NODEJS_SOURCES ${SOURCES} PARENT_SCOPE)
set(NODEJS_INCLUDE_DIRS ${INCLUDE_DIRS} PARENT_SCOPE)
set(NODEJS_LIBRARIES ${LIBRARIES} PARENT_SCOPE)
set(NODEJS_LINK_FLAGS ${LINK_FLAGS} PARENT_SCOPE)
set(NODEJS_DEFINITIONS ${DEFINITIONS} PARENT_SCOPE)
# Prevents this function from executing more than once
set(NODEJS_INIT TRUE PARENT_SCOPE)
endfunction()
# Helper function for defining a node module
# After nodejs_init, all of the settings and dependencies necessary to do
# this yourself are defined, but this helps make sure everything is configured
# correctly. Feel free to use it as a model to do this by hand (or to
# tweak this configuration if you need something custom).
function(add_nodejs_module NAME)
# Validate name parameter (must be a valid C identifier)
string(MAKE_C_IDENTIFIER ${NAME} ${NAME}_SYMBOL_CHECK)
if(NOT "${NAME}" STREQUAL "${${NAME}_SYMBOL_CHECK}")
message(FATAL_ERROR
"Module name must be a valid C identifier. "
"Suggested alternative: '${${NAME}_SYMBOL_CHECK}'"
)
endif()
# Make sure node is initialized (variables set) before defining the module
if(NOT NODEJS_INIT)
message(FATAL_ERROR
"Node.js has not been initialized. "
"Call nodejs_init before adding any modules"
)
endif()
# In order to match node-gyp, we need to build into type specific folders
# ncmake takes care of this, but be sure to set CMAKE_BUILD_TYPE yourself
# if invoking CMake directly
if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
message(FATAL_ERROR
"Configuration type must be specified. "
"Set CMAKE_BUILD_TYPE or use a different generator"
)
endif()
# A node module is a shared library
add_library(${NAME} SHARED ${NODEJS_SOURCES} ${ARGN})
# Add compiler defines for the module
# Two helpful ones:
# MODULE_NAME must match the name of the build library, define that here
# ${NAME}_BUILD is for symbol visibility under windows
string(TOUPPER "${NAME}_BUILD" ${NAME}_BUILD_DEF)
target_compile_definitions(${NAME}
PRIVATE MODULE_NAME=${NAME}
PRIVATE ${${NAME}_BUILD_DEF}
PUBLIC ${NODEJS_DEFINITIONS}
)
# This properly defines includes for the module
target_include_directories(${NAME} PUBLIC ${NODEJS_INCLUDE_DIRS})
# Add link flags to the module
target_link_libraries(${NAME} ${NODEJS_LIBRARIES})
# Set required properties for the module to build properly
# Correct naming, symbol visiblity and C++ standard
set_target_properties(${NAME} PROPERTIES
OUTPUT_NAME ${NAME}
PREFIX ""
SUFFIX ".node"
MACOSX_RPATH ON
C_VISIBILITY_PRESET hidden
CXX_VISIBILITY_PRESET hidden
POSITION_INDEPENDENT_CODE TRUE
CMAKE_CXX_STANDARD_REQUIRED TRUE
CXX_STANDARD 11
LINK_FLAGS "${NODEJS_LINK_FLAGS}"
)
# Make sure we're buiilding in a build specific output directory
# Only necessary on single-target generators (Make, Ninja)
# Multi-target generators do this automatically
# This (luckily) mirrors node-gyp conventions
if(NOT CMAKE_CONFIGURATION_TYPES)
set_property(TARGET ${NAME} PROPERTY
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BUILD_TYPE}
)
endif()
endfunction()
+587
View File
@@ -0,0 +1,587 @@
# Copyright (c) 2015, Colin Taylor
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
# FindNodeJS.cmake CMake module vendored from the node-cmake project (v1.2).
# This script uses CMake 3.1+ features
if(CMAKE_MINIMUM_REQUIRED_VERSION VERSION_LESS 3.1.0)
message(FATAL_ERROR "FindNodeJS.cmake uses CMake 3.1+ features")
endif()
# Force a build type to be set (ignored on config based generators)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Build type" FORCE)
endif()
# Capture module information
set(NodeJS_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})
get_filename_component(NodeJS_MODULE_NAME ${NodeJS_MODULE_PATH} NAME)
# Allow users to specify the installed location of the Node.js package
set(NodeJS_ROOT_DIR "" CACHE PATH
"The root directory of the node.js installed package")
# Allow users to specify that downloaded sources should be used
option(NodeJS_DOWNLOAD "Download the required source files" Off)
# Allow users to force downloading of node packages
option(NodeJS_FORCE_DOWNLOAD "Download the source files every time" Off)
# Allow users to force archive extraction
option(NodeJS_FORCE_EXTRACT "Extract the archive every time" Off)
# Make libc++ the default when compiling with clang
option(NodeJS_USE_CLANG_STDLIB "Use libc++ when compiling with clang" On)
if(APPLE)
set(NodeJS_USE_CLANG_STDLIB On CACHE BOOL "" FORCE)
endif()
if(WIN32)
# Allow users to specify that the executable should be downloaded
option(NodeJS_DOWNLOAD_EXECUTABLE
"Download matching executable if available" Off
)
endif()
# Try to find the node.js executable
# The node executable under linux may not be the correct program
find_program(NodeJS_EXECUTABLE
NAMES node
PATHS ${NodeJS_ROOT_DIR}
PATH_SUFFIXES nodejs node
)
set(NodeJS_VALIDATE_EXECUTABLE 1)
if(NodeJS_EXECUTABLE)
execute_process(
COMMAND ${NodeJS_EXECUTABLE} --version
RESULT_VARIABLE NodeJS_VALIDATE_EXECUTABLE
OUTPUT_VARIABLE NodeJS_INSTALLED_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND ${NodeJS_EXECUTABLE} -p "process.platform"
OUTPUT_VARIABLE NodeJS_INSTALLED_PLATFORM
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND ${NodeJS_EXECUTABLE} -p "process.arch"
OUTPUT_VARIABLE NodeJS_INSTALLED_ARCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()
# If node isn't the node.js binary, try the nodejs binary
if(NOT NodeJS_VALIDATE_EXECUTABLE EQUAL 0)
find_program(NodeJS_EXECUTABLE
NAMES nodejs
PATHS ${NodeJS_ROOT_DIR}
PATH_SUFFIXES nodejs node
)
set(NodeJS_VALIDATE_EXECUTABLE 1)
if(NodeJS_EXECUTABLE)
execute_process(
COMMAND ${NodeJS_EXECUTABLE} --version
RESULT_VARIABLE NodeJS_VALIDATE_EXECUTABLE
OUTPUT_VARIABLE NodeJS_INSTALLED_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()
if(NOT NodeJS_VALIDATE_EXECUTABLE EQUAL 0)
message(WARNING "Node.js executable could not be found. \
Set NodeJS_ROOT_DIR to the installed location of the executable or \
install Node.js to its default location.")
endif()
endif()
# Determine if a variant is set in the components
list(APPEND NodeJS_OTHER_COMPONENTS
X64 IA32 ARM WIN32 LINUX DARWIN
)
set(NodeJS_COMPONENTS_CONTAINS_VARIANT False)
foreach(NodeJS_COMPONENT ${NodeJS_FIND_COMPONENTS})
list(FIND NodeJS_OTHER_COMPONENTS ${NodeJS_COMPONENT} NodeJS_OTHER_INDEX)
if(NodeJS_OTHER_INDEX EQUAL -1)
set(NodeJS_COMPONENTS_CONTAINS_VARIANT True)
break()
endif()
endforeach()
# Get the targeted version of Node.js (or one of its derivatives)
if(NOT NodeJS_VERSION)
if(NodeJS_FIND_VERSION)
set(NodeJS_VERSION ${NodeJS_FIND_VERSION})
elseif(NodeJS_INSTALLED_VERSION AND NOT NodeJS_COMPONENTS_CONTAINS_VARIANT)
string(SUBSTRING ${NodeJS_INSTALLED_VERSION} 1 -1 NodeJS_VERSION)
else()
message(FATAL_ERROR "Node.js version is not set. Set the VERSION \
property of the find_package command to the required version of the \
Node.js sources")
endif()
endif()
# Determine the target platform for the compiled module
# Uses several mechanisms in order:
#
# 1. CMake cache (allows overriding on the command line)
# 2. Node architecture when binary is available
# 3. CMake architecture
#
set(NodeJS_PLATFORM "" CACHE STRING "Target node.js platform for module")
if(NOT NodeJS_PLATFORM)
if(NodeJS_EXECUTABLE)
set(NodeJS_PLATFORM ${NodeJS_INSTALLED_PLATFORM})
elseif(WIN32)
set(NodeJS_PLATFORM "win32")
elseif(UNIX)
if(APPLE)
set(NodeJS_PLATFORM "darwin")
else()
set(NodeJS_PLATFORM "linux")
endif()
else()
message(FATAL_ERROR "Node.js platform is not set. Add the platform \
to the find_package components section or set NodeJS_PLATFORM in the \
cache.")
endif()
endif()
# Convenience variables for the platform type
if(NodeJS_PLATFORM STREQUAL "win32")
set(NodeJS_PLATFORM_WIN32 True)
set(NodeJS_PLATFORM_LINUX False)
set(NodeJS_PLATFORM_DARWIN False)
elseif(NodeJS_PLATFORM STREQUAL "linux")
set(NodeJS_PLATFORM_WIN32 False)
set(NodeJS_PLATFORM_LINUX True)
set(NodeJS_PLATFORM_DARWIN False)
elseif(NodeJS_PLATFORM STREQUAL "darwin")
set(NodeJS_PLATFORM_WIN32 False)
set(NodeJS_PLATFORM_LINUX False)
set(NodeJS_PLATFORM_DARWIN True)
endif()
# Determine the target architecture for the compiled module
# Uses several mechanisms in order:
#
# 1. CMake cache (allows overriding on the command line)
# 2. Node architecture when binary is available
# 3. Compiler architecture under MSVC
#
set(NodeJS_ARCH "" CACHE STRING "Target node.js architecture for module")
if(NOT NodeJS_ARCH)
if(NodeJS_EXECUTABLE)
set(NodeJS_ARCH ${NodeJS_INSTALLED_ARCH})
elseif(MSVC)
if(CMAKE_CL_64)
set(NodeJS_ARCH "x64")
else()
set(NodeJS_ARCH "ia32")
endif()
else()
message(FATAL_ERROR "Node.js architecture is not set. Add the \
architecture to the find_package components section or set NodeJS_ARCH \
in the cache.")
endif()
endif()
# Convenience variables for the architecture
if(NodeJS_ARCH STREQUAL "x64")
set(NodeJS_ARCH_X64 True)
set(NodeJS_ARCH_IA32 False)
set(NodeJS_ARCH_ARM False)
elseif(NodeJS_ARCH STREQUAL "ia32")
set(NodeJS_ARCH_X64 False)
set(NodeJS_ARCH_IA32 True)
set(NodeJS_ARCH_ARM False)
elseif(NodeJS_ARCH STREQUAL "arm")
set(NodeJS_ARCH_X64 False)
set(NodeJS_ARCH_IA32 False)
set(NodeJS_ARCH_ARM True)
endif()
# Include helper functions
include(util/NodeJSUtil)
# Default variant name
# Used by the installed header comparison below
set(NodeJS_DEFAULT_VARIANT_NAME "node.js")
# Variables for Node.js artifacts across variants
# Specify all of these variables for each new variant
set(NodeJS_VARIANT_NAME "") # The printable name of the variant
set(NodeJS_VARIANT_BASE "") # A file name safe version of the variant
set(NodeJS_URL "") # The URL for the artifacts
set(NodeJS_SOURCE_PATH "") # The URL path of the source archive
set(NodeJS_CHECKSUM_PATH "") # The URL path of the checksum file
set(NodeJS_CHECKSUM_TYPE "") # The checksum type (algorithm)
set(NodeJS_WIN32_LIBRARY_PATH "") # The URL path of the windows library
set(NodeJS_WIN32_BINARY_PATH "") # The URL path of the windows executable
set(NodeJS_WIN32_LIBRARY_NAME "") # The name of the windows library
set(NodeJS_WIN32_BINARY_NAME "") # The name of the windows executable
set(NodeJS_DEFAULT_INCLUDE True) # Enable default include behavior
set(NodeJS_DEFAULT_LIBS True) # Include the default libraries
set(NodeJS_HAS_WIN32_PREFIX True) # Does the variant use library prefixes
set(NodeJS_HAS_WIN32_BINARY True) # Does the variant have win32 executables
set(NodeJS_HAS_OPENSSL True) # Does the variant include openssl headers
set(NodeJS_HEADER_VERSION 0.12.7) # Version after header-only archives start
set(NodeJS_SHA256_VERSION 0.7.0) # Version after sha256 checksums start
set(NodeJS_PREFIX_VERSION 0.12.7) # Version after windows prefixing starts
set(NodeJS_CXX11R_VERSION 0.12.7) # Version after c++11 is required
set(NodeJS_SOURCE_INCLUDE True) # Use the include paths from a source archive
set(NodeJS_HEADER_INCLUDE False) # Use the include paths from a header archive
set(NodeJS_INCLUDE_PATHS "") # Set of header dirs inside the source archive
set(NodeJS_LIBRARIES "") # The set of libraries to link with addon
set(NodeJS_WIN32_DELAYLOAD "") # Set of executables to delayload on windows
# NodeJS variants
# Selects download target based on configured component
# Include NodeJS last to provide default configurations when omitted
file(
GLOB NodeJS_SUPPORTED_VARIANTS
RELATIVE ${CMAKE_CURRENT_LIST_DIR}/variants
${CMAKE_CURRENT_LIST_DIR}/variants/*
)
foreach(NodeJS_SUPPORTED_VARIANT ${NodeJS_SUPPORTED_VARIANTS})
get_filename_component(NodeJS_SUPPORTED_VARIANT_NAME
${NodeJS_SUPPORTED_VARIANT} NAME_WE
)
if(NOT NodeJS_SUPPORTED_VARIANT_NAME STREQUAL "NodeJS")
include(variants/${NodeJS_SUPPORTED_VARIANT_NAME})
endif()
endforeach()
include(variants/NodeJS)
# Populate version variables, including version components
set(NodeJS_VERSION_STRING "v${NodeJS_VERSION}")
# Populate the remaining version variables
string(REPLACE "." ";" NodeJS_VERSION_PARTS ${NodeJS_VERSION})
list(GET NodeJS_VERSION_PARTS 0 NodeJS_VERSION_MAJOR)
list(GET NodeJS_VERSION_PARTS 1 NodeJS_VERSION_MINOR)
list(GET NodeJS_VERSION_PARTS 2 NodeJS_VERSION_PATCH)
# If the version we're looking for is the version that is installed,
# try finding the required headers. Don't do this under windows (where
# headers are not part of the installed content), when the user has
# specified that headers should be downloaded or when using a variant other
# than the default
if((NOT NodeJS_PLATFORM_WIN32) AND (NOT NodeJS_DOWNLOAD) AND
NodeJS_VARIANT_NAME STREQUAL NodeJS_DEFAULT_VARIANT_NAME AND
NodeJS_INSTALLED_VERSION STREQUAL NodeJS_VERSION_STRING AND
NodeJS_INSTALLED_PLATFORM STREQUAL NodeJS_PLATFORM AND
NodeJS_INSTALLED_ARCH STREQUAL NodeJS_ARCH)
# node.h is really generic and too easy for cmake to find the wrong
# file, so use the directory as a guard, and then just tack it on to
# the actual path
#
# Specifically ran into this under OSX, where python contains a node.h
# that gets found instead
find_path(NodeJS_INCLUDE_PARENT node/node.h)
set(NodeJS_INCLUDE_DIRS ${NodeJS_INCLUDE_PARENT}/node)
# Under all systems that support this, there are no libraries required
# for linking (symbols are resolved via the main executable at runtime)
set(NodeJS_LIBRARIES "")
# Otherwise, headers and required libraries must be downloaded to the project
# to supplement what is installed
else()
# Create a folder for downloaded artifacts
set(NodeJS_DOWNLOAD_PATH
${CMAKE_CURRENT_BINARY_DIR}/${NodeJS_VARIANT_BASE}
)
set(NodeJS_DOWNLOAD_PATH ${NodeJS_DOWNLOAD_PATH}-${NodeJS_VERSION_STRING})
file(MAKE_DIRECTORY ${NodeJS_DOWNLOAD_PATH})
# Download the checksum file for validating all other downloads
# Conveniently, if this doesn't download correctly, the setup fails
# due to checksum failures
set(NodeJS_CHECKSUM_FILE ${NodeJS_DOWNLOAD_PATH}/CHECKSUM)
nodejs_download(
${NodeJS_URL}/${NodeJS_CHECKSUM_PATH}
${NodeJS_CHECKSUM_FILE}
${NodeJS_FORCE_DOWNLOAD}
)
file(READ ${NodeJS_CHECKSUM_FILE} NodeJS_CHECKSUM_DATA)
# Download and extract the main source archive
set(NodeJS_SOURCE_FILE ${NodeJS_DOWNLOAD_PATH}/headers.tar.gz)
nodejs_checksum(
${NodeJS_CHECKSUM_DATA} ${NodeJS_SOURCE_PATH} NodeJS_SOURCE_CHECKSUM
)
nodejs_download(
${NodeJS_URL}/${NodeJS_SOURCE_PATH}
${NodeJS_SOURCE_FILE}
${NodeJS_SOURCE_CHECKSUM}
${NodeJS_CHECKSUM_TYPE}
${NodeJS_FORCE_DOWNLOAD}
)
set(NodeJS_HEADER_PATH ${NodeJS_DOWNLOAD_PATH}/src)
nodejs_extract(
${NodeJS_SOURCE_FILE}
${NodeJS_HEADER_PATH}
${NodeJS_FORCE_EXTRACT}
)
# Populate include directories from the extracted source archive
foreach(NodeJS_HEADER_BASE ${NodeJS_INCLUDE_PATHS})
set(NodeJS_INCLUDE_DIR ${NodeJS_HEADER_PATH}/${NodeJS_HEADER_BASE})
if(NOT EXISTS ${NodeJS_INCLUDE_DIR})
message(FATAL_ERROR "Include does not exist: ${NodeJS_INCLUDE_DIR}")
endif()
list(APPEND NodeJS_INCLUDE_DIRS ${NodeJS_INCLUDE_DIR})
endforeach()
# Download required library files when targeting windows
if(NodeJS_PLATFORM_WIN32)
# Download the windows library
set(NodeJS_WIN32_LIBRARY_FILE
${NodeJS_DOWNLOAD_PATH}/lib/${NodeJS_ARCH}
)
set(NodeJS_WIN32_LIBRARY_FILE
${NodeJS_WIN32_LIBRARY_FILE}/${NodeJS_WIN32_LIBRARY_NAME}
)
nodejs_checksum(
${NodeJS_CHECKSUM_DATA} ${NodeJS_WIN32_LIBRARY_PATH}
NodeJS_WIN32_LIBRARY_CHECKSUM
)
nodejs_download(
${NodeJS_URL}/${NodeJS_WIN32_LIBRARY_PATH}
${NodeJS_WIN32_LIBRARY_FILE}
${NodeJS_WIN32_LIBRARY_CHECKSUM}
${NodeJS_CHECKSUM_TYPE}
${NodeJS_FORCE_DOWNLOAD}
)
list(APPEND NodeJS_LIBRARIES ${NodeJS_WIN32_LIBRARY_FILE})
# If provided, download the windows executable
if(NodeJS_WIN32_BINARY_PATH AND
NodeJS_DOWNLOAD_EXECUTABLE)
set(NodeJS_WIN32_BINARY_FILE
${NodeJS_DOWNLOAD_PATH}/lib/${NodeJS_ARCH}
)
set(NodeJS_WIN32_BINARY_FILE
${NodeJS_WIN32_BINARY_FILE}/${NodeJS_WIN32_BINARY_NAME}
)
nodejs_checksum(
${NodeJS_CHECKSUM_DATA} ${NodeJS_WIN32_BINARY_PATH}
NodeJS_WIN32_BINARY_CHECKSUM
)
nodejs_download(
${NodeJS_URL}/${NodeJS_WIN32_BINARY_PATH}
${NodeJS_WIN32_BINARY_FILE}
${NodeJS_WIN32_BINARY_CHECKSUM}
${NodeJS_CHECKSUM_TYPE}
${NodeJS_FORCE_DOWNLOAD}
)
endif()
endif()
endif()
# Support windows delay loading
if(NodeJS_PLATFORM_WIN32)
list(APPEND NodeJS_LINK_FLAGS /IGNORE:4199)
set(NodeJS_WIN32_DELAYLOAD_CONDITION "")
foreach(NodeJS_WIN32_DELAYLOAD_BINARY ${NodeJS_WIN32_DELAYLOAD})
list(APPEND NodeJS_LINK_FLAGS
/DELAYLOAD:${NodeJS_WIN32_DELAYLOAD_BINARY}
)
list(APPEND NodeJS_WIN32_DELAYLOAD_CONDITION
"_stricmp(info->szDll, \"${NodeJS_WIN32_DELAYLOAD_BINARY}\") != 0"
)
endforeach()
string(REPLACE ";" " &&\n "
NodeJS_WIN32_DELAYLOAD_CONDITION
"${NodeJS_WIN32_DELAYLOAD_CONDITION}"
)
configure_file(
${NodeJS_MODULE_PATH}/src/win_delay_load_hook.c
${CMAKE_CURRENT_BINARY_DIR}/win_delay_load_hook.c @ONLY
)
list(APPEND NodeJS_ADDITIONAL_SOURCES
${CMAKE_CURRENT_BINARY_DIR}/win_delay_load_hook.c
)
endif()
# Allow undefined symbols on OSX
if(NodeJS_PLATFORM_DARWIN)
list(APPEND NodeJS_LINK_FLAGS "-undefined dynamic_lookup")
endif()
# Use libc++ when clang is the compiler by default
if(NodeJS_USE_CLANG_STDLIB AND CMAKE_CXX_COMPILER_ID MATCHES ".*Clang.*")
list(APPEND NodeJS_COMPILE_OPTIONS -stdlib=libc++)
endif()
# Require c++11 support after a specific point, but only if the user hasn't
# specified an override
if(NOT NodeJS_CXX_STANDARD)
if(NodeJS_VERSION VERSION_GREATER NodeJS_CXX11R_VERSION)
set(NodeJS_CXX_STANDARD 11)
else()
set(NodeJS_CXX_STANDARD 98)
endif()
endif()
# Set required definitions
list(APPEND NodeJS_DEFINITIONS BUILDING_NODE_EXTENSION)
if(NodeJS_PLATFORM_DARWIN)
list(APPEND NodeJS_DEFINITIONS _DARWIN_USE_64_BIT_INODE=1)
endif()
if(NOT NodeJS_PLATFORM_WIN32)
list(APPEND NodeJS_DEFINITIONS
_LARGEFILE_SOURCE
_FILE_OFFSET_BITS=64
)
endif()
function(add_nodejs_module NAME)
# Build a shared library for the module
add_library(${NAME} SHARED ${ARGN} ${NodeJS_ADDITIONAL_SOURCES})
# Include required headers
# Find and include Nan as well (always available as its a
# dependency of this module)
nodejs_find_module_fallback(nan ${CMAKE_CURRENT_SOURCE_DIR} NAN_PATH)
target_include_directories(${NAME}
PUBLIC ${NodeJS_INCLUDE_DIRS}
PUBLIC ${NAN_PATH}
)
# Set module properties
# This ensures proper naming of the module library across all platforms
get_target_property(COMPILE_OPTIONS ${NAME} COMPILE_OPTIONS)
if(NOT COMPILE_OPTIONS)
set(COMPILE_OPTIONS "")
endif()
set(COMPILE_OPTIONS ${COMPILE_OPTIONS} ${NodeJS_COMPILE_OPTIONS})
get_target_property(LINK_FLAGS ${NAME} LINK_FLAGS)
if(NOT LINK_FLAGS)
set(LINK_FLAGS "")
endif()
foreach(NodeJS_LINK_FLAG ${NodeJS_LINK_FLAGS})
set(LINK_FLAGS "${LINK_FLAGS} ${NodeJS_LINK_FLAG}")
endforeach()
set_target_properties(${NAME} PROPERTIES
PREFIX ""
SUFFIX ".node"
MACOSX_RPATH ON
POSITION_INDEPENDENT_CODE TRUE
COMPILE_OPTIONS "${COMPILE_OPTIONS}"
LINK_FLAGS "${LINK_FLAGS}"
CXX_STANDARD_REQUIRED TRUE
CXX_STANDARD ${NodeJS_CXX_STANDARD}
)
# Output the module in a per build type directory
# This makes builds consistent with visual studio and other generators
# that build by configuration
if(NOT CMAKE_CONFIGURATION_TYPES)
set_property(TARGET ${NAME} PROPERTY LIBRARY_OUTPUT_DIRECTORY
${CMAKE_BUILD_TYPE}
)
endif()
# Set any required complier flags
# Mostly used under windows
target_compile_definitions(${NAME} PRIVATE ${NodeJS_DEFINITIONS})
# Link against required NodeJS libraries
target_link_libraries(${NAME} ${NodeJS_LIBRARIES})
endfunction()
# Write out the configuration for node scripts
configure_file(
${NodeJS_MODULE_PATH}/build.json.in
${CMAKE_CURRENT_BINARY_DIR}/build.json @ONLY
)
# Make sure we haven't violated the version-to-standard mapping
if(NodeJS_VERSION VERSION_GREATER NodeJS_CXX11R_VERSION AND
NodeJS_CXX_STANDARD EQUAL 98)
message(FATAL_ERROR "${NodeJS_VARIANT_NAME} ${NodeJS_VERSION} \
requires C++11 or newer to build")
endif()
# This is a find_package file, handle the standard invocation
include(FindPackageHandleStandardArgs)
set(NodeJS_TARGET "${NodeJS_VARIANT_NAME} ${NodeJS_PLATFORM}/${NodeJS_ARCH}")
find_package_handle_standard_args(NodeJS
FOUND_VAR NodeJS_FOUND
REQUIRED_VARS NodeJS_TARGET NodeJS_INCLUDE_DIRS
VERSION_VAR NodeJS_VERSION
)
# Mark variables that users shouldn't modify
mark_as_advanced(
NodeJS_VALIDATE_EXECUTABLE
NodeJS_OTHER_COMPONENTS
NodeJS_COMPONENTS_CONTAINS_VARIANT
NodeJS_COMPONENT
NodeJS_OTHER_INDEX
NodeJS_VERSION_STRING
NodeJS_VERSION_MAJOR
NodeJS_VERSION_MINOR
NodeJS_VERSION_PATCH
NodeJS_VERSION_TWEAK
NodeJS_PLATFORM
NodeJS_PLATFORM_WIN32
NodeJS_PLATFORM_LINUX
NodeJS_PLATFORM_DARWIN
NodeJS_ARCH
NodeJS_ARCH_X64
NodeJS_ARCH_IA32
NodeJS_ARCH_ARM
NodeJS_DEFAULT_VARIANT_NAME
NodeJS_VARIANT_BASE
NodeJS_VARIANT_NAME
NodeJS_URL
NodeJS_SOURCE_PATH
NodeJS_CHECKSUM_PATH
NodeJS_CHECKSUM_TYPE
NodeJS_WIN32_LIBRARY_PATH
NodeJS_WIN32_BINARY_PATH
NodeJS_WIN32_LIBRARY_NAME
NodeJS_WIN32_BINARY_NAME
NodeJS_DEFAULT_INCLUDE
NodeJS_DEFAULT_LIBS
NodeJS_HAS_WIN32_BINARY
NodeJS_HEADER_VERSION
NodeJS_SHA256_VERISON
NodeJS_PREFIX_VERSION
NodeJS_SOURCE_INCLUDE
NodeJS_HEADER_INCLUDE
NodeJS_INCLUDE_PATHS
NodeJS_WIN32_DELAYLOAD
NodeJS_DOWNLOAD_PATH
NodeJS_CHECKSUM_FILE
NodeJS_CHECKSUM_DATA
NodeJS_SOURCE_FILE
NodeJS_SOURCE_CHECKSUM
NodeJS_HEADER_PATH
NodeJS_HEADER_BASE
NodeJS_INCLUDE_DIR
NodeJS_WIN32_LIBRARY_FILE
NodeJS_WIN32_LIBRARY_CHECKSUM
NodeJS_WIN32_BINARY_FILE
NodeJS_WIN32_BINARY_CHECKSUM
NodeJS_NAN_PATH
NodeJS_LINK_FLAGS
NodeJS_COMPILE_OPTIONS
NodeJS_ADDITIONAL_SOURCES
NodeJS_WIN32_DELAYLOAD_CONDITION
NodeJS_WIN32_DELAYLOAD_BINARY
NodeJS_TARGET
)
+10
View File
@@ -0,0 +1,10 @@
{
"build_type": "@CMAKE_BUILD_TYPE@",
"generator": "@CMAKE_GENERATOR@",
"toolset": "@CMAKE_GENERATOR_TOOLSET@",
"platform": "@CMAKE_GENERATOR_PLATFORM@",
"variant": "@NodeJS_VARIANT_BASE@",
"version": "@NodeJS_VERSION@",
"download": "@NodeJS_DOWNLOAD@",
"standard": "@NodeJS_CXX_STANDARD@"
}
+28
View File
@@ -0,0 +1,28 @@
set(GITHUB_API_TOKEN $ENV{GITHUB_API_TOKEN})
set(GITHUB_AUTH "")
if(GITHUB_API_TOKEN)
set(GITHUB_AUTH "?access_token=${GITHUB_API_TOKEN}")
endif()
set(GITHUB_API_URL "https://api.github.com")
function(github_get_rate_limit VAR)
set(RATE_LIMIT_FILE ${CMAKE_CURRENT_BINARY_DIR}/GITHUBRATE)
set(RATE_LIMIT_URL ${GITHUB_API_URL}/rate_limit${GITHUB_AUTH})
nodejs_download(
${RATE_LIMIT_URL}
${RATE_LIMIT_FILE}
ON
)
file(READ ${RATE_LIMIT_FILE} RATE_LIMIT_DATA)
string(REGEX MATCH "\"remaining\": ([0-9]+),"
RATE_LIMIT_MATCH ${RATE_LIMIT_DATA})
set(${VAR} ${CMAKE_MATCH_1} PARENT_SCOPE)
endfunction()
mark_as_advanced(
GITHUB_AUTH
GITHUB_API_TOKEN
GITHUB_API_URL
)
+166
View File
@@ -0,0 +1,166 @@
function(nodejs_check_file FILE)
set(MESSAGE "File ${FILE} does not exist or is empty")
if(ARGC GREATER 1)
set(MESSAGE ${ARGV1})
endif()
# Make sure the file has contents
file(READ ${FILE} FILE_CONTENT LIMIT 1 HEX)
if(NOT FILE_CONTENT)
file(REMOVE ${FILE})
message(FATAL_ERROR ${MESSAGE})
endif()
endfunction()
function(nodejs_download URL FILE)
# Function optionally takes a checksum and a checksum type, and
# a force value
# Either can be specified without the other, but checksum must come first
if(ARGC GREATER 2)
set(CHECKSUM ${ARGV2})
if(CHECKSUM STREQUAL "On" OR CHECKSUM STREQUAL "ON" OR
CHECKSUM STREQUAL "True" OR CHECKSUM STREQUAL "TRUE" OR
CHECKSUM STREQUAL "Off" OR CHECKSUM STREQUAL "OFF" OR
CHECKSUM STREQUAL "False" OR CHECKSUM STREQUAL "FALSE")
set(FORCE ${CHECKSUM})
unset(CHECKSUM)
elseif(ARGC GREATER 3)
set(TYPE ${ARGV3})
else()
message(FATAL_ERROR "Checksum type must be specified")
endif()
elseif(ARGC GREATER 4)
set(CHECKSUM ${ARGV2})
set(TYPE ${ARGV3})
set(FORCE ${ARGV4})
endif()
# If the file exists, no need to download it again unless its being forced
if(NOT FORCE AND EXISTS ${FILE})
return()
endif()
# Download the file
message(STATUS "Downloading: ${URL}")
file(DOWNLOAD
${URL}
${FILE}
SHOW_PROGRESS
)
# Make sure the file has contents
nodejs_check_file(${FILE} "Unable to download ${URL}")
# If a checksum is provided, validate the downloaded file
if(CHECKSUM)
message(STATUS "Validating: ${FILE}")
file(${TYPE} ${FILE} DOWNLOAD_CHECKSUM)
message(STATUS "Checksum: ${CHECKSUM}")
message(STATUS "Download: ${DOWNLOAD_CHECKSUM}")
if(NOT CHECKSUM STREQUAL DOWNLOAD_CHECKSUM)
file(REMOVE ${FILE})
message(FATAL_ERROR "Validation failure: ${FILE}")
endif()
endif()
endfunction()
function(nodejs_checksum DATA FILE VAR)
string(REGEX MATCH "([A-Fa-f0-9]+)[\t ]+${FILE}" CHECKSUM_MATCH ${DATA})
if(CMAKE_MATCH_1)
set(${VAR} ${CMAKE_MATCH_1} PARENT_SCOPE)
else()
message(FATAL_ERROR "Unable to extract file checksum")
endif()
endfunction()
function(nodejs_extract FILE DIR)
# Function optionally takes a force value
if(ARGC GREATER 2)
set(FORCE ${ARGV2})
endif()
# If the archvie has been extracted, no need to extract again unless it
# is being forced
if(NOT FORCE AND EXISTS ${DIR})
return()
endif()
# Make a temporary directory for extracting the output
set(EXTRACT_DIR ${CMAKE_CURRENT_BINARY_DIR}/extract)
if(EXISTS ${EXTRACT_DIR})
file(REMOVE_RECURSE ${EXTRACT_DIR})
endif()
file(MAKE_DIRECTORY ${EXTRACT_DIR})
# Extract the archive
execute_process(
COMMAND ${CMAKE_COMMAND} -E tar xfz ${FILE}
WORKING_DIRECTORY ${EXTRACT_DIR}
)
# If only one element is extracted, the archive contained a nested
# folder; use the inner folder as the extracted folder
file(GLOB EXTRACT_CHILDREN ${EXTRACT_DIR}/*)
list(LENGTH EXTRACT_CHILDREN NUM_CHILDREN)
set(TARGET_DIR ${EXTRACT_DIR})
if(NUM_CHILDREN EQUAL 1)
list(GET EXTRACT_CHILDREN 0 TARGET_DIR)
endif()
# Move the folder to the target path
if(EXISTS ${DIR})
file(REMOVE_RECURSE ${DIR})
endif()
file(RENAME ${TARGET_DIR} ${DIR})
# Make sure to clean up the extraction folder when the inner folder
# is used
file(REMOVE_RECURSE ${EXTRACT_DIR})
endfunction()
function(nodejs_find_module NAME BASE PATH)
# Find a node module using the same search path that require uses
# without needing a node binary
set(ROOT ${BASE})
set(DRIVE "^[A-Za-z]?:?/$")
# Walk up the directory tree until at the root
while(NOT ROOT MATCHES ${DRIVE} AND NOT
EXISTS ${ROOT}/node_modules/${NAME})
get_filename_component(ROOT ${ROOT} DIRECTORY)
endwhile()
# Operate like the CMake find_* functions, returning NOTFOUND if the
# module can't be found
if(ROOT MATCHES ${DRIVE})
set(${PATH} ${NAME}-NOTFOUND PARENT_SCOPE)
else()
set(${PATH} ${ROOT}/node_modules/${NAME} PARENT_SCOPE)
endif()
endfunction()
macro(nodejs_find_module_fallback NAME BASE PATH)
# Look in the provided path first
# If the module isn't found, try searching from the module
nodejs_find_module(${NAME} ${BASE} ${PATH})
if(NOT ${PATH})
nodejs_find_module(${NAME} ${NodeJS_MODULE_PATH} ${PATH})
endif()
endmacro()
function(nodejs_get_version URL VAR)
set(NWJS_LATEST_RELEASE_URL
"${NWJS_URL_BASE}/latest/${NodeJS_CHECKSUM_PATH}")
set(VERSION_FILE ${CMAKE_CURRENT_BINARY_DIR}/VERSION)
nodejs_download(
${URL}
${VERSION_FILE}
ON
)
nodejs_check_file(${VERSION_FILE})
file(READ ${VERSION_FILE} VERSION_DATA)
string(REGEX MATCH "v([0-9]+\.[0-9]+\.[0-9]+)"
VERSION_MATCH ${VERSION_DATA}
)
set(${VAR} ${CMAKE_MATCH_1} PARENT_SCOPE)
endfunction()
+81
View File
@@ -0,0 +1,81 @@
set(ELECTRON_VARIANT_BASE "electron")
set(ELECTRON_WIN32_BINARY_NAME "${ELECTRON_VARIANT_BASE}.exe")
list(APPEND NodeJS_WIN32_DELAYLOAD ${ELECTRON_WIN32_BINARY_NAME})
if(NodeJS_FIND_REQUIRED_ELECTRON OR
NodeJS_VARIANT STREQUAL ${ELECTRON_VARIANT_BASE})
if(NodeJS_VERSION STREQUAL "latest")
include(util/Github)
github_get_rate_limit(GITHUB_RATE_LIMIT)
# Handle determining the latest release
# Very complicated, due to electron not following the "latest"
# convention of other variants
set(ELECTRON_LATEST_RELEASE_FILE ${CMAKE_CURRENT_BINARY_DIR}/ELECTRON)
set(ELECTRON_LATEST_RELEASE_URL
${GITHUB_API_URL}/repos/atom/electron/releases/latest${GITHUB_AUTH}
)
if(GITHUB_RATE_LIMIT GREATER 0)
nodejs_download(
${ELECTRON_LATEST_RELEASE_URL}
${ELECTRON_LATEST_RELEASE_FILE}
ON
)
endif()
nodejs_check_file(
${ELECTRON_LATEST_RELEASE_FILE}
"Releases file could not be downloaded, likely \
because github rate limit was exceeded. Wait until the limit \
passes or set GITHUB_API_TOKEN in your environment to a valid \
github developer token."
)
file(READ ${ELECTRON_LATEST_RELEASE_FILE} ELECTRON_LATEST_RELEASE_DATA)
string(REGEX MATCH "\"tag_name\"\: \"v([0-9]+\.[0-9]+\.[0-9]+)\""
ELECTRON_LATEST_RELEASE_MATCH ${ELECTRON_LATEST_RELEASE_DATA})
set(NodeJS_VERSION ${CMAKE_MATCH_1})
endif()
set(NodeJS_VARIANT_NAME "Electron.js")
# SHASUMS of any kind is inaccessible prior to 0.16.0
if(NodeJS_VERSION VERSION_LESS 0.16.0)
message(FATAL_ERROR "Electron is only supported for versions >= 0.16.0")
endif()
# Electron switched to IOJS after 0.25.0
# Probably needs to be bounded on the upper side if/when they switch
# back to node mainline due to iojs-node merge
set(NodeJS_VARIANT_BASE "node")
if(NodeJS_VERSION VERSION_GREATER 0.25.0)
set(NodeJS_VARIANT_BASE "iojs")
endif()
# Url is hard to get, because it will immediately resolve to a CDN
# Extracted from the electron website
set(NodeJS_URL
"https://atom.io/download/atom-shell/v${NodeJS_VERSION}"
)
# Headers become available for IOJS base ONLY!
# Variant base switch above handles this
set(NodeJS_HEADER_VERSION 0.30.1)
# Header only archive uses source style paths
set(NodeJS_DEFAULT_INCLUDE False)
# Hard to determine, but versions seem to start at 16, and SHA256 is
# available
set(NodeJS_SHA256_VERSION 0.15.9)
# C++11 and Prefixing start after the IOJS switch
# Will carry forward after node mainline so no need for upper bound (whew)
set(NodeJS_PREFIX_VERSION 0.25.0)
set(NodeJS_CXX11R_VERSION 0.25.0)
# The executable is not provided on the CDN
# In theory, I could support a BINARY_URL to get this from github
set(NodeJS_HAS_WIN32_BINARY False)
# OpenSSL isn't included in the headers
set(NodeJS_HAS_OPENSSL False)
endif()
+25
View File
@@ -0,0 +1,25 @@
set(IOJS_URL_BASE "https://iojs.org/dist")
set(IOJS_VARIANT_BASE "iojs")
set(IOJS_WIN32_BINARY_NAME "${IOJS_VARIANT_BASE}.exe")
list(APPEND NodeJS_WIN32_DELAYLOAD ${IOJS_WIN32_BINARY_NAME})
if(NodeJS_FIND_REQUIRED_IOJS OR NodeJS_VARIANT STREQUAL ${IOJS_VARIANT_BASE})
if(NodeJS_VERSION STREQUAL "latest")
set(IOJS_LATEST_RELEASE_URL
"${IOJS_URL_BASE}/latest/SHASUMS256.txt")
nodejs_get_version(${IOJS_LATEST_RELEASE_URL} NodeJS_VERSION)
endif()
set(NodeJS_VARIANT_NAME "io.js")
set(NodeJS_VARIANT_BASE ${IOJS_VARIANT_BASE})
set(NodeJS_URL "${IOJS_URL_BASE}/v${NodeJS_VERSION}")
set(NodeJS_HEADER_VERSION 2.3.1)
set(NodeJS_WIN32_BINARY_NAME "${IOJS_WIN32_BINARY_NAME}")
endif()
mark_as_advanced(
IOJS_URL_BASE
IOJS_VARIANT_BASE
IOJS_WIN32_BINARY_NAME
IOJS_LATEST_RELEASE_URL
)
+30
View File
@@ -0,0 +1,30 @@
set(NWJS_URL_BASE "http://dl.nwjs.io")
set(NWJS_VARIANT_BASE "nw")
set(NWJS_WIN32_BINARY_NAME "${NWJS_VARIANT_BASE}.exe")
list(APPEND NodeJS_WIN32_DELAYLOAD ${NWJS_WIN32_BINARY_NAME})
if(NodeJS_FIND_REQUIRED_NWJS OR NodeJS_VARIANT STREQUAL ${NWJS_VARIANT_BASE})
set(NodeJS_CHECKSUM_PATH "MD5SUMS")
set(NodeJS_CHECKSUM_TYPE "MD5")
if(NodeJS_VERSION STREQUAL "latest")
set(NWJS_LATEST_RELEASE_URL
"${NWJS_URL_BASE}/latest/${NodeJS_CHECKSUM_PATH}")
nodejs_get_version(${NWJS_LATEST_RELEASE_URL} NodeJS_VERSION)
endif()
set(NodeJS_VARIANT_NAME "nw.js")
set(NodeJS_VARIANT_BASE ${NWJS_VARIANT_BASE})
set(NodeJS_URL "${NWJS_URL_BASE}/v${NodeJS_VERSION}")
set(NodeJS_SOURCE_PATH "nw-headers-v${NodeJS_VERSION}.tar.gz")
set(NodeJS_DEFAULT_INCLUDE False)
set(NodeJS_HAS_WIN32_PREFIX False)
set(NodeJS_HAS_WIN32_BINARY False)
endif()
mark_as_advanced(
NWJS_URL_BASE
NWJS_VARIANT_BASE
NWJS_WIN32_BINARY_NAME
NWJS_LATEST_RELEASE_URL
)
+131
View File
@@ -0,0 +1,131 @@
set(NodeJS_URL_BASE http://nodejs.org/dist)
set(NodeJS_DEFAULT_VARIANT_BASE "node")
set(NodeJS_DEFAULT_WIN32_BINARY_NAME "${NodeJS_DEFAULT_VARIANT_BASE}.exe")
list(APPEND NodeJS_WIN32_DELAYLOAD ${NodeJS_DEFAULT_WIN32_BINARY_NAME})
if(NodeJS_VERSION STREQUAL "latest")
set(NodeJS_LATEST_RELEASE_URL
"${NodeJS_URL_BASE}/latest/SHASUMS256.txt")
nodejs_get_version(${NodeJS_LATEST_RELEASE_URL} NodeJS_VERSION)
endif()
if(NOT NodeJS_VARIANT_NAME)
set(NodeJS_VARIANT_NAME ${NodeJS_DEFAULT_VARIANT_NAME})
endif()
if(NOT NodeJS_VARIANT_BASE)
set(NodeJS_VARIANT_BASE ${NodeJS_DEFAULT_VARIANT_BASE})
endif()
if(NOT NodeJS_URL)
set(NodeJS_URL "${NodeJS_URL_BASE}/v${NodeJS_VERSION}")
endif()
if(NOT NodeJS_SOURCE_PATH)
set(NodeJS_SOURCE_PATH "${NodeJS_VARIANT_BASE}-v${NodeJS_VERSION}")
# Use the headers archive when its available
if(NodeJS_VERSION VERSION_GREATER ${NodeJS_HEADER_VERSION})
set(NodeJS_SOURCE_PATH "${NodeJS_SOURCE_PATH}-headers")
endif()
set(NodeJS_SOURCE_PATH "${NodeJS_SOURCE_PATH}.tar.gz")
endif()
if(NodeJS_DEFAULT_INCLUDE AND
NodeJS_VERSION VERSION_GREATER ${NodeJS_HEADER_VERSION})
set(NodeJS_SOURCE_INCLUDE False)
set(NodeJS_HEADER_INCLUDE True)
endif()
if(NodeJS_SOURCE_INCLUDE)
list(APPEND NodeJS_INCLUDE_PATHS
src
deps/uv/include
deps/v8/include
deps/zlib
)
# OpenSSL is an optional header
if(NodeJS_HAS_OPENSSL)
list(APPEND NodeJS_INCLUDE_PATHS
deps/openssl/openssl/include
)
endif()
endif()
if(NodeJS_HEADER_INCLUDE)
set(NodeJS_INCLUDE_PATHS include/node)
endif()
if(NOT NodeJS_CHECKSUM_TYPE)
# Use SHA256 when available
if(NodeJS_VERSION VERSION_GREATER ${NodeJS_SHA256_VERSION})
set(NodeJS_CHECKSUM_TYPE "SHA256")
else()
set(NodeJS_CHECKSUM_TYPE "SHA1")
endif()
endif()
if(NOT NodeJS_CHECKSUM_PATH)
set(NodeJS_CHECKSUM_PATH "SHASUMS")
if(NodeJS_CHECKSUM_TYPE STREQUAL "SHA256")
set(NodeJS_CHECKSUM_PATH "${NodeJS_CHECKSUM_PATH}256")
endif()
set(NodeJS_CHECKSUM_PATH "${NodeJS_CHECKSUM_PATH}.txt")
endif()
# Library and binary are based on variant base
if(NOT NodeJS_WIN32_LIBRARY_NAME)
set(NodeJS_WIN32_LIBRARY_NAME ${NodeJS_VARIANT_BASE}.lib)
endif()
if(NOT NodeJS_WIN32_BINARY_NAME)
set(NodeJS_WIN32_BINARY_NAME ${NodeJS_VARIANT_BASE}.exe)
endif()
if(NOT NodeJS_WIN32_LIBRARY_PATH)
# The library location is prefixed after a specific version
if(NodeJS_HAS_WIN32_PREFIX AND
NodeJS_VERSION VERSION_GREATER ${NodeJS_PREFIX_VERSION})
set(NodeJS_WIN32_LIBRARY_PATH "win-")
if(NodeJS_ARCH_IA32)
set(NodeJS_WIN32_LIBRARY_PATH "${NodeJS_WIN32_LIBRARY_PATH}x86/")
endif()
endif()
# 64-bit versions are prefixed
if(NodeJS_ARCH_X64)
set(NodeJS_WIN32_LIBRARY_PATH "${NodeJS_WIN32_LIBRARY_PATH}x64/")
endif()
set(NodeJS_WIN32_LIBRARY_PATH
"${NodeJS_WIN32_LIBRARY_PATH}${NodeJS_WIN32_LIBRARY_NAME}"
)
endif()
if(NodeJS_HAS_WIN32_BINARY AND NOT NodeJS_WIN32_BINARY_PATH)
# The executable location is prefixed after a specific version
if(NodeJS_HAS_WIN32_PREFIX AND
NodeJS_VERSION VERSION_GREATER ${NodeJS_PREFIX_VERSION})
set(NodeJS_WIN32_BINARY_PATH "win-")
if(NodeJS_ARCH_IA32)
set(NodeJS_WIN32_BINARY_PATH "${NodeJS_WIN32_BINARY_PATH}x86/")
endif()
endif()
# 64-bit versions are prefixed
if(NodeJS_ARCH_X64)
set(NodeJS_WIN32_BINARY_PATH "${NodeJS_WIN32_BINARY_PATH}x64/")
endif()
set(NodeJS_WIN32_BINARY_PATH
"${NodeJS_WIN32_BINARY_PATH}${NodeJS_WIN32_BINARY_NAME}"
)
endif()
# Specify windows libraries
# XXX: This may need to be version/variant specific in the future
if(NodeJS_DEFAULT_LIBS AND NodeJS_PLATFORM_WIN32)
list(APPEND NodeJS_LIBRARIES
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib
advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib
odbc32.lib DelayImp.lib
)
endif()
mark_as_advanced(
NodeJS_URL_BASE
NodeJS_DEFAULT_VARIANT_BASE
NodeJS_DEFAULT_WIN32_BINARY_NAME
NodeJS_LATEST_RELEASE_URL
)
+1
View File
@@ -1,6 +1,7 @@
coverage:
ignore:
- unit_tests/.*
- third_party/.*
comment: off
+1 -1
View File
@@ -3,5 +3,5 @@ module.exports = {
verify: '--strict --tags ~@stress --tags ~@todo -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 --tags ~@alternative --tags ~@matrix --tags ~@trip --require features/support --require features/step_definitions -f progress'
mld: '--strict --tags ~@stress --tags ~@todo --tags ~@match --tags ~@alternative --tags ~@matrix --tags ~@trip --tags ~@via --require features/support --require features/step_definitions -f progress'
}
+3 -5
View File
@@ -279,8 +279,6 @@ In addition to the [general options](#general-options) the following options are
|overview |`simplified` (default), `full`, `false` |Add overview geometry either full, simplified according to highest zoom level it could be display on, or not at all.|
|timestamps |`{timestamp};{timestamp}[;{timestamp} ...]` |Timestamps for the input locations in seconds since UNIX epoch. Timestamps need to be monotonically increasing. |
|radiuses |`{radius};{radius}[;{radius} ...]` |Standard deviation of GPS precision used for map matching. If applicable use GPS accuracy.|
|gaps |`split` (default), `ignore` |Allows the input track splitting based on huge timestamp gaps between points. |
|tidy |`true`, `false` (default) |Allows the input track modification to obtain better matching quality for noisy tracks. |
|Parameter |Values |
|------------|-----------------------------------|
@@ -316,7 +314,7 @@ All other properties might be undefined.
The trip plugin solves the Traveling Salesman Problem using a greedy heuristic (farthest-insertion algorithm) for 10 or more waypoints and uses brute force for less than 10 waypoints.
The returned path does not have to be the fastest path. As TSP is NP-hard it only returns an approximation.
Note that all input coordinates have to be connected for the trip service to work.
Note that all input coordinates have to be connected for the trip service to work.
```endpoint
GET /trip/v1/{profile}/{coordinates}?roundtrip={true|false}&source{any|first}&destination{any|last}&steps={true|false}&geometries={polyline|polyline6|geojson}&overview={simplified|full|false}&annotations={true|false}'
@@ -336,7 +334,7 @@ In addition to the [general options](#general-options) the following options are
**Fixing Start and End Points**
It is possible to explicitely set the start or end coordinate of the trip.
It is possible to explicitely set the start or end coordinate of the trip.
When source is set to `first`, the first coordinate is used as start coordinate of the trip in the output. When destination is set to `last`, the last coordinate will be used as destination of the trip in the returned output. If you specify `any`, any of the coordinates can be used as the first or last coordinate in the output.
However, if `source=any&destination=any` the returned round-trip will still start at the first input coordinate by default.
@@ -346,7 +344,7 @@ Right now, the following combinations are possible:
| roundtrip | source | destination | supported |
| :-- | :-- | :-- | :-- |
| true | first | last | **yes** |
| true | first | last | **yes** |
| true | first | any | **yes** |
| true | any | last | **yes** |
| true | any | any | **yes** |
+3 -80
View File
@@ -25,19 +25,6 @@ As you scroll down the file you'll see local variables, and then local functions
`way_function` and `node_function` are the important functions which are called when extracting OpenStreetMap data with `osrm-extract`.
The following global properties can be set in your profile:
Attribute | Type | Notes
------------------------------|----------|----------------------------------------------------------------------------
weight_name | String | Name used in output for the routing weight property (default 'duration')
weight_precision | Unsigned | Decimal precision of edge weights (default 1)
left_hand_driving | Boolean | Are vehicles assumed to drive on the left? (used in guidance)
use_turn_restrictions | Boolean | Are turn instructions followed?
continue_straight_at_waypoint | Boolean | Must the route continue straight on at a via point, or are U-turns allowed?
max_speed_for_map_matching | Float | Maximum vehicle speed to be assumed in matching (in m/s)
max_turn_weight | Float | Maximum turn penalty weight
force_split_edges | Boolean | True value forces a split of forward and backward edges of extracted ways and guarantees that segment_function will be called for all segments
## way_function
Given an OpenStreetMap way, the way_function will either return nothing (meaning we are not going to route over this way at all), or it will set up a result hash to be returned. The most important thing it will do is set the value of `result.forward_speed` and `result.backward_speed` as a suitable integer value representing the speed for traversing the way.
@@ -46,79 +33,15 @@ All other calculations stem from that, including the returned timings in driving
Using the power of the scripting language you wouldn't typically see something as simple as a `result.forward_speed = 20` line within the way_function. Instead a way_function will examine the tagging (e.g. `way:get_value_by_key("highway")` and many others), process this information in various ways, calling other local functions, referencing the global variables and look-up hashes, before arriving at the result.
The following attributes can be set on the result in way_function:
Attribute | Type | Notes
----------------------------------------|----------|--------------------------------------------------------------------------
forward_speed | Float | Speed on this way in km/h
backward_speed | Float | " "
forward_rate | Float | Routing weight, expressed as meters/*weight* (e.g. for a fastest-route weighting, you would want this to be meters/second, so set it to forward_speed/3.6)
backward_rate | Float | " "
forward_mode | Enum | Mode of travel (e.g. car, ferry). Defined in include/extractor/travel_mode.hpp
backward_mode | Enum | " "
duration | Float | Alternative setter for duration of the whole way in both directions
weight | Float | Alternative setter for weight of the whole way in both directions
turn_lanes_forward | String | Directions for individual lanes (normalised OSM turn:lanes value)
turn_lanes_backward | String | " "
forward_restricted | Boolean | Is this a restricted access road? (e.g. private, or deliveries only; used to enable high turn penalty, so that way is only chosen for start/end of route)
backward_restricted | Boolean | " "
is_startpoint | Boolean | Can a journey start on this way? (e.g. ferry; if false, prevents snapping the start point to this way)
roundabout | Boolean | Is this part of a roundabout?
circular | Boolean | Is this part of a non-roundabout circular junction?
name | String | Name of the way
ref | String | Road number
pronunciation | String | Name pronunciation
road_classification.motorway_class | Boolean | Guidance: way is a motorway
road_classification.link_class | Boolean | Guidance: way is a slip/link road
road_classification.road_priority_class | Enum | Guidance: order in priority list. Defined in include/extractor/guidance/road_classification.hpp
road_classification.may_be_ignored | Boolean | Guidance: way is non-highway
road_classification.num_lanes | Unsigned | Guidance: total number of lanes in way
### Guidance
## Guidance
The guidance parameters in profiles are currently a work in progress. They can and will change.
Please be aware of this when using guidance configuration possibilities.
### Road Classification
Guidance uses road classes to decide on when/if to emit specific instructions and to discover which road is obvious when following a route.
Classification uses three flags and a priority-category.
The flags indicate whether a road is a motorway (required for on/off ramps), a link type (the ramps itself, if also a motorway) and whether a road may be omittted in considerations (is considered purely for connectivity).
The priority-category influences the decision which road is considered the obvious choice and which roads can be seen as fork.
Forks can be emitted between roads of similar priority category only. Obvious choices follow a major priority road, if the priority difference is large.
## node_function
The following attributes can be set on the result in node_function:
Attribute | Type | Notes
----------------|---------|-------------------------------------------------------
barrier | Boolean | Is it an impassable barrier?
traffic_lights | Boolean | Is it a traffic light (incurs delay in turn_function)?
## segment_function
The following attributes can be read and set on the result in segment_function:
Attribute | Read/write? | Type | Notes
-------------------|-------------|---------|------------------------------------------------------
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
weight | Read/write | Float | Routing weight for this segment
duration | Read/write | Float | Duration for this segment
## turn_function
The following attributes can be read and set on the result in turn_function:
Attribute | Read/write? | Type | Notes
-------------------|-------------|---------|------------------------------------------------------
direction_modifier | Read | Enum | Geometry of turn. Defined in include/extractor/guidance/turn_instruction.hpp
turn_type | Read | Enum | Priority of turn. Defined in include/extractor/guidance/turn_instruction.hpp
has_traffic_light | Read | Boolean | Is a traffic light present at this turn?
source_restricted | Read | Boolean | Is it from a restricted access road? (See definition in way_function)
target_restricted | Read | Boolean | Is it to a restricted access road? (See definition in way_function)
angle | Read | Float | Angle of turn in degrees (0-360: 0=u-turn, 180=straight on)
duration | Read/write | Float | Penalty to be applied for this turn (duration in deciseconds)
weight | Read/write | Float | Penalty to be applied for this turn (routing weight)
+9 -13
View File
@@ -32,25 +32,21 @@ We may introduce forward-compatible changes: query parameters and response prope
- The `master` branch is for the bleeding edge development
- We create and maintain release branches `x.y` to control the release flow
- We create the release branch once we create release branches once we want to release the first RC
- RCs go in the release branch, commits needs to be cherry-picked from master
- We create the release branch once we tagged the final version `x.y.0` version, RCs go on master
- No minor or major version will be released without a code-equal release candidates
- For quality assurance, release candidates need to be staged beforing tagging a final release
- For quality assurance, release candidates will be run on the demo server for 24 hours before releaseing the version proper
- Patch versions may be released without a release candidate
- We may backport fixes to older versions and release them as patch versions
## Releasing a version
1. Check out the appropriate release branch `x.y`
2. Make sure `CHANGELOG.md` is up to date.
3. Make sure the OSRM version in `CMakeLists.txt` is up to date
4. Make sure the `package.json` is up to date.
5. Make sure all tests are passing (e.g. Travis CI gives you a :thumbs_up:)
6. Use an annotated tag to mark the release: `git tag vx.y.z -a` Body of the tag description should be the changelog entries.
7. Use `npm run build-api-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
8. Push tags and commits: `git push; git push --tags`
2. Make sure all tests are passing (e.g. Travis CI gives you a :thumbs_up:)
3. Make sure `CHANGELOG.md` is up to date.
4. Make sure the OSRM version in `CMakeLists.txt` is up to date
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.
6. Use `npm run build-api-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
6. Push tags and commits: `git push; git push --tags`
8. Proceede with the `node-osrm` release as [outlined in the repository](https://github.com/Project-OSRM/node-osrm/blob/master/docs/releasing.md).
9. If not a release-candidate: Write a mailing-list post to osrm-talk@openstreetmap.org to announce the release
10. Wait until the travis build has been completed and check if the node binaries were published by doing:
`rm -rf node_modules && npm install` locally.
11. For final releases run `npm publish` or `npm publish --tag next` for release candidates.
-16
View File
@@ -79,19 +79,3 @@ Feature: Bike - Cycle tracks/lanes
| residential | lane | yes | x | x |
| footway | lane | yes | x | x |
| cycleway | lane | yes | x | x |
Scenario: Bike - Cycleway on oneways, modes
Then routability should be
| highway | cycleway | oneway | forw | backw |
| motorway | track | yes | cycling | |
| residential | track | yes | cycling | pushing bike |
| cycleway | track | yes | cycling | pushing bike |
| footway | track | yes | pushing bike | pushing bike |
Scenario: Bike - Cycleway on oneways, speeds
Then routability should be
| highway | cycleway | oneway | forw | backw |
| motorway | track | yes | 15 km/h | |
| residential | track | yes | 15 km/h | 6 km/h |
| cycleway | track | yes | 15 km/h | 6 km/h |
| footway | track | yes | 6 km/h +-1 | 6 km/h +-1 |
+3 -3
View File
@@ -10,11 +10,11 @@ Feature: osrm-partition command line options: help
And stdout should contain "--help"
And stdout should contain "Configuration:"
And stdout should contain "--threads"
And stdout should contain "--min-cell-size"
And stdout should contain "--balance"
And stdout should contain "--boundary"
And stdout should contain "--optimizing-cuts"
And stdout should contain "--small-component-size"
And stdout should contain "--max-cell-sizes"
And it should exit with an error
Scenario: osrm-partition - Help, short
@@ -26,11 +26,11 @@ Feature: osrm-partition command line options: help
And stdout should contain "--help"
And stdout should contain "Configuration:"
And stdout should contain "--threads"
And stdout should contain "--min-cell-size"
And stdout should contain "--balance"
And stdout should contain "--boundary"
And stdout should contain "--optimizing-cuts"
And stdout should contain "--small-component-size"
And stdout should contain "--max-cell-sizes"
And it should exit successfully
Scenario: osrm-partition - Help, long
@@ -42,9 +42,9 @@ Feature: osrm-partition command line options: help
And stdout should contain "--help"
And stdout should contain "Configuration:"
And stdout should contain "--threads"
And stdout should contain "--min-cell-size"
And stdout should contain "--balance"
And stdout should contain "--boundary"
And stdout should contain "--optimizing-cuts"
And stdout should contain "--small-component-size"
And stdout should contain "--max-cell-sizes"
And it should exit successfully
@@ -18,15 +18,3 @@ Feature: osrm-partition command line options: invalid options
And stderr should contain "option"
And stderr should contain "fly-me-to-the-moon"
And it should exit with an error
Scenario: osrm-partition - Check invalid values
When I try to run "osrm-partition --max-cell-sizes 4,6@4,16 fly-me-to-the-moon.osrm"
Then stdout should be empty
And stderr should contain "is invalid"
And it should exit with an error
Scenario: osrm-partition - Check non-descending order
When I try to run "osrm-partition --max-cell-sizes 4,64,16 fly-me-to-the-moon.osrm"
Then stdout should be empty
And stderr should contain "must be sorted in non-descending order"
And it should exit with an error
+4 -6
View File
@@ -2,10 +2,10 @@
Feature: osrm-extract with a profile containing raster source
Scenario: osrm-extract on a valid profile
Given the profile "rasterbot"
And the node locations
| node | lat | lon |
| a | 0.1 | 0.1 |
| b | 0.05 | 0.1 |
And the node map
"""
a b
"""
And the ways
| nodes |
| ab |
@@ -20,6 +20,4 @@ Feature: osrm-extract with a profile containing raster source
And the data has been saved to disk
When I run "osrm-extract {osm_file} -p {profile_file}"
Then stdout should contain "source loader"
Then stdout should contain "slope: 0.0899"
Then stdout should contain "slope: -0.0899"
And it should exit successfully
+2 -3
View File
@@ -50,9 +50,8 @@ Feature: Raster - weights
And I route I should get
| from | to | route | speed |
| a | b | ab,ab | 8 km/h |
| b | a | ab,ab | 22 km/h |
| a | c | ab,bc,bc | 12 km/h |
| b | c | bc,bc | 22 km/h |
| a | c | ad,dc,dc | 15 km/h |
| b | c | bc,bc | 8 km/h |
| a | d | ad,ad | 15 km/h |
| d | c | dc,dc | 15 km/h |
| d | e | de,de | 10 km/h |
+2 -1
View File
@@ -175,7 +175,8 @@ module.exports = function () {
if (headers.has('matchings')) {
if (subMatchings.length != row.matchings.split(',').length) {
return cb(new Error('*** table matchings and api response are not the same'));
ok = false;
cb(new Error('*** table matchings and api response are not the same'));
}
row.matchings.split(',').forEach((sub, si) => {
-78
View File
@@ -40,84 +40,6 @@ Feature: Basic Map Matching
| trace | timestamps | matchings |
| abcd | 0 1 62 63 | ab,cd |
Scenario: Testbot - Map matching with trace splitting suppression
Given the query options
| gaps | ignore |
Given the node map
"""
a b c d
e
"""
And the ways
| nodes | oneway |
| abcd | no |
When I match I should get
| trace | timestamps | matchings |
| abcd | 0 1 62 63 | abcd |
Scenario: Testbot - Map matching with trace tidying. Clean case.
Given a grid size of 100 meters
Given the query options
| tidy | true |
Given the node map
"""
a b c d
e
"""
And the ways
| nodes | oneway |
| abcd | no |
When I match I should get
| trace | timestamps | matchings |
| abcd | 0 10 20 30 | abcd |
Scenario: Testbot - Map matching with trace tidying. Dirty case by ts.
Given a grid size of 100 meters
Given the query options
| tidy | true |
Given the node map
"""
a b c d
e
"""
And the ways
| nodes | oneway |
| abcd | no |
When I match I should get
| trace | timestamps | matchings |
| abacd | 0 10 12 20 30 | abcd |
Scenario: Testbot - Map matching with trace tidying. Dirty case by dist.
Given a grid size of 8 meters
Given the query options
| tidy | true |
Given the node map
"""
a q b c d
e
"""
And the ways
| nodes | oneway |
| aqbcd | no |
When I match I should get
| trace | matchings |
| abcbd | abbd |
Scenario: Testbot - Map matching with core factor
Given the contract extra arguments "--core 0.8"
Given the node map
+5 -3
View File
@@ -3,7 +3,7 @@ Feature: Multi level routing
Background:
Given the profile "testbot"
And the partition extra arguments "--small-component-size 1 --max-cell-sizes 4,16,64"
And the partition extra arguments "--min-cell-size 4 --small-component-size 1"
Scenario: Testbot - Multi level routing check partition
Given the node map
@@ -31,7 +31,7 @@ Feature: Multi level routing
| be | primary |
And the data has been extracted
When I run "osrm-partition --max-cell-sizes 4,16 --small-component-size 1 {processed_file}"
When I run "osrm-partition --min-cell-size 4 --small-component-size 1 {processed_file}"
Then it should exit successfully
And stdout should not contain "level 1 #cells 1 bit size 1"
@@ -57,6 +57,7 @@ Feature: Multi level routing
| cm | primary |
| hj | primary |
| kp | primary |
And the partition extra arguments "--min-cell-size 4 --small-component-size 1"
When I route I should get
| from | to | route | time |
@@ -87,6 +88,7 @@ Feature: Multi level routing
| dim | primary |
| glr | primary |
| ot | secondary |
And the partition extra arguments "--min-cell-size 4 --small-component-size 1"
When I route I should get
| from | to | route | time |
@@ -111,7 +113,6 @@ Feature: Multi level routing
lk
"""
And the partition extra arguments "--small-component-size 1 --max-cell-sizes 4,16"
And the ways
| nodes | maxspeed |
| abcda | 5 |
@@ -123,6 +124,7 @@ Feature: Multi level routing
| fi | 15 |
| gi | 15 |
| hf | 100 |
And the partition extra arguments "--min-cell-size 4 --small-component-size 1"
When I route I should get
| from | to | route | time |
+3 -2
View File
@@ -68,8 +68,9 @@ class Contractor
void WriteCoreNodeMarker(std::vector<bool> &&is_core_node) const;
void WriteNodeLevels(std::vector<float> &&node_levels) const;
void ReadNodeLevels(std::vector<float> &contraction_order) const;
void WriteContractedGraph(unsigned number_of_edge_based_nodes,
util::DeallocatingVector<QueryEdge> contracted_edge_list);
std::size_t
WriteContractedGraph(unsigned number_of_edge_based_nodes,
const util::DeallocatingVector<QueryEdge> &contracted_edge_list);
void FindComponents(unsigned max_edge_id,
const util::DeallocatingVector<extractor::EdgeBasedEdge> &edges,
std::vector<extractor::EdgeBasedNode> &nodes) const;
-50
View File
@@ -1,50 +0,0 @@
#ifndef OSRM_CONTRACTOR_FILES_HPP
#define OSRM_CONTRACTOR_FILES_HPP
#include "contractor/query_graph.hpp"
#include "util/serialization.hpp"
#include "storage/io.hpp"
namespace osrm
{
namespace contractor
{
namespace files
{
// reads .osrm.hsgr file
template <typename QueryGraphT>
inline void readGraph(const boost::filesystem::path &path, unsigned &checksum, QueryGraphT &graph)
{
static_assert(std::is_same<QueryGraphView, QueryGraphT>::value ||
std::is_same<QueryGraph, QueryGraphT>::value,
"graph must be of type QueryGraph<>");
const auto fingerprint = storage::io::FileReader::VerifyFingerprint;
storage::io::FileReader reader{path, fingerprint};
reader.ReadInto(checksum);
util::serialization::read(reader, graph);
}
// writes .osrm.hsgr file
template <typename QueryGraphT>
inline void
writeGraph(const boost::filesystem::path &path, unsigned checksum, const QueryGraphT &graph)
{
static_assert(std::is_same<QueryGraphView, QueryGraphT>::value ||
std::is_same<QueryGraph, QueryGraphT>::value,
"graph must be of type QueryGraph<>");
const auto fingerprint = storage::io::FileWriter::GenerateFingerprint;
storage::io::FileWriter writer{path, fingerprint};
writer.WriteOne(checksum);
util::serialization::write(writer, graph);
}
}
}
}
#endif
-25
View File
@@ -1,25 +0,0 @@
#ifndef OSRM_CONTRACTOR_QUERY_GRAPH_HPP
#define OSRM_CONTRACTOR_QUERY_GRAPH_HPP
#include "contractor/query_edge.hpp"
#include "util/static_graph.hpp"
#include "util/typedefs.hpp"
namespace osrm
{
namespace contractor
{
namespace detail
{
template <storage::Ownership Ownership>
using QueryGraph = util::StaticGraph<typename QueryEdge::EdgeData, Ownership>;
}
using QueryGraph = detail::QueryGraph<storage::Ownership::Container>;
using QueryGraphView = detail::QueryGraph<storage::Ownership::View>;
}
}
#endif // QUERYEDGE_HPP
+32 -53
View File
@@ -5,8 +5,7 @@
#include "partition/multi_level_partition.hpp"
#include "util/binary_heap.hpp"
#include <tbb/enumerable_thread_specific.h>
#include <boost/thread/tss.hpp>
#include <unordered_set>
namespace osrm
@@ -16,22 +15,12 @@ namespace customizer
class CellCustomizer
{
private:
struct HeapData
{
bool from_clique;
};
public:
using Heap =
util::BinaryHeap<NodeID, NodeID, EdgeWeight, HeapData, util::ArrayStorage<NodeID, int>>;
using HeapPtr = tbb::enumerable_thread_specific<Heap>;
CellCustomizer(const partition::MultiLevelPartition &partition) : partition(partition) {}
template <typename GraphT>
void Customize(
const GraphT &graph, Heap &heap, partition::CellStorage &cells, LevelID level, CellID id)
void Customize(const GraphT &graph, partition::CellStorage &cells, LevelID level, CellID id)
{
auto cell = cells.GetCell(level, id);
auto destinations = cell.GetDestinationNodes();
@@ -40,8 +29,8 @@ class CellCustomizer
for (auto source : cell.GetSourceNodes())
{
std::unordered_set<NodeID> destinations_set(destinations.begin(), destinations.end());
heap.Clear();
heap.Insert(source, 0, {false});
Heap heap(graph.GetNumberOfNodes());
heap.Insert(source, 0, {});
// explore search space
while (!heap.Empty() && !destinations_set.empty())
@@ -50,9 +39,9 @@ class CellCustomizer
const EdgeWeight weight = heap.GetKey(node);
if (level == 1)
RelaxNode<true>(graph, cells, heap, level, node, weight);
RelaxNode<true>(graph, cells, heap, level, id, node, weight);
else
RelaxNode<false>(graph, cells, heap, level, node, weight);
RelaxNode<false>(graph, cells, heap, level, id, node, weight);
destinations_set.erase(node);
}
@@ -71,67 +60,58 @@ class CellCustomizer
template <typename GraphT> void Customize(const GraphT &graph, partition::CellStorage &cells)
{
Heap heap_exemplar(graph.GetNumberOfNodes());
HeapPtr heaps(heap_exemplar);
for (std::size_t level = 1; level < partition.GetNumberOfLevels(); ++level)
{
tbb::parallel_for(tbb::blocked_range<std::size_t>(0, partition.GetNumberOfCells(level)),
[&](const tbb::blocked_range<std::size_t> &range) {
auto &heap = heaps.local();
for (auto id = range.begin(), end = range.end(); id != end; ++id)
{
Customize(graph, heap, cells, level, id);
Customize(graph, cells, level, id);
}
});
}
}
private:
struct HeapData
{
};
using Heap = util::
BinaryHeap<NodeID, NodeID, EdgeWeight, HeapData, util::UnorderedMapStorage<NodeID, int>>;
using HeapPtr = boost::thread_specific_ptr<Heap>;
template <bool first_level, typename GraphT>
void RelaxNode(const GraphT &graph,
const partition::CellStorage &cells,
Heap &heap,
LevelID level,
CellID id,
NodeID node,
EdgeWeight weight) const
{
BOOST_ASSERT(heap.WasInserted(node));
if (!first_level)
{
// if we reaches this node from a clique arc we don't need to scan
// the clique arcs again because of the triangle inequality
//
// d(parent, node) + d(node, v) >= d(parent, v)
//
// And if there is a path (parent, node, v) there must also be a
// clique arc (parent, v) with d(parent, v).
if (!heap.GetData(node).from_clique)
// Relax sub-cell nodes
auto subcell_id = partition.GetCell(level - 1, node);
auto subcell = cells.GetCell(level - 1, subcell_id);
auto subcell_destination = subcell.GetDestinationNodes().begin();
for (auto subcell_weight : subcell.GetOutWeight(node))
{
// Relax sub-cell nodes
auto subcell_id = partition.GetCell(level - 1, node);
auto subcell = cells.GetCell(level - 1, subcell_id);
auto subcell_destination = subcell.GetDestinationNodes().begin();
for (auto subcell_weight : subcell.GetOutWeight(node))
if (subcell_weight != INVALID_EDGE_WEIGHT)
{
if (subcell_weight != INVALID_EDGE_WEIGHT)
const NodeID to = *subcell_destination;
const EdgeWeight to_weight = subcell_weight + weight;
if (!heap.WasInserted(to))
{
const NodeID to = *subcell_destination;
const EdgeWeight to_weight = subcell_weight + weight;
if (!heap.WasInserted(to))
{
heap.Insert(to, to_weight, {true});
}
else if (to_weight < heap.GetKey(to))
{
heap.DecreaseKey(to, to_weight);
heap.GetData(to).from_clique = true;
}
heap.Insert(to, to_weight, {});
}
else if (to_weight < heap.GetKey(to))
{
heap.DecreaseKey(to, to_weight);
}
++subcell_destination;
}
++subcell_destination;
}
}
@@ -147,12 +127,11 @@ class CellCustomizer
const EdgeWeight to_weight = data.weight + weight;
if (!heap.WasInserted(to))
{
heap.Insert(to, to_weight, {false});
heap.Insert(to, to_weight, {});
}
else if (to_weight < heap.GetKey(to))
{
heap.DecreaseKey(to, to_weight);
heap.GetData(to).from_clique = false;
}
}
}
+4 -7
View File
@@ -7,8 +7,6 @@
#include "util/static_graph.hpp"
#include "util/typedefs.hpp"
#include "storage/shared_memory_ownership.hpp"
#include <boost/filesystem/path.hpp>
namespace osrm
@@ -18,17 +16,16 @@ namespace customizer
using EdgeBasedGraphEdgeData = partition::EdgeBasedGraphEdgeData;
struct MultiLevelEdgeBasedGraph
: public partition::MultiLevelGraph<EdgeBasedGraphEdgeData, storage::Ownership::Container>
struct MultiLevelEdgeBasedGraph : public partition::MultiLevelGraph<EdgeBasedGraphEdgeData, false>
{
using Base = partition::MultiLevelGraph<EdgeBasedGraphEdgeData, storage::Ownership::Container>;
using Base = partition::MultiLevelGraph<EdgeBasedGraphEdgeData, false>;
using Base::Base;
};
struct MultiLevelEdgeBasedGraphView
: public partition::MultiLevelGraph<EdgeBasedGraphEdgeData, storage::Ownership::View>
: public partition::MultiLevelGraph<EdgeBasedGraphEdgeData, true>
{
using Base = partition::MultiLevelGraph<EdgeBasedGraphEdgeData, storage::Ownership::View>;
using Base = partition::MultiLevelGraph<EdgeBasedGraphEdgeData, true>;
using Base::Base;
};
+18
View File
@@ -0,0 +1,18 @@
#ifndef OSRM_CUSTOMIZER_IO_HPP
#define OSRM_CUSTOMIZER_IO_HPP
#include "customizer/edge_based_graph.hpp"
#include "storage/io.hpp"
namespace osrm
{
namespace customizer
{
namespace io
{
}
}
}
#endif
+41 -34
View File
@@ -7,36 +7,30 @@ namespace osrm
{
namespace engine
{
namespace routing_algorithms
namespace algorithm
{
// Contraction Hiearchy
namespace ch
{
struct Algorithm final
struct CH final
{
};
}
// Contraction Hiearchy with core
namespace corech
{
struct Algorithm final
struct CoreCH final
{
};
}
// Multi-Level Dijkstra
namespace mld
{
struct Algorithm final
struct MLD final
{
};
template <typename AlgorithmT> const char *name();
template <> inline const char *name<CH>() { return "CH"; }
template <> inline const char *name<CoreCH>() { return "CoreCH"; }
template <> inline const char *name<MLD>() { return "MLD"; }
}
// Algorithm names
template <typename AlgorithmT> const char *name();
template <> inline const char *name<ch::Algorithm>() { return "CH"; }
template <> inline const char *name<corech::Algorithm>() { return "CoreCH"; }
template <> inline const char *name<mld::Algorithm>() { return "MLD"; }
namespace algorithm_trais
{
template <typename AlgorithmT> struct HasAlternativePathSearch final : std::false_type
{
@@ -57,49 +51,62 @@ template <typename AlgorithmT> struct HasGetTileTurns final : std::false_type
{
};
// Algorithms supported by Contraction Hierarchies
template <> struct HasAlternativePathSearch<ch::Algorithm> final : std::true_type
template <> struct HasAlternativePathSearch<algorithm::CH> final : std::true_type
{
};
template <> struct HasShortestPathSearch<ch::Algorithm> final : std::true_type
template <> struct HasShortestPathSearch<algorithm::CH> final : std::true_type
{
};
template <> struct HasDirectShortestPathSearch<ch::Algorithm> final : std::true_type
template <> struct HasDirectShortestPathSearch<algorithm::CH> final : std::true_type
{
};
template <> struct HasMapMatching<ch::Algorithm> final : std::true_type
template <> struct HasMapMatching<algorithm::CH> final : std::true_type
{
};
template <> struct HasManyToManySearch<ch::Algorithm> final : std::true_type
template <> struct HasManyToManySearch<algorithm::CH> final : std::true_type
{
};
template <> struct HasGetTileTurns<ch::Algorithm> final : std::true_type
template <> struct HasGetTileTurns<algorithm::CH> final : std::true_type
{
};
// Algorithms supported by Contraction Hierarchies with core
// the rest is disabled because of performance reasons
template <> struct HasShortestPathSearch<corech::Algorithm> final : std::true_type
// disbaled because of perfomance reasons
template <> struct HasAlternativePathSearch<algorithm::CoreCH> final : std::false_type
{
};
template <> struct HasDirectShortestPathSearch<corech::Algorithm> final : std::true_type
template <> struct HasManyToManySearch<algorithm::CoreCH> final : std::false_type
{
};
template <> struct HasMapMatching<corech::Algorithm> final : std::true_type
template <> struct HasShortestPathSearch<algorithm::CoreCH> final : std::true_type
{
};
template <> struct HasGetTileTurns<corech::Algorithm> final : std::true_type
template <> struct HasDirectShortestPathSearch<algorithm::CoreCH> final : std::true_type
{
};
template <> struct HasMapMatching<algorithm::CoreCH> final : std::true_type
{
};
template <> struct HasGetTileTurns<algorithm::CoreCH> final : std::true_type
{
};
// Algorithms supported by Multi-Level Dijkstra
template <> struct HasDirectShortestPathSearch<mld::Algorithm> final : std::true_type
// disbaled because of perfomance reasons
template <> struct HasAlternativePathSearch<algorithm::MLD> final : std::false_type
{
};
template <> struct HasShortestPathSearch<mld::Algorithm> final : std::true_type
template <> struct HasManyToManySearch<algorithm::MLD> final : std::false_type
{
};
template <> struct HasMapMatching<mld::Algorithm> final : std::true_type
template <> struct HasShortestPathSearch<algorithm::MLD> final : std::false_type
{
};
template <> struct HasDirectShortestPathSearch<algorithm::MLD> final : std::true_type
{
};
template <> struct HasMapMatching<algorithm::MLD> final : std::false_type
{
};
template <> struct HasGetTileTurns<algorithm::MLD> final : std::false_type
{
};
}
+3 -14
View File
@@ -2,7 +2,6 @@
#define ENGINE_API_MATCH_HPP
#include "engine/api/match_parameters.hpp"
#include "engine/api/match_parameters_tidy.hpp"
#include "engine/api/route_api.hpp"
#include "engine/datafacade/datafacade_base.hpp"
@@ -22,10 +21,8 @@ namespace api
class MatchAPI final : public RouteAPI
{
public:
MatchAPI(const datafacade::BaseDataFacade &facade_,
const MatchParameters &parameters_,
const tidy::Result &tidy_result_)
: RouteAPI(facade_, parameters_), parameters(parameters_), tidy_result(tidy_result_)
MatchAPI(const datafacade::BaseDataFacade &facade_, const MatchParameters &parameters_)
: RouteAPI(facade_, parameters_), parameters(parameters_)
{
}
@@ -86,20 +83,13 @@ class MatchAPI final : public RouteAPI
for (auto point_index : util::irange(
0u, static_cast<unsigned>(sub_matchings[sub_matching_index].indices.size())))
{
trace_idx_to_matching_idx[tidy_result
.tidied_to_original[sub_matchings[sub_matching_index]
.indices[point_index]]] =
trace_idx_to_matching_idx[sub_matchings[sub_matching_index].indices[point_index]] =
MatchingIndex{sub_matching_index, point_index};
}
}
for (auto trace_index : util::irange<std::size_t>(0UL, parameters.coordinates.size()))
{
if (tidy_result.can_be_removed[trace_index])
{
waypoints.values.push_back(util::json::Null());
continue;
}
auto matching_index = trace_idx_to_matching_idx[trace_index];
if (matching_index.NotMatched())
{
@@ -121,7 +111,6 @@ class MatchAPI final : public RouteAPI
}
const MatchParameters &parameters;
const tidy::Result &tidy_result;
};
} // ns api
+3 -14
View File
@@ -50,34 +50,23 @@ namespace api
*/
struct MatchParameters : public RouteParameters
{
enum class GapsType
{
Split,
Ignore
};
MatchParameters()
: RouteParameters(false,
false,
false,
RouteParameters::GeometriesType::Polyline,
RouteParameters::OverviewType::Simplified,
{}),
gaps(GapsType::Split), tidy(false)
{})
{
}
template <typename... Args>
MatchParameters(std::vector<unsigned> timestamps_, GapsType gaps_, bool tidy_, Args... args_)
: RouteParameters{std::forward<Args>(args_)...}, timestamps{std::move(timestamps_)},
gaps(gaps_), tidy(tidy_)
MatchParameters(std::vector<unsigned> timestamps_, Args... args_)
: RouteParameters{std::forward<Args>(args_)...}, timestamps{std::move(timestamps_)}
{
}
std::vector<unsigned> timestamps;
GapsType gaps;
bool tidy;
bool IsValid() const
{
return RouteParameters::IsValid() &&
@@ -1,167 +0,0 @@
#ifndef COORDINATE_TIDY
#define COORDINATE_TIDY
#include <algorithm>
#include <cstdint>
#include <iterator>
#include "engine/api/match_parameters.hpp"
#include "util/coordinate_calculation.hpp"
#include <boost/assert.hpp>
#include <boost/dynamic_bitset.hpp>
namespace osrm
{
namespace engine
{
namespace api
{
namespace tidy
{
struct Thresholds
{
double distance_in_meters;
std::int32_t duration_in_seconds;
};
using Mask = boost::dynamic_bitset<>;
using Mapping = std::vector<std::size_t>;
struct Result
{
// Tidied parameters
MatchParameters parameters;
// Masking the MatchParameter parallel arrays for items which should be removed.
Mask can_be_removed;
// Maps the MatchParameter's original items to items which should not be removed.
Mapping tidied_to_original;
};
inline Result keep_all(const MatchParameters &params)
{
Result result;
result.can_be_removed.resize(params.coordinates.size(), false);
result.tidied_to_original.reserve(params.coordinates.size());
for (std::size_t current = 0; current < params.coordinates.size(); ++current)
{
result.tidied_to_original.push_back(current);
}
BOOST_ASSERT(result.can_be_removed.size() == params.coordinates.size());
// We have to filter parallel arrays that may be empty or the exact same size.
// result.parameters contains an empty MatchParameters at this point: conditionally fill.
for (std::size_t i = 0; i < result.can_be_removed.size(); ++i)
{
if (!result.can_be_removed[i])
{
result.parameters.coordinates.push_back(params.coordinates[i]);
if (!params.hints.empty())
result.parameters.hints.push_back(params.hints[i]);
if (!params.radiuses.empty())
result.parameters.radiuses.push_back(params.radiuses[i]);
if (!params.bearings.empty())
result.parameters.bearings.push_back(params.bearings[i]);
if (!params.timestamps.empty())
result.parameters.timestamps.push_back(params.timestamps[i]);
}
}
return result;
}
inline Result tidy(const MatchParameters &params, Thresholds cfg = {15., 5})
{
Result result;
result.can_be_removed.resize(params.coordinates.size(), false);
result.tidied_to_original.push_back(0);
const auto uses_timestamps = !params.timestamps.empty();
Thresholds running{0., 0};
// Walk over adjacent (coord, ts)-pairs, with rhs being the candidate to discard or keep
for (std::size_t current = 0; current < params.coordinates.size() - 1; ++current)
{
const auto next = current + 1;
auto distance_delta = util::coordinate_calculation::haversineDistance(
params.coordinates[current], params.coordinates[next]);
running.distance_in_meters += distance_delta;
const auto over_distance = running.distance_in_meters >= cfg.distance_in_meters;
if (uses_timestamps)
{
auto duration_delta = params.timestamps[next] - params.timestamps[current];
running.duration_in_seconds += duration_delta;
const auto over_duration = running.duration_in_seconds >= cfg.duration_in_seconds;
if (over_distance && over_duration)
{
result.tidied_to_original.push_back(next);
running = {0., 0}; // reset running distance and time
}
else
{
result.can_be_removed.set(next, true);
}
}
else
{
if (over_distance)
{
result.tidied_to_original.push_back(next);
running = {0., 0}; // reset running distance and time
}
else
{
result.can_be_removed.set(next, true);
}
}
}
BOOST_ASSERT(result.can_be_removed.size() == params.coordinates.size());
// We have to filter parallel arrays that may be empty or the exact same size.
// result.parameters contains an empty MatchParameters at this point: conditionally fill.
for (std::size_t i = 0; i < result.can_be_removed.size(); ++i)
{
if (!result.can_be_removed[i])
{
result.parameters.coordinates.push_back(params.coordinates[i]);
if (!params.hints.empty())
result.parameters.hints.push_back(params.hints[i]);
if (!params.radiuses.empty())
result.parameters.radiuses.push_back(params.radiuses[i]);
if (!params.bearings.empty())
result.parameters.bearings.push_back(params.bearings[i]);
if (!params.timestamps.empty())
result.parameters.timestamps.push_back(params.timestamps[i]);
}
}
BOOST_ASSERT(result.tidied_to_original.size() == result.parameters.coordinates.size());
return result;
}
} // ns tidy
} // ns api
} // ns engine
} // ns osrm
#endif
@@ -17,16 +17,11 @@ namespace engine
namespace datafacade
{
// Namespace local aliases for algorithms
using CH = routing_algorithms::ch::Algorithm;
using CoreCH = routing_algorithms::corech::Algorithm;
using MLD = routing_algorithms::mld::Algorithm;
using EdgeRange = util::range<EdgeID>;
template <typename AlgorithmT> class AlgorithmDataFacade;
template <> class AlgorithmDataFacade<CH>
template <> class AlgorithmDataFacade<algorithm::CH>
{
public:
using EdgeData = contractor::QueryEdge::EdgeData;
@@ -61,7 +56,7 @@ template <> class AlgorithmDataFacade<CH>
const std::function<bool(EdgeData)> filter) const = 0;
};
template <> class AlgorithmDataFacade<CoreCH>
template <> class AlgorithmDataFacade<algorithm::CoreCH>
{
public:
using EdgeData = contractor::QueryEdge::EdgeData;
@@ -69,7 +64,7 @@ template <> class AlgorithmDataFacade<CoreCH>
virtual bool IsCoreNode(const NodeID id) const = 0;
};
template <> class AlgorithmDataFacade<MLD>
template <> class AlgorithmDataFacade<algorithm::MLD>
{
public:
using EdgeData = extractor::EdgeBasedEdge::EdgeData;
@@ -15,15 +15,11 @@
#include "extractor/guidance/turn_lane_types.hpp"
#include "extractor/profile_properties.hpp"
#include "extractor/segment_data_container.hpp"
#include "extractor/turn_data_container.hpp"
#include "contractor/query_graph.hpp"
#include "partition/cell_storage.hpp"
#include "partition/multi_level_partition.hpp"
#include "storage/shared_datatype.hpp"
#include "storage/shared_memory_ownership.hpp"
#include "util/exception.hpp"
#include "util/exception_utils.hpp"
@@ -61,14 +57,15 @@ namespace datafacade
template <typename AlgorithmT> class ContiguousInternalMemoryAlgorithmDataFacade;
template <>
class ContiguousInternalMemoryAlgorithmDataFacade<CH> : public datafacade::AlgorithmDataFacade<CH>
class ContiguousInternalMemoryAlgorithmDataFacade<algorithm::CH>
: public datafacade::AlgorithmDataFacade<algorithm::CH>
{
private:
using QueryGraph = contractor::QueryGraphView;
using QueryGraph = util::StaticGraph<EdgeData, true>;
using GraphNode = QueryGraph::NodeArrayEntry;
using GraphEdge = QueryGraph::EdgeArrayEntry;
QueryGraph m_query_graph;
std::unique_ptr<QueryGraph> m_query_graph;
// allocator that keeps the allocation data
std::shared_ptr<ContiguousBlockAllocator> allocator;
@@ -81,11 +78,11 @@ class ContiguousInternalMemoryAlgorithmDataFacade<CH> : public datafacade::Algor
auto graph_edges_ptr = data_layout.GetBlockPtr<GraphEdge>(
memory_block, storage::DataLayout::CH_GRAPH_EDGE_LIST);
util::vector_view<GraphNode> node_list(
util::ShM<GraphNode, true>::vector node_list(
graph_nodes_ptr, data_layout.num_entries[storage::DataLayout::CH_GRAPH_NODE_LIST]);
util::vector_view<GraphEdge> edge_list(
util::ShM<GraphEdge, true>::vector edge_list(
graph_edges_ptr, data_layout.num_entries[storage::DataLayout::CH_GRAPH_EDGE_LIST]);
m_query_graph = QueryGraph(node_list, edge_list);
m_query_graph.reset(new QueryGraph(node_list, edge_list));
}
public:
@@ -102,62 +99,62 @@ class ContiguousInternalMemoryAlgorithmDataFacade<CH> : public datafacade::Algor
}
// search graph access
unsigned GetNumberOfNodes() const override final { return m_query_graph.GetNumberOfNodes(); }
unsigned GetNumberOfNodes() const override final { return m_query_graph->GetNumberOfNodes(); }
unsigned GetNumberOfEdges() const override final { return m_query_graph.GetNumberOfEdges(); }
unsigned GetNumberOfEdges() const override final { return m_query_graph->GetNumberOfEdges(); }
unsigned GetOutDegree(const NodeID n) const override final
{
return m_query_graph.GetOutDegree(n);
return m_query_graph->GetOutDegree(n);
}
NodeID GetTarget(const EdgeID e) const override final { return m_query_graph.GetTarget(e); }
NodeID GetTarget(const EdgeID e) const override final { return m_query_graph->GetTarget(e); }
const EdgeData &GetEdgeData(const EdgeID e) const override final
EdgeData &GetEdgeData(const EdgeID e) const override final
{
return m_query_graph.GetEdgeData(e);
return m_query_graph->GetEdgeData(e);
}
EdgeID BeginEdges(const NodeID n) const override final { return m_query_graph.BeginEdges(n); }
EdgeID BeginEdges(const NodeID n) const override final { return m_query_graph->BeginEdges(n); }
EdgeID EndEdges(const NodeID n) const override final { return m_query_graph.EndEdges(n); }
EdgeID EndEdges(const NodeID n) const override final { return m_query_graph->EndEdges(n); }
EdgeRange GetAdjacentEdgeRange(const NodeID node) const override final
{
return m_query_graph.GetAdjacentEdgeRange(node);
return m_query_graph->GetAdjacentEdgeRange(node);
}
// searches for a specific edge
EdgeID FindEdge(const NodeID from, const NodeID to) const override final
{
return m_query_graph.FindEdge(from, to);
return m_query_graph->FindEdge(from, to);
}
EdgeID FindEdgeInEitherDirection(const NodeID from, const NodeID to) const override final
{
return m_query_graph.FindEdgeInEitherDirection(from, to);
return m_query_graph->FindEdgeInEitherDirection(from, to);
}
EdgeID
FindEdgeIndicateIfReverse(const NodeID from, const NodeID to, bool &result) const override final
{
return m_query_graph.FindEdgeIndicateIfReverse(from, to, result);
return m_query_graph->FindEdgeIndicateIfReverse(from, to, result);
}
EdgeID FindSmallestEdge(const NodeID from,
const NodeID to,
std::function<bool(EdgeData)> filter) const override final
{
return m_query_graph.FindSmallestEdge(from, to, filter);
return m_query_graph->FindSmallestEdge(from, to, filter);
}
};
template <>
class ContiguousInternalMemoryAlgorithmDataFacade<CoreCH>
: public datafacade::AlgorithmDataFacade<CoreCH>
class ContiguousInternalMemoryAlgorithmDataFacade<algorithm::CoreCH>
: public datafacade::AlgorithmDataFacade<algorithm::CoreCH>
{
private:
util::vector_view<bool> m_is_core_node;
util::ShM<bool, true>::vector m_is_core_node;
// allocator that keeps the allocation data
std::shared_ptr<ContiguousBlockAllocator> allocator;
@@ -166,7 +163,7 @@ class ContiguousInternalMemoryAlgorithmDataFacade<CoreCH>
{
auto core_marker_ptr =
data_layout.GetBlockPtr<unsigned>(memory_block, storage::DataLayout::CH_CORE_MARKER);
util::vector_view<bool> is_core_node(
util::ShM<bool, true>::vector is_core_node(
core_marker_ptr, data_layout.num_entries[storage::DataLayout::CH_CORE_MARKER]);
m_is_core_node = std::move(is_core_node);
}
@@ -202,9 +199,10 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
{
private:
using super = BaseDataFacade;
using IndexBlock = util::RangeTable<16, storage::Ownership::View>::BlockT;
using IndexBlock = util::RangeTable<16, true>::BlockT;
using RTreeLeaf = super::RTreeLeaf;
using SharedRTree = util::StaticRTree<RTreeLeaf, storage::Ownership::View>;
using SharedRTree =
util::StaticRTree<RTreeLeaf, util::ShM<util::Coordinate, true>::vector, true>;
using SharedGeospatialQuery = GeospatialQuery<SharedRTree, BaseDataFacade>;
using RTreeNode = SharedRTree::TreeNode;
@@ -213,20 +211,28 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
extractor::Datasources *m_datasources;
unsigned m_check_sum;
util::vector_view<util::Coordinate> m_coordinate_list;
util::PackedVectorView<OSMNodeID> m_osmnodeid_list;
util::ShM<util::Coordinate, true>::vector m_coordinate_list;
util::PackedVector<OSMNodeID, true> m_osmnodeid_list;
util::ShM<GeometryID, true>::vector m_via_geometry_list;
util::ShM<NameID, true>::vector m_name_ID_list;
util::ShM<LaneDataID, true>::vector m_lane_data_id;
util::ShM<extractor::guidance::TurnInstruction, true>::vector m_turn_instruction_list;
util::ShM<extractor::TravelMode, true>::vector m_travel_mode_list;
util::ShM<util::guidance::TurnBearing, true>::vector m_pre_turn_bearing;
util::ShM<util::guidance::TurnBearing, true>::vector m_post_turn_bearing;
util::NameTable m_names_table;
util::vector_view<std::uint32_t> m_lane_description_offsets;
util::vector_view<extractor::guidance::TurnLaneType::Mask> m_lane_description_masks;
util::vector_view<TurnPenalty> m_turn_weight_penalties;
util::vector_view<TurnPenalty> m_turn_duration_penalties;
util::ShM<unsigned, true>::vector m_name_begin_indices;
util::ShM<bool, true>::vector m_is_core_node;
util::ShM<std::uint32_t, true>::vector m_lane_description_offsets;
util::ShM<extractor::guidance::TurnLaneType::Mask, true>::vector m_lane_description_masks;
util::ShM<TurnPenalty, true>::vector m_turn_weight_penalties;
util::ShM<TurnPenalty, true>::vector m_turn_duration_penalties;
extractor::SegmentDataView segment_data;
extractor::TurnDataView turn_data;
util::vector_view<char> m_datasource_name_data;
util::vector_view<std::size_t> m_datasource_name_offsets;
util::vector_view<std::size_t> m_datasource_name_lengths;
util::vector_view<util::guidance::LaneTupleIdPair> m_lane_tupel_id_pairs;
util::ShM<char, true>::vector m_datasource_name_data;
util::ShM<std::size_t, true>::vector m_datasource_name_offsets;
util::ShM<std::size_t, true>::vector m_datasource_name_lengths;
util::ShM<util::guidance::LaneTupleIdPair, true>::vector m_lane_tupel_id_pairs;
std::unique_ptr<SharedRTree> m_static_rtree;
std::unique_ptr<SharedGeospatialQuery> m_geospatial_query;
@@ -234,17 +240,17 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
util::NameTable m_name_table;
// bearing classes by node based node
util::vector_view<BearingClassID> m_bearing_class_id_table;
util::ShM<BearingClassID, true>::vector m_bearing_class_id_table;
// entry class IDs
util::vector_view<EntryClassID> m_entry_class_id_list;
util::ShM<EntryClassID, true>::vector m_entry_class_id_list;
// the look-up table for entry classes. An entry class lists the possibility of entry for all
// available turns. Such a class id is stored with every edge.
util::vector_view<util::guidance::EntryClass> m_entry_class_table;
util::ShM<util::guidance::EntryClass, true>::vector m_entry_class_table;
// the look-up table for distinct bearing classes. A bearing class lists the available bearings
// at an intersection
std::shared_ptr<util::RangeTable<16, storage::Ownership::View>> m_bearing_ranges_table;
util::vector_view<DiscreteBearing> m_bearing_values_table;
std::shared_ptr<util::RangeTable<16, true>> m_bearing_ranges_table;
util::ShM<DiscreteBearing, true>::vector m_bearing_values_table;
// allocator that keeps the allocation data
std::shared_ptr<ContiguousBlockAllocator> allocator;
@@ -297,7 +303,8 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
new SharedGeospatialQuery(*m_static_rtree, m_coordinate_list, *this));
}
void InitializeNodeInformationPointers(storage::DataLayout &data_layout, char *memory_block)
void InitializeNodeAndEdgeInformationPointers(storage::DataLayout &data_layout,
char *memory_block)
{
const auto coordinate_list_ptr = data_layout.GetBlockPtr<util::Coordinate>(
memory_block, storage::DataLayout::COORDINATE_LIST);
@@ -316,59 +323,66 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
// We (ab)use the number of coordinates here because we know we have the same amount of ids
m_osmnodeid_list.set_number_of_entries(
data_layout.num_entries[storage::DataLayout::COORDINATE_LIST]);
}
void InitializeEdgeInformationPointers(storage::DataLayout &layout, char *memory_ptr)
{
auto via_geometry_list_ptr =
layout.GetBlockPtr<GeometryID>(memory_ptr, storage::DataLayout::VIA_NODE_LIST);
util::vector_view<GeometryID> geometry_ids(
via_geometry_list_ptr, layout.num_entries[storage::DataLayout::VIA_NODE_LIST]);
const auto travel_mode_list_ptr =
layout.GetBlockPtr<extractor::TravelMode>(memory_ptr, storage::DataLayout::TRAVEL_MODE);
util::vector_view<extractor::TravelMode> travel_modes(
travel_mode_list_ptr, layout.num_entries[storage::DataLayout::TRAVEL_MODE]);
const auto travel_mode_list_ptr = data_layout.GetBlockPtr<extractor::TravelMode>(
memory_block, storage::DataLayout::TRAVEL_MODE);
util::ShM<extractor::TravelMode, true>::vector travel_mode_list(
travel_mode_list_ptr, data_layout.num_entries[storage::DataLayout::TRAVEL_MODE]);
m_travel_mode_list = std::move(travel_mode_list);
const auto lane_data_id_ptr =
layout.GetBlockPtr<LaneDataID>(memory_ptr, storage::DataLayout::LANE_DATA_ID);
util::vector_view<LaneDataID> lane_data_ids(
lane_data_id_ptr, layout.num_entries[storage::DataLayout::LANE_DATA_ID]);
data_layout.GetBlockPtr<LaneDataID>(memory_block, storage::DataLayout::LANE_DATA_ID);
util::ShM<LaneDataID, true>::vector lane_data_id(
lane_data_id_ptr, data_layout.num_entries[storage::DataLayout::LANE_DATA_ID]);
m_lane_data_id = std::move(lane_data_id);
const auto lane_tupel_id_pair_ptr =
data_layout.GetBlockPtr<util::guidance::LaneTupleIdPair>(
memory_block, storage::DataLayout::TURN_LANE_DATA);
util::ShM<util::guidance::LaneTupleIdPair, true>::vector lane_tupel_id_pair(
lane_tupel_id_pair_ptr, data_layout.num_entries[storage::DataLayout::TURN_LANE_DATA]);
m_lane_tupel_id_pairs = std::move(lane_tupel_id_pair);
const auto turn_instruction_list_ptr =
layout.GetBlockPtr<extractor::guidance::TurnInstruction>(
memory_ptr, storage::DataLayout::TURN_INSTRUCTION);
util::vector_view<extractor::guidance::TurnInstruction> turn_instructions(
turn_instruction_list_ptr, layout.num_entries[storage::DataLayout::TURN_INSTRUCTION]);
data_layout.GetBlockPtr<extractor::guidance::TurnInstruction>(
memory_block, storage::DataLayout::TURN_INSTRUCTION);
util::ShM<extractor::guidance::TurnInstruction, true>::vector turn_instruction_list(
turn_instruction_list_ptr,
data_layout.num_entries[storage::DataLayout::TURN_INSTRUCTION]);
m_turn_instruction_list = std::move(turn_instruction_list);
const auto name_id_list_ptr =
layout.GetBlockPtr<NameID>(memory_ptr, storage::DataLayout::NAME_ID_LIST);
util::vector_view<NameID> name_ids(name_id_list_ptr,
layout.num_entries[storage::DataLayout::NAME_ID_LIST]);
data_layout.GetBlockPtr<NameID>(memory_block, storage::DataLayout::NAME_ID_LIST);
util::ShM<NameID, true>::vector name_id_list(
name_id_list_ptr, data_layout.num_entries[storage::DataLayout::NAME_ID_LIST]);
m_name_ID_list = std::move(name_id_list);
const auto entry_class_id_list_ptr =
layout.GetBlockPtr<EntryClassID>(memory_ptr, storage::DataLayout::ENTRY_CLASSID);
util::vector_view<EntryClassID> entry_class_ids(
entry_class_id_list_ptr, layout.num_entries[storage::DataLayout::ENTRY_CLASSID]);
data_layout.GetBlockPtr<EntryClassID>(memory_block, storage::DataLayout::ENTRY_CLASSID);
typename util::ShM<EntryClassID, true>::vector entry_class_id_list(
entry_class_id_list_ptr, data_layout.num_entries[storage::DataLayout::ENTRY_CLASSID]);
m_entry_class_id_list = std::move(entry_class_id_list);
const auto pre_turn_bearing_ptr = layout.GetBlockPtr<util::guidance::TurnBearing>(
memory_ptr, storage::DataLayout::PRE_TURN_BEARING);
util::vector_view<util::guidance::TurnBearing> pre_turn_bearings(
pre_turn_bearing_ptr, layout.num_entries[storage::DataLayout::PRE_TURN_BEARING]);
const auto pre_turn_bearing_ptr = data_layout.GetBlockPtr<util::guidance::TurnBearing>(
memory_block, storage::DataLayout::PRE_TURN_BEARING);
typename util::ShM<util::guidance::TurnBearing, true>::vector pre_turn_bearing(
pre_turn_bearing_ptr, data_layout.num_entries[storage::DataLayout::PRE_TURN_BEARING]);
m_pre_turn_bearing = std::move(pre_turn_bearing);
const auto post_turn_bearing_ptr = layout.GetBlockPtr<util::guidance::TurnBearing>(
memory_ptr, storage::DataLayout::POST_TURN_BEARING);
util::vector_view<util::guidance::TurnBearing> post_turn_bearings(
post_turn_bearing_ptr, layout.num_entries[storage::DataLayout::POST_TURN_BEARING]);
const auto post_turn_bearing_ptr = data_layout.GetBlockPtr<util::guidance::TurnBearing>(
memory_block, storage::DataLayout::POST_TURN_BEARING);
typename util::ShM<util::guidance::TurnBearing, true>::vector post_turn_bearing(
post_turn_bearing_ptr, data_layout.num_entries[storage::DataLayout::POST_TURN_BEARING]);
m_post_turn_bearing = std::move(post_turn_bearing);
}
turn_data = extractor::TurnDataView(std::move(geometry_ids),
std::move(name_ids),
std::move(turn_instructions),
std::move(lane_data_ids),
std::move(travel_modes),
std::move(entry_class_ids),
std::move(pre_turn_bearings),
std::move(post_turn_bearings));
void InitializeViaNodeListPointer(storage::DataLayout &data_layout, char *memory_block)
{
auto via_geometry_list_ptr =
data_layout.GetBlockPtr<GeometryID>(memory_block, storage::DataLayout::VIA_NODE_LIST);
util::ShM<GeometryID, true>::vector via_geometry_list(
via_geometry_list_ptr, data_layout.num_entries[storage::DataLayout::VIA_NODE_LIST]);
m_via_geometry_list = std::move(via_geometry_list);
}
void InitializeNamePointers(storage::DataLayout &data_layout, char *memory_block)
@@ -384,35 +398,28 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
{
auto offsets_ptr = data_layout.GetBlockPtr<std::uint32_t>(
memory_block, storage::DataLayout::LANE_DESCRIPTION_OFFSETS);
util::vector_view<std::uint32_t> offsets(
util::ShM<std::uint32_t, true>::vector offsets(
offsets_ptr, data_layout.num_entries[storage::DataLayout::LANE_DESCRIPTION_OFFSETS]);
m_lane_description_offsets = std::move(offsets);
auto masks_ptr = data_layout.GetBlockPtr<extractor::guidance::TurnLaneType::Mask>(
memory_block, storage::DataLayout::LANE_DESCRIPTION_MASKS);
util::vector_view<extractor::guidance::TurnLaneType::Mask> masks(
util::ShM<extractor::guidance::TurnLaneType::Mask, true>::vector masks(
masks_ptr, data_layout.num_entries[storage::DataLayout::LANE_DESCRIPTION_MASKS]);
m_lane_description_masks = std::move(masks);
const auto lane_tupel_id_pair_ptr =
data_layout.GetBlockPtr<util::guidance::LaneTupleIdPair>(
memory_block, storage::DataLayout::TURN_LANE_DATA);
util::vector_view<util::guidance::LaneTupleIdPair> lane_tupel_id_pair(
lane_tupel_id_pair_ptr, data_layout.num_entries[storage::DataLayout::TURN_LANE_DATA]);
m_lane_tupel_id_pairs = std::move(lane_tupel_id_pair);
}
void InitializeTurnPenalties(storage::DataLayout &data_layout, char *memory_block)
{
auto turn_weight_penalties_ptr = data_layout.GetBlockPtr<TurnPenalty>(
memory_block, storage::DataLayout::TURN_WEIGHT_PENALTIES);
m_turn_weight_penalties = util::vector_view<TurnPenalty>(
m_turn_weight_penalties = util::ShM<TurnPenalty, true>::vector(
turn_weight_penalties_ptr,
data_layout.num_entries[storage::DataLayout::TURN_WEIGHT_PENALTIES]);
auto turn_duration_penalties_ptr = data_layout.GetBlockPtr<TurnPenalty>(
memory_block, storage::DataLayout::TURN_DURATION_PENALTIES);
m_turn_duration_penalties = util::vector_view<TurnPenalty>(
m_turn_duration_penalties = util::ShM<TurnPenalty, true>::vector(
turn_duration_penalties_ptr,
data_layout.num_entries[storage::DataLayout::TURN_DURATION_PENALTIES]);
}
@@ -421,42 +428,42 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
{
auto geometries_index_ptr =
data_layout.GetBlockPtr<unsigned>(memory_block, storage::DataLayout::GEOMETRIES_INDEX);
util::vector_view<unsigned> geometry_begin_indices(
util::ShM<unsigned, true>::vector geometry_begin_indices(
geometries_index_ptr, data_layout.num_entries[storage::DataLayout::GEOMETRIES_INDEX]);
auto geometries_node_list_ptr = data_layout.GetBlockPtr<NodeID>(
memory_block, storage::DataLayout::GEOMETRIES_NODE_LIST);
util::vector_view<NodeID> geometry_node_list(
util::ShM<NodeID, true>::vector geometry_node_list(
geometries_node_list_ptr,
data_layout.num_entries[storage::DataLayout::GEOMETRIES_NODE_LIST]);
auto geometries_fwd_weight_list_ptr = data_layout.GetBlockPtr<EdgeWeight>(
memory_block, storage::DataLayout::GEOMETRIES_FWD_WEIGHT_LIST);
util::vector_view<EdgeWeight> geometry_fwd_weight_list(
util::ShM<EdgeWeight, true>::vector geometry_fwd_weight_list(
geometries_fwd_weight_list_ptr,
data_layout.num_entries[storage::DataLayout::GEOMETRIES_FWD_WEIGHT_LIST]);
auto geometries_rev_weight_list_ptr = data_layout.GetBlockPtr<EdgeWeight>(
memory_block, storage::DataLayout::GEOMETRIES_REV_WEIGHT_LIST);
util::vector_view<EdgeWeight> geometry_rev_weight_list(
util::ShM<EdgeWeight, true>::vector geometry_rev_weight_list(
geometries_rev_weight_list_ptr,
data_layout.num_entries[storage::DataLayout::GEOMETRIES_REV_WEIGHT_LIST]);
auto geometries_fwd_duration_list_ptr = data_layout.GetBlockPtr<EdgeWeight>(
memory_block, storage::DataLayout::GEOMETRIES_FWD_DURATION_LIST);
util::vector_view<EdgeWeight> geometry_fwd_duration_list(
util::ShM<EdgeWeight, true>::vector geometry_fwd_duration_list(
geometries_fwd_duration_list_ptr,
data_layout.num_entries[storage::DataLayout::GEOMETRIES_FWD_DURATION_LIST]);
auto geometries_rev_duration_list_ptr = data_layout.GetBlockPtr<EdgeWeight>(
memory_block, storage::DataLayout::GEOMETRIES_REV_DURATION_LIST);
util::vector_view<EdgeWeight> geometry_rev_duration_list(
util::ShM<EdgeWeight, true>::vector geometry_rev_duration_list(
geometries_rev_duration_list_ptr,
data_layout.num_entries[storage::DataLayout::GEOMETRIES_REV_DURATION_LIST]);
auto datasources_list_ptr = data_layout.GetBlockPtr<DatasourceID>(
memory_block, storage::DataLayout::DATASOURCES_LIST);
util::vector_view<DatasourceID> datasources_list(
util::ShM<DatasourceID, true>::vector datasources_list(
datasources_list_ptr, data_layout.num_entries[storage::DataLayout::DATASOURCES_LIST]);
segment_data = extractor::SegmentDataView{std::move(geometry_begin_indices),
@@ -475,13 +482,13 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
{
auto bearing_class_id_ptr = data_layout.GetBlockPtr<BearingClassID>(
memory_block, storage::DataLayout::BEARING_CLASSID);
typename util::vector_view<BearingClassID> bearing_class_id_table(
typename util::ShM<BearingClassID, true>::vector bearing_class_id_table(
bearing_class_id_ptr, data_layout.num_entries[storage::DataLayout::BEARING_CLASSID]);
m_bearing_class_id_table = std::move(bearing_class_id_table);
auto bearing_class_ptr = data_layout.GetBlockPtr<DiscreteBearing>(
memory_block, storage::DataLayout::BEARING_VALUES);
typename util::vector_view<DiscreteBearing> bearing_class_table(
typename util::ShM<DiscreteBearing, true>::vector bearing_class_table(
bearing_class_ptr, data_layout.num_entries[storage::DataLayout::BEARING_VALUES]);
m_bearing_values_table = std::move(bearing_class_table);
@@ -489,17 +496,17 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
data_layout.GetBlockPtr<unsigned>(memory_block, storage::DataLayout::BEARING_OFFSETS);
auto blocks_ptr =
data_layout.GetBlockPtr<IndexBlock>(memory_block, storage::DataLayout::BEARING_BLOCKS);
util::vector_view<unsigned> bearing_offsets(
util::ShM<unsigned, true>::vector bearing_offsets(
offsets_ptr, data_layout.num_entries[storage::DataLayout::BEARING_OFFSETS]);
util::vector_view<IndexBlock> bearing_blocks(
util::ShM<IndexBlock, true>::vector bearing_blocks(
blocks_ptr, data_layout.num_entries[storage::DataLayout::BEARING_BLOCKS]);
m_bearing_ranges_table = std::make_unique<util::RangeTable<16, storage::Ownership::View>>(
m_bearing_ranges_table = std::make_unique<util::RangeTable<16, true>>(
bearing_offsets, bearing_blocks, static_cast<unsigned>(m_bearing_values_table.size()));
auto entry_class_ptr = data_layout.GetBlockPtr<util::guidance::EntryClass>(
memory_block, storage::DataLayout::ENTRY_CLASS);
typename util::vector_view<util::guidance::EntryClass> entry_class_table(
typename util::ShM<util::guidance::EntryClass, true>::vector entry_class_table(
entry_class_ptr, data_layout.num_entries[storage::DataLayout::ENTRY_CLASS]);
m_entry_class_table = std::move(entry_class_table);
}
@@ -507,11 +514,11 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
void InitializeInternalPointers(storage::DataLayout &data_layout, char *memory_block)
{
InitializeChecksumPointer(data_layout, memory_block);
InitializeNodeInformationPointers(data_layout, memory_block);
InitializeEdgeInformationPointers(data_layout, memory_block);
InitializeNodeAndEdgeInformationPointers(data_layout, memory_block);
InitializeTurnPenalties(data_layout, memory_block);
InitializeGeometryPointers(data_layout, memory_block);
InitializeTimestampPointer(data_layout, memory_block);
InitializeViaNodeListPointer(data_layout, memory_block);
InitializeNamePointers(data_layout, memory_block);
InitializeTurnLaneDescriptionsPointers(data_layout, memory_block);
InitializeProfilePropertiesPointer(data_layout, memory_block);
@@ -600,7 +607,7 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
virtual GeometryID GetGeometryIndexForEdgeID(const EdgeID id) const override final
{
return turn_data.GetGeometryID(id);
return m_via_geometry_list.at(id);
}
virtual TurnPenalty GetWeightPenaltyForEdgeID(const unsigned id) const override final
@@ -618,12 +625,12 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
extractor::guidance::TurnInstruction
GetTurnInstructionForEdgeID(const EdgeID id) const override final
{
return turn_data.GetTurnInstruction(id);
return m_turn_instruction_list.at(id);
}
extractor::TravelMode GetTravelModeForEdgeID(const EdgeID id) const override final
{
return turn_data.GetTravelMode(id);
return m_travel_mode_list.at(id);
}
std::vector<RTreeLeaf> GetEdgesInBox(const util::Coordinate south_west,
@@ -745,7 +752,7 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
NameID GetNameIndexFromEdgeID(const EdgeID id) const override final
{
return turn_data.GetNameID(id);
return m_name_ID_list.at(id);
}
StringView GetNameForID(const NameID id) const override final
@@ -817,16 +824,16 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
EntryClassID GetEntryClassID(const EdgeID eid) const override final
{
return turn_data.GetEntryClassID(eid);
return m_entry_class_id_list.at(eid);
}
util::guidance::TurnBearing PreTurnBearing(const EdgeID eid) const override final
{
return turn_data.GetPreTurnBearing(eid);
return m_pre_turn_bearing.at(eid);
}
util::guidance::TurnBearing PostTurnBearing(const EdgeID eid) const override final
{
return turn_data.GetPostTurnBearing(eid);
return m_post_turn_bearing.at(eid);
}
util::guidance::EntryClass GetEntryClass(const EntryClassID entry_class_id) const override final
@@ -834,12 +841,15 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
return m_entry_class_table.at(entry_class_id);
}
bool HasLaneData(const EdgeID id) const override final { return turn_data.HasLaneData(id); }
bool hasLaneData(const EdgeID id) const override final
{
return INVALID_LANE_DATAID != m_lane_data_id.at(id);
}
util::guidance::LaneTupleIdPair GetLaneData(const EdgeID id) const override final
{
BOOST_ASSERT(HasLaneData(id));
return m_lane_tupel_id_pairs.at(turn_data.GetLaneDataID(id));
BOOST_ASSERT(hasLaneData(id));
return m_lane_tupel_id_pairs.at(m_lane_data_id.at(id));
}
extractor::guidance::TurnLaneDescription
@@ -858,34 +868,36 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
template <typename AlgorithmT> class ContiguousInternalMemoryDataFacade;
template <>
class ContiguousInternalMemoryDataFacade<CH>
class ContiguousInternalMemoryDataFacade<algorithm::CH>
: public ContiguousInternalMemoryDataFacadeBase,
public ContiguousInternalMemoryAlgorithmDataFacade<CH>
public ContiguousInternalMemoryAlgorithmDataFacade<algorithm::CH>
{
public:
ContiguousInternalMemoryDataFacade(std::shared_ptr<ContiguousBlockAllocator> allocator)
: ContiguousInternalMemoryDataFacadeBase(allocator),
ContiguousInternalMemoryAlgorithmDataFacade<CH>(allocator)
ContiguousInternalMemoryAlgorithmDataFacade<algorithm::CH>(allocator)
{
}
};
template <>
class ContiguousInternalMemoryDataFacade<CoreCH> final
: public ContiguousInternalMemoryDataFacade<CH>,
public ContiguousInternalMemoryAlgorithmDataFacade<CoreCH>
class ContiguousInternalMemoryDataFacade<algorithm::CoreCH> final
: public ContiguousInternalMemoryDataFacade<algorithm::CH>,
public ContiguousInternalMemoryAlgorithmDataFacade<algorithm::CoreCH>
{
public:
ContiguousInternalMemoryDataFacade(std::shared_ptr<ContiguousBlockAllocator> allocator)
: ContiguousInternalMemoryDataFacade<CH>(allocator),
ContiguousInternalMemoryAlgorithmDataFacade<CoreCH>(allocator)
: ContiguousInternalMemoryDataFacade<algorithm::CH>(allocator),
ContiguousInternalMemoryAlgorithmDataFacade<algorithm::CoreCH>(allocator)
{
}
};
template <> class ContiguousInternalMemoryAlgorithmDataFacade<MLD> : public AlgorithmDataFacade<MLD>
template <>
class ContiguousInternalMemoryAlgorithmDataFacade<algorithm::MLD>
: public datafacade::AlgorithmDataFacade<algorithm::MLD>
{
// MLD data
partition::MultiLevelPartitionView mld_partition;
@@ -910,20 +922,22 @@ template <> class ContiguousInternalMemoryAlgorithmDataFacade<MLD> : public Algo
BOOST_ASSERT(data_layout.GetBlockSize(storage::DataLayout::MLD_CELL_TO_CHILDREN) > 0);
auto level_data =
data_layout.GetBlockPtr<partition::MultiLevelPartitionView::LevelData>(
*data_layout.GetBlockPtr<partition::MultiLevelPartitionView::LevelData>(
memory_block, storage::DataLayout::MLD_LEVEL_DATA);
auto mld_partition_ptr = data_layout.GetBlockPtr<PartitionID>(
memory_block, storage::DataLayout::MLD_PARTITION);
auto partition_entries_count =
data_layout.GetBlockEntries(storage::DataLayout::MLD_PARTITION);
util::vector_view<PartitionID> partition(mld_partition_ptr, partition_entries_count);
util::ShM<PartitionID, true>::vector partition(mld_partition_ptr,
partition_entries_count);
auto mld_chilren_ptr = data_layout.GetBlockPtr<CellID>(
memory_block, storage::DataLayout::MLD_CELL_TO_CHILDREN);
auto children_entries_count =
data_layout.GetBlockEntries(storage::DataLayout::MLD_CELL_TO_CHILDREN);
util::vector_view<CellID> cell_to_children(mld_chilren_ptr, children_entries_count);
util::ShM<CellID, true>::vector cell_to_children(mld_chilren_ptr,
children_entries_count);
mld_partition =
partition::MultiLevelPartitionView{level_data, partition, cell_to_children};
@@ -955,15 +969,15 @@ template <> class ContiguousInternalMemoryAlgorithmDataFacade<MLD> : public Algo
auto cell_level_offsets_entries_count =
data_layout.GetBlockEntries(storage::DataLayout::MLD_CELL_LEVEL_OFFSETS);
util::vector_view<EdgeWeight> weights(mld_cell_weights_ptr, weight_entries_count);
util::vector_view<NodeID> source_boundary(mld_source_boundary_ptr,
source_boundary_entries_count);
util::vector_view<NodeID> destination_boundary(mld_destination_boundary_ptr,
destination_boundary_entries_count);
util::vector_view<partition::CellStorageView::CellData> cells(mld_cells_ptr,
cells_entries_counts);
util::vector_view<std::uint64_t> level_offsets(mld_cell_level_offsets_ptr,
cell_level_offsets_entries_count);
util::ShM<EdgeWeight, true>::vector weights(mld_cell_weights_ptr, weight_entries_count);
util::ShM<NodeID, true>::vector source_boundary(mld_source_boundary_ptr,
source_boundary_entries_count);
util::ShM<NodeID, true>::vector destination_boundary(
mld_destination_boundary_ptr, destination_boundary_entries_count);
util::ShM<partition::CellStorageView::CellData, true>::vector cells(
mld_cells_ptr, cells_entries_counts);
util::ShM<std::uint64_t, true>::vector level_offsets(mld_cell_level_offsets_ptr,
cell_level_offsets_entries_count);
mld_cell_storage = partition::CellStorageView{std::move(weights),
std::move(source_boundary),
@@ -983,11 +997,11 @@ template <> class ContiguousInternalMemoryAlgorithmDataFacade<MLD> : public Algo
auto graph_node_to_offset_ptr = data_layout.GetBlockPtr<QueryGraph::EdgeOffset>(
memory_block, storage::DataLayout::MLD_GRAPH_NODE_TO_OFFSET);
util::vector_view<GraphNode> node_list(
util::ShM<GraphNode, true>::vector node_list(
graph_nodes_ptr, data_layout.num_entries[storage::DataLayout::MLD_GRAPH_NODE_LIST]);
util::vector_view<GraphEdge> edge_list(
util::ShM<GraphEdge, true>::vector edge_list(
graph_edges_ptr, data_layout.num_entries[storage::DataLayout::MLD_GRAPH_EDGE_LIST]);
util::vector_view<QueryGraph::EdgeOffset> node_to_offset(
util::ShM<QueryGraph::EdgeOffset, true>::vector node_to_offset(
graph_node_to_offset_ptr,
data_layout.num_entries[storage::DataLayout::MLD_GRAPH_NODE_TO_OFFSET]);
@@ -1052,15 +1066,15 @@ template <> class ContiguousInternalMemoryAlgorithmDataFacade<MLD> : public Algo
};
template <>
class ContiguousInternalMemoryDataFacade<MLD> final
class ContiguousInternalMemoryDataFacade<algorithm::MLD> final
: public ContiguousInternalMemoryDataFacadeBase,
public ContiguousInternalMemoryAlgorithmDataFacade<MLD>
public ContiguousInternalMemoryAlgorithmDataFacade<algorithm::MLD>
{
private:
public:
ContiguousInternalMemoryDataFacade(std::shared_ptr<ContiguousBlockAllocator> allocator)
: ContiguousInternalMemoryDataFacadeBase(allocator),
ContiguousInternalMemoryAlgorithmDataFacade<MLD>(allocator)
ContiguousInternalMemoryAlgorithmDataFacade<algorithm::MLD>(allocator)
{
}
@@ -130,7 +130,7 @@ class BaseDataFacade
const int bearing,
const int bearing_range) const = 0;
virtual bool HasLaneData(const EdgeID id) const = 0;
virtual bool hasLaneData(const EdgeID id) const = 0;
virtual util::guidance::LaneTupleIdPair GetLaneData(const EdgeID id) const = 0;
virtual extractor::guidance::TurnLaneDescription
GetTurnDescription(const LaneDescriptionID lane_description_id) const = 0;
+17 -18
View File
@@ -49,7 +49,7 @@ class EngineInterface
virtual Status Tile(const api::TileParameters &parameters, std::string &result) const = 0;
};
template <typename Algorithm> class Engine final : public EngineInterface
template <typename AlgorithmT> class Engine final : public EngineInterface
{
public:
explicit Engine(const EngineConfig &config)
@@ -64,14 +64,15 @@ template <typename Algorithm> class Engine final : public EngineInterface
if (config.use_shared_memory)
{
util::Log(logDEBUG) << "Using shared memory with algorithm "
<< routing_algorithms::name<Algorithm>();
facade_provider = std::make_unique<WatchingProvider<Algorithm>>();
<< algorithm::name<AlgorithmT>();
facade_provider = std::make_unique<WatchingProvider<AlgorithmT>>();
}
else
{
util::Log(logDEBUG) << "Using internal memory with algorithm "
<< routing_algorithms::name<Algorithm>();
facade_provider = std::make_unique<ImmutableProvider<Algorithm>>(config.storage_config);
<< algorithm::name<AlgorithmT>();
facade_provider =
std::make_unique<ImmutableProvider<AlgorithmT>>(config.storage_config);
}
}
@@ -86,7 +87,7 @@ template <typename Algorithm> class Engine final : public EngineInterface
util::json::Object &result) const override final
{
auto facade = facade_provider->Get();
auto algorithms = RoutingAlgorithms<Algorithm>{heaps, *facade};
auto algorithms = RoutingAlgorithms<AlgorithmT>{heaps, *facade};
return route_plugin.HandleRequest(*facade, algorithms, params, result);
}
@@ -94,7 +95,7 @@ template <typename Algorithm> class Engine final : public EngineInterface
util::json::Object &result) const override final
{
auto facade = facade_provider->Get();
auto algorithms = RoutingAlgorithms<Algorithm>{heaps, *facade};
auto algorithms = RoutingAlgorithms<AlgorithmT>{heaps, *facade};
return table_plugin.HandleRequest(*facade, algorithms, params, result);
}
@@ -102,14 +103,14 @@ template <typename Algorithm> class Engine final : public EngineInterface
util::json::Object &result) const override final
{
auto facade = facade_provider->Get();
auto algorithms = RoutingAlgorithms<Algorithm>{heaps, *facade};
auto algorithms = RoutingAlgorithms<AlgorithmT>{heaps, *facade};
return nearest_plugin.HandleRequest(*facade, algorithms, params, result);
}
Status Trip(const api::TripParameters &params, util::json::Object &result) const override final
{
auto facade = facade_provider->Get();
auto algorithms = RoutingAlgorithms<Algorithm>{heaps, *facade};
auto algorithms = RoutingAlgorithms<AlgorithmT>{heaps, *facade};
return trip_plugin.HandleRequest(*facade, algorithms, params, result);
}
@@ -117,22 +118,22 @@ template <typename Algorithm> class Engine final : public EngineInterface
util::json::Object &result) const override final
{
auto facade = facade_provider->Get();
auto algorithms = RoutingAlgorithms<Algorithm>{heaps, *facade};
auto algorithms = RoutingAlgorithms<AlgorithmT>{heaps, *facade};
return match_plugin.HandleRequest(*facade, algorithms, params, result);
}
Status Tile(const api::TileParameters &params, std::string &result) const override final
{
auto facade = facade_provider->Get();
auto algorithms = RoutingAlgorithms<Algorithm>{heaps, *facade};
auto algorithms = RoutingAlgorithms<AlgorithmT>{heaps, *facade};
return tile_plugin.HandleRequest(*facade, algorithms, params, result);
}
static bool CheckCompability(const EngineConfig &config);
private:
std::unique_ptr<DataFacadeProvider<Algorithm>> facade_provider;
mutable SearchEngineData<Algorithm> heaps;
std::unique_ptr<DataFacadeProvider<AlgorithmT>> facade_provider;
mutable SearchEngineData heaps;
const plugins::ViaRoutePlugin route_plugin;
const plugins::TablePlugin table_plugin;
@@ -142,8 +143,7 @@ template <typename Algorithm> class Engine final : public EngineInterface
const plugins::TilePlugin tile_plugin;
};
template <>
bool Engine<routing_algorithms::ch::Algorithm>::CheckCompability(const EngineConfig &config)
template <> bool Engine<algorithm::CH>::CheckCompability(const EngineConfig &config)
{
if (config.use_shared_memory)
{
@@ -168,10 +168,9 @@ bool Engine<routing_algorithms::ch::Algorithm>::CheckCompability(const EngineCon
}
}
template <>
bool Engine<routing_algorithms::corech::Algorithm>::CheckCompability(const EngineConfig &config)
template <> bool Engine<algorithm::CoreCH>::CheckCompability(const EngineConfig &config)
{
if (!Engine<routing_algorithms::ch::Algorithm>::CheckCompability(config))
if (!Engine<algorithm::CH>::CheckCompability(config))
{
return false;
}
+61 -71
View File
@@ -38,8 +38,7 @@ class RoutingAlgorithmsInterface
MapMatching(const routing_algorithms::CandidateLists &candidates_list,
const std::vector<util::Coordinate> &trace_coordinates,
const std::vector<unsigned> &trace_timestamps,
const std::vector<boost::optional<double>> &trace_gps_precision,
const bool allow_splitting) const = 0;
const std::vector<boost::optional<double>> &trace_gps_precision) const = 0;
virtual std::vector<routing_algorithms::TurnData>
GetTileTurns(const std::vector<datafacade::BaseDataFacade::RTreeLeaf> &edges,
@@ -54,11 +53,11 @@ class RoutingAlgorithmsInterface
};
// Short-lived object passed to each plugin in request to wrap routing algorithms
template <typename Algorithm> class RoutingAlgorithms final : public RoutingAlgorithmsInterface
template <typename AlgorithmT> class RoutingAlgorithms final : public RoutingAlgorithmsInterface
{
public:
RoutingAlgorithms(SearchEngineData<Algorithm> &heaps,
const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade)
RoutingAlgorithms(SearchEngineData &heaps,
const datafacade::ContiguousInternalMemoryDataFacade<AlgorithmT> &facade)
: heaps(heaps), facade(facade)
{
}
@@ -80,12 +79,11 @@ template <typename Algorithm> class RoutingAlgorithms final : public RoutingAlgo
const std::vector<std::size_t> &source_indices,
const std::vector<std::size_t> &target_indices) const final override;
routing_algorithms::SubMatchingList
MapMatching(const routing_algorithms::CandidateLists &candidates_list,
const std::vector<util::Coordinate> &trace_coordinates,
const std::vector<unsigned> &trace_timestamps,
const std::vector<boost::optional<double>> &trace_gps_precision,
const bool allow_splitting) const final override;
routing_algorithms::SubMatchingList MapMatching(
const routing_algorithms::CandidateLists &candidates_list,
const std::vector<util::Coordinate> &trace_coordinates,
const std::vector<unsigned> &trace_timestamps,
const std::vector<boost::optional<double>> &trace_gps_precision) const final override;
std::vector<routing_algorithms::TurnData>
GetTileTurns(const std::vector<datafacade::BaseDataFacade::RTreeLeaf> &edges,
@@ -93,49 +91,49 @@ template <typename Algorithm> class RoutingAlgorithms final : public RoutingAlgo
bool HasAlternativePathSearch() const final override
{
return routing_algorithms::HasAlternativePathSearch<Algorithm>::value;
return algorithm_trais::HasAlternativePathSearch<AlgorithmT>::value;
}
bool HasShortestPathSearch() const final override
{
return routing_algorithms::HasShortestPathSearch<Algorithm>::value;
return algorithm_trais::HasShortestPathSearch<AlgorithmT>::value;
}
bool HasDirectShortestPathSearch() const final override
{
return routing_algorithms::HasDirectShortestPathSearch<Algorithm>::value;
return algorithm_trais::HasDirectShortestPathSearch<AlgorithmT>::value;
}
bool HasMapMatching() const final override
{
return routing_algorithms::HasMapMatching<Algorithm>::value;
return algorithm_trais::HasMapMatching<AlgorithmT>::value;
}
bool HasManyToManySearch() const final override
{
return routing_algorithms::HasManyToManySearch<Algorithm>::value;
return algorithm_trais::HasManyToManySearch<AlgorithmT>::value;
}
bool HasGetTileTurns() const final override
{
return routing_algorithms::HasGetTileTurns<Algorithm>::value;
return algorithm_trais::HasGetTileTurns<AlgorithmT>::value;
}
private:
SearchEngineData<Algorithm> &heaps;
SearchEngineData &heaps;
// Owned by shared-ptr passed to the query
const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade;
const datafacade::ContiguousInternalMemoryDataFacade<AlgorithmT> &facade;
};
template <typename Algorithm>
template <typename AlgorithmT>
InternalRouteResult
RoutingAlgorithms<Algorithm>::AlternativePathSearch(const PhantomNodes &phantom_node_pair) const
RoutingAlgorithms<AlgorithmT>::AlternativePathSearch(const PhantomNodes &phantom_node_pair) const
{
return routing_algorithms::ch::alternativePathSearch(heaps, facade, phantom_node_pair);
return routing_algorithms::alternativePathSearch(heaps, facade, phantom_node_pair);
}
template <typename Algorithm>
InternalRouteResult RoutingAlgorithms<Algorithm>::ShortestPathSearch(
template <typename AlgorithmT>
InternalRouteResult RoutingAlgorithms<AlgorithmT>::ShortestPathSearch(
const std::vector<PhantomNodes> &phantom_node_pair,
const boost::optional<bool> continue_straight_at_waypoint) const
{
@@ -143,87 +141,79 @@ InternalRouteResult RoutingAlgorithms<Algorithm>::ShortestPathSearch(
heaps, facade, phantom_node_pair, continue_straight_at_waypoint);
}
template <typename Algorithm>
template <typename AlgorithmT>
InternalRouteResult
RoutingAlgorithms<Algorithm>::DirectShortestPathSearch(const PhantomNodes &phantom_nodes) const
RoutingAlgorithms<AlgorithmT>::DirectShortestPathSearch(const PhantomNodes &phantom_nodes) const
{
return routing_algorithms::directShortestPathSearch(heaps, facade, phantom_nodes);
}
template <typename Algorithm>
std::vector<EdgeWeight>
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
template <typename AlgorithmT>
std::vector<EdgeWeight> RoutingAlgorithms<AlgorithmT>::ManyToManySearch(
const std::vector<PhantomNode> &phantom_nodes,
const std::vector<std::size_t> &source_indices,
const std::vector<std::size_t> &target_indices) const
{
return routing_algorithms::ch::manyToManySearch(
return routing_algorithms::manyToManySearch(
heaps, facade, phantom_nodes, source_indices, target_indices);
}
template <typename Algorithm>
inline routing_algorithms::SubMatchingList RoutingAlgorithms<Algorithm>::MapMatching(
template <typename AlgorithmT>
inline routing_algorithms::SubMatchingList RoutingAlgorithms<AlgorithmT>::MapMatching(
const routing_algorithms::CandidateLists &candidates_list,
const std::vector<util::Coordinate> &trace_coordinates,
const std::vector<unsigned> &trace_timestamps,
const std::vector<boost::optional<double>> &trace_gps_precision,
const bool allow_splitting) const
const std::vector<boost::optional<double>> &trace_gps_precision) const
{
return routing_algorithms::mapMatching(heaps,
facade,
candidates_list,
trace_coordinates,
trace_timestamps,
trace_gps_precision,
allow_splitting);
return routing_algorithms::mapMatching(
heaps, facade, candidates_list, trace_coordinates, trace_timestamps, trace_gps_precision);
}
template <typename Algorithm>
inline std::vector<routing_algorithms::TurnData> RoutingAlgorithms<Algorithm>::GetTileTurns(
template <typename AlgorithmT>
inline std::vector<routing_algorithms::TurnData> RoutingAlgorithms<AlgorithmT>::GetTileTurns(
const std::vector<datafacade::BaseDataFacade::RTreeLeaf> &edges,
const std::vector<std::size_t> &sorted_edge_indexes) const
{
return routing_algorithms::getTileTurns(facade, edges, sorted_edge_indexes);
}
// CoreCH overrides
template <>
InternalRouteResult inline RoutingAlgorithms<
routing_algorithms::corech::Algorithm>::AlternativePathSearch(const PhantomNodes &) const
{
throw util::exception("AlternativePathSearch is disabled due to performance reasons");
}
template <>
inline std::vector<EdgeWeight>
RoutingAlgorithms<routing_algorithms::corech::Algorithm>::ManyToManySearch(
const std::vector<PhantomNode> &,
const std::vector<std::size_t> &,
const std::vector<std::size_t> &) const
{
throw util::exception("ManyToManySearch is disabled due to performance reasons");
}
// MLD overrides for not implemented
template <>
InternalRouteResult inline RoutingAlgorithms<
routing_algorithms::mld::Algorithm>::AlternativePathSearch(const PhantomNodes &) const
InternalRouteResult inline RoutingAlgorithms<algorithm::MLD>::AlternativePathSearch(
const PhantomNodes &) const
{
throw util::exception("AlternativePathSearch is not implemented");
}
template <>
inline InternalRouteResult
RoutingAlgorithms<algorithm::MLD>::ShortestPathSearch(const std::vector<PhantomNodes> &,
const boost::optional<bool>) const
{
throw util::exception("ShortestPathSearch is not implemented");
}
template <>
inline std::vector<EdgeWeight>
RoutingAlgorithms<routing_algorithms::mld::Algorithm>::ManyToManySearch(
const std::vector<PhantomNode> &,
const std::vector<std::size_t> &,
const std::vector<std::size_t> &) const
RoutingAlgorithms<algorithm::MLD>::ManyToManySearch(const std::vector<PhantomNode> &,
const std::vector<std::size_t> &,
const std::vector<std::size_t> &) const
{
throw util::exception("ManyToManySearch is not implemented");
}
template <>
inline std::vector<routing_algorithms::TurnData>
RoutingAlgorithms<routing_algorithms::mld::Algorithm>::GetTileTurns(
inline routing_algorithms::SubMatchingList
RoutingAlgorithms<algorithm::MLD>::MapMatching(const routing_algorithms::CandidateLists &,
const std::vector<util::Coordinate> &,
const std::vector<unsigned> &,
const std::vector<boost::optional<double>> &) const
{
throw util::exception("MapMatching is not implemented");
}
template <>
inline std::vector<routing_algorithms::TurnData> RoutingAlgorithms<algorithm::MLD>::GetTileTurns(
const std::vector<datafacade::BaseDataFacade::RTreeLeaf> &,
const std::vector<std::size_t> &) const
{
@@ -15,13 +15,12 @@ namespace engine
{
namespace routing_algorithms
{
namespace ch
{
InternalRouteResult
alternativePathSearch(SearchEngineData<Algorithm> &search_engine_data,
const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
alternativePathSearch(SearchEngineData &search_engine_data,
const datafacade::ContiguousInternalMemoryDataFacade<algorithm::CH> &facade,
const PhantomNodes &phantom_node_pair);
} // namespace ch
} // namespace routing_algorithms
} // namespace engine
} // namespace osrm
@@ -21,17 +21,12 @@ namespace routing_algorithms
/// by the previous route.
/// This variation is only an optimazation for graphs with slow queries, for example
/// not fully contracted graphs.
template <typename Algorithm>
template <typename AlgorithmT>
InternalRouteResult
directShortestPathSearch(SearchEngineData<Algorithm> &engine_working_data,
const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
directShortestPathSearch(SearchEngineData &engine_working_data,
const datafacade::ContiguousInternalMemoryDataFacade<AlgorithmT> &facade,
const PhantomNodes &phantom_nodes);
InternalRouteResult directShortestPathSearch(
SearchEngineData<mld::Algorithm> &engine_working_data,
const datafacade::ContiguousInternalMemoryDataFacade<mld::Algorithm> &facade,
const PhantomNodes &phantom_nodes);
} // namespace routing_algorithms
} // namespace engine
} // namespace osrm
@@ -13,18 +13,16 @@ namespace osrm
{
namespace engine
{
namespace routing_algorithms
{
namespace ch
{
std::vector<EdgeWeight>
manyToManySearch(SearchEngineData<Algorithm> &engine_working_data,
const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
manyToManySearch(SearchEngineData &engine_working_data,
const datafacade::ContiguousInternalMemoryDataFacade<algorithm::CH> &facade,
const std::vector<PhantomNode> &phantom_nodes,
const std::vector<std::size_t> &source_indices,
const std::vector<std::size_t> &target_indices);
} // namespace ch
} // namespace routing_algorithms
} // namespace engine
@@ -22,17 +22,23 @@ static const constexpr double DEFAULT_GPS_PRECISION = 5;
//[1] "Hidden Markov Map Matching Through Noise and Sparseness";
// P. Newson and J. Krumm; 2009; ACM GIS
template <typename Algorithm>
SubMatchingList mapMatching(SearchEngineData<Algorithm> &engine_working_data,
const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
const CandidateLists &candidates_list,
const std::vector<util::Coordinate> &trace_coordinates,
const std::vector<unsigned> &trace_timestamps,
const std::vector<boost::optional<double>> &trace_gps_precision,
const bool allow_splitting);
SubMatchingList
mapMatching(SearchEngineData &engine_working_data,
const datafacade::ContiguousInternalMemoryDataFacade<algorithm::CH> &facade,
const CandidateLists &candidates_list,
const std::vector<util::Coordinate> &trace_coordinates,
const std::vector<unsigned> &trace_timestamps,
const std::vector<boost::optional<double>> &trace_gps_precision);
} // namespace routing_algorithms
} // namespace engine
} // namespace osrm
SubMatchingList
mapMatching(SearchEngineData &engine_working_data,
const datafacade::ContiguousInternalMemoryDataFacade<algorithm::CoreCH> &facade,
const CandidateLists &candidates_list,
const std::vector<util::Coordinate> &trace_coordinates,
const std::vector<unsigned> &trace_timestamps,
const std::vector<boost::optional<double>> &trace_gps_precision);
}
}
}
#endif /* MAP_MATCHING_HPP */
@@ -37,10 +37,6 @@ static constexpr bool FORWARD_DIRECTION = true;
static constexpr bool REVERSE_DIRECTION = false;
static constexpr bool DO_NOT_FORCE_LOOPS = false;
bool needsLoopForward(const PhantomNode &source_phantom, const PhantomNode &target_phantom);
bool needsLoopBackwards(const PhantomNode &source_phantom, const PhantomNode &target_phantom);
template <bool DIRECTION, typename Heap>
void insertNodesInHeap(Heap &heap, const PhantomNode &phantom_node)
{
@@ -62,8 +58,7 @@ void insertNodesInHeap(Heap &heap, const PhantomNode &phantom_node)
}
template <bool DIRECTION>
void insertNodesInHeap(SearchEngineData<ch::Algorithm>::ManyToManyQueryHeap &heap,
const PhantomNode &phantom_node)
void insertNodesInHeap(SearchEngineData::ManyToManyQueryHeap &heap, const PhantomNode &phantom_node)
{
BOOST_ASSERT(phantom_node.IsValid());
@@ -174,7 +169,7 @@ void annotatePath(const FacadeT &facade,
util::guidance::TurnBearing(0)});
}
BOOST_ASSERT(unpacked_path.size() > 0);
if (facade.HasLaneData(turn_id))
if (facade.hasLaneData(turn_id))
unpacked_path.back().lane_data = facade.GetLaneData(turn_id);
unpacked_path.back().entry_classid = facade.GetEntryClassID(turn_id);
@@ -310,57 +305,6 @@ void annotatePath(const FacadeT &facade,
}
}
template <typename Algorithm>
double getPathDistance(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
const std::vector<PathData> unpacked_path,
const PhantomNode &source_phantom,
const PhantomNode &target_phantom)
{
using util::coordinate_calculation::detail::DEGREE_TO_RAD;
using util::coordinate_calculation::detail::EARTH_RADIUS;
double distance = 0;
double prev_lat = static_cast<double>(toFloating(source_phantom.location.lat)) * DEGREE_TO_RAD;
double prev_lon = static_cast<double>(toFloating(source_phantom.location.lon)) * DEGREE_TO_RAD;
double prev_cos = std::cos(prev_lat);
for (const auto &p : unpacked_path)
{
const auto current_coordinate = facade.GetCoordinateOfNode(p.turn_via_node);
const double current_lat =
static_cast<double>(toFloating(current_coordinate.lat)) * DEGREE_TO_RAD;
const double current_lon =
static_cast<double>(toFloating(current_coordinate.lon)) * DEGREE_TO_RAD;
const double current_cos = std::cos(current_lat);
const double sin_dlon = std::sin((prev_lon - current_lon) / 2.0);
const double sin_dlat = std::sin((prev_lat - current_lat) / 2.0);
const double aharv = sin_dlat * sin_dlat + prev_cos * current_cos * sin_dlon * sin_dlon;
const double charv = 2. * std::atan2(std::sqrt(aharv), std::sqrt(1.0 - aharv));
distance += EARTH_RADIUS * charv;
prev_lat = current_lat;
prev_lon = current_lon;
prev_cos = current_cos;
}
const double current_lat =
static_cast<double>(toFloating(target_phantom.location.lat)) * DEGREE_TO_RAD;
const double current_lon =
static_cast<double>(toFloating(target_phantom.location.lon)) * DEGREE_TO_RAD;
const double current_cos = std::cos(current_lat);
const double sin_dlon = std::sin((prev_lon - current_lon) / 2.0);
const double sin_dlat = std::sin((prev_lat - current_lat) / 2.0);
const double aharv = sin_dlat * sin_dlat + prev_cos * current_cos * sin_dlon * sin_dlon;
const double charv = 2. * std::atan2(std::sqrt(aharv), std::sqrt(1.0 - aharv));
distance += EARTH_RADIUS * charv;
return distance;
}
} // namespace routing_algorithms
} // namespace engine
} // namespace osrm
@@ -23,7 +23,7 @@ namespace ch
// Stalling
template <bool DIRECTION, typename HeapT>
bool stallAtNode(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
bool stallAtNode(const datafacade::ContiguousInternalMemoryDataFacade<algorithm::CH> &facade,
const NodeID node,
const EdgeWeight weight,
const HeapT &query_heap)
@@ -49,10 +49,10 @@ bool stallAtNode(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm>
}
template <bool DIRECTION>
void relaxOutgoingEdges(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
void relaxOutgoingEdges(const datafacade::ContiguousInternalMemoryDataFacade<algorithm::CH> &facade,
const NodeID node,
const EdgeWeight weight,
SearchEngineData<Algorithm>::QueryHeap &heap)
SearchEngineData::QueryHeap &heap)
{
for (const auto edge : facade.GetAdjacentEdgeRange(node))
{
@@ -113,9 +113,9 @@ we need to add an offset to the termination criterion.
static constexpr bool ENABLE_STALLING = true;
static constexpr bool DISABLE_STALLING = false;
template <bool DIRECTION, bool STALLING = ENABLE_STALLING>
void routingStep(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
SearchEngineData<Algorithm>::QueryHeap &forward_heap,
SearchEngineData<Algorithm>::QueryHeap &reverse_heap,
void routingStep(const datafacade::ContiguousInternalMemoryDataFacade<algorithm::CH> &facade,
SearchEngineData::QueryHeap &forward_heap,
SearchEngineData::QueryHeap &reverse_heap,
NodeID &middle_node_id,
EdgeWeight &upper_bound,
EdgeWeight min_edge_offset,
@@ -186,8 +186,9 @@ void routingStep(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm>
}
template <bool UseDuration>
EdgeWeight getLoopWeight(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
NodeID node)
EdgeWeight
getLoopWeight(const datafacade::ContiguousInternalMemoryDataFacade<algorithm::CH> &facade,
NodeID node)
{
EdgeWeight loop_weight = UseDuration ? MAXIMAL_EDGE_DURATION : INVALID_EDGE_WEIGHT;
for (auto edge : facade.GetAdjacentEdgeRange(node))
@@ -227,7 +228,7 @@ EdgeWeight getLoopWeight(const datafacade::ContiguousInternalMemoryDataFacade<Al
* original edge found.
*/
template <typename BidirectionalIterator, typename Callback>
void unpackPath(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
void unpackPath(const datafacade::ContiguousInternalMemoryDataFacade<algorithm::CH> &facade,
BidirectionalIterator packed_path_begin,
BidirectionalIterator packed_path_end,
Callback &&callback)
@@ -324,17 +325,17 @@ void unpackPath(const FacadeT &facade,
* @param to the node the CH edge finishes at
* @param unpacked_path the sequence of original NodeIDs that make up the expanded CH edge
*/
void unpackEdge(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
void unpackEdge(const datafacade::ContiguousInternalMemoryDataFacade<algorithm::CH> &facade,
const NodeID from,
const NodeID to,
std::vector<NodeID> &unpacked_path);
void retrievePackedPathFromHeap(const SearchEngineData<Algorithm>::QueryHeap &forward_heap,
const SearchEngineData<Algorithm>::QueryHeap &reverse_heap,
void retrievePackedPathFromHeap(const SearchEngineData::QueryHeap &forward_heap,
const SearchEngineData::QueryHeap &reverse_heap,
const NodeID middle_node_id,
std::vector<NodeID> &packed_path);
void retrievePackedPathFromSingleHeap(const SearchEngineData<Algorithm>::QueryHeap &search_heap,
void retrievePackedPathFromSingleHeap(const SearchEngineData::QueryHeap &search_heap,
const NodeID middle_node_id,
std::vector<NodeID> &packed_path);
@@ -350,9 +351,9 @@ void retrievePackedPathFromSingleHeap(const SearchEngineData<Algorithm>::QueryHe
// && source_phantom.GetForwardWeightPlusOffset() > target_phantom.GetForwardWeightPlusOffset())
// requires
// a force loop, if the heaps have been initialized with positive offsets.
void search(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
SearchEngineData<Algorithm>::QueryHeap &forward_heap,
SearchEngineData<Algorithm>::QueryHeap &reverse_heap,
void search(const datafacade::ContiguousInternalMemoryDataFacade<algorithm::CH> &facade,
SearchEngineData::QueryHeap &forward_heap,
SearchEngineData::QueryHeap &reverse_heap,
std::int32_t &weight,
std::vector<NodeID> &packed_leg,
const bool force_loop_forward,
@@ -360,16 +361,15 @@ void search(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &fac
const int duration_upper_bound = INVALID_EDGE_WEIGHT);
// Alias to be compatible with the overload for CoreCH that needs 4 heaps
inline void search(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
SearchEngineData<Algorithm>::QueryHeap &forward_heap,
SearchEngineData<Algorithm>::QueryHeap &reverse_heap,
SearchEngineData<Algorithm>::QueryHeap &,
SearchEngineData<Algorithm>::QueryHeap &,
EdgeWeight &weight,
inline void search(const datafacade::ContiguousInternalMemoryDataFacade<algorithm::CH> &facade,
SearchEngineData::QueryHeap &forward_heap,
SearchEngineData::QueryHeap &reverse_heap,
SearchEngineData::QueryHeap &,
SearchEngineData::QueryHeap &,
std::int32_t &weight,
std::vector<NodeID> &packed_leg,
const bool force_loop_forward,
const bool force_loop_reverse,
const PhantomNodes & /*phantom_nodes*/,
const int duration_upper_bound = INVALID_EDGE_WEIGHT)
{
search(facade,
@@ -382,35 +382,6 @@ inline void search(const datafacade::ContiguousInternalMemoryDataFacade<Algorith
duration_upper_bound);
}
// Requires the heaps for be empty
// If heaps should be adjusted to be initialized outside of this function,
// the addition of force_loop parameters might be required
double
getNetworkDistance(const datafacade::ContiguousInternalMemoryDataFacade<ch::Algorithm> &facade,
SearchEngineData<Algorithm>::QueryHeap &forward_heap,
SearchEngineData<Algorithm>::QueryHeap &reverse_heap,
const PhantomNode &source_phantom,
const PhantomNode &target_phantom,
int duration_upper_bound = INVALID_EDGE_WEIGHT);
// Alias to be compatible with the overload for CoreCH that needs 4 heaps
inline double
getNetworkDistance(const datafacade::ContiguousInternalMemoryDataFacade<ch::Algorithm> &facade,
SearchEngineData<Algorithm>::QueryHeap &forward_heap,
SearchEngineData<Algorithm>::QueryHeap &reverse_heap,
SearchEngineData<Algorithm>::QueryHeap &,
SearchEngineData<Algorithm>::QueryHeap &,
const PhantomNode &source_phantom,
const PhantomNode &target_phantom,
int duration_upper_bound = INVALID_EDGE_WEIGHT)
{
return getNetworkDistance(
facade, forward_heap, reverse_heap, source_phantom, target_phantom, duration_upper_bound);
}
} // namespace ch
namespace corech
{
// assumes that heaps are already setup correctly.
// A forced loop might be necessary, if source and target are on the same segment.
// If this is the case and the offsets of the respective direction are larger for the source
@@ -420,43 +391,66 @@ namespace corech
// && source_phantom.GetForwardWeightPlusOffset() > target_phantom.GetForwardWeightPlusOffset())
// requires
// a force loop, if the heaps have been initialized with positive offsets.
void search(const datafacade::ContiguousInternalMemoryDataFacade<corech::Algorithm> &facade,
SearchEngineData<Algorithm>::QueryHeap &forward_heap,
SearchEngineData<Algorithm>::QueryHeap &reverse_heap,
SearchEngineData<Algorithm>::QueryHeap &forward_core_heap,
SearchEngineData<Algorithm>::QueryHeap &reverse_core_heap,
void search(const datafacade::ContiguousInternalMemoryDataFacade<algorithm::CoreCH> &facade,
SearchEngineData::QueryHeap &forward_heap,
SearchEngineData::QueryHeap &reverse_heap,
SearchEngineData::QueryHeap &forward_core_heap,
SearchEngineData::QueryHeap &reverse_core_heap,
int &weight,
std::vector<NodeID> &packed_leg,
const bool force_loop_forward,
const bool force_loop_reverse,
const PhantomNodes &phantom_nodes,
int duration_upper_bound = INVALID_EDGE_WEIGHT);
bool needsLoopForward(const PhantomNode &source_phantom, const PhantomNode &target_phantom);
bool needsLoopBackwards(const PhantomNode &source_phantom, const PhantomNode &target_phantom);
double getPathDistance(const datafacade::ContiguousInternalMemoryDataFacade<algorithm::CH> &facade,
const std::vector<NodeID> &packed_path,
const PhantomNode &source_phantom,
const PhantomNode &target_phantom);
// Requires the heaps for be empty
// If heaps should be adjusted to be initialized outside of this function,
// the addition of force_loop parameters might be required
double
getNetworkDistance(const datafacade::ContiguousInternalMemoryDataFacade<corech::Algorithm> &facade,
SearchEngineData<Algorithm>::QueryHeap &forward_heap,
SearchEngineData<Algorithm>::QueryHeap &reverse_heap,
SearchEngineData<Algorithm>::QueryHeap &forward_core_heap,
SearchEngineData<Algorithm>::QueryHeap &reverse_core_heap,
getNetworkDistance(const datafacade::ContiguousInternalMemoryDataFacade<algorithm::CoreCH> &facade,
SearchEngineData::QueryHeap &forward_heap,
SearchEngineData::QueryHeap &reverse_heap,
SearchEngineData::QueryHeap &forward_core_heap,
SearchEngineData::QueryHeap &reverse_core_heap,
const PhantomNode &source_phantom,
const PhantomNode &target_phantom,
int duration_upper_bound = INVALID_EDGE_WEIGHT);
template <typename RandomIter, typename FacadeT>
void unpackPath(const FacadeT &facade,
RandomIter packed_path_begin,
RandomIter packed_path_end,
const PhantomNodes &phantom_nodes,
std::vector<PathData> &unpacked_path)
// Requires the heaps for be empty
// If heaps should be adjusted to be initialized outside of this function,
// the addition of force_loop parameters might be required
double
getNetworkDistance(const datafacade::ContiguousInternalMemoryDataFacade<algorithm::CH> &facade,
SearchEngineData::QueryHeap &forward_heap,
SearchEngineData::QueryHeap &reverse_heap,
const PhantomNode &source_phantom,
const PhantomNode &target_phantom,
int duration_upper_bound = INVALID_EDGE_WEIGHT);
// Alias to be compatible with the overload for CoreCH that needs 4 heaps
inline double
getNetworkDistance(const datafacade::ContiguousInternalMemoryDataFacade<algorithm::CH> &facade,
SearchEngineData::QueryHeap &forward_heap,
SearchEngineData::QueryHeap &reverse_heap,
SearchEngineData::QueryHeap &,
SearchEngineData::QueryHeap &,
const PhantomNode &source_phantom,
const PhantomNode &target_phantom,
int duration_upper_bound = INVALID_EDGE_WEIGHT)
{
return ch::unpackPath(facade, packed_path_begin, packed_path_end, phantom_nodes, unpacked_path);
return getNetworkDistance(
facade, forward_heap, reverse_heap, source_phantom, target_phantom, duration_upper_bound);
}
} // namespace corech
} // namespace ch
} // namespace routing_algorithms
} // namespace engine
} // namespace osrm
@@ -24,9 +24,9 @@ namespace
// Unrestricted search (Args is const PhantomNodes &):
// * use partition.GetQueryLevel to find the node query level based on source and target phantoms
// * allow to traverse all cells
inline LevelID getNodeQureyLevel(const partition::MultiLevelPartitionView &partition,
NodeID node,
const PhantomNodes &phantom_nodes)
LevelID getNodeQureyLevel(const partition::MultiLevelPartitionView &partition,
NodeID node,
const PhantomNodes &phantom_nodes)
{
auto level = [&partition, node](const SegmentID &source, const SegmentID &target) {
if (source.enabled && target.enabled)
@@ -43,31 +43,25 @@ inline LevelID getNodeQureyLevel(const partition::MultiLevelPartitionView &parti
phantom_nodes.target_phantom.reverse_segment_id)));
}
inline bool checkParentCellRestriction(CellID, const PhantomNodes &) { return true; }
bool checkParentCellRestriction(CellID, const PhantomNodes &) { return true; }
// 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
inline LevelID
getNodeQureyLevel(const partition::MultiLevelPartitionView &, NodeID, LevelID level, CellID)
LevelID getNodeQureyLevel(const partition::MultiLevelPartitionView &, NodeID, LevelID level, CellID)
{
return level;
}
inline bool checkParentCellRestriction(CellID cell, LevelID, CellID parent)
{
return cell == parent;
}
bool checkParentCellRestriction(CellID cell, LevelID, CellID parent) { return cell == parent; }
}
template <bool DIRECTION, typename... Args>
void routingStep(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
SearchEngineData<Algorithm>::QueryHeap &forward_heap,
SearchEngineData<Algorithm>::QueryHeap &reverse_heap,
void routingStep(const datafacade::ContiguousInternalMemoryDataFacade<algorithm::MLD> &facade,
SearchEngineData::MultiLayerDijkstraHeap &forward_heap,
SearchEngineData::MultiLayerDijkstraHeap &reverse_heap,
NodeID &middle_node,
EdgeWeight &path_upper_bound,
const bool force_loop_forward,
const bool force_loop_reverse,
Args... args)
{
const auto &partition = facade.GetMultiLevelPartition();
@@ -85,11 +79,7 @@ void routingStep(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm>
{
auto reverse_weight = reverse_heap.GetKey(node);
auto path_weight = weight + reverse_weight;
// if loops are forced, they are so at the source
if (!(force_loop_forward && forward_heap.GetData(node).parent == node) &&
!(force_loop_reverse && reverse_heap.GetData(node).parent == node) &&
(path_weight >= 0) && (path_weight < path_upper_bound))
if (path_weight >= 0 && path_weight < path_upper_bound)
{
middle_node = node;
path_upper_bound = path_weight;
@@ -181,11 +171,9 @@ void routingStep(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm>
template <typename... Args>
std::tuple<EdgeWeight, NodeID, NodeID, std::vector<EdgeID>>
search(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
SearchEngineData<Algorithm>::QueryHeap &forward_heap,
SearchEngineData<Algorithm>::QueryHeap &reverse_heap,
const bool force_loop_forward,
const bool force_loop_reverse,
search(const datafacade::ContiguousInternalMemoryDataFacade<algorithm::MLD> &facade,
SearchEngineData::MultiLayerDijkstraHeap &forward_heap,
SearchEngineData::MultiLayerDijkstraHeap &reverse_heap,
Args... args)
{
@@ -204,27 +192,15 @@ search(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
{
if (!forward_heap.Empty())
{
routingStep<FORWARD_DIRECTION>(facade,
forward_heap,
reverse_heap,
middle,
weight,
force_loop_forward,
force_loop_reverse,
args...);
routingStep<FORWARD_DIRECTION>(
facade, forward_heap, reverse_heap, middle, weight, args...);
if (!forward_heap.Empty())
forward_heap_min = forward_heap.MinKey();
}
if (!reverse_heap.Empty())
{
routingStep<REVERSE_DIRECTION>(facade,
reverse_heap,
forward_heap,
middle,
weight,
force_loop_reverse,
force_loop_forward,
args...);
routingStep<REVERSE_DIRECTION>(
facade, reverse_heap, forward_heap, middle, weight, args...);
if (!reverse_heap.Empty())
reverse_heap_min = reverse_heap.MinKey();
}
@@ -292,13 +268,7 @@ search(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
NodeID subpath_source, subpath_target;
std::vector<EdgeID> subpath;
std::tie(subpath_weight, subpath_source, subpath_target, subpath) =
search(facade,
forward_heap,
reverse_heap,
force_loop_forward,
force_loop_reverse,
sublevel,
parent_cell_id);
search(facade, forward_heap, reverse_heap, sublevel, parent_cell_id);
BOOST_ASSERT(!subpath.empty());
BOOST_ASSERT(subpath_source == source);
BOOST_ASSERT(subpath_target == target);
@@ -309,94 +279,6 @@ search(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
return std::make_tuple(weight, source_node, target_node, std::move(unpacked_path));
}
// Alias to be compatible with the overload for CoreCH that needs 4 heaps for shortest path search
inline void search(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
SearchEngineData<Algorithm>::QueryHeap &forward_heap,
SearchEngineData<Algorithm>::QueryHeap &reverse_heap,
SearchEngineData<Algorithm>::QueryHeap &,
SearchEngineData<Algorithm>::QueryHeap &,
EdgeWeight &weight,
std::vector<NodeID> &packed_leg,
const bool force_loop_forward,
const bool force_loop_reverse,
const PhantomNodes &phantom_nodes,
const int duration_upper_bound = INVALID_EDGE_WEIGHT)
{
(void)duration_upper_bound; // TODO: limiting search radius is not implemented for MLD
NodeID source_node, target_node;
std::vector<EdgeID> unpacked_edges;
std::tie(weight, source_node, target_node, unpacked_edges) = mld::search(
facade, forward_heap, reverse_heap, force_loop_forward, force_loop_reverse, phantom_nodes);
if (weight != INVALID_EDGE_WEIGHT)
{
packed_leg.push_back(source_node);
std::transform(unpacked_edges.begin(),
unpacked_edges.end(),
std::back_inserter(packed_leg),
[&facade](const auto edge) { return facade.GetTarget(edge); });
}
}
template <typename RandomIter, typename FacadeT>
void unpackPath(const FacadeT &facade,
RandomIter packed_path_begin,
RandomIter packed_path_end,
const PhantomNodes &phantom_nodes,
std::vector<PathData> &unpacked_path)
{
const auto nodes_number = std::distance(packed_path_begin, packed_path_end);
BOOST_ASSERT(nodes_number > 0);
std::vector<EdgeID> unpacked_edges;
auto source_node = *packed_path_begin, target_node = *packed_path_begin;
if (nodes_number > 1)
{
target_node = *std::prev(packed_path_end);
util::for_each_pair(packed_path_begin,
packed_path_end,
[&facade, &unpacked_edges](const auto from, const auto to) {
unpacked_edges.push_back(facade.FindEdge(from, to));
});
}
annotatePath(facade, source_node, target_node, unpacked_edges, phantom_nodes, unpacked_path);
}
inline double
getNetworkDistance(const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
SearchEngineData<Algorithm>::QueryHeap &forward_heap,
SearchEngineData<Algorithm>::QueryHeap &reverse_heap,
SearchEngineData<Algorithm>::QueryHeap & /*forward_core_heap*/,
SearchEngineData<Algorithm>::QueryHeap & /*reverse_core_heap*/,
const PhantomNode &source_phantom,
const PhantomNode &target_phantom,
int /*duration_upper_bound*/)
{
forward_heap.Clear();
reverse_heap.Clear();
const PhantomNodes phantom_nodes{source_phantom, target_phantom};
insertNodesInHeaps(forward_heap, reverse_heap, phantom_nodes);
EdgeWeight weight;
NodeID source_node, target_node;
std::vector<EdgeID> unpacked_edges;
std::tie(weight, source_node, target_node, unpacked_edges) = search(
facade, forward_heap, reverse_heap, DO_NOT_FORCE_LOOPS, DO_NOT_FORCE_LOOPS, phantom_nodes);
if (weight == INVALID_EDGE_WEIGHT)
return std::numeric_limits<double>::max();
std::vector<PathData> unpacked_path;
annotatePath(facade, source_node, target_node, unpacked_edges, phantom_nodes, unpacked_path);
return getPathDistance(facade, unpacked_path, source_phantom, target_phantom);
}
} // namespace mld
} // namespace routing_algorithms
} // namespace engine
@@ -13,10 +13,15 @@ namespace engine
namespace routing_algorithms
{
template <typename Algorithm>
InternalRouteResult
shortestPathSearch(SearchEngineData<Algorithm> &engine_working_data,
const datafacade::ContiguousInternalMemoryDataFacade<Algorithm> &facade,
shortestPathSearch(SearchEngineData &engine_working_data,
const datafacade::ContiguousInternalMemoryDataFacade<algorithm::CH> &facade,
const std::vector<PhantomNodes> &phantom_nodes_vector,
const boost::optional<bool> continue_straight_at_waypoint);
InternalRouteResult
shortestPathSearch(SearchEngineData &engine_working_data,
const datafacade::ContiguousInternalMemoryDataFacade<algorithm::CoreCH> &facade,
const std::vector<PhantomNodes> &phantom_nodes_vector,
const boost::optional<bool> continue_straight_at_waypoint);
@@ -29,7 +29,7 @@ struct TurnData final
using RTreeLeaf = datafacade::BaseDataFacade::RTreeLeaf;
std::vector<TurnData>
getTileTurns(const datafacade::ContiguousInternalMemoryDataFacade<ch::Algorithm> &facade,
getTileTurns(const datafacade::ContiguousInternalMemoryDataFacade<algorithm::CH> &facade,
const std::vector<RTreeLeaf> &edges,
const std::vector<std::size_t> &sorted_edge_indexes);
+24 -33
View File
@@ -3,7 +3,7 @@
#include <boost/thread/tss.hpp>
#include "engine/algorithm.hpp"
#include "partition/multi_level_partition.hpp"
#include "util/binary_heap.hpp"
#include "util/typedefs.hpp"
@@ -24,7 +24,14 @@ struct ManyToManyHeapData : HeapData
ManyToManyHeapData(NodeID p, EdgeWeight duration) : HeapData(p), duration(duration) {}
};
template <typename Algorithm> struct SearchEngineData
struct MultiLayerDijkstraHeapData : HeapData
{
bool from_clique_arc;
MultiLayerDijkstraHeapData(NodeID p) : HeapData(p), from_clique_arc(false) {}
MultiLayerDijkstraHeapData(NodeID p, bool from) : HeapData(p), from_clique_arc(from) {}
};
struct SearchEngineData
{
using QueryHeap = util::
BinaryHeap<NodeID, NodeID, EdgeWeight, HeapData, util::UnorderedMapStorage<NodeID, int>>;
@@ -38,6 +45,14 @@ template <typename Algorithm> struct SearchEngineData
using ManyToManyHeapPtr = boost::thread_specific_ptr<ManyToManyQueryHeap>;
using MultiLayerDijkstraHeap = util::BinaryHeap<NodeID,
NodeID,
EdgeWeight,
MultiLayerDijkstraHeapData,
util::UnorderedMapStorage<NodeID, int>>;
using MultiLayerDijkstraHeapPtr = boost::thread_specific_ptr<MultiLayerDijkstraHeap>;
static SearchEngineHeapPtr forward_heap_1;
static SearchEngineHeapPtr reverse_heap_1;
static SearchEngineHeapPtr forward_heap_2;
@@ -45,42 +60,18 @@ template <typename Algorithm> struct SearchEngineData
static SearchEngineHeapPtr forward_heap_3;
static SearchEngineHeapPtr reverse_heap_3;
static ManyToManyHeapPtr many_to_many_heap;
static MultiLayerDijkstraHeapPtr mld_forward_heap;
static MultiLayerDijkstraHeapPtr mld_reverse_heap;
void InitializeOrClearFirstThreadLocalStorage(unsigned number_of_nodes);
void InitializeOrClearFirstThreadLocalStorage(const unsigned number_of_nodes);
void InitializeOrClearSecondThreadLocalStorage(unsigned number_of_nodes);
void InitializeOrClearSecondThreadLocalStorage(const unsigned number_of_nodes);
void InitializeOrClearThirdThreadLocalStorage(unsigned number_of_nodes);
void InitializeOrClearThirdThreadLocalStorage(const unsigned number_of_nodes);
void InitializeOrClearManyToManyThreadLocalStorage(unsigned number_of_nodes);
};
void InitializeOrClearManyToManyThreadLocalStorage(const unsigned number_of_nodes);
struct MultiLayerDijkstraHeapData
{
NodeID parent;
bool from_clique_arc;
MultiLayerDijkstraHeapData(NodeID p) : parent(p), from_clique_arc(false) {}
MultiLayerDijkstraHeapData(NodeID p, bool from) : parent(p), from_clique_arc(from) {}
};
template <> struct SearchEngineData<routing_algorithms::mld::Algorithm>
{
using QueryHeap = util::BinaryHeap<NodeID,
NodeID,
EdgeWeight,
MultiLayerDijkstraHeapData,
util::UnorderedMapStorage<NodeID, int>>;
using SearchEngineHeapPtr = boost::thread_specific_ptr<QueryHeap>;
static SearchEngineHeapPtr forward_heap_1;
static SearchEngineHeapPtr reverse_heap_1;
static SearchEngineHeapPtr forward_heap_2;
static SearchEngineHeapPtr reverse_heap_2;
void InitializeOrClearFirstThreadLocalStorage(unsigned number_of_nodes);
void InitializeOrClearSecondThreadLocalStorage(unsigned number_of_nodes);
void InitializeOrClearMultiLayerDijkstraThreadLocalStorage(const unsigned number_of_nodes);
};
}
}
@@ -21,7 +21,6 @@
#include "util/guidance/entry_class.hpp"
#include "util/name_table.hpp"
#include "util/node_based_graph.hpp"
#include "util/packed_vector.hpp"
#include "util/typedefs.hpp"
#include "storage/io.hpp"
@@ -73,8 +72,7 @@ class EdgeBasedGraphFactory
const std::unordered_set<NodeID> &barrier_nodes,
const std::unordered_set<NodeID> &traffic_lights,
std::shared_ptr<const RestrictionMap> restriction_map,
const std::vector<util::Coordinate> &coordinates,
const util::PackedVector<OSMNodeID> &osm_node_ids,
const std::vector<QueryNode> &node_info_list,
ProfileProperties profile_properties,
const util::NameTable &name_table,
std::vector<std::uint32_t> &turn_lane_offsets,
@@ -130,8 +128,7 @@ class EdgeBasedGraphFactory
util::DeallocatingVector<EdgeBasedEdge> m_edge_based_edge_list;
EdgeID m_max_edge_id;
const std::vector<util::Coordinate> &m_coordinates;
const util::PackedVector<OSMNodeID> &m_osm_node_ids;
const std::vector<QueryNode> &m_node_info_list;
std::shared_ptr<util::NodeBasedDynamicGraph> m_node_based_graph;
std::shared_ptr<RestrictionMap const> m_restriction_map;
+13 -6
View File
@@ -62,6 +62,13 @@ struct ExtractionWay
forward_restricted = false;
}
// These accessors exists because it's not possible to take the address of a bitfield,
// and LUA therefore cannot read/write the mode attributes directly.
void set_forward_mode(const TravelMode m) { forward_travel_mode = m; }
TravelMode get_forward_mode() const { return forward_travel_mode; }
void set_backward_mode(const TravelMode m) { backward_travel_mode = m; }
TravelMode get_backward_mode() const { return backward_travel_mode; }
// wrappers to allow assigning nil (nullptr) to string values
void SetName(const char *value) { detail::maybeSetString(name, value); }
const char *GetName() const { return name.c_str(); }
@@ -98,14 +105,14 @@ struct ExtractionWay
std::string destinations;
std::string turn_lanes_forward;
std::string turn_lanes_backward;
guidance::RoadClassification road_classification;
bool roundabout;
bool circular;
bool is_startpoint;
bool backward_restricted;
bool forward_restricted;
TravelMode forward_travel_mode : 4;
TravelMode backward_travel_mode : 4;
bool roundabout : 1;
bool circular : 1;
bool is_startpoint : 1;
bool forward_restricted : 1;
bool backward_restricted : 1;
guidance::RoadClassification road_classification;
};
}
}
+5 -6
View File
@@ -58,8 +58,7 @@ class Extractor
std::pair<std::size_t, EdgeID>
BuildEdgeExpandedGraph(ScriptingEnvironment &scripting_environment,
std::vector<util::Coordinate> &coordinates,
util::PackedVector<OSMNodeID> &osm_node_ids,
std::vector<QueryNode> &internal_to_external_node_map,
std::vector<EdgeBasedNode> &node_based_edge_list,
std::vector<bool> &node_is_startpoint,
std::vector<EdgeWeight> &edge_based_node_weights,
@@ -67,18 +66,18 @@ class Extractor
const std::string &intersection_class_output_file);
void WriteProfileProperties(const std::string &output_path,
const ProfileProperties &properties) const;
void WriteNodeMapping(const std::vector<QueryNode> &internal_to_external_node_map);
void FindComponents(unsigned max_edge_id,
const util::DeallocatingVector<EdgeBasedEdge> &edges,
std::vector<EdgeBasedNode> &nodes) const;
void BuildRTree(std::vector<EdgeBasedNode> node_based_edge_list,
std::vector<bool> node_is_startpoint,
const std::vector<util::Coordinate> &coordinates);
const std::vector<QueryNode> &internal_to_external_node_map);
std::shared_ptr<RestrictionMap> LoadRestrictionMap();
std::shared_ptr<util::NodeBasedDynamicGraph>
LoadNodeBasedGraph(std::unordered_set<NodeID> &barrier_nodes,
std::unordered_set<NodeID> &traffic_lights,
std::vector<util::Coordinate> &coordinates,
util::PackedVector<OSMNodeID> &osm_node_ids);
std::vector<QueryNode> &internal_to_external_node_map);
void WriteEdgeBasedGraph(const std::string &output_file_filename,
const EdgeID max_edge_id,
@@ -95,7 +94,7 @@ class Extractor
// Writes compressed node based graph and its embedding into a file for osrm-partition to use.
static void WriteCompressedNodeBasedGraph(const std::string &path,
const util::NodeBasedDynamicGraph &graph,
const std::vector<util::Coordinate> &coordiantes);
const std::vector<QueryNode> &externals);
// globals persisting during the extraction process and the graph generation process
@@ -63,7 +63,6 @@ class ExtractorCallbacks
guidance::LaneDescriptionMap lane_description_map;
ExtractionContainers &external_memory;
bool fallback_to_duration;
bool force_split_edges;
public:
explicit ExtractorCallbacks(ExtractionContainers &extraction_containers,
-180
View File
@@ -1,180 +0,0 @@
#ifndef OSRM_EXTRACTOR_FILES_HPP
#define OSRM_EXTRACTOR_FILES_HPP
#include "extractor/guidance/turn_lane_types.hpp"
#include "extractor/serialization.hpp"
#include "util/coordinate.hpp"
#include "util/packed_vector.hpp"
#include "util/serialization.hpp"
#include <boost/assert.hpp>
namespace osrm
{
namespace extractor
{
namespace files
{
// reads .osrm.nodes
template <typename CoordinatesT, typename PackedOSMIDsT>
inline void readNodes(const boost::filesystem::path &path,
CoordinatesT &coordinates,
PackedOSMIDsT &osm_node_ids)
{
static_assert(std::is_same<typename CoordinatesT::value_type, util::Coordinate>::value, "");
static_assert(std::is_same<typename PackedOSMIDsT::value_type, OSMNodeID>::value, "");
const auto fingerprint = storage::io::FileReader::VerifyFingerprint;
storage::io::FileReader reader{path, fingerprint};
storage::serialization::read(reader, coordinates);
util::serialization::read(reader, osm_node_ids);
}
// writes .osrm.nodes
template <typename CoordinatesT, typename PackedOSMIDsT>
inline void writeNodes(const boost::filesystem::path &path,
const CoordinatesT &coordinates,
const PackedOSMIDsT &osm_node_ids)
{
static_assert(std::is_same<typename CoordinatesT::value_type, util::Coordinate>::value, "");
static_assert(std::is_same<typename PackedOSMIDsT::value_type, OSMNodeID>::value, "");
const auto fingerprint = storage::io::FileWriter::GenerateFingerprint;
storage::io::FileWriter writer{path, fingerprint};
storage::serialization::write(writer, coordinates);
util::serialization::write(writer, osm_node_ids);
}
// reads .osrm.cnbg_to_ebg
inline void readNBGMapping(const boost::filesystem::path &path, std::vector<NBGToEBG> &mapping)
{
const auto fingerprint = storage::io::FileReader::VerifyFingerprint;
storage::io::FileReader reader{path, fingerprint};
storage::serialization::read(reader, mapping);
}
// writes .osrm.cnbg_to_ebg
inline void writeNBGMapping(const boost::filesystem::path &path,
const std::vector<NBGToEBG> &mapping)
{
const auto fingerprint = storage::io::FileWriter::GenerateFingerprint;
storage::io::FileWriter writer{path, fingerprint};
storage::serialization::write(writer, mapping);
}
// reads .osrm.datasource_names
inline void readDatasources(const boost::filesystem::path &path, Datasources &sources)
{
const auto fingerprint = storage::io::FileReader::HasNoFingerprint;
storage::io::FileReader reader{path, fingerprint};
serialization::read(reader, sources);
}
// writes .osrm.datasource_names
inline void writeDatasources(const boost::filesystem::path &path, Datasources &sources)
{
const auto fingerprint = storage::io::FileWriter::HasNoFingerprint;
storage::io::FileWriter writer{path, fingerprint};
serialization::write(writer, sources);
}
// reads .osrm.geometry
template <typename SegmentDataT>
inline void readSegmentData(const boost::filesystem::path &path, SegmentDataT &segment_data)
{
static_assert(std::is_same<SegmentDataContainer, SegmentDataT>::value ||
std::is_same<SegmentDataView, SegmentDataT>::value,
"");
const auto fingerprint = storage::io::FileReader::HasNoFingerprint;
storage::io::FileReader reader{path, fingerprint};
serialization::read(reader, segment_data);
}
// writes .osrm.geometry
template <typename SegmentDataT>
inline void writeSegmentData(const boost::filesystem::path &path, const SegmentDataT &segment_data)
{
static_assert(std::is_same<SegmentDataContainer, SegmentDataT>::value ||
std::is_same<SegmentDataView, SegmentDataT>::value,
"");
const auto fingerprint = storage::io::FileWriter::HasNoFingerprint;
storage::io::FileWriter writer{path, fingerprint};
serialization::write(writer, segment_data);
}
// reads .osrm.edges
template <typename TurnDataT>
inline void readTurnData(const boost::filesystem::path &path, TurnDataT &turn_data)
{
static_assert(std::is_same<TurnDataContainer, TurnDataT>::value ||
std::is_same<TurnDataView, TurnDataT>::value,
"");
const auto fingerprint = storage::io::FileReader::HasNoFingerprint;
storage::io::FileReader reader{path, fingerprint};
serialization::read(reader, turn_data);
}
// writes .osrm.edges
template <typename TurnDataT>
inline void writeTurnData(const boost::filesystem::path &path, const TurnDataT &turn_data)
{
static_assert(std::is_same<TurnDataContainer, TurnDataT>::value ||
std::is_same<TurnDataView, TurnDataT>::value,
"");
const auto fingerprint = storage::io::FileWriter::HasNoFingerprint;
storage::io::FileWriter writer{path, fingerprint};
serialization::write(writer, turn_data);
}
// reads .osrm.tls
template <typename OffsetsT, typename MaskT>
inline void readTurnLaneDescriptions(const boost::filesystem::path &path,
OffsetsT &turn_offsets,
MaskT &turn_masks)
{
static_assert(
std::is_same<typename MaskT::value_type, extractor::guidance::TurnLaneType::Mask>::value,
"");
static_assert(std::is_same<typename OffsetsT::value_type, std::uint32_t>::value, "");
const auto fingerprint = storage::io::FileReader::HasNoFingerprint;
storage::io::FileReader reader{path, fingerprint};
storage::serialization::read(reader, turn_offsets);
storage::serialization::read(reader, turn_masks);
}
// writes .osrm.tls
template <typename OffsetsT, typename MaskT>
inline void writeTurnLaneDescriptions(const boost::filesystem::path &path,
const OffsetsT &turn_offsets,
const MaskT &turn_masks)
{
static_assert(
std::is_same<typename MaskT::value_type, extractor::guidance::TurnLaneType::Mask>::value,
"");
static_assert(std::is_same<typename OffsetsT::value_type, std::uint32_t>::value, "");
const auto fingerprint = storage::io::FileWriter::HasNoFingerprint;
storage::io::FileWriter writer{path, fingerprint};
storage::serialization::write(writer, turn_offsets);
storage::serialization::write(writer, turn_masks);
}
}
}
}
#endif
@@ -23,7 +23,7 @@ class CoordinateExtractor
public:
CoordinateExtractor(const util::NodeBasedDynamicGraph &node_based_graph,
const extractor::CompressedEdgeContainer &compressed_geometries,
const std::vector<util::Coordinate> &node_coordinates);
const std::vector<extractor::QueryNode> &node_coordinates);
/* Find a interpolated coordinate a long the compressed geometries. The desired coordinate
* should be in a certain distance. This method is dedicated to find representative coordinates
@@ -156,7 +156,7 @@ class CoordinateExtractor
private:
const util::NodeBasedDynamicGraph &node_based_graph;
const extractor::CompressedEdgeContainer &compressed_geometries;
const std::vector<util::Coordinate> &node_coordinates;
const std::vector<extractor::QueryNode> &node_coordinates;
double ComputeInterpolationFactor(const double desired_distance,
const double distance_to_first,
@@ -40,7 +40,7 @@ class IntersectionGenerator
IntersectionGenerator(const util::NodeBasedDynamicGraph &node_based_graph,
const RestrictionMap &restriction_map,
const std::unordered_set<NodeID> &barrier_nodes,
const std::vector<util::Coordinate> &coordinates,
const std::vector<QueryNode> &node_info_list,
const CompressedEdgeContainer &compressed_edge_container);
// For a source node `a` and a via edge `ab` creates an intersection at target `b`.
@@ -112,7 +112,7 @@ class IntersectionGenerator
const util::NodeBasedDynamicGraph &node_based_graph;
const RestrictionMap &restriction_map;
const std::unordered_set<NodeID> &barrier_nodes;
const std::vector<util::Coordinate> &coordinates;
const std::vector<QueryNode> &node_info_list;
// own state, used to find the correct coordinates along a road
const CoordinateExtractor coordinate_extractor;
@@ -34,7 +34,7 @@ class IntersectionHandler
{
public:
IntersectionHandler(const util::NodeBasedDynamicGraph &node_based_graph,
const std::vector<util::Coordinate> &coordinates,
const std::vector<QueryNode> &node_info_list,
const util::NameTable &name_table,
const SuffixTable &street_name_suffix_table,
const IntersectionGenerator &intersection_generator);
@@ -51,7 +51,7 @@ class IntersectionHandler
protected:
const util::NodeBasedDynamicGraph &node_based_graph;
const std::vector<util::Coordinate> &coordinates;
const std::vector<QueryNode> &node_info_list;
const util::NameTable &name_table;
const SuffixTable &street_name_suffix_table;
const IntersectionGenerator &intersection_generator;
@@ -43,7 +43,7 @@ class IntersectionNormalizer
std::vector<IntersectionNormalizationOperation> performed_merges;
};
IntersectionNormalizer(const util::NodeBasedDynamicGraph &node_based_graph,
const std::vector<util::Coordinate> &node_coordinates,
const std::vector<extractor::QueryNode> &node_coordinates,
const util::NameTable &name_table,
const SuffixTable &street_name_suffix_table,
const IntersectionGenerator &intersection_generator);
@@ -2,7 +2,6 @@
#define OSRM_EXTRACTOR_GUIDANCE_MERGEABLE_ROADS
#include "extractor/guidance/intersection.hpp"
#include "util/coordinate.hpp"
#include "util/node_based_graph.hpp"
#include "util/typedefs.hpp"
@@ -23,6 +22,7 @@ class NameTable;
namespace extractor
{
struct QueryNode;
class SuffixTable;
namespace guidance
@@ -37,7 +37,7 @@ class MergableRoadDetector
using MergableRoadData = IntersectionShapeData;
MergableRoadDetector(const util::NodeBasedDynamicGraph &node_based_graph,
const std::vector<util::Coordinate> &node_coordinates,
const std::vector<QueryNode> &node_coordinates,
const IntersectionGenerator &intersection_generator,
const CoordinateExtractor &coordinate_extractor,
const util::NameTable &name_table,
@@ -138,7 +138,7 @@ class MergableRoadDetector
bool IsLinkRoad(const NodeID intersection_node, const MergableRoadData &road) const;
const util::NodeBasedDynamicGraph &node_based_graph;
const std::vector<util::Coordinate> &node_coordinates;
const std::vector<QueryNode> &node_coordinates;
const IntersectionGenerator &intersection_generator;
const CoordinateExtractor &coordinate_extractor;
@@ -25,7 +25,7 @@ class MotorwayHandler : public IntersectionHandler
{
public:
MotorwayHandler(const util::NodeBasedDynamicGraph &node_based_graph,
const std::vector<util::Coordinate> &coordinates,
const std::vector<QueryNode> &node_info_list,
const util::NameTable &name_table,
const SuffixTable &street_name_suffix_table,
const IntersectionGenerator &intersection_generator);
@@ -41,7 +41,7 @@ class RoundaboutHandler : public IntersectionHandler
{
public:
RoundaboutHandler(const util::NodeBasedDynamicGraph &node_based_graph,
const std::vector<util::Coordinate> &coordinates,
const std::vector<QueryNode> &node_info_list,
const CompressedEdgeContainer &compressed_edge_container,
const util::NameTable &name_table,
const SuffixTable &street_name_suffix_table,
@@ -27,7 +27,7 @@ class SliproadHandler final : public IntersectionHandler
public:
SliproadHandler(const IntersectionGenerator &intersection_generator,
const util::NodeBasedDynamicGraph &node_based_graph,
const std::vector<util::Coordinate> &coordinates,
const std::vector<QueryNode> &node_info_list,
const util::NameTable &name_table,
const SuffixTable &street_name_suffix_table);
@@ -23,7 +23,7 @@ class SuppressModeHandler final : public IntersectionHandler
public:
SuppressModeHandler(const IntersectionGenerator &intersection_generator,
const util::NodeBasedDynamicGraph &node_based_graph,
const std::vector<util::Coordinate> &coordinates,
const std::vector<QueryNode> &node_info_list,
const util::NameTable &name_table,
const SuffixTable &street_name_suffix_table);
+1 -1
View File
@@ -40,7 +40,7 @@ class TurnAnalysis
{
public:
TurnAnalysis(const util::NodeBasedDynamicGraph &node_based_graph,
const std::vector<util::Coordinate> &coordinates,
const std::vector<QueryNode> &node_info_list,
const RestrictionMap &restriction_map,
const std::unordered_set<NodeID> &barrier_nodes,
const CompressedEdgeContainer &compressed_edge_container,
+1 -1
View File
@@ -29,7 +29,7 @@ class TurnHandler : public IntersectionHandler
{
public:
TurnHandler(const util::NodeBasedDynamicGraph &node_based_graph,
const std::vector<util::Coordinate> &coordinates,
const std::vector<QueryNode> &node_info_list,
const util::NameTable &name_table,
const SuffixTable &street_name_suffix_table,
const IntersectionGenerator &intersection_generator);
+103
View File
@@ -0,0 +1,103 @@
#ifndef OSRM_EXTRACTOR_IO_HPP
#define OSRM_EXTRACTOR_IO_HPP
#include "extractor/datasources.hpp"
#include "extractor/nbg_to_ebg.hpp"
#include "extractor/segment_data_container.hpp"
#include "storage/io.hpp"
#include <boost/assert.hpp>
namespace osrm
{
namespace extractor
{
namespace io
{
inline void read(const boost::filesystem::path &path, std::vector<NBGToEBG> &mapping)
{
const auto fingerprint = storage::io::FileReader::VerifyFingerprint;
storage::io::FileReader reader{path, fingerprint};
reader.DeserializeVector(mapping);
}
inline void write(const boost::filesystem::path &path, const std::vector<NBGToEBG> &mapping)
{
const auto fingerprint = storage::io::FileWriter::GenerateFingerprint;
storage::io::FileWriter reader{path, fingerprint};
reader.SerializeVector(mapping);
}
inline void read(const boost::filesystem::path &path, Datasources &sources)
{
const auto fingerprint = storage::io::FileReader::HasNoFingerprint;
storage::io::FileReader reader{path, fingerprint};
reader.ReadInto(sources);
}
inline void write(const boost::filesystem::path &path, Datasources &sources)
{
const auto fingerprint = storage::io::FileWriter::HasNoFingerprint;
storage::io::FileWriter writer{path, fingerprint};
writer.WriteFrom(sources);
}
template <>
inline void read(const boost::filesystem::path &path, SegmentDataContainer &segment_data)
{
const auto fingerprint = storage::io::FileReader::HasNoFingerprint;
storage::io::FileReader reader{path, fingerprint};
auto num_indices = reader.ReadElementCount32();
segment_data.index.resize(num_indices);
reader.ReadInto(segment_data.index.data(), num_indices);
auto num_entries = reader.ReadElementCount32();
segment_data.nodes.resize(num_entries);
segment_data.fwd_weights.resize(num_entries);
segment_data.rev_weights.resize(num_entries);
segment_data.fwd_durations.resize(num_entries);
segment_data.rev_durations.resize(num_entries);
segment_data.datasources.resize(num_entries);
reader.ReadInto(segment_data.nodes);
reader.ReadInto(segment_data.fwd_weights);
reader.ReadInto(segment_data.rev_weights);
reader.ReadInto(segment_data.fwd_durations);
reader.ReadInto(segment_data.rev_durations);
reader.ReadInto(segment_data.datasources);
}
template <>
inline void write(const boost::filesystem::path &path, const SegmentDataContainer &segment_data)
{
const auto fingerprint = storage::io::FileWriter::HasNoFingerprint;
storage::io::FileWriter writer{path, fingerprint};
writer.WriteElementCount32(segment_data.index.size());
writer.WriteFrom(segment_data.index);
writer.WriteElementCount32(segment_data.nodes.size());
BOOST_ASSERT(segment_data.fwd_weights.size() == segment_data.nodes.size());
BOOST_ASSERT(segment_data.rev_weights.size() == segment_data.nodes.size());
BOOST_ASSERT(segment_data.fwd_durations.size() == segment_data.nodes.size());
BOOST_ASSERT(segment_data.rev_durations.size() == segment_data.nodes.size());
BOOST_ASSERT(segment_data.datasources.size() == segment_data.nodes.size());
writer.WriteFrom(segment_data.nodes);
writer.WriteFrom(segment_data.fwd_weights);
writer.WriteFrom(segment_data.rev_weights);
writer.WriteFrom(segment_data.fwd_durations);
writer.WriteFrom(segment_data.rev_durations);
writer.WriteFrom(segment_data.datasources);
}
}
}
}
#endif
-1
View File
@@ -87,7 +87,6 @@ struct ProfileProperties
//! stores the name of the weight (e.g. 'duration', 'distance', 'safety')
char weight_name[MAX_WEIGHT_NAME_LENGTH + 1];
unsigned weight_precision = 1;
bool force_split_edges = false;
};
}
}
+18 -21
View File
@@ -1,11 +1,8 @@
#ifndef OSRM_EXTRACTOR_SEGMENT_DATA_CONTAINER_HPP_
#define OSRM_EXTRACTOR_SEGMENT_DATA_CONTAINER_HPP_
#include "util/shared_memory_vector_wrapper.hpp"
#include "util/typedefs.hpp"
#include "util/vector_view.hpp"
#include "storage/io_fwd.hpp"
#include "storage/shared_memory_ownership.hpp"
#include <boost/filesystem/path.hpp>
#include <boost/range/adaptor/reversed.hpp>
@@ -25,24 +22,24 @@ class CompressedEdgeContainer;
namespace detail
{
template <storage::Ownership Ownership> class SegmentDataContainerImpl;
template <bool UseShareMemory> class SegmentDataContainerImpl;
}
namespace serialization
namespace io
{
template <storage::Ownership Ownership>
inline void read(storage::io::FileReader &reader,
detail::SegmentDataContainerImpl<Ownership> &segment_data);
template <storage::Ownership Ownership>
inline void write(storage::io::FileWriter &writer,
const detail::SegmentDataContainerImpl<Ownership> &segment_data);
template <bool UseShareMemory>
inline void read(const boost::filesystem::path &path,
detail::SegmentDataContainerImpl<UseShareMemory> &segment_data);
template <bool UseShareMemory>
inline void write(const boost::filesystem::path &path,
const detail::SegmentDataContainerImpl<UseShareMemory> &segment_data);
}
namespace detail
{
template <storage::Ownership Ownership> class SegmentDataContainerImpl
template <bool UseShareMemory> class SegmentDataContainerImpl
{
template <typename T> using Vector = util::ViewOrVector<T, Ownership>;
template <typename T> using Vector = typename util::ShM<T, UseShareMemory>::vector;
friend CompressedEdgeContainer;
@@ -192,11 +189,11 @@ template <storage::Ownership Ownership> class SegmentDataContainerImpl
auto GetNumberOfSegments() const { return fwd_weights.size(); }
friend void
serialization::read<Ownership>(storage::io::FileReader &reader,
detail::SegmentDataContainerImpl<Ownership> &segment_data);
friend void serialization::write<Ownership>(
storage::io::FileWriter &writer,
const detail::SegmentDataContainerImpl<Ownership> &segment_data);
io::read<UseShareMemory>(const boost::filesystem::path &path,
detail::SegmentDataContainerImpl<UseShareMemory> &segment_data);
friend void
io::write<UseShareMemory>(const boost::filesystem::path &path,
const detail::SegmentDataContainerImpl<UseShareMemory> &segment_data);
private:
Vector<std::uint32_t> index;
@@ -209,8 +206,8 @@ template <storage::Ownership Ownership> class SegmentDataContainerImpl
};
}
using SegmentDataView = detail::SegmentDataContainerImpl<storage::Ownership::View>;
using SegmentDataContainer = detail::SegmentDataContainerImpl<storage::Ownership::Container>;
using SegmentDataView = detail::SegmentDataContainerImpl<true>;
using SegmentDataContainer = detail::SegmentDataContainerImpl<false>;
}
}
-88
View File
@@ -1,88 +0,0 @@
#ifndef OSRM_EXTRACTOR_IO_HPP
#define OSRM_EXTRACTOR_IO_HPP
#include "extractor/datasources.hpp"
#include "extractor/nbg_to_ebg.hpp"
#include "extractor/segment_data_container.hpp"
#include "extractor/turn_data_container.hpp"
#include "storage/io.hpp"
#include "storage/serialization.hpp"
#include <boost/assert.hpp>
namespace osrm
{
namespace extractor
{
namespace serialization
{
inline void read(storage::io::FileReader &reader, Datasources &sources)
{
reader.ReadInto(sources);
}
inline void write(storage::io::FileWriter &writer, Datasources &sources)
{
writer.WriteFrom(sources);
}
template <storage::Ownership Ownership>
inline void read(storage::io::FileReader &reader,
detail::SegmentDataContainerImpl<Ownership> &segment_data)
{
storage::serialization::read(reader, segment_data.index);
storage::serialization::read(reader, segment_data.nodes);
storage::serialization::read(reader, segment_data.fwd_weights);
storage::serialization::read(reader, segment_data.rev_weights);
storage::serialization::read(reader, segment_data.fwd_durations);
storage::serialization::read(reader, segment_data.rev_durations);
storage::serialization::read(reader, segment_data.datasources);
}
template <storage::Ownership Ownership>
inline void write(storage::io::FileWriter &writer,
const detail::SegmentDataContainerImpl<Ownership> &segment_data)
{
storage::serialization::write(writer, segment_data.index);
storage::serialization::write(writer, segment_data.nodes);
storage::serialization::write(writer, segment_data.fwd_weights);
storage::serialization::write(writer, segment_data.rev_weights);
storage::serialization::write(writer, segment_data.fwd_durations);
storage::serialization::write(writer, segment_data.rev_durations);
storage::serialization::write(writer, segment_data.datasources);
}
template <storage::Ownership Ownership>
inline void read(storage::io::FileReader &reader,
detail::TurnDataContainerImpl<Ownership> &turn_data_container)
{
storage::serialization::read(reader, turn_data_container.geometry_ids);
storage::serialization::read(reader, turn_data_container.name_ids);
storage::serialization::read(reader, turn_data_container.turn_instructions);
storage::serialization::read(reader, turn_data_container.lane_data_ids);
storage::serialization::read(reader, turn_data_container.travel_modes);
storage::serialization::read(reader, turn_data_container.entry_class_ids);
storage::serialization::read(reader, turn_data_container.pre_turn_bearings);
storage::serialization::read(reader, turn_data_container.post_turn_bearings);
}
template <storage::Ownership Ownership>
inline void write(storage::io::FileWriter &writer,
const detail::TurnDataContainerImpl<Ownership> &turn_data_container)
{
storage::serialization::write(writer, turn_data_container.geometry_ids);
storage::serialization::write(writer, turn_data_container.name_ids);
storage::serialization::write(writer, turn_data_container.turn_instructions);
storage::serialization::write(writer, turn_data_container.lane_data_ids);
storage::serialization::write(writer, turn_data_container.travel_modes);
storage::serialization::write(writer, turn_data_container.entry_class_ids);
storage::serialization::write(writer, turn_data_container.pre_turn_bearings);
storage::serialization::write(writer, turn_data_container.post_turn_bearings);
}
}
}
}
#endif
-130
View File
@@ -1,130 +0,0 @@
#ifndef OSRM_EXTRACTOR_TURN_DATA_CONTAINER_HPP
#define OSRM_EXTRACTOR_TURN_DATA_CONTAINER_HPP
#include "extractor/guidance/turn_instruction.hpp"
#include "extractor/travel_mode.hpp"
#include "storage/io_fwd.hpp"
#include "storage/shared_memory_ownership.hpp"
#include "util/guidance/turn_bearing.hpp"
#include "util/vector_view.hpp"
#include "util/typedefs.hpp"
namespace osrm
{
namespace extractor
{
namespace detail
{
template <storage::Ownership Ownership> class TurnDataContainerImpl;
}
namespace serialization
{
template <storage::Ownership Ownership>
void read(storage::io::FileReader &reader, detail::TurnDataContainerImpl<Ownership> &turn_data);
template <storage::Ownership Ownership>
void write(storage::io::FileWriter &writer,
const detail::TurnDataContainerImpl<Ownership> &turn_data);
}
namespace detail
{
template <storage::Ownership Ownership> class TurnDataContainerImpl
{
template <typename T> using Vector = util::ViewOrVector<T, Ownership>;
public:
TurnDataContainerImpl() = default;
TurnDataContainerImpl(Vector<GeometryID> geometry_ids_,
Vector<NameID> name_ids_,
Vector<extractor::guidance::TurnInstruction> turn_instructions_,
Vector<LaneDataID> lane_data_ids_,
Vector<extractor::TravelMode> travel_modes_,
Vector<EntryClassID> entry_class_ids_,
Vector<util::guidance::TurnBearing> pre_turn_bearings_,
Vector<util::guidance::TurnBearing> post_turn_bearings_)
: geometry_ids(std::move(geometry_ids_)), name_ids(std::move(name_ids_)),
turn_instructions(std::move(turn_instructions_)),
lane_data_ids(std::move(lane_data_ids_)), travel_modes(std::move(travel_modes_)),
entry_class_ids(std::move(entry_class_ids_)),
pre_turn_bearings(std::move(pre_turn_bearings_)),
post_turn_bearings(std::move(post_turn_bearings_))
{
}
GeometryID GetGeometryID(const EdgeID id) const { return geometry_ids[id]; }
EntryClassID GetEntryClassID(const EdgeID id) const { return entry_class_ids[id]; }
extractor::TravelMode GetTravelMode(const EdgeID id) const { return travel_modes[id]; }
util::guidance::TurnBearing GetPreTurnBearing(const EdgeID id) const
{
return pre_turn_bearings[id];
}
util::guidance::TurnBearing GetPostTurnBearing(const EdgeID id) const
{
return post_turn_bearings[id];
}
LaneDataID GetLaneDataID(const EdgeID id) const { return lane_data_ids[id]; }
bool HasLaneData(const EdgeID id) const { return INVALID_LANE_DATAID != lane_data_ids[id]; }
NameID GetNameID(const EdgeID id) const { return name_ids[id]; }
extractor::guidance::TurnInstruction GetTurnInstruction(const EdgeID id) const
{
return turn_instructions[id];
}
// Used by EdgeBasedGraphFactory to fill data structure
template <typename = std::enable_if<Ownership == storage::Ownership::Container>>
void push_back(GeometryID geometry_id,
NameID name_id,
extractor::guidance::TurnInstruction turn_instruction,
LaneDataID lane_data_id,
EntryClassID entry_class_id,
extractor::TravelMode travel_mode,
util::guidance::TurnBearing pre_turn_bearing,
util::guidance::TurnBearing post_turn_bearing)
{
geometry_ids.push_back(geometry_id);
name_ids.push_back(name_id);
turn_instructions.push_back(turn_instruction);
lane_data_ids.push_back(lane_data_id);
travel_modes.push_back(travel_mode);
entry_class_ids.push_back(entry_class_id);
pre_turn_bearings.push_back(pre_turn_bearing);
post_turn_bearings.push_back(post_turn_bearing);
}
friend void serialization::read<Ownership>(storage::io::FileReader &reader,
TurnDataContainerImpl &turn_data_container);
friend void serialization::write<Ownership>(storage::io::FileWriter &writer,
const TurnDataContainerImpl &turn_data_container);
private:
Vector<GeometryID> geometry_ids;
Vector<NameID> name_ids;
Vector<extractor::guidance::TurnInstruction> turn_instructions;
Vector<LaneDataID> lane_data_ids;
Vector<extractor::TravelMode> travel_modes;
Vector<EntryClassID> entry_class_ids;
Vector<util::guidance::TurnBearing> pre_turn_bearings;
Vector<util::guidance::TurnBearing> post_turn_bearings;
};
}
using TurnDataContainer = detail::TurnDataContainerImpl<storage::Ownership::Container>;
using TurnDataView = detail::TurnDataContainerImpl<storage::Ownership::View>;
}
}
#endif
-76
View File
@@ -112,13 +112,7 @@ inline engine_config_ptr argumentsToEngineConfig(const Nan::FunctionCallbackInfo
auto params = Nan::To<v8::Object>(args[0]).ToLocalChecked();
auto path = params->Get(Nan::New("path").ToLocalChecked());
if (path.IsEmpty())
return engine_config_ptr();
auto shared_memory = params->Get(Nan::New("shared_memory").ToLocalChecked());
if (shared_memory.IsEmpty())
return engine_config_ptr();
if (!path->IsUndefined())
{
engine_config->storage_config =
@@ -146,9 +140,6 @@ inline engine_config_ptr argumentsToEngineConfig(const Nan::FunctionCallbackInfo
}
auto algorithm = params->Get(Nan::New("algorithm").ToLocalChecked());
if (algorithm.IsEmpty())
return engine_config_ptr();
if (algorithm->IsString())
{
auto algorithm_str = Nan::To<v8::String>(algorithm).ToLocalChecked();
@@ -189,8 +180,6 @@ parseCoordinateArray(const v8::Local<v8::Array> &coordinates_array)
for (uint32_t i = 0; i < coordinates_array->Length(); ++i)
{
v8::Local<v8::Value> coordinate = coordinates_array->Get(i);
if (coordinate.IsEmpty())
return resulting_coordinates;
if (!coordinate->IsArray())
{
@@ -258,9 +247,6 @@ inline bool argumentsToParameter(const Nan::FunctionCallbackInfo<v8::Value> &arg
v8::Local<v8::Object> obj = Nan::To<v8::Object>(args[0]).ToLocalChecked();
v8::Local<v8::Value> coordinates = obj->Get(Nan::New("coordinates").ToLocalChecked());
if (coordinates.IsEmpty())
return false;
if (coordinates->IsUndefined())
{
Nan::ThrowError("Must provide a coordinates property");
@@ -301,8 +287,6 @@ inline bool argumentsToParameter(const Nan::FunctionCallbackInfo<v8::Value> &arg
if (obj->Has(Nan::New("bearings").ToLocalChecked()))
{
v8::Local<v8::Value> bearings = obj->Get(Nan::New("bearings").ToLocalChecked());
if (bearings.IsEmpty())
return false;
if (!bearings->IsArray())
{
@@ -321,8 +305,6 @@ inline bool argumentsToParameter(const Nan::FunctionCallbackInfo<v8::Value> &arg
for (uint32_t i = 0; i < bearings_array->Length(); ++i)
{
v8::Local<v8::Value> bearing_raw = bearings_array->Get(i);
if (bearing_raw.IsEmpty())
return false;
if (bearing_raw->IsNull())
{
@@ -367,8 +349,6 @@ inline bool argumentsToParameter(const Nan::FunctionCallbackInfo<v8::Value> &arg
if (obj->Has(Nan::New("hints").ToLocalChecked()))
{
v8::Local<v8::Value> hints = obj->Get(Nan::New("hints").ToLocalChecked());
if (hints.IsEmpty())
return false;
if (!hints->IsArray())
{
@@ -387,9 +367,6 @@ inline bool argumentsToParameter(const Nan::FunctionCallbackInfo<v8::Value> &arg
for (uint32_t i = 0; i < hints_array->Length(); ++i)
{
v8::Local<v8::Value> hint = hints_array->Get(i);
if (hint.IsEmpty())
return false;
if (hint->IsString())
{
if (hint->ToString()->Length() == 0)
@@ -416,8 +393,6 @@ inline bool argumentsToParameter(const Nan::FunctionCallbackInfo<v8::Value> &arg
if (obj->Has(Nan::New("radiuses").ToLocalChecked()))
{
v8::Local<v8::Value> radiuses = obj->Get(Nan::New("radiuses").ToLocalChecked());
if (radiuses.IsEmpty())
return false;
if (!radiuses->IsArray())
{
@@ -436,9 +411,6 @@ inline bool argumentsToParameter(const Nan::FunctionCallbackInfo<v8::Value> &arg
for (uint32_t i = 0; i < radiuses_array->Length(); ++i)
{
v8::Local<v8::Value> radius = radiuses_array->Get(i);
if (radius.IsEmpty())
return false;
if (radius->IsNull())
{
params->radiuses.emplace_back();
@@ -458,8 +430,6 @@ inline bool argumentsToParameter(const Nan::FunctionCallbackInfo<v8::Value> &arg
if (obj->Has(Nan::New("generate_hints").ToLocalChecked()))
{
v8::Local<v8::Value> generate_hints = obj->Get(Nan::New("generate_hints").ToLocalChecked());
if (generate_hints.IsEmpty())
return false;
if (!generate_hints->IsBoolean())
{
@@ -479,9 +449,6 @@ inline bool parseCommonParameters(const v8::Local<v8::Object> &obj, ParamType &p
if (obj->Has(Nan::New("steps").ToLocalChecked()))
{
auto steps = obj->Get(Nan::New("steps").ToLocalChecked());
if (steps.IsEmpty())
return false;
if (steps->IsBoolean())
{
params->steps = steps->BooleanValue();
@@ -496,9 +463,6 @@ inline bool parseCommonParameters(const v8::Local<v8::Object> &obj, ParamType &p
if (obj->Has(Nan::New("annotations").ToLocalChecked()))
{
auto annotations = obj->Get(Nan::New("annotations").ToLocalChecked());
if (annotations.IsEmpty())
return false;
if (annotations->IsBoolean())
{
params->annotations = annotations->BooleanValue();
@@ -559,8 +523,6 @@ inline bool parseCommonParameters(const v8::Local<v8::Object> &obj, ParamType &p
if (obj->Has(Nan::New("geometries").ToLocalChecked()))
{
v8::Local<v8::Value> geometries = obj->Get(Nan::New("geometries").ToLocalChecked());
if (geometries.IsEmpty())
return false;
if (!geometries->IsString())
{
@@ -593,8 +555,6 @@ inline bool parseCommonParameters(const v8::Local<v8::Object> &obj, ParamType &p
if (obj->Has(Nan::New("overview").ToLocalChecked()))
{
v8::Local<v8::Value> overview = obj->Get(Nan::New("overview").ToLocalChecked());
if (overview.IsEmpty())
return false;
if (!overview->IsString())
{
@@ -641,13 +601,9 @@ argumentsToRouteParameter(const Nan::FunctionCallbackInfo<v8::Value> &args,
if (obj->Has(Nan::New("continue_straight").ToLocalChecked()))
{
auto value = obj->Get(Nan::New("continue_straight").ToLocalChecked());
if (value.IsEmpty())
return route_parameters_ptr();
if (!value->IsBoolean() && !value->IsNull())
{
Nan::ThrowError("'continue_straight' parama must be boolean or null");
return route_parameters_ptr();
}
if (value->IsBoolean())
{
@@ -658,13 +614,9 @@ argumentsToRouteParameter(const Nan::FunctionCallbackInfo<v8::Value> &args,
if (obj->Has(Nan::New("alternatives").ToLocalChecked()))
{
auto value = obj->Get(Nan::New("alternatives").ToLocalChecked());
if (value.IsEmpty())
return route_parameters_ptr();
if (!value->IsBoolean())
{
Nan::ThrowError("'alternatives' parama must be boolean");
return route_parameters_ptr();
}
params->alternatives = value->BooleanValue();
}
@@ -706,8 +658,6 @@ argumentsToTileParameters(const Nan::FunctionCallbackInfo<v8::Value> &args, bool
v8::Local<v8::Value> x = array->Get(0);
v8::Local<v8::Value> y = array->Get(1);
v8::Local<v8::Value> z = array->Get(2);
if (x.IsEmpty() || y.IsEmpty() || z.IsEmpty())
return tile_parameters_ptr();
if (!x->IsUint32() && !x->IsUndefined())
{
@@ -748,8 +698,6 @@ argumentsToNearestParameter(const Nan::FunctionCallbackInfo<v8::Value> &args,
return nearest_parameters_ptr();
v8::Local<v8::Object> obj = Nan::To<v8::Object>(args[0]).ToLocalChecked();
if (obj.IsEmpty())
return nearest_parameters_ptr();
if (obj->Has(Nan::New("number").ToLocalChecked()))
{
@@ -787,14 +735,10 @@ argumentsToTableParameter(const Nan::FunctionCallbackInfo<v8::Value> &args,
return table_parameters_ptr();
v8::Local<v8::Object> obj = Nan::To<v8::Object>(args[0]).ToLocalChecked();
if (obj.IsEmpty())
return table_parameters_ptr();
if (obj->Has(Nan::New("sources").ToLocalChecked()))
{
v8::Local<v8::Value> sources = obj->Get(Nan::New("sources").ToLocalChecked());
if (sources.IsEmpty())
return table_parameters_ptr();
if (!sources->IsArray())
{
@@ -806,9 +750,6 @@ argumentsToTableParameter(const Nan::FunctionCallbackInfo<v8::Value> &args,
for (uint32_t i = 0; i < sources_array->Length(); ++i)
{
v8::Local<v8::Value> source = sources_array->Get(i);
if (source.IsEmpty())
return table_parameters_ptr();
if (source->IsUint32())
{
size_t source_value = static_cast<size_t>(source->NumberValue());
@@ -832,8 +773,6 @@ argumentsToTableParameter(const Nan::FunctionCallbackInfo<v8::Value> &args,
if (obj->Has(Nan::New("destinations").ToLocalChecked()))
{
v8::Local<v8::Value> destinations = obj->Get(Nan::New("destinations").ToLocalChecked());
if (destinations.IsEmpty())
return table_parameters_ptr();
if (!destinations->IsArray())
{
@@ -845,9 +784,6 @@ argumentsToTableParameter(const Nan::FunctionCallbackInfo<v8::Value> &args,
for (uint32_t i = 0; i < destinations_array->Length(); ++i)
{
v8::Local<v8::Value> destination = destinations_array->Get(i);
if (destination.IsEmpty())
return table_parameters_ptr();
if (destination->IsUint32())
{
size_t destination_value = static_cast<size_t>(destination->NumberValue());
@@ -891,9 +827,6 @@ argumentsToTripParameter(const Nan::FunctionCallbackInfo<v8::Value> &args,
if (obj->Has(Nan::New("roundtrip").ToLocalChecked()))
{
auto roundtrip = obj->Get(Nan::New("roundtrip").ToLocalChecked());
if (roundtrip.IsEmpty())
return trip_parameters_ptr();
if (roundtrip->IsBoolean())
{
params->roundtrip = roundtrip->BooleanValue();
@@ -908,8 +841,6 @@ argumentsToTripParameter(const Nan::FunctionCallbackInfo<v8::Value> &args,
if (obj->Has(Nan::New("source").ToLocalChecked()))
{
v8::Local<v8::Value> source = obj->Get(Nan::New("source").ToLocalChecked());
if (source.IsEmpty())
return trip_parameters_ptr();
if (!source->IsString())
{
@@ -937,8 +868,6 @@ argumentsToTripParameter(const Nan::FunctionCallbackInfo<v8::Value> &args,
if (obj->Has(Nan::New("destination").ToLocalChecked()))
{
v8::Local<v8::Value> destination = obj->Get(Nan::New("destination").ToLocalChecked());
if (destination.IsEmpty())
return trip_parameters_ptr();
if (!destination->IsString())
{
@@ -980,8 +909,6 @@ argumentsToMatchParameter(const Nan::FunctionCallbackInfo<v8::Value> &args,
if (obj->Has(Nan::New("timestamps").ToLocalChecked()))
{
v8::Local<v8::Value> timestamps = obj->Get(Nan::New("timestamps").ToLocalChecked());
if (timestamps.IsEmpty())
return match_parameters_ptr();
if (!timestamps->IsArray())
{
@@ -1001,9 +928,6 @@ argumentsToMatchParameter(const Nan::FunctionCallbackInfo<v8::Value> &args,
for (uint32_t i = 0; i < timestamps_array->Length(); ++i)
{
v8::Local<v8::Value> timestamp = timestamps_array->Get(i);
if (timestamp.IsEmpty())
return match_parameters_ptr();
if (!timestamp->IsNumber())
{
Nan::ThrowError("Timestamps array items must be numbers");
+21 -23
View File
@@ -6,11 +6,10 @@
#include "util/assert.hpp"
#include "util/for_each_range.hpp"
#include "util/log.hpp"
#include "util/shared_memory_vector_wrapper.hpp"
#include "util/typedefs.hpp"
#include "util/vector_view.hpp"
#include "storage/io_fwd.hpp"
#include "storage/shared_memory_ownership.hpp"
#include "storage/io.hpp"
#include <boost/iterator/iterator_facade.hpp>
#include <boost/range/iterator_range.hpp>
@@ -27,23 +26,24 @@ namespace partition
{
namespace detail
{
template <storage::Ownership Ownership> class CellStorageImpl;
template <bool UseShareMemory> class CellStorageImpl;
}
using CellStorage = detail::CellStorageImpl<storage::Ownership::Container>;
using CellStorageView = detail::CellStorageImpl<storage::Ownership::View>;
using CellStorage = detail::CellStorageImpl<false>;
using CellStorageView = detail::CellStorageImpl<true>;
namespace serialization
namespace io
{
template <storage::Ownership Ownership>
inline void read(storage::io::FileReader &reader, detail::CellStorageImpl<Ownership> &storage);
template <storage::Ownership Ownership>
inline void write(storage::io::FileWriter &writer,
const detail::CellStorageImpl<Ownership> &storage);
template <bool UseShareMemory>
inline void read(const boost::filesystem::path &path,
detail::CellStorageImpl<UseShareMemory> &storage);
template <bool UseShareMemory>
inline void write(const boost::filesystem::path &path,
const detail::CellStorageImpl<UseShareMemory> &storage);
}
namespace detail
{
template <storage::Ownership Ownership> class CellStorageImpl
template <bool UseShareMemory> class CellStorageImpl
{
public:
using WeightOffset = std::uint32_t;
@@ -65,7 +65,7 @@ template <storage::Ownership Ownership> class CellStorageImpl
};
private:
template <typename T> using Vector = util::ViewOrVector<T, Ownership>;
template <typename T> using Vector = typename util::ShM<T, UseShareMemory>::vector;
// Implementation of the cell view. We need a template parameter here
// because we need to derive a read-only and read-write view from this.
@@ -185,8 +185,7 @@ template <storage::Ownership Ownership> class CellStorageImpl
CellStorageImpl() {}
template <typename GraphT,
typename = std::enable_if<Ownership == storage::Ownership::Container>>
template <typename GraphT, typename = std::enable_if<!UseShareMemory>>
CellStorageImpl(const partition::MultiLevelPartition &partition, const GraphT &base_graph)
{
// pre-allocate storge for CellData so we can have random access to it by cell id
@@ -315,7 +314,7 @@ template <storage::Ownership Ownership> class CellStorageImpl
weights.resize(weight_offset + 1, INVALID_EDGE_WEIGHT);
}
template <typename = std::enable_if<Ownership == storage::Ownership::View>>
template <typename = std::enable_if<UseShareMemory>>
CellStorageImpl(Vector<EdgeWeight> weights_,
Vector<NodeID> source_boundary_,
Vector<NodeID> destination_boundary_,
@@ -340,8 +339,7 @@ template <storage::Ownership Ownership> class CellStorageImpl
destination_boundary.empty() ? nullptr : destination_boundary.data()};
}
template <typename = std::enable_if<Ownership == storage::Ownership::Container>>
Cell GetCell(LevelID level, CellID id)
template <typename = std::enable_if<!UseShareMemory>> Cell GetCell(LevelID level, CellID id)
{
const auto level_index = LevelIDToIndex(level);
BOOST_ASSERT(level_index < level_to_cell_offset.size());
@@ -352,10 +350,10 @@ template <storage::Ownership Ownership> class CellStorageImpl
cells[cell_index], weights.data(), source_boundary.data(), destination_boundary.data()};
}
friend void serialization::read<Ownership>(storage::io::FileReader &reader,
detail::CellStorageImpl<Ownership> &storage);
friend void serialization::write<Ownership>(storage::io::FileWriter &writer,
const detail::CellStorageImpl<Ownership> &storage);
friend void io::read<UseShareMemory>(const boost::filesystem::path &path,
detail::CellStorageImpl<UseShareMemory> &storage);
friend void io::write<UseShareMemory>(const boost::filesystem::path &path,
const detail::CellStorageImpl<UseShareMemory> &storage);
private:
Vector<EdgeWeight> weights;
-104
View File
@@ -1,104 +0,0 @@
#ifndef OSRM_PARTITION_SERILIZATION_HPP
#define OSRM_PARTITION_SERILIZATION_HPP
#include "customizer/edge_based_graph.hpp"
#include "partition/serialization.hpp"
#include "storage/io.hpp"
namespace osrm
{
namespace partition
{
namespace files
{
// reads .osrm.mldgr file
template <typename MultiLevelGraphT>
inline void readGraph(const boost::filesystem::path &path, MultiLevelGraphT &graph)
{
static_assert(std::is_same<customizer::MultiLevelEdgeBasedGraphView, MultiLevelGraphT>::value ||
std::is_same<customizer::MultiLevelEdgeBasedGraph, MultiLevelGraphT>::value,
"");
const auto fingerprint = storage::io::FileReader::VerifyFingerprint;
storage::io::FileReader reader{path, fingerprint};
serialization::read(reader, graph);
}
// writes .osrm.mldgr file
template <typename MultiLevelGraphT>
inline void writeGraph(const boost::filesystem::path &path, const MultiLevelGraphT &graph)
{
static_assert(std::is_same<customizer::MultiLevelEdgeBasedGraphView, MultiLevelGraphT>::value ||
std::is_same<customizer::MultiLevelEdgeBasedGraph, MultiLevelGraphT>::value,
"");
const auto fingerprint = storage::io::FileWriter::GenerateFingerprint;
storage::io::FileWriter writer{path, fingerprint};
serialization::write(writer, graph);
}
// read .osrm.partition file
template <typename MultiLevelPartitionT>
inline void readPartition(const boost::filesystem::path &path, MultiLevelPartitionT &mlp)
{
static_assert(std::is_same<MultiLevelPartitionView, MultiLevelPartitionT>::value ||
std::is_same<MultiLevelPartition, MultiLevelPartitionT>::value,
"");
const auto fingerprint = storage::io::FileReader::VerifyFingerprint;
storage::io::FileReader reader{path, fingerprint};
serialization::read(reader, mlp);
}
// writes .osrm.partition file
template <typename MultiLevelPartitionT>
inline void writePartition(const boost::filesystem::path &path, const MultiLevelPartitionT &mlp)
{
static_assert(std::is_same<MultiLevelPartitionView, MultiLevelPartitionT>::value ||
std::is_same<MultiLevelPartition, MultiLevelPartitionT>::value,
"");
const auto fingerprint = storage::io::FileWriter::GenerateFingerprint;
storage::io::FileWriter writer{path, fingerprint};
serialization::write(writer, mlp);
}
// reads .osrm.cells file
template <typename CellStorageT>
inline void readCells(const boost::filesystem::path &path, CellStorageT &storage)
{
static_assert(std::is_same<CellStorageView, CellStorageT>::value ||
std::is_same<CellStorage, CellStorageT>::value,
"");
const auto fingerprint = storage::io::FileReader::VerifyFingerprint;
storage::io::FileReader reader{path, fingerprint};
serialization::read(reader, storage);
}
// writes .osrm.cells file
template <typename CellStorageT>
inline void writeCells(const boost::filesystem::path &path, CellStorageT &storage)
{
static_assert(std::is_same<CellStorageView, CellStorageT>::value ||
std::is_same<CellStorage, CellStorageT>::value,
"");
const auto fingerprint = storage::io::FileWriter::GenerateFingerprint;
storage::io::FileWriter writer{path, fingerprint};
serialization::write(writer, storage);
}
}
}
}
#endif
+89
View File
@@ -0,0 +1,89 @@
#ifndef OSRM_PARTITION_IO_HPP
#define OSRM_PARTITION_IO_HPP
#include "partition/cell_storage.hpp"
#include "partition/edge_based_graph.hpp"
#include "partition/multi_level_graph.hpp"
#include "partition/multi_level_partition.hpp"
#include "storage/io.hpp"
namespace osrm
{
namespace partition
{
namespace io
{
template <typename EdgeDataT, bool UseSharedMemory>
inline void read(const boost::filesystem::path &path,
MultiLevelGraph<EdgeDataT, UseSharedMemory> &graph)
{
const auto fingerprint = storage::io::FileReader::VerifyFingerprint;
storage::io::FileReader reader{path, fingerprint};
reader.DeserializeVector(graph.node_array);
reader.DeserializeVector(graph.edge_array);
reader.DeserializeVector(graph.edge_to_level);
}
template <typename EdgeDataT, bool UseSharedMemory>
inline void write(const boost::filesystem::path &path,
const MultiLevelGraph<EdgeDataT, UseSharedMemory> &graph)
{
const auto fingerprint = storage::io::FileWriter::GenerateFingerprint;
storage::io::FileWriter writer{path, fingerprint};
writer.SerializeVector(graph.node_array);
writer.SerializeVector(graph.edge_array);
writer.SerializeVector(graph.node_to_edge_offset);
}
template <> inline void read(const boost::filesystem::path &path, MultiLevelPartition &mlp)
{
const auto fingerprint = storage::io::FileReader::VerifyFingerprint;
storage::io::FileReader reader{path, fingerprint};
reader.ReadInto<MultiLevelPartition::LevelData>(mlp.level_data);
reader.DeserializeVector(mlp.partition);
reader.DeserializeVector(mlp.cell_to_children);
}
template <> inline void write(const boost::filesystem::path &path, const MultiLevelPartition &mlp)
{
const auto fingerprint = storage::io::FileWriter::GenerateFingerprint;
storage::io::FileWriter writer{path, fingerprint};
writer.WriteOne(mlp.level_data);
writer.SerializeVector(mlp.partition);
writer.SerializeVector(mlp.cell_to_children);
}
template <> inline void read(const boost::filesystem::path &path, CellStorage &storage)
{
const auto fingerprint = storage::io::FileReader::VerifyFingerprint;
storage::io::FileReader reader{path, fingerprint};
reader.DeserializeVector(storage.weights);
reader.DeserializeVector(storage.source_boundary);
reader.DeserializeVector(storage.destination_boundary);
reader.DeserializeVector(storage.cells);
reader.DeserializeVector(storage.level_to_cell_offset);
}
template <> inline void write(const boost::filesystem::path &path, const CellStorage &storage)
{
const auto fingerprint = storage::io::FileWriter::GenerateFingerprint;
storage::io::FileWriter writer{path, fingerprint};
writer.SerializeVector(storage.weights);
writer.SerializeVector(storage.source_boundary);
writer.SerializeVector(storage.destination_boundary);
writer.SerializeVector(storage.cells);
writer.SerializeVector(storage.level_to_cell_offset);
}
}
}
}
#endif
+16 -28
View File
@@ -3,11 +3,7 @@
#include "partition/multi_level_partition.hpp"
#include "storage/io_fwd.hpp"
#include "storage/shared_memory_ownership.hpp"
#include "util/static_graph.hpp"
#include "util/vector_view.hpp"
#include <tbb/parallel_sort.h>
@@ -16,26 +12,26 @@
namespace osrm
{
namespace partition
{
template <typename EdgeDataT, storage::Ownership Ownership> class MultiLevelGraph;
template <typename EdgeDataT, bool UseSharedMemory> class MultiLevelGraph;
namespace serialization
namespace io
{
template <typename EdgeDataT, storage::Ownership Ownership>
void read(storage::io::FileReader &reader, MultiLevelGraph<EdgeDataT, Ownership> &graph);
template <typename EdgeDataT, bool UseSharedMemory>
void read(const boost::filesystem::path &path, MultiLevelGraph<EdgeDataT, UseSharedMemory> &graph);
template <typename EdgeDataT, storage::Ownership Ownership>
void write(storage::io::FileWriter &writer, const MultiLevelGraph<EdgeDataT, Ownership> &graph);
template <typename EdgeDataT, bool UseSharedMemory>
void write(const boost::filesystem::path &path,
const MultiLevelGraph<EdgeDataT, UseSharedMemory> &graph);
}
template <typename EdgeDataT, storage::Ownership Ownership>
class MultiLevelGraph : public util::StaticGraph<EdgeDataT, Ownership>
template <typename EdgeDataT, bool UseSharedMemory>
class MultiLevelGraph : public util::StaticGraph<EdgeDataT, UseSharedMemory>
{
private:
using SuperT = util::StaticGraph<EdgeDataT, Ownership>;
template <typename T> using Vector = util::ViewOrVector<T, Ownership>;
using SuperT = util::StaticGraph<EdgeDataT, UseSharedMemory>;
template <typename T> using Vector = typename util::ShM<T, UseSharedMemory>::vector;
public:
// We limit each node to have 255 edges
@@ -114,17 +110,9 @@ class MultiLevelGraph : public util::StaticGraph<EdgeDataT, Ownership>
// which can be smaller then the total number of nodes.
// this will save memory in case we sort the border nodes first
if (index >= node_to_edge_offset.size() - 1)
{
// On level 0 all edges are border edges
if (level == 0)
return SuperT::BeginEdges(node);
else
return SuperT::EndEdges(node);
}
return SuperT::BeginEdges(node);
else
{
return SuperT::BeginEdges(node) + node_to_edge_offset[index + level];
}
}
// We save the level as sentinel at the end
@@ -194,11 +182,11 @@ class MultiLevelGraph : public util::StaticGraph<EdgeDataT, Ownership>
}
friend void
serialization::read<EdgeDataT, Ownership>(storage::io::FileReader &reader,
MultiLevelGraph<EdgeDataT, Ownership> &graph);
io::read<EdgeDataT, UseSharedMemory>(const boost::filesystem::path &path,
MultiLevelGraph<EdgeDataT, UseSharedMemory> &graph);
friend void
serialization::write<EdgeDataT, Ownership>(storage::io::FileWriter &writer,
const MultiLevelGraph<EdgeDataT, Ownership> &graph);
io::write<EdgeDataT, UseSharedMemory>(const boost::filesystem::path &path,
const MultiLevelGraph<EdgeDataT, UseSharedMemory> &graph);
Vector<EdgeOffset> node_to_edge_offset;
};
+35 -48
View File
@@ -4,11 +4,10 @@
#include "util/exception.hpp"
#include "util/for_each_pair.hpp"
#include "util/msb.hpp"
#include "util/shared_memory_vector_wrapper.hpp"
#include "util/typedefs.hpp"
#include "util/vector_view.hpp"
#include "storage/io_fwd.hpp"
#include "storage/shared_memory_ownership.hpp"
#include "storage/io.hpp"
#include <algorithm>
#include <array>
@@ -26,29 +25,31 @@ namespace partition
{
namespace detail
{
template <storage::Ownership Ownership> class MultiLevelPartitionImpl;
template <bool UseShareMemory> class MultiLevelPartitionImpl;
}
using MultiLevelPartition = detail::MultiLevelPartitionImpl<storage::Ownership::Container>;
using MultiLevelPartitionView = detail::MultiLevelPartitionImpl<storage::Ownership::View>;
using MultiLevelPartition = detail::MultiLevelPartitionImpl<false>;
using MultiLevelPartitionView = detail::MultiLevelPartitionImpl<true>;
namespace serialization
namespace io
{
template <storage::Ownership Ownership>
void read(storage::io::FileReader &reader, detail::MultiLevelPartitionImpl<Ownership> &mlp);
template <storage::Ownership Ownership>
void write(storage::io::FileWriter &writer, const detail::MultiLevelPartitionImpl<Ownership> &mlp);
template <bool UseShareMemory>
void read(const boost::filesystem::path &file,
detail::MultiLevelPartitionImpl<UseShareMemory> &mlp);
template <bool UseShareMemory>
void write(const boost::filesystem::path &file,
const detail::MultiLevelPartitionImpl<UseShareMemory> &mlp);
}
namespace detail
{
template <storage::Ownership Ownership> class MultiLevelPartitionImpl final
template <bool UseShareMemory> class MultiLevelPartitionImpl final
{
// we will support at most 16 levels
static const constexpr std::uint8_t MAX_NUM_LEVEL = 16;
static const constexpr std::uint8_t NUM_PARTITION_BITS = sizeof(PartitionID) * CHAR_BIT;
template <typename T> using Vector = util::ViewOrVector<T, Ownership>;
template <typename T> using Vector = typename util::ShM<T, UseShareMemory>::vector;
public:
// Contains all data necessary to describe the level hierarchy
@@ -61,16 +62,13 @@ template <storage::Ownership Ownership> class MultiLevelPartitionImpl final
std::array<LevelID, NUM_PARTITION_BITS> bit_to_level;
std::array<std::uint32_t, MAX_NUM_LEVEL - 1> lidx_to_children_offsets;
};
using LevelDataPtr = typename std::conditional<Ownership == storage::Ownership::View,
LevelData *,
std::unique_ptr<LevelData>>::type;
MultiLevelPartitionImpl();
MultiLevelPartitionImpl() = default;
// cell_sizes is index by level (starting at 0, the base graph).
// However level 0 always needs to have cell size 1, since it is the
// basegraph.
template <typename = typename std::enable_if<Ownership == storage::Ownership::Container>>
template <typename = typename std::enable_if<!UseShareMemory>>
MultiLevelPartitionImpl(const std::vector<std::vector<CellID>> &partitions,
const std::vector<std::uint32_t> &lidx_to_num_cells)
: level_data(MakeLevelData(lidx_to_num_cells))
@@ -78,8 +76,8 @@ template <storage::Ownership Ownership> class MultiLevelPartitionImpl final
InitializePartitionIDs(partitions);
}
template <typename = typename std::enable_if<Ownership == storage::Ownership::View>>
MultiLevelPartitionImpl(LevelDataPtr level_data,
template <typename = typename std::enable_if<UseShareMemory>>
MultiLevelPartitionImpl(LevelData level_data,
Vector<PartitionID> partition_,
Vector<CellID> cell_to_children_)
: level_data(std::move(level_data)), partition(std::move(partition_)),
@@ -92,8 +90,8 @@ template <storage::Ownership Ownership> class MultiLevelPartitionImpl final
{
auto p = partition[node];
auto lidx = LevelIDToIndex(l);
auto masked = p & level_data->lidx_to_mask[lidx];
return masked >> level_data->lidx_to_offset[lidx];
auto masked = p & level_data.lidx_to_mask[lidx];
return masked >> level_data.lidx_to_offset[lidx];
}
LevelID GetQueryLevel(NodeID start, NodeID target, NodeID node) const
@@ -108,10 +106,10 @@ template <storage::Ownership Ownership> class MultiLevelPartitionImpl final
return 0;
auto msb = util::msb(partition[first] ^ partition[second]);
return level_data->bit_to_level[msb];
return level_data.bit_to_level[msb];
}
std::uint8_t GetNumberOfLevels() const { return level_data->num_level; }
std::uint8_t GetNumberOfLevels() const { return level_data.num_level; }
std::uint32_t GetNumberOfCells(LevelID level) const
{
@@ -123,7 +121,7 @@ template <storage::Ownership Ownership> class MultiLevelPartitionImpl final
{
BOOST_ASSERT(level > 1);
auto lidx = LevelIDToIndex(level);
auto offset = level_data->lidx_to_children_offsets[lidx];
auto offset = level_data.lidx_to_children_offsets[lidx];
return cell_to_children[offset + cell];
}
@@ -132,14 +130,14 @@ template <storage::Ownership Ownership> class MultiLevelPartitionImpl final
{
BOOST_ASSERT(level > 1);
auto lidx = LevelIDToIndex(level);
auto offset = level_data->lidx_to_children_offsets[lidx];
auto offset = level_data.lidx_to_children_offsets[lidx];
return cell_to_children[offset + cell + 1];
}
friend void serialization::read<Ownership>(storage::io::FileReader &reader,
MultiLevelPartitionImpl &mlp);
friend void serialization::write<Ownership>(storage::io::FileWriter &writer,
const MultiLevelPartitionImpl &mlp);
friend void io::read<UseShareMemory>(const boost::filesystem::path &file,
MultiLevelPartitionImpl &mlp);
friend void io::write<UseShareMemory>(const boost::filesystem::path &file,
const MultiLevelPartitionImpl &mlp);
private:
auto MakeLevelData(const std::vector<std::uint32_t> &lidx_to_num_cells)
@@ -148,7 +146,7 @@ template <storage::Ownership Ownership> class MultiLevelPartitionImpl final
auto offsets = MakeLevelOffsets(lidx_to_num_cells);
auto masks = MakeLevelMasks(offsets, num_level);
auto bits = MakeBitToLevel(offsets, num_level);
return std::make_unique<LevelData>(LevelData{num_level, offsets, masks, bits, {0}});
return LevelData{num_level, offsets, masks, bits, {0}};
}
inline std::size_t LevelIDToIndex(LevelID l) const { return l - 1; }
@@ -162,8 +160,8 @@ template <storage::Ownership Ownership> class MultiLevelPartitionImpl final
{
auto lidx = LevelIDToIndex(l);
auto shifted_id = cell_id << level_data->lidx_to_offset[lidx];
auto cleared_cell = partition[node] & ~level_data->lidx_to_mask[lidx];
auto shifted_id = cell_id << level_data.lidx_to_offset[lidx];
auto cleared_cell = partition[node] & ~level_data.lidx_to_mask[lidx];
partition[node] = cleared_cell | shifted_id;
}
@@ -291,13 +289,13 @@ template <storage::Ownership Ownership> class MultiLevelPartitionImpl final
level--;
}
level_data->lidx_to_children_offsets[0] = 0;
level_data.lidx_to_children_offsets[0] = 0;
for (auto level_idx = 0UL; level_idx < partitions.size() - 1; ++level_idx)
{
const auto &parent_partition = partitions[level_idx + 1];
level_data->lidx_to_children_offsets[level_idx + 1] = cell_to_children.size();
level_data.lidx_to_children_offsets[level_idx + 1] = cell_to_children.size();
CellID last_parent_id = parent_partition[permutation.front()];
cell_to_children.push_back(GetCell(level_idx + 1, permutation.front()));
@@ -316,22 +314,11 @@ template <storage::Ownership Ownership> class MultiLevelPartitionImpl final
}
}
LevelDataPtr level_data = {};
//! this is always owned by this class because it is so small
LevelData level_data;
Vector<PartitionID> partition;
Vector<CellID> cell_to_children;
};
template <>
inline MultiLevelPartitionImpl<storage::Ownership::Container>::MultiLevelPartitionImpl()
: level_data(std::make_unique<LevelData>())
{
}
template <>
inline MultiLevelPartitionImpl<storage::Ownership::View>::MultiLevelPartitionImpl()
: level_data(nullptr)
{
}
}
}
}
+2 -7
View File
@@ -13,12 +13,7 @@ namespace partition
struct PartitionConfig
{
PartitionConfig()
: requested_num_threads(0), balance(1.2), boundary_factor(0.25), num_optimizing_cuts(10),
small_component_size(1000),
max_cell_sizes{128, 128 * 32, 128 * 32 * 16, 128 * 32 * 16 * 32}
{
}
PartitionConfig() : requested_num_threads(0) {}
void UseDefaults()
{
@@ -54,11 +49,11 @@ struct PartitionConfig
unsigned requested_num_threads;
std::size_t minimum_cell_size;
double balance;
double boundary_factor;
std::size_t num_optimizing_cuts;
std::size_t small_component_size;
std::vector<std::size_t> max_cell_sizes;
};
}
}
-78
View File
@@ -1,78 +0,0 @@
#ifndef OSRM_PARTITION_SERIALIZATION_HPP
#define OSRM_PARTITION_SERIALIZATION_HPP
#include "partition/cell_storage.hpp"
#include "partition/edge_based_graph.hpp"
#include "partition/multi_level_graph.hpp"
#include "partition/multi_level_partition.hpp"
#include "storage/io.hpp"
#include "storage/serialization.hpp"
#include "storage/shared_memory_ownership.hpp"
namespace osrm
{
namespace partition
{
namespace serialization
{
template <typename EdgeDataT, storage::Ownership Ownership>
inline void read(storage::io::FileReader &reader, MultiLevelGraph<EdgeDataT, Ownership> &graph)
{
storage::serialization::read(reader, graph.node_array);
storage::serialization::read(reader, graph.edge_array);
storage::serialization::read(reader, graph.node_to_edge_offset);
}
template <typename EdgeDataT, storage::Ownership Ownership>
inline void write(storage::io::FileWriter &writer,
const MultiLevelGraph<EdgeDataT, Ownership> &graph)
{
storage::serialization::write(writer, graph.node_array);
storage::serialization::write(writer, graph.edge_array);
storage::serialization::write(writer, graph.node_to_edge_offset);
}
template <storage::Ownership Ownership>
inline void read(storage::io::FileReader &reader, detail::MultiLevelPartitionImpl<Ownership> &mlp)
{
reader.ReadInto(*mlp.level_data);
storage::serialization::read(reader, mlp.partition);
storage::serialization::read(reader, mlp.cell_to_children);
}
template <storage::Ownership Ownership>
inline void write(storage::io::FileWriter &writer,
const detail::MultiLevelPartitionImpl<Ownership> &mlp)
{
writer.WriteOne(*mlp.level_data);
storage::serialization::write(writer, mlp.partition);
storage::serialization::write(writer, mlp.cell_to_children);
}
template <storage::Ownership Ownership>
inline void read(storage::io::FileReader &reader, detail::CellStorageImpl<Ownership> &storage)
{
storage::serialization::read(reader, storage.weights);
storage::serialization::read(reader, storage.source_boundary);
storage::serialization::read(reader, storage.destination_boundary);
storage::serialization::read(reader, storage.cells);
storage::serialization::read(reader, storage.level_to_cell_offset);
}
template <storage::Ownership Ownership>
inline void write(storage::io::FileWriter &writer,
const detail::CellStorageImpl<Ownership> &storage)
{
storage::serialization::write(writer, storage.weights);
storage::serialization::write(writer, storage.source_boundary);
storage::serialization::write(writer, storage.destination_boundary);
storage::serialization::write(writer, storage.cells);
storage::serialization::write(writer, storage.level_to_cell_offset);
}
}
}
}
#endif
+2 -13
View File
@@ -33,24 +33,13 @@ struct MatchParametersGrammar final : public RouteParametersGrammar<Iterator, Si
(qi::uint_ %
';')[ph::bind(&engine::api::MatchParameters::timestamps, qi::_r1) = qi::_1];
gaps_type.add("split", engine::api::MatchParameters::GapsType::Split)(
"ignore", engine::api::MatchParameters::GapsType::Ignore);
root_rule =
BaseGrammar::query_rule(qi::_r1) > -qi::lit(".json") >
-('?' > (timestamps_rule(qi::_r1) | BaseGrammar::base_rule(qi::_r1) |
(qi::lit("gaps=") >
gaps_type[ph::bind(&engine::api::MatchParameters::gaps, qi::_r1) = qi::_1]) |
(qi::lit("tidy=") >
qi::bool_[ph::bind(&engine::api::MatchParameters::tidy, qi::_r1) = qi::_1])) %
'&');
root_rule = BaseGrammar::query_rule(qi::_r1) > -qi::lit(".json") >
-('?' > (timestamps_rule(qi::_r1) | BaseGrammar::base_rule(qi::_r1)) % '&');
}
private:
qi::rule<Iterator, Signature> root_rule;
qi::rule<Iterator, Signature> timestamps_rule;
qi::symbols<char, engine::api::MatchParameters::GapsType> gaps_type;
};
}
}
+70
View File
@@ -128,6 +128,20 @@ class FileReader
std::uint32_t ReadElementCount32() { return ReadOne<std::uint32_t>(); }
std::uint64_t ReadElementCount64() { return ReadOne<std::uint64_t>(); }
template <typename T> void DeserializeVector(std::vector<T> &data)
{
const auto count = ReadElementCount64();
data.resize(count);
ReadInto(data.data(), count);
}
template <typename T> std::size_t GetVectorMemorySize()
{
const auto count = ReadElementCount64();
Skip<T>(count);
return sizeof(count) + sizeof(T) * count;
}
template <typename T> std::size_t ReadVectorSize()
{
const auto count = ReadElementCount64();
@@ -135,6 +149,19 @@ class FileReader
return count;
}
template <typename T> void *DeserializeVector(void *begin, const void *end)
{
auto count = ReadElementCount64();
auto required = reinterpret_cast<char *>(begin) + sizeof(count) + sizeof(T) * count;
if (required > end)
throw util::exception("Not enough memory ");
*reinterpret_cast<decltype(count) *>(begin) = count;
ReadInto(reinterpret_cast<T *>(reinterpret_cast<char *>(begin) + sizeof(decltype(count))),
count);
return required;
}
bool ReadAndCheckFingerprint()
{
auto loaded_fingerprint = ReadOne<util::FingerPrint>();
@@ -172,6 +199,42 @@ class FileReader
input_stream.seekg(current_pos, input_stream.beg);
return length;
}
std::vector<std::string> ReadLines()
{
std::vector<std::string> result;
std::string thisline;
try
{
while (std::getline(input_stream, thisline))
{
result.push_back(thisline);
}
}
catch (const std::ios_base::failure &)
{
// EOF is OK here, everything else, re-throw
if (!input_stream.eof())
throw;
}
return result;
}
std::string ReadLine()
{
std::string thisline;
try
{
std::getline(input_stream, thisline);
}
catch (const std::ios_base::failure & /*e*/)
{
// EOF is OK here, everything else, re-throw
if (!input_stream.eof())
throw;
}
return thisline;
}
};
class FileWriter
@@ -233,6 +296,13 @@ class FileWriter
void WriteElementCount32(const std::uint32_t count) { WriteOne<std::uint32_t>(count); }
void WriteElementCount64(const std::uint64_t count) { WriteOne<std::uint64_t>(count); }
template <typename T> void SerializeVector(const std::vector<T> &data)
{
const auto count = data.size();
WriteElementCount64(count);
return WriteFrom(data.data(), count);
}
void WriteFingerprint()
{
const auto fingerprint = util::FingerPrint::GetValid();
-18
View File
@@ -1,18 +0,0 @@
#ifndef OSRM_STORAGE_IO_FWD_HPP_
#define OSRM_STORAGE_IO_FWD_HPP_
namespace osrm
{
namespace storage
{
namespace io
{
class FileReader;
class FileWriter;
} // ns io
} // ns storage
} // ns osrm
#endif
+105 -20
View File
@@ -1,9 +1,23 @@
#ifndef OSRM_STORAGE_SERIALIZATION_HPP
#define OSRM_STORAGE_SERIALIZATION_HPP
#include "util/vector_view.hpp"
#ifndef OSRM_STORAGE_SERIALIZATION_HPP_
#define OSRM_STORAGE_SERIALIZATION_HPP_
#include "contractor/query_edge.hpp"
#include "extractor/extractor.hpp"
#include "extractor/original_edge_data.hpp"
#include "extractor/query_node.hpp"
#include "storage/io.hpp"
#include "util/exception.hpp"
#include "util/fingerprint.hpp"
#include "util/log.hpp"
#include "util/static_graph.hpp"
#include <boost/filesystem/fstream.hpp>
#include <boost/iostreams/seek.hpp>
#include <cerrno>
#include <cstring>
#include <tuple>
#include <type_traits>
namespace osrm
{
@@ -12,32 +26,103 @@ namespace storage
namespace serialization
{
template <typename T> void read(io::FileReader &reader, std::vector<T> &data)
// To make function calls consistent, this function returns the fixed number of properties
inline std::size_t readPropertiesCount() { return 1; }
struct HSGRHeader
{
const auto count = reader.ReadElementCount64();
data.resize(count);
reader.ReadInto(data.data(), count);
std::uint32_t checksum;
std::uint64_t number_of_nodes;
std::uint64_t number_of_edges;
};
// Reads the checksum, number of nodes and number of edges written in the header file of a `.hsgr`
// file and returns them in a HSGRHeader struct
inline HSGRHeader readHSGRHeader(io::FileReader &input_file)
{
HSGRHeader header;
input_file.ReadInto(header.checksum);
input_file.ReadInto(header.number_of_nodes);
input_file.ReadInto(header.number_of_edges);
// If we have edges, then we must have nodes.
// However, there can be nodes with no edges (some test cases create this)
BOOST_ASSERT_MSG(header.number_of_edges == 0 || header.number_of_nodes > 0,
"edges exist, but there are no nodes");
return header;
}
template <typename T> void write(io::FileWriter &writer, const std::vector<T> &data)
// Reads the graph data of a `.hsgr` file into memory
// Needs to be called after readHSGRHeader() to get the correct offset in the stream
using NodeT = typename util::StaticGraph<contractor::QueryEdge::EdgeData>::NodeArrayEntry;
using EdgeT = typename util::StaticGraph<contractor::QueryEdge::EdgeData>::EdgeArrayEntry;
inline void readHSGR(io::FileReader &input_file,
NodeT *node_buffer,
const std::uint64_t number_of_nodes,
EdgeT *edge_buffer,
const std::uint64_t number_of_edges)
{
const auto count = data.size();
writer.WriteElementCount64(count);
return writer.WriteFrom(data.data(), count);
BOOST_ASSERT(node_buffer);
BOOST_ASSERT(edge_buffer);
input_file.ReadInto(node_buffer, number_of_nodes);
input_file.ReadInto(edge_buffer, number_of_edges);
}
template <typename T> void read(io::FileReader &reader, util::vector_view<T> &data)
// Loads edge data from .edge files into memory which includes its
// geometry, name ID, turn instruction, lane data ID, travel mode, entry class ID
// Needs to be called after readElementCount() to get the correct offset in the stream
inline void readEdges(io::FileReader &edges_input_file,
GeometryID *geometry_list,
NameID *name_id_list,
extractor::guidance::TurnInstruction *turn_instruction_list,
LaneDataID *lane_data_id_list,
extractor::TravelMode *travel_mode_list,
EntryClassID *entry_class_id_list,
util::guidance::TurnBearing *pre_turn_bearing_list,
util::guidance::TurnBearing *post_turn_bearing_list,
const std::uint64_t number_of_edges)
{
const auto count = reader.ReadElementCount64();
BOOST_ASSERT(data.size() == count);
reader.ReadInto(data.data(), count);
BOOST_ASSERT(geometry_list);
BOOST_ASSERT(name_id_list);
BOOST_ASSERT(turn_instruction_list);
BOOST_ASSERT(lane_data_id_list);
BOOST_ASSERT(travel_mode_list);
BOOST_ASSERT(entry_class_id_list);
extractor::OriginalEdgeData current_edge_data;
for (std::uint64_t i = 0; i < number_of_edges; ++i)
{
edges_input_file.ReadInto(current_edge_data);
geometry_list[i] = current_edge_data.via_geometry;
name_id_list[i] = current_edge_data.name_id;
turn_instruction_list[i] = current_edge_data.turn_instruction;
lane_data_id_list[i] = current_edge_data.lane_data_id;
travel_mode_list[i] = current_edge_data.travel_mode;
entry_class_id_list[i] = current_edge_data.entry_classid;
pre_turn_bearing_list[i] = current_edge_data.pre_turn_bearing;
post_turn_bearing_list[i] = current_edge_data.post_turn_bearing;
}
}
template <typename T> void write(io::FileWriter &writer, const util::vector_view<T> &data)
// Loads coordinates and OSM node IDs from .nodes files into memory
// Needs to be called after readElementCount() to get the correct offset in the stream
template <typename OSMNodeIDVectorT>
void readNodes(io::FileReader &nodes_file,
util::Coordinate *coordinate_list,
OSMNodeIDVectorT &osmnodeid_list,
const std::uint64_t number_of_coordinates)
{
const auto count = data.size();
writer.WriteElementCount64(count);
return writer.WriteFrom(data.data(), count);
BOOST_ASSERT(coordinate_list);
extractor::QueryNode current_node;
for (std::uint64_t i = 0; i < number_of_coordinates; ++i)
{
nodes_file.ReadInto(current_node);
coordinate_list[i] = util::Coordinate(current_node.lon, current_node.lat);
osmnodeid_list.push_back(current_node.node_id);
BOOST_ASSERT(coordinate_list[i].IsValid());
}
}
}
}
+3 -5
View File
@@ -25,8 +25,6 @@
#include <exception>
#include <thread>
#include "storage/shared_memory_ownership.hpp"
namespace osrm
{
namespace storage
@@ -153,7 +151,7 @@ class SharedMemory
#else
void WaitForDetach()
{
util::Log(logDEBUG)
util::Log(logWARNING)
<< "Shared memory support for non-Linux systems does not wait for clients to "
"dettach. Going to sleep for 50ms.";
std::this_thread::sleep_for(std::chrono::milliseconds(50));
@@ -247,8 +245,8 @@ class SharedMemory
void WaitForDetach()
{
// FIXME this needs an implementation for Windows
util::Log(logDEBUG) << "Shared memory support for Windows does not wait for clients to "
"dettach. Going to sleep for 50ms.";
util::Log(logWARNING) << "Shared memory support for Windows does not wait for clients to "
"dettach. Going to sleep for 50ms.";
std::this_thread::sleep_for(std::chrono::milliseconds(50));
}
@@ -1,17 +0,0 @@
#ifndef SHARED_MEMORY_OWNERSHIP_HPP
#define SHARED_MEMORY_OWNERSHIP_HPP
namespace osrm
{
namespace storage
{
enum class Ownership
{
Container,
View
};
}
}
#endif // SHARED_MEMORY_OWNERSHIP_HPP
+4 -42
View File
@@ -16,48 +16,6 @@ namespace osrm
namespace util
{
template <typename NodeID, typename Key> class GenerationArrayStorage
{
using GenerationCounter = std::uint16_t;
public:
explicit GenerationArrayStorage(std::size_t size)
: positions(size, 0), generation(1), generations(size, 0)
{
}
Key &operator[](NodeID node)
{
generation[node] = generation;
return positions[node];
}
Key peek_index(const NodeID node) const
{
if (generations[node] < generation)
{
return std::numeric_limits<Key>::max();
}
return positions[node];
}
void Clear()
{
generation++;
// if generation overflows we end up at 0 again and need to clear the vector
if (generation == 0)
{
generation = 1;
std::fill(generations.begin(), generations.end(), 0);
}
}
private:
GenerationCounter generation;
std::vector<GenerationCounter> generations;
std::vector<Key> positions;
};
template <typename NodeID, typename Key> class ArrayStorage
{
public:
@@ -134,6 +92,10 @@ template <typename NodeID,
typename IndexStorage = ArrayStorage<NodeID, NodeID>>
class BinaryHeap
{
private:
BinaryHeap(const BinaryHeap &right);
void operator=(const BinaryHeap &right);
public:
using WeightType = Weight;
using DataType = Data;
-7
View File
@@ -239,13 +239,6 @@ class DeallocatingVector
bucket_list.emplace_back(new ElementT[ELEMENTS_PER_BLOCK]);
}
// copying is not safe since this would only do a shallow copy
DeallocatingVector(DeallocatingVector &other) = delete;
DeallocatingVector &operator=(DeallocatingVector &other) = delete;
// moving is fine
DeallocatingVector(DeallocatingVector &&other) = default;
DeallocatingVector &operator=(DeallocatingVector &&other) = default;
~DeallocatingVector() { clear(); }
friend void swap<>(DeallocatingVector<ElementT, ELEMENTS_PER_BLOCK> &lhs,
-12
View File
@@ -5,8 +5,6 @@
#include "util/integer_range.hpp"
#include "util/typedefs.hpp"
#include "storage/io_fwd.hpp"
#include <boost/assert.hpp>
#include <cstdint>
@@ -21,16 +19,6 @@ namespace osrm
{
namespace util
{
template <typename EdgeDataT> class DynamicGraph;
namespace serialization
{
template <typename EdgeDataT, bool UseSharedMemory>
void read(storage::io::FileReader &reader, DynamicGraph<EdgeDataT> &graph);
template <typename EdgeDataT, bool UseSharedMemory>
void write(storage::io::FileWriter &writer, const DynamicGraph<EdgeDataT> &graph);
}
template <typename EdgeDataT> class DynamicGraph
{
+5 -8
View File
@@ -9,7 +9,6 @@
#include "util/exception.hpp"
#include "util/fingerprint.hpp"
#include "util/log.hpp"
#include "util/packed_vector.hpp"
#include "util/typedefs.hpp"
#include <boost/assert.hpp>
@@ -58,23 +57,21 @@ template <typename BarrierOutIter, typename TrafficSignalsOutIter>
NodeID loadNodesFromFile(storage::io::FileReader &file_reader,
BarrierOutIter barriers,
TrafficSignalsOutIter traffic_signals,
std::vector<util::Coordinate> &coordinates,
util::PackedVector<OSMNodeID> &osm_node_ids)
std::vector<extractor::QueryNode> &node_array)
{
NodeID number_of_nodes = file_reader.ReadElementCount32();
Log() << "Importing number_of_nodes new = " << number_of_nodes << " nodes ";
coordinates.resize(number_of_nodes);
osm_node_ids.reserve(number_of_nodes);
node_array.resize(number_of_nodes);
extractor::ExternalMemoryNode current_node;
for (NodeID i = 0; i < number_of_nodes; ++i)
{
file_reader.ReadInto(&current_node, 1);
coordinates[i].lon = current_node.lon;
coordinates[i].lat = current_node.lat;
osm_node_ids.push_back(current_node.node_id);
node_array[i].lon = current_node.lon;
node_array[i].lat = current_node.lat;
node_array[i].node_id = current_node.node_id;
if (current_node.barrier)
{
+46
View File
@@ -0,0 +1,46 @@
#ifndef OSRM_INCLUDE_UTIL_IO_HPP_
#define OSRM_INCLUDE_UTIL_IO_HPP_
#include "util/log.hpp"
#include <boost/filesystem.hpp>
#include <boost/numeric/conversion/cast.hpp>
#include <cstddef>
#include <cstdint>
#include <bitset>
#include <fstream>
#include <stxxl/vector>
#include <vector>
#include "storage/io.hpp"
#include "util/fingerprint.hpp"
namespace osrm
{
namespace util
{
template <typename simple_type>
void deserializeAdjacencyArray(const std::string &filename,
std::vector<std::uint32_t> &offsets,
std::vector<simple_type> &data)
{
storage::io::FileReader file(filename, storage::io::FileReader::HasNoFingerprint);
file.DeserializeVector(offsets);
file.DeserializeVector(data);
// offsets have to match up with the size of the data
if (offsets.empty() || (offsets.back() != boost::numeric_cast<std::uint32_t>(data.size())))
throw util::exception(
"Error in " + filename +
(offsets.empty() ? "Offsets are empty" : "Offset and data size do not match") +
SOURCE_REF);
}
} // namespace util
} // namespace osrm
#endif // OSRM_INCLUDE_UTIL_IO_HPP_
+1
View File
@@ -2,6 +2,7 @@
#define OSRM_UTIL_NAME_TABLE_HPP
#include "util/indexed_data.hpp"
#include "util/shared_memory_vector_wrapper.hpp"
#include "util/string_view.hpp"
#include "util/typedefs.hpp"
+14 -46
View File
@@ -1,11 +1,8 @@
#ifndef PACKED_VECTOR_HPP
#define PACKED_VECTOR_HPP
#include "util/shared_memory_vector_wrapper.hpp"
#include "util/typedefs.hpp"
#include "util/vector_view.hpp"
#include "storage/io_fwd.hpp"
#include "storage/shared_memory_ownership.hpp"
#include <cmath>
#include <vector>
@@ -14,22 +11,7 @@ namespace osrm
{
namespace util
{
namespace detail
{
template <typename T, storage::Ownership Ownership> class PackedVector;
}
namespace serialization
{
template <typename T, storage::Ownership Ownership>
inline void read(storage::io::FileReader &reader, detail::PackedVector<T, Ownership> &vec);
template <typename T, storage::Ownership Ownership>
inline void write(storage::io::FileWriter &writer, const detail::PackedVector<T, Ownership> &vec);
}
namespace detail
{
/**
* Since OSM node IDs are (at the time of writing) not quite yet overflowing 32 bits, and
* will predictably be containable within 33 bits for a long time, the following packs
@@ -38,15 +20,13 @@ namespace detail
* NOTE: this type is templated for future use, but will require a slight refactor to
* configure BITSIZE and ELEMSIZE
*/
template <typename T, storage::Ownership Ownership> class PackedVector
template <typename T, bool UseSharedMemory = false> class PackedVector
{
static const constexpr std::size_t BITSIZE = 33;
static const constexpr std::size_t ELEMSIZE = 64;
static const constexpr std::size_t PACKSIZE = BITSIZE * ELEMSIZE;
public:
using value_type = T;
/**
* Returns the size of the packed vector datastructure with `elements` packed elements (the size
* of
@@ -97,9 +77,7 @@ template <typename T, storage::Ownership Ownership> class PackedVector
num_elements++;
}
T operator[](const std::size_t index) const { return at(index); }
T at(const std::size_t a_index) const
T at(const std::size_t &a_index) const
{
BOOST_ASSERT(a_index < num_elements);
@@ -142,20 +120,20 @@ template <typename T, storage::Ownership Ownership> class PackedVector
std::size_t size() const { return num_elements; }
template <bool enabled = (Ownership == storage::Ownership::View)>
template <bool enabled = UseSharedMemory>
void reserve(typename std::enable_if<!enabled, std::size_t>::type capacity)
{
vec.reserve(elements_to_blocks(capacity));
}
template <bool enabled = (Ownership == storage::Ownership::View)>
template <bool enabled = UseSharedMemory>
void reset(typename std::enable_if<enabled, std::uint64_t>::type *ptr,
typename std::enable_if<enabled, std::size_t>::type size)
{
vec.reset(ptr, size);
}
template <bool enabled = (Ownership == storage::Ownership::View)>
template <bool enabled = UseSharedMemory>
void set_number_of_entries(typename std::enable_if<enabled, std::size_t>::type count)
{
num_elements = count;
@@ -166,61 +144,51 @@ template <typename T, storage::Ownership Ownership> class PackedVector
return std::floor(static_cast<double>(vec.capacity()) * ELEMSIZE / BITSIZE);
}
friend void serialization::read<T, Ownership>(storage::io::FileReader &reader,
detail::PackedVector<T, Ownership> &vec);
friend void serialization::write<T, Ownership>(storage::io::FileWriter &writer,
const detail::PackedVector<T, Ownership> &vec);
private:
util::ViewOrVector<std::uint64_t, Ownership> vec;
typename util::ShM<std::uint64_t, UseSharedMemory>::vector vec;
std::uint64_t num_elements = 0;
std::size_t num_elements = 0;
signed cursor = -1;
template <bool enabled = (Ownership == storage::Ownership::View)>
template <bool enabled = UseSharedMemory>
void replace_last_elem(typename std::enable_if<enabled, std::uint64_t>::type last_elem)
{
vec[cursor] = last_elem;
}
template <bool enabled = (Ownership == storage::Ownership::View)>
template <bool enabled = UseSharedMemory>
void replace_last_elem(typename std::enable_if<!enabled, std::uint64_t>::type last_elem)
{
vec.back() = last_elem;
}
template <bool enabled = (Ownership == storage::Ownership::View)>
template <bool enabled = UseSharedMemory>
void add_last_elem(typename std::enable_if<enabled, std::uint64_t>::type last_elem)
{
vec[cursor + 1] = last_elem;
cursor++;
}
template <bool enabled = (Ownership == storage::Ownership::View)>
template <bool enabled = UseSharedMemory>
void add_last_elem(typename std::enable_if<!enabled, std::uint64_t>::type last_elem)
{
vec.push_back(last_elem);
}
template <bool enabled = (Ownership == storage::Ownership::View)>
template <bool enabled = UseSharedMemory>
std::uint64_t vec_back(typename std::enable_if<enabled>::type * = nullptr)
{
return vec[cursor];
}
template <bool enabled = (Ownership == storage::Ownership::View)>
template <bool enabled = UseSharedMemory>
std::uint64_t vec_back(typename std::enable_if<!enabled>::type * = nullptr)
{
return vec.back();
}
};
}
template <typename T> using PackedVector = detail::PackedVector<T, storage::Ownership::Container>;
template <typename T> using PackedVectorView = detail::PackedVector<T, storage::Ownership::View>;
}
}
#endif /* PACKED_VECTOR_HPP */
+18 -19
View File
@@ -2,9 +2,8 @@
#define RANGE_TABLE_HPP
#include "storage/io.hpp"
#include "storage/shared_memory_ownership.hpp"
#include "util/integer_range.hpp"
#include "util/vector_view.hpp"
#include "util/shared_memory_vector_wrapper.hpp"
#include <array>
#include <fstream>
@@ -19,14 +18,13 @@ namespace util
* and otherwise the compiler gets confused.
*/
template <unsigned BLOCK_SIZE = 16, storage::Ownership Ownership = storage::Ownership::Container>
class RangeTable;
template <unsigned BLOCK_SIZE = 16, bool USE_SHARED_MEMORY = false> class RangeTable;
template <unsigned BLOCK_SIZE, storage::Ownership Ownership>
std::ostream &operator<<(std::ostream &out, const RangeTable<BLOCK_SIZE, Ownership> &table);
template <unsigned BLOCK_SIZE, bool USE_SHARED_MEMORY>
std::ostream &operator<<(std::ostream &out, const RangeTable<BLOCK_SIZE, USE_SHARED_MEMORY> &table);
template <unsigned BLOCK_SIZE, storage::Ownership Ownership>
std::istream &operator>>(std::istream &in, RangeTable<BLOCK_SIZE, Ownership> &table);
template <unsigned BLOCK_SIZE, bool USE_SHARED_MEMORY>
std::istream &operator>>(std::istream &in, RangeTable<BLOCK_SIZE, USE_SHARED_MEMORY> &table);
/**
* Stores adjacent ranges in a compressed format.
@@ -37,12 +35,12 @@ std::istream &operator>>(std::istream &in, RangeTable<BLOCK_SIZE, Ownership> &ta
* But each block consists of an absolute value and BLOCK_SIZE differential values.
* So the effective block size is sizeof(unsigned) + BLOCK_SIZE.
*/
template <unsigned BLOCK_SIZE, storage::Ownership Ownership> class RangeTable
template <unsigned BLOCK_SIZE, bool USE_SHARED_MEMORY> class RangeTable
{
public:
using BlockT = std::array<unsigned char, BLOCK_SIZE>;
using BlockContainerT = util::ViewOrVector<BlockT, Ownership>;
using OffsetContainerT = util::ViewOrVector<unsigned, Ownership>;
using BlockContainerT = typename ShM<BlockT, USE_SHARED_MEMORY>::vector;
using OffsetContainerT = typename ShM<unsigned, USE_SHARED_MEMORY>::vector;
using RangeT = range<unsigned>;
friend std::ostream &operator<<<>(std::ostream &out, const RangeTable &table);
@@ -141,7 +139,7 @@ template <unsigned BLOCK_SIZE, storage::Ownership Ownership> class RangeTable
sum_lengths = lengths_prefix_sum;
}
void Write(storage::io::FileWriter &filewriter)
void Write(osrm::storage::io::FileWriter &filewriter)
{
unsigned number_of_blocks = diff_blocks.size();
@@ -153,7 +151,7 @@ template <unsigned BLOCK_SIZE, storage::Ownership Ownership> class RangeTable
filewriter.WriteFrom(diff_blocks.data(), number_of_blocks);
}
void Read(storage::io::FileReader &filereader)
void Read(osrm::storage::io::FileReader &filereader)
{
unsigned number_of_blocks = filereader.ReadElementCount32();
// read total length
@@ -214,8 +212,9 @@ template <unsigned BLOCK_SIZE, storage::Ownership Ownership> class RangeTable
unsigned sum_lengths;
};
template <unsigned BLOCK_SIZE, storage::Ownership Ownership>
unsigned RangeTable<BLOCK_SIZE, Ownership>::PrefixSumAtIndex(int index, const BlockT &block) const
template <unsigned BLOCK_SIZE, bool USE_SHARED_MEMORY>
unsigned RangeTable<BLOCK_SIZE, USE_SHARED_MEMORY>::PrefixSumAtIndex(int index,
const BlockT &block) const
{
// this loop looks inefficent, but a modern compiler
// will emit nice SIMD here, at least for sensible block sizes. (I checked.)
@@ -228,8 +227,8 @@ unsigned RangeTable<BLOCK_SIZE, Ownership>::PrefixSumAtIndex(int index, const Bl
return sum;
}
template <unsigned BLOCK_SIZE, storage::Ownership Ownership>
std::ostream &operator<<(std::ostream &out, const RangeTable<BLOCK_SIZE, Ownership> &table)
template <unsigned BLOCK_SIZE, bool USE_SHARED_MEMORY>
std::ostream &operator<<(std::ostream &out, const RangeTable<BLOCK_SIZE, USE_SHARED_MEMORY> &table)
{
// write number of block
const unsigned number_of_blocks = table.diff_blocks.size();
@@ -244,8 +243,8 @@ std::ostream &operator<<(std::ostream &out, const RangeTable<BLOCK_SIZE, Ownersh
return out;
}
template <unsigned BLOCK_SIZE, storage::Ownership Ownership>
std::istream &operator>>(std::istream &in, RangeTable<BLOCK_SIZE, Ownership> &table)
template <unsigned BLOCK_SIZE, bool USE_SHARED_MEMORY>
std::istream &operator>>(std::istream &in, RangeTable<BLOCK_SIZE, USE_SHARED_MEMORY> &table)
{
// read number of block
unsigned number_of_blocks;
-73
View File
@@ -1,73 +0,0 @@
#ifndef OSMR_UTIL_SERIALIZATION_HPP
#define OSMR_UTIL_SERIALIZATION_HPP
#include "util/dynamic_graph.hpp"
#include "util/packed_vector.hpp"
#include "util/static_graph.hpp"
#include "storage/io.hpp"
#include "storage/serialization.hpp"
namespace osrm
{
namespace util
{
namespace serialization
{
template <typename T, storage::Ownership Ownership>
inline void read(storage::io::FileReader &reader, detail::PackedVector<T, Ownership> &vec)
{
vec.num_elements = reader.ReadOne<std::uint64_t>();
storage::serialization::read(reader, vec.vec);
}
template <typename T, storage::Ownership Ownership>
inline void write(storage::io::FileWriter &writer, const detail::PackedVector<T, Ownership> &vec)
{
writer.WriteOne(vec.num_elements);
storage::serialization::write(writer, vec.vec);
}
template <typename EdgeDataT, storage::Ownership Ownership>
inline void read(storage::io::FileReader &reader, StaticGraph<EdgeDataT, Ownership> &graph)
{
storage::serialization::read(reader, graph.node_array);
storage::serialization::read(reader, graph.edge_array);
}
template <typename EdgeDataT, storage::Ownership Ownership>
inline void write(storage::io::FileWriter &writer, const StaticGraph<EdgeDataT, Ownership> &graph)
{
storage::serialization::write(writer, graph.node_array);
storage::serialization::write(writer, graph.edge_array);
}
template <typename EdgeDataT>
inline void read(storage::io::FileReader &reader, DynamicGraph<EdgeDataT> &graph)
{
storage::serialization::read(reader, graph.node_array);
auto num_edges = reader.ReadElementCount64();
graph.edge_list.resize(num_edges);
for (auto index : irange<std::size_t>(0, num_edges))
{
reader.ReadOne(graph.edge_list[index]);
}
graph.number_of_nodes = graph.node_array.size();
graph.number_of_edges = num_edges;
}
template <typename EdgeDataT>
inline void write(storage::io::FileWriter &writer, const DynamicGraph<EdgeDataT> &graph)
{
storage::serialization::write(writer, graph.node_array);
writer.WriteElementCount64(graph.number_of_edges);
for (auto index : irange<std::size_t>(0, graph.number_of_edges))
{
writer.WriteOne(graph.edge_list[index]);
}
}
}
}
}
#endif
@@ -1,11 +1,8 @@
#ifndef UTIL_VECTOR_VIEW_HPP
#define UTIL_VECTOR_VIEW_HPP
#ifndef SHARED_MEMORY_VECTOR_WRAPPER_HPP
#define SHARED_MEMORY_VECTOR_WRAPPER_HPP
#include "util/exception.hpp"
#include "util/log.hpp"
#include "storage/shared_memory_ownership.hpp"
#include <boost/assert.hpp>
#include <boost/iterator/iterator_facade.hpp>
#include <boost/iterator/reverse_iterator.hpp>
@@ -25,13 +22,10 @@ namespace util
{
template <typename DataT>
class VectorViewIterator : public boost::iterator_facade<VectorViewIterator<DataT>,
DataT,
boost::random_access_traversal_tag>
class ShMemIterator
: public boost::iterator_facade<ShMemIterator<DataT>, DataT, boost::random_access_traversal_tag>
{
typedef boost::iterator_facade<VectorViewIterator<DataT>,
DataT,
boost::random_access_traversal_tag>
typedef boost::iterator_facade<ShMemIterator<DataT>, DataT, boost::random_access_traversal_tag>
base_t;
public:
@@ -40,16 +34,16 @@ class VectorViewIterator : public boost::iterator_facade<VectorViewIterator<Data
typedef typename base_t::reference reference;
typedef std::random_access_iterator_tag iterator_category;
explicit VectorViewIterator() : m_value(nullptr) {}
explicit VectorViewIterator(DataT *x) : m_value(x) {}
explicit ShMemIterator() : m_value(nullptr) {}
explicit ShMemIterator(DataT *x) : m_value(x) {}
private:
void increment() { ++m_value; }
void decrement() { --m_value; }
void advance(difference_type offset) { m_value += offset; }
bool equal(const VectorViewIterator &other) const { return m_value == other.m_value; }
bool equal(const ShMemIterator &other) const { return m_value == other.m_value; }
reference dereference() const { return *m_value; }
difference_type distance_to(const VectorViewIterator &other) const
difference_type distance_to(const ShMemIterator &other) const
{
return other.m_value - m_value;
}
@@ -58,7 +52,7 @@ class VectorViewIterator : public boost::iterator_facade<VectorViewIterator<Data
DataT *m_value;
};
template <typename DataT> class vector_view
template <typename DataT> class SharedMemoryWrapper
{
private:
DataT *m_ptr;
@@ -66,13 +60,13 @@ template <typename DataT> class vector_view
public:
using value_type = DataT;
using iterator = VectorViewIterator<DataT>;
using const_iterator = VectorViewIterator<const DataT>;
using iterator = ShMemIterator<DataT>;
using const_iterator = ShMemIterator<const DataT>;
using reverse_iterator = boost::reverse_iterator<iterator>;
vector_view() : m_ptr(nullptr), m_size(0) {}
SharedMemoryWrapper() : m_ptr(nullptr), m_size(0) {}
vector_view(DataT *ptr, std::size_t size) : m_ptr(ptr), m_size(size) {}
SharedMemoryWrapper(DataT *ptr, std::size_t size) : m_ptr(ptr), m_size(size) {}
void reset(DataT *ptr, std::size_t size)
{
@@ -132,21 +126,20 @@ template <typename DataT> class vector_view
auto data() const { return m_ptr; }
template <typename T> friend void swap(vector_view<T> &, vector_view<T> &) noexcept;
template <typename T>
friend void swap(SharedMemoryWrapper<T> &, SharedMemoryWrapper<T> &) noexcept;
};
template <> class vector_view<bool>
template <> class SharedMemoryWrapper<bool>
{
private:
unsigned *m_ptr;
std::size_t m_size;
public:
using value_type = bool;
SharedMemoryWrapper() : m_ptr(nullptr), m_size(0) {}
vector_view() : m_ptr(nullptr), m_size(0) {}
vector_view(unsigned *ptr, std::size_t size) : m_ptr(ptr), m_size(size) {}
SharedMemoryWrapper(unsigned *ptr, std::size_t size) : m_ptr(ptr), m_size(size) {}
bool at(const std::size_t index) const
{
@@ -156,7 +149,11 @@ template <> class vector_view<bool>
return m_ptr[bucket] & (1u << offset);
}
void reset(unsigned *, std::size_t size) { m_size = size; }
void reset(unsigned *ptr, std::size_t size)
{
m_ptr = ptr;
m_size = size;
}
std::size_t size() const { return m_size; }
@@ -164,20 +161,24 @@ template <> class vector_view<bool>
bool operator[](const unsigned index) const { return at(index); }
template <typename T> friend void swap(vector_view<T> &, vector_view<T> &) noexcept;
template <typename T>
friend void swap(SharedMemoryWrapper<T> &, SharedMemoryWrapper<T> &) noexcept;
};
// Both vector_view<T> and the vector_view<bool> specializations share this impl.
template <typename DataT> void swap(vector_view<DataT> &lhs, vector_view<DataT> &rhs) noexcept
// Both SharedMemoryWrapper<T> and the SharedMemoryWrapper<bool> specializations share this impl.
template <typename DataT>
void swap(SharedMemoryWrapper<DataT> &lhs, SharedMemoryWrapper<DataT> &rhs) noexcept
{
std::swap(lhs.m_ptr, rhs.m_ptr);
std::swap(lhs.m_size, rhs.m_size);
}
template <typename DataT, storage::Ownership Ownership>
using ViewOrVector = typename std::conditional<Ownership == storage::Ownership::View,
vector_view<DataT>,
std::vector<DataT>>::type;
template <typename DataT, bool UseSharedMemory> struct ShM
{
using vector = typename std::conditional<UseSharedMemory,
SharedMemoryWrapper<DataT>,
std::vector<DataT>>::type;
};
}
}
+11 -32
View File
@@ -4,11 +4,8 @@
#include "util/graph_traits.hpp"
#include "util/integer_range.hpp"
#include "util/percent.hpp"
#include "util/shared_memory_vector_wrapper.hpp"
#include "util/typedefs.hpp"
#include "util/vector_view.hpp"
#include "storage/io_fwd.hpp"
#include "storage/shared_memory_ownership.hpp"
#include <boost/assert.hpp>
@@ -22,16 +19,6 @@ namespace osrm
{
namespace util
{
template <typename EdgeDataT, storage::Ownership Ownership> class StaticGraph;
namespace serialization
{
template <typename EdgeDataT, storage::Ownership Ownership>
void read(storage::io::FileReader &reader, StaticGraph<EdgeDataT, Ownership> &graph);
template <typename EdgeDataT, storage::Ownership Ownership>
void write(storage::io::FileWriter &writer, const StaticGraph<EdgeDataT, Ownership> &graph);
}
namespace static_graph_details
{
@@ -110,11 +97,8 @@ EntryT edgeToEntry(const OtherEdge &from, std::false_type)
} // namespace static_graph_details
template <typename EdgeDataT, storage::Ownership Ownership = storage::Ownership::Container>
class StaticGraph
template <typename EdgeDataT, bool UseSharedMemory = false> class StaticGraph
{
template <typename T> using Vector = util::ViewOrVector<T, Ownership>;
public:
using InputEdge = static_graph_details::SortableEdgeWithData<EdgeDataT>;
using NodeIterator = static_graph_details::NodeIterator;
@@ -130,7 +114,7 @@ class StaticGraph
StaticGraph() {}
template <typename ContainerT> StaticGraph(const std::uint32_t nodes, const ContainerT &edges)
template <typename ContainerT> StaticGraph(const int nodes, const ContainerT &edges)
{
BOOST_ASSERT(std::is_sorted(const_cast<ContainerT &>(edges).begin(),
const_cast<ContainerT &>(edges).end()));
@@ -138,7 +122,8 @@ class StaticGraph
InitializeFromSortedEdgeRange(nodes, edges.begin(), edges.end());
}
StaticGraph(Vector<NodeArrayEntry> node_array_, Vector<EdgeArrayEntry> edge_array_)
StaticGraph(typename ShM<NodeArrayEntry, UseSharedMemory>::vector node_array_,
typename ShM<EdgeArrayEntry, UseSharedMemory>::vector edge_array_)
: node_array(std::move(node_array_)), edge_array(std::move(edge_array_))
{
BOOST_ASSERT(!node_array.empty());
@@ -241,15 +226,11 @@ class StaticGraph
return current_iterator;
}
friend void serialization::read<EdgeDataT, Ownership>(storage::io::FileReader &reader,
StaticGraph<EdgeDataT, Ownership> &graph);
friend void
serialization::write<EdgeDataT, Ownership>(storage::io::FileWriter &writer,
const StaticGraph<EdgeDataT, Ownership> &graph);
const NodeArrayEntry &GetNode(const NodeID nid) const { return node_array[nid]; }
const EdgeArrayEntry &GetEdge(const EdgeID eid) const { return edge_array[eid]; }
protected:
template <typename IterT>
void InitializeFromSortedEdgeRange(const std::uint32_t nodes, IterT begin, IterT end)
void InitializeFromSortedEdgeRange(const unsigned nodes, IterT begin, IterT end)
{
number_of_nodes = nodes;
number_of_edges = static_cast<EdgeIterator>(std::distance(begin, end));
@@ -263,9 +244,7 @@ class StaticGraph
unsigned offset = std::distance(begin, iter);
node_array.push_back(NodeArrayEntry{offset});
}
BOOST_ASSERT_MSG(
iter == end,
("Still " + std::to_string(std::distance(iter, end)) + " edges left.").c_str());
BOOST_ASSERT(iter == end);
BOOST_ASSERT(node_array.size() == number_of_nodes + 1);
edge_array.resize(number_of_edges);
@@ -279,8 +258,8 @@ class StaticGraph
NodeIterator number_of_nodes;
EdgeIterator number_of_edges;
Vector<NodeArrayEntry> node_array;
Vector<EdgeArrayEntry> edge_array;
typename ShM<NodeArrayEntry, UseSharedMemory>::vector node_array;
typename ShM<EdgeArrayEntry, UseSharedMemory>::vector edge_array;
};
} // namespace util

Some files were not shown because too many files have changed in this diff Show More