added max_speed to the profiles (#3089)
This commit is contained in:
parent
5da63998d6
commit
c30f43b148
@ -1,5 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
var util = require('util');
|
||||
var d3 = require('d3-queue');
|
||||
var polyline = require('polyline');
|
||||
|
||||
module.exports = function () {
|
||||
@ -44,14 +45,25 @@ module.exports = function () {
|
||||
if (res.statusCode === 200) {
|
||||
if (headers.has('matchings')) {
|
||||
subMatchings = [];
|
||||
var sub = [json.tracepoints[0].location];
|
||||
for(var i = 1; i < json.tracepoints.length; i++){
|
||||
if(json.tracepoints[i-1].matchings_index === json.tracepoints[i].matchings_index) {
|
||||
sub.push(json.tracepoints[i].location);
|
||||
} else {
|
||||
subMatchings.push(sub);
|
||||
sub = [json.tracepoints[i].location];
|
||||
|
||||
// find the first matched
|
||||
let start_index = 0;
|
||||
while (start_index < json.tracepoints.length && json.tracepoints[start_index] === null) start_index++;
|
||||
|
||||
var sub = [];
|
||||
let prev_index = null;
|
||||
for(var i = start_index; i < json.tracepoints.length; i++){
|
||||
if (json.tracepoints[i] === null) continue;
|
||||
|
||||
let current_index = json.tracepoints[i].matchings_index;
|
||||
|
||||
if(prev_index !== current_index) {
|
||||
if (sub.length > 0) subMatchings.push(sub);
|
||||
sub = [];
|
||||
prev_index = current_index;
|
||||
}
|
||||
|
||||
sub.push(json.tracepoints[i].location);
|
||||
}
|
||||
subMatchings.push(sub);
|
||||
}
|
||||
@ -82,7 +94,7 @@ module.exports = function () {
|
||||
}
|
||||
|
||||
if (headers.has('OSM IDs')) {
|
||||
if (json.matchings.length != 1) throw new Error('*** CHecking annotation only supported for matchings with one subtrace');
|
||||
if (json.matchings.length != 1) throw new Error('*** Checking annotation only supported for matchings with one subtrace');
|
||||
OSMIDs = this.OSMIDList(json.matchings[0]);
|
||||
}
|
||||
}
|
||||
@ -118,17 +130,8 @@ module.exports = function () {
|
||||
var encodedResult = '',
|
||||
extendedTarget = '';
|
||||
|
||||
var q = d3.queue();
|
||||
|
||||
var testSubMatching = (sub, si, scb) => {
|
||||
if (si >= subMatchings.length) {
|
||||
ok = false;
|
||||
q.abort();
|
||||
scb();
|
||||
} else {
|
||||
var sq = d3.queue();
|
||||
|
||||
var testSubNode = (ni, ncb) => {
|
||||
var testSubMatching = (sub, si) => {
|
||||
var testSubNode = (ni) => {
|
||||
var node = this.findNodeByName(sub[ni]),
|
||||
outNode = subMatchings[si][ni];
|
||||
|
||||
@ -136,26 +139,30 @@ module.exports = function () {
|
||||
encodedResult += sub[ni];
|
||||
extendedTarget += sub[ni];
|
||||
} else {
|
||||
if (outNode != null) {
|
||||
encodedResult += util.format('? [%s,%s]', outNode[0], outNode[1]);
|
||||
} else {
|
||||
encodedResult += '?';
|
||||
}
|
||||
extendedTarget += util.format('%s [%d,%d]', node.lat, node.lon);
|
||||
ok = false;
|
||||
}
|
||||
ncb();
|
||||
};
|
||||
|
||||
for (var i=0; i<sub.length; i++) {
|
||||
sq.defer(testSubNode, i);
|
||||
}
|
||||
|
||||
sq.awaitAll(scb);
|
||||
testSubNode(i);
|
||||
}
|
||||
};
|
||||
|
||||
if (subMatchings.length != row.matchings.split(',').length) {
|
||||
ok = false;
|
||||
cb(new Error('*** table matchings and api response are not the same'));
|
||||
}
|
||||
|
||||
row.matchings.split(',').forEach((sub, si) => {
|
||||
q.defer(testSubMatching, sub, si);
|
||||
testSubMatching(sub, si);
|
||||
});
|
||||
|
||||
q.awaitAll(() => {
|
||||
if (ok) {
|
||||
if (headers.has('matchings')) {
|
||||
got.matchings = row.matchings;
|
||||
@ -170,7 +177,6 @@ module.exports = function () {
|
||||
}
|
||||
|
||||
cb(null, got);
|
||||
});
|
||||
};
|
||||
|
||||
if (row.request) {
|
||||
|
@ -107,6 +107,7 @@ module.exports = {
|
||||
}
|
||||
|
||||
matchLocation (got, want) {
|
||||
if (got == null || want == null) return false;
|
||||
return this.match(got[0], util.format('%d ~0.0025%', want.lon)) &&
|
||||
this.match(got[1], util.format('%d ~0.0025%', want.lat));
|
||||
}
|
||||
|
@ -9,10 +9,11 @@ Feature: Basic Map Matching
|
||||
| geometries | geojson |
|
||||
|
||||
Scenario: Testbot - Map matching with outlier that has no candidate
|
||||
Given a grid size of 10 meters
|
||||
Given a grid size of 100 meters
|
||||
Given the node map
|
||||
"""
|
||||
a b c d
|
||||
|
||||
1
|
||||
"""
|
||||
|
||||
@ -22,7 +23,7 @@ Feature: Basic Map Matching
|
||||
|
||||
When I match I should get
|
||||
| trace | timestamps | matchings |
|
||||
| ab1d | 0 1 2 3 | abcd |
|
||||
| ab1d | 0 1 2 3 | ad |
|
||||
|
||||
Scenario: Testbot - Map matching with trace splitting
|
||||
Given the node map
|
||||
@ -169,3 +170,42 @@ Feature: Basic Map Matching
|
||||
When I match I should get
|
||||
| trace | matchings | geometry |
|
||||
| abd | abd | 1,1,1.000089,1,1.000089,1,1.000089,0.99991 |
|
||||
|
||||
Scenario: Testbot - Speed greater than speed threshhold, should split -- returns trace as abcd but should be split into ab,cd
|
||||
Given a grid size of 10 meters
|
||||
Given the query options
|
||||
| geometries | geojson |
|
||||
|
||||
Given the node map
|
||||
"""
|
||||
a b ---- x
|
||||
|
|
||||
|
|
||||
y --- c d
|
||||
"""
|
||||
|
||||
And the ways
|
||||
| nodes | oneway |
|
||||
| abxycd | no |
|
||||
|
||||
When I match I should get
|
||||
| trace | timestamps | matchings |
|
||||
| abcd | 0 1 2 3 | ab,cd |
|
||||
|
||||
Scenario: Testbot - Speed less than speed threshhold, should not split
|
||||
Given a grid size of 10 meters
|
||||
Given the query options
|
||||
| geometries | geojson |
|
||||
|
||||
Given the node map
|
||||
"""
|
||||
a b c d
|
||||
"""
|
||||
|
||||
And the ways
|
||||
| nodes | oneway |
|
||||
| abcd | no |
|
||||
|
||||
When I match I should get
|
||||
| trace | timestamps | matchings |
|
||||
| abcd | 0 1 2 3 | abcd |
|
||||
|
@ -173,6 +173,8 @@ class BaseDataFacade
|
||||
|
||||
virtual bool GetContinueStraightDefault() const = 0;
|
||||
|
||||
virtual double GetMapMatchingMaxSpeed() const = 0;
|
||||
|
||||
virtual BearingClassID GetBearingClassID(const NodeID id) const = 0;
|
||||
|
||||
virtual util::guidance::TurnBearing PreTurnBearing(const EdgeID eid) const = 0;
|
||||
|
@ -899,6 +899,11 @@ class InternalDataFacade final : public BaseDataFacade
|
||||
return m_profile_properties.continue_straight_at_waypoint;
|
||||
}
|
||||
|
||||
double GetMapMatchingMaxSpeed() const override final
|
||||
{
|
||||
return m_profile_properties.max_speed_for_map_matching;
|
||||
}
|
||||
|
||||
BearingClassID GetBearingClassID(const NodeID nid) const override final
|
||||
{
|
||||
return m_bearing_class_id_table.at(nid);
|
||||
|
@ -931,6 +931,11 @@ class SharedDataFacade final : public BaseDataFacade
|
||||
return m_profile_properties->continue_straight_at_waypoint;
|
||||
}
|
||||
|
||||
double GetMapMatchingMaxSpeed() const override final
|
||||
{
|
||||
return m_profile_properties->max_speed_for_map_matching;
|
||||
}
|
||||
|
||||
BearingClassID GetBearingClassID(const NodeID id) const override final
|
||||
{
|
||||
return m_bearing_class_id_table.at(id);
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "engine/map_matching/matching_confidence.hpp"
|
||||
#include "engine/map_matching/sub_matching.hpp"
|
||||
|
||||
#include "extractor/profile_properties.hpp"
|
||||
#include "util/coordinate_calculation.hpp"
|
||||
#include "util/for_each_pair.hpp"
|
||||
|
||||
@ -32,7 +33,6 @@ using HMM = map_matching::HiddenMarkovModel<CandidateLists>;
|
||||
using SubMatchingList = std::vector<map_matching::SubMatching>;
|
||||
|
||||
constexpr static const unsigned MAX_BROKEN_STATES = 10;
|
||||
constexpr static const double MAX_SPEED = 180 / 3.6; // 180km -> m/s
|
||||
static const constexpr double MATCHING_BETA = 10;
|
||||
constexpr static const double MAX_DISTANCE_DELTA = 2000.;
|
||||
|
||||
@ -46,6 +46,7 @@ class MapMatching final : public BasicRoutingInterface<DataFacadeT, MapMatching<
|
||||
map_matching::EmissionLogProbability default_emission_log_probability;
|
||||
map_matching::TransitionLogProbability transition_log_probability;
|
||||
map_matching::MatchingConfidence confidence;
|
||||
extractor::ProfileProperties m_profile_properties;
|
||||
|
||||
unsigned GetMedianSampleTime(const std::vector<unsigned> ×tamps) const
|
||||
{
|
||||
@ -98,7 +99,7 @@ class MapMatching final : public BasicRoutingInterface<DataFacadeT, MapMatching<
|
||||
const auto max_distance_delta = [&] {
|
||||
if (use_timestamps)
|
||||
{
|
||||
return median_sample_time * MAX_SPEED;
|
||||
return median_sample_time * facade.GetMapMatchingMaxSpeed();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -172,56 +173,29 @@ class MapMatching final : public BasicRoutingInterface<DataFacadeT, MapMatching<
|
||||
prev_unbroken_timestamps.push_back(initial_timestamp);
|
||||
for (auto t = initial_timestamp + 1; t < candidates_list.size(); ++t)
|
||||
{
|
||||
// breakage recover has removed all previous good points
|
||||
bool trace_split = prev_unbroken_timestamps.empty();
|
||||
|
||||
const bool gap_in_trace = [&, use_timestamps]() {
|
||||
// use temporal information if available to determine a split
|
||||
if (use_timestamps)
|
||||
{
|
||||
trace_split =
|
||||
trace_split ||
|
||||
(trace_timestamps[t] - trace_timestamps[prev_unbroken_timestamps.back()] >
|
||||
max_broken_time);
|
||||
return trace_timestamps[t] - trace_timestamps[prev_unbroken_timestamps.back()] >
|
||||
max_broken_time;
|
||||
}
|
||||
else
|
||||
{
|
||||
trace_split =
|
||||
trace_split || (t - prev_unbroken_timestamps.back() > MAX_BROKEN_STATES);
|
||||
return t - prev_unbroken_timestamps.back() > MAX_BROKEN_STATES;
|
||||
}
|
||||
}();
|
||||
|
||||
if (trace_split)
|
||||
if (!gap_in_trace)
|
||||
{
|
||||
std::size_t split_index = t;
|
||||
if (breakage_begin != map_matching::INVALID_STATE)
|
||||
{
|
||||
split_index = breakage_begin;
|
||||
breakage_begin = map_matching::INVALID_STATE;
|
||||
}
|
||||
split_points.push_back(split_index);
|
||||
|
||||
// note: this preserves everything before split_index
|
||||
model.Clear(split_index);
|
||||
std::size_t new_start = model.initialize(split_index);
|
||||
// no new start was found -> stop viterbi calculation
|
||||
if (new_start == map_matching::INVALID_STATE)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
prev_unbroken_timestamps.clear();
|
||||
prev_unbroken_timestamps.push_back(new_start);
|
||||
// Important: We potentially go back here!
|
||||
// However since t > new_start >= breakge_begin
|
||||
// we can only reset trace_coordindates.size() times.
|
||||
t = new_start + 1;
|
||||
}
|
||||
|
||||
BOOST_ASSERT(!prev_unbroken_timestamps.empty());
|
||||
const std::size_t prev_unbroken_timestamp = prev_unbroken_timestamps.back();
|
||||
|
||||
const auto &prev_viterbi = model.viterbi[prev_unbroken_timestamp];
|
||||
const auto &prev_pruned = model.pruned[prev_unbroken_timestamp];
|
||||
const auto &prev_unbroken_timestamps_list = candidates_list[prev_unbroken_timestamp];
|
||||
const auto &prev_unbroken_timestamps_list =
|
||||
candidates_list[prev_unbroken_timestamp];
|
||||
const auto &prev_coordinate = trace_coordinates[prev_unbroken_timestamp];
|
||||
|
||||
auto ¤t_viterbi = model.viterbi[t];
|
||||
@ -234,7 +208,7 @@ class MapMatching final : public BasicRoutingInterface<DataFacadeT, MapMatching<
|
||||
const auto haversine_distance = util::coordinate_calculation::haversineDistance(
|
||||
prev_coordinate, current_coordinate);
|
||||
// assumes minumum of 0.1 m/s
|
||||
const int duration_uppder_bound =
|
||||
const int duration_upper_bound =
|
||||
((haversine_distance + max_distance_delta) * 0.25) * 10;
|
||||
|
||||
// compute d_t for this timestamp and the next one
|
||||
@ -245,9 +219,9 @@ class MapMatching final : public BasicRoutingInterface<DataFacadeT, MapMatching<
|
||||
continue;
|
||||
}
|
||||
|
||||
for (const auto s_prime : util::irange<std::size_t>(0UL, current_viterbi.size()))
|
||||
for (const auto s_prime :
|
||||
util::irange<std::size_t>(0UL, current_viterbi.size()))
|
||||
{
|
||||
|
||||
const double emission_pr = emission_log_probabilities[t][s_prime];
|
||||
double new_value = prev_viterbi[s] + emission_pr;
|
||||
if (current_viterbi[s_prime] > new_value)
|
||||
@ -271,7 +245,7 @@ class MapMatching final : public BasicRoutingInterface<DataFacadeT, MapMatching<
|
||||
reverse_core_heap,
|
||||
prev_unbroken_timestamps_list[s].phantom_node,
|
||||
current_timestamps_list[s_prime].phantom_node,
|
||||
duration_uppder_bound);
|
||||
duration_upper_bound);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -324,6 +298,39 @@ class MapMatching final : public BasicRoutingInterface<DataFacadeT, MapMatching<
|
||||
}
|
||||
}
|
||||
|
||||
// breakage recover has removed all previous good points
|
||||
const bool trace_split = prev_unbroken_timestamps.empty();
|
||||
|
||||
if (trace_split || gap_in_trace)
|
||||
{
|
||||
std::size_t split_index = t;
|
||||
if (breakage_begin != map_matching::INVALID_STATE)
|
||||
{
|
||||
split_index = breakage_begin;
|
||||
breakage_begin = map_matching::INVALID_STATE;
|
||||
}
|
||||
split_points.push_back(split_index);
|
||||
|
||||
// note: this preserves everything before split_index
|
||||
model.Clear(split_index);
|
||||
std::size_t new_start = model.initialize(split_index);
|
||||
// no new start was found -> stop viterbi calculation
|
||||
if (new_start == map_matching::INVALID_STATE)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
prev_unbroken_timestamps.clear();
|
||||
prev_unbroken_timestamps.push_back(new_start);
|
||||
// Important: We potentially go back here!
|
||||
// However since t > new_start >= breakge_begin
|
||||
// we can only reset trace_coordindates.size() times.
|
||||
t = new_start;
|
||||
// note: the head of the loop will call ++t, hence the next
|
||||
// iteration will actually be on new_start+1
|
||||
}
|
||||
}
|
||||
|
||||
if (!prev_unbroken_timestamps.empty())
|
||||
{
|
||||
split_points.push_back(prev_unbroken_timestamps.back() + 1);
|
||||
|
@ -8,10 +8,13 @@ namespace osrm
|
||||
namespace extractor
|
||||
{
|
||||
|
||||
const constexpr auto DEFAULT_MAX_SPEED = 180 / 3.6; // 180kmph -> m/s
|
||||
|
||||
struct ProfileProperties
|
||||
{
|
||||
ProfileProperties()
|
||||
: traffic_signal_penalty(0), u_turn_penalty(0), continue_straight_at_waypoint(true),
|
||||
: traffic_signal_penalty(0), u_turn_penalty(0),
|
||||
max_speed_for_map_matching(DEFAULT_MAX_SPEED), continue_straight_at_waypoint(true),
|
||||
use_turn_restrictions(false), left_hand_driving(false)
|
||||
{
|
||||
}
|
||||
@ -30,10 +33,18 @@ struct ProfileProperties
|
||||
traffic_signal_penalty = boost::numeric_cast<int>(traffic_signal_penalty_ * 10.);
|
||||
}
|
||||
|
||||
double GetMaxSpeedForMapMatching() const { return max_speed_for_map_matching; }
|
||||
|
||||
void SetMaxSpeedForMapMatching(const double max_speed_for_map_matching_)
|
||||
{
|
||||
max_speed_for_map_matching = max_speed_for_map_matching_;
|
||||
}
|
||||
|
||||
//! penalty to cross a traffic light in deci-seconds
|
||||
int traffic_signal_penalty;
|
||||
//! penalty to do a uturn in deci-seconds
|
||||
int u_turn_penalty;
|
||||
double max_speed_for_map_matching;
|
||||
bool continue_straight_at_waypoint;
|
||||
bool use_turn_restrictions;
|
||||
bool left_hand_driving;
|
||||
|
@ -93,8 +93,9 @@ surface_speeds = {
|
||||
|
||||
-- these need to be global because they are accesed externaly
|
||||
properties.traffic_signal_penalty = 2
|
||||
properties.use_turn_restrictions = false
|
||||
properties.u_turn_penalty = 20
|
||||
properties.max_speed_for_map_matching = 110/3.6 -- kmph -> m/s
|
||||
properties.use_turn_restrictions = false
|
||||
properties.continue_straight_at_waypoint = false
|
||||
|
||||
local obey_oneway = true
|
||||
|
@ -147,6 +147,7 @@ maxspeed_table = {
|
||||
-- set profile properties
|
||||
properties.u_turn_penalty = 20
|
||||
properties.traffic_signal_penalty = 2
|
||||
properties.max_speed_for_map_matching = 180/3.6 -- 180kmph -> m/s
|
||||
properties.use_turn_restrictions = true
|
||||
properties.continue_straight_at_waypoint = true
|
||||
properties.left_hand_driving = false
|
||||
|
@ -66,6 +66,7 @@ leisure_speeds = {
|
||||
|
||||
properties.traffic_signal_penalty = 2
|
||||
properties.u_turn_penalty = 2
|
||||
properties.max_speed_for_map_matching = 40/3.6 -- kmph -> m/s
|
||||
properties.use_turn_restrictions = false
|
||||
properties.continue_straight_at_waypoint = false
|
||||
|
||||
|
@ -20,6 +20,7 @@ properties.continue_straight_at_waypoint = true
|
||||
properties.use_turn_restrictions = true
|
||||
properties.traffic_signal_penalty = 7 -- seconds
|
||||
properties.u_turn_penalty = 20
|
||||
properties.max_speed_for_map_matching = 30/3.6 --km -> m/s
|
||||
|
||||
function limit_speed(speed, limits)
|
||||
-- don't use ipairs(), since it stops at the first nil value
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "engine/api/match_api.hpp"
|
||||
#include "engine/api/match_parameters.hpp"
|
||||
#include "engine/map_matching/bayes_classifier.hpp"
|
||||
#include "engine/map_matching/sub_matching.hpp"
|
||||
#include "util/coordinate_calculation.hpp"
|
||||
#include "util/integer_range.hpp"
|
||||
#include "util/json_util.hpp"
|
||||
|
@ -131,6 +131,9 @@ void LuaScriptingEnvironment::InitContext(LuaScriptingContext &context)
|
||||
.property("u_turn_penalty",
|
||||
&ProfileProperties::GetUturnPenalty,
|
||||
&ProfileProperties::SetUturnPenalty)
|
||||
.property("max_speed_for_map_matching",
|
||||
&ProfileProperties::GetMaxSpeedForMapMatching,
|
||||
&ProfileProperties::SetMaxSpeedForMapMatching)
|
||||
.def_readwrite("use_turn_restrictions", &ProfileProperties::use_turn_restrictions)
|
||||
.def_readwrite("continue_straight_at_waypoint",
|
||||
&ProfileProperties::continue_straight_at_waypoint)
|
||||
|
@ -206,6 +206,7 @@ class MockDataFacade final : public engine::datafacade::BaseDataFacade
|
||||
std::size_t GetCoreSize() const override { return 0; }
|
||||
std::string GetTimestamp() const override { return ""; }
|
||||
bool GetContinueStraightDefault() const override { return true; }
|
||||
double GetMapMatchingMaxSpeed() const override { return 180 / 3.6; }
|
||||
BearingClassID GetBearingClassID(const NodeID /*id*/) const override { return 0; }
|
||||
EntryClassID GetEntryClassID(const EdgeID /*id*/) const override { return 0; }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user