-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Multi-metric support #4007
Description
Multi-Metric Overlays
Goal
Currently we only allow one metric per profile, for example fastest or shortest. We want to be able to support multiple metrics per profile and select between them at query-time. This will for example allow to run a single OSRM instance and support both queries for fastest and shortest.
API changes
Lua profile
With #77 we introduced the notion of arbitrary weights. We now need to extend this to be able to set multiple ones per way.
Below is a sketch of what the new lua API could look like.
function way_function(way, result)
result.forward_rate['routabiliy'] = 50.0
result.forward_rate['distance'] = 30
end
function turn_function(turn)
turn.weight['distance'] = 0
turn.weight['routability'] = turn.angle / 360. * 2
endWe also need to configure the notion of a default metric. profile.weight_name might serve here.
HTTP/node
At query time we need to select which metric the query should use:
metricString Can be a string that identifies a metric likedistanceorroutabilityordefault.
This would only allow for one metric per query. The ration for this would be to keep the worst-case query time low. The same behavior can be achieved by running multiple queries.
We need to also adapt the the JSON response:
route[i].weight_namewill refer tometricroute[i].weight,route[i].legs[i].weight,route[i].legs[i].annotations.weight, androute[i].legs[i].steps[i].weightwill contain the weight of the specific metric that was used for routing.
osrm-contract/osrm-customize
Both tools need to know which metric they are operating on an create a unique file for each metric.
--metric=(-m) String name of the metric to process. Default:default(used the default metric selected in the profile)
Example:
osrm-customize --metric=distance data.osrm
This would create files data.osrm.{ch,mld}_metric_{metric_name}, e.g. data.osrm.mld_metric_distance in this case.
osrm-datastore
The datastore need to know which metric it is supposed to load into memory. To be consistent with osmr-contract and osrm-customize this would work over multiple --metric options.
--metric=(-m) String name of the metric to load. Default:default(used the default metric selected in the profile)
Example:
osrm-datastore --metric=distance --metric=routability data.osrm
This would look for files data.osrm.{ch,mld}_metric_distance and data.osrm.{ch,mld}_metric_routability.
Implementation changes
-
All data structures involved with weights need to be extended/split:
-
SegmentDataContainer: Split out the segment weights -
MultiLevelGraph:Split out the turn weights -
Graph compression,
EdgeBasedGraphFactoryneed to know about every weight -
For MLD:
- Cell arc weights (currently part of
.osrm.cells) - Base graph weights (currently part of
.osrm.mldgr) - Segment weights (currently part of
.osrm.geometries)
- Cell arc weights (currently part of
-
For CH:
- Contracted graph and weights (currently
.osrm.hsgr) - Segment weights (currently part of
.osrm.geometries)
- Contracted graph and weights (currently
-
-
Algorithm specific tools
osrm-customizeandosrm-contractneed to know which metric to read/update/process. -
Extend
osrm-datastoreto load all metric files specified, depending on algorithm type. -
Extent engine to select metric at query time:
- Dataface needs to be extended to retrieve the corresponding graph (CH) and cell overlay (MLD)
PhantomNodegeneration (geospatial_index.hpp) needs to know for which metric it should generate offsets- Search functions need to be parametrized to take:
For CH:graph with shortcuts and weights
For MLD:base graph with weight, cellstorage with weights