Compare commits

...

18 Commits

Author SHA1 Message Date
Patrick Niklaus
8e0b8e43d0 Bump verison to 5.8.1 2017-06-30 09:27:49 +00:00
Patrick Niklaus
43e67241a0 Update changelog 2017-06-30 09:27:08 +00:00
Moritz Kobitzsch
217d2afbb4 don't collapse u-turns into combined turns 2017-06-30 09:26:10 +00:00
Michael Krasnyk
6e9bb4ad75 Test case with incorrect u-turn collapsing
http://map.project-osrm.org/?z=18&center=52.169237%2C10.032722&loc=52.168628%2C10.030759&loc=52.168707%2C10.030952&loc=52.168457%2C10.030432&hl=en&alt=0
2017-06-30 09:26:01 +00:00
Daniel J. Hofmann
165dba8fcc Adapts obvious turn classification: no longer take entry_allowed into account, resolves #3987 2017-06-29 15:26:18 +00:00
Daniel J. Hofmann
2bd511f194 Adds a failing test case for obvious turn at the end of the road, see #3987 2017-06-29 15:26:09 +00:00
Patrick Niklaus
2d5ef1f4cf Update changelog 2017-06-29 15:25:27 +00:00
Michael Krasnyk
76457a423f Propagate lane data across traffic lights 2017-06-29 15:11:50 +00:00
Michael Krasnyk
9ec4348bd1 Test case for #4189 2017-06-29 15:11:41 +00:00
Michael Krasnyk
309d00c5e3 Correct condition for is_going_straight_and_turns_continue 2017-06-29 15:11:31 +00:00
Michael Krasnyk
effc85fa07 Review adjustments for driveway handler, #4151 2017-06-29 15:08:36 +00:00
Michael Krasnyk
e0eedbc5f6 Added driveway handler 2017-06-29 15:08:11 +00:00
Michael Krasnyk
655d03592f
Use thread-safe lock-free assignment in PackedVector::set_value
PR uses TBB internal atomic's for atomic CAS on non-atomic data

Corresponding PR https://github.com/Project-OSRM/osrm-backend/pull/4199

Other options:

* use sequential update

* use an internal packed vector lock -> makes packed vector non-movable

* use boost.interprocess atomics implementation -> outdated and only 32 bit version

* use glib atomic's -> requires new dependency

*  wait for https://isocpp.org/blog/2014/05/n4013 as_atomic

*  use c11 _Atomic and atomic_compare_exchange_weak -> not possible to mix c++11 and c11

* use builtin functions gcc __sync_bool_compare_and_swap and msvc _InterlockedCompareExchange64 -> possible, but requires proper testing

boolean CompareAndSwapPointer(volatile * void * ptr,
                              void * new_value,
                              void * old_value) {
if defined(_MSC_VER)
   if (InterlockedCompareExchange(ptr, new_value, old_value) == old_value) return false;
   else return true;
elif (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) > 40100
   return __sync_bool_compare_and_swap(ptr, old_value, new_value);
else
  error No implementation
endif
}

* use Boost.Atomic -> requires new dependency

        WordT local_lower_word = lower_word, new_lower_word;
        do
        {
            new_lower_word = set_lower_value<WordT, T>(local_lower_word,
                                                       lower_mask[internal_index.element],
                                                       lower_offset[internal_index.element],
                                                       value);
        } while (!boost::atomics::detail::operations<sizeof(WordT), false>::compare_exchange_weak(
            lower_word,
            local_lower_word,
            new_lower_word,
            boost::memory_order_release,
            boost::memory_order_relaxed));
2017-06-27 13:05:31 +02:00
Patrick Niklaus
6fadc4d8b8 Enable travis 2017-06-19 16:03:36 +00:00
Patrick Niklaus
00230967af Change OSRM version to 5.8.0 2017-06-19 16:03:15 +00:00
Patrick Niklaus
f4bf76c98e Refactor tile tests 2017-06-19 16:00:34 +00:00
Daniel Patterson
1142a9e49b Add layer to debug tiles to expose all OSM nodes in that area. 2017-06-19 16:00:25 +00:00
Patrick Niklaus
b168eca6d5 Bump version 2017-06-15 16:10:37 +00:00
26 changed files with 695 additions and 158 deletions

View File

@ -17,6 +17,7 @@ notifications:
branches: branches:
only: only:
- master - master
- "5.8"
# enable building tags # enable building tags
- /^v\d+\.\d+(\.\d+)?(-\S*)?$/ - /^v\d+\.\d+(\.\d+)?(-\S*)?$/

View File

@ -1,3 +1,12 @@
# 5.8.1
- Changes from 5.8.0:
- Bugfixes:
- Fixes #4152: Superflous turn left instruction, when crossing a service-road.
- Fixes #4189: Fixes missing turn lane information after a traffic light.
- Fixes #4199: Data race-condition when updating segment speeds.
- Fixes #3987: Fixes obvious turn detection at T-intersections with slip-roads.
- Fixes #4161: Don't collapse U-Turns with other steps.
# 5.8.0 # 5.8.0
- Changes from 5.7 - Changes from 5.7
- API: - API:
@ -26,6 +35,7 @@
- Fixed a copy/paste issue assigning wrong directions in similar turns (left over right) - Fixed a copy/paste issue assigning wrong directions in similar turns (left over right)
- #4074: fixed a bug that would announce entering highway ramps as u-turns - #4074: fixed a bug that would announce entering highway ramps as u-turns
- #4122: osrm-routed/libosrm should throw exception when a dataset incompatible with the requested algorithm is loaded - #4122: osrm-routed/libosrm should throw exception when a dataset incompatible with the requested algorithm is loaded
- Avoid collapsing u-turns into combined turn instructions
# 5.7.1 # 5.7.1
- Bugfixes - Bugfixes

View File

@ -55,7 +55,7 @@ endif()
project(OSRM C CXX) project(OSRM C CXX)
set(OSRM_VERSION_MAJOR 5) set(OSRM_VERSION_MAJOR 5)
set(OSRM_VERSION_MINOR 8) set(OSRM_VERSION_MINOR 8)
set(OSRM_VERSION_PATCH 0) set(OSRM_VERSION_PATCH 1)
set(OSRM_VERSION "${OSRM_VERSION_MAJOR}.${OSRM_VERSION_MINOR}.${OSRM_VERSION_PATCH}") set(OSRM_VERSION "${OSRM_VERSION_MAJOR}.${OSRM_VERSION_MINOR}.${OSRM_VERSION_PATCH}")
add_definitions(-DOSRM_PROJECT_DIR="${CMAKE_CURRENT_SOURCE_DIR}") add_definitions(-DOSRM_PROJECT_DIR="${CMAKE_CURRENT_SOURCE_DIR}")

View File

@ -35,10 +35,10 @@ Feature: Turn Lane Guidance
| restriction | bc | cd | c | no_right_turn | | restriction | bc | cd | c | no_right_turn |
When I route I should get When I route I should get
| waypoints | route | turns | lanes | | waypoints | route | turns | lanes |
| a,e | in,cross,cross | depart,turn left,arrive | ,left:true straight:false right:false, | | a,e | in,cross,cross | depart,turn left,arrive | ,left:true straight:false, |
| a,g | in,straight,straight | depart,new name straight,arrive | ,left:false straight:true right:false, | | a,g | in,straight,straight | depart,new name straight,arrive | ,left:false straight:true, |
| a,f | in,cross,cross | depart,turn right,arrive | ,left:false straight:false right:true, | | a,f | in,cross,cross | depart,continue right,arrive | ,, |
@sliproads @sliproads
Scenario: Separate Turn Lanes Scenario: Separate Turn Lanes

View File

@ -359,7 +359,7 @@ Feature: Collapse
| a,g | first,second,second | depart,turn left,arrive | a,b,g | | a,g | first,second,second | depart,turn left,arrive | a,b,g |
| d,g | first,second,second | depart,turn right,arrive | d,e,g | | d,g | first,second,second | depart,turn right,arrive | d,e,g |
| g,f | second,first,first | depart,turn right,arrive | g,e,f | | g,f | second,first,first | depart,turn right,arrive | g,e,f |
| g,c | second,first,first | depart,end of road left,arrive | g,b,c | | g,c | second,first,first | depart,turn left,arrive | g,e,c |
Scenario: Do not collapse turning roads Scenario: Do not collapse turning roads
Given the node map Given the node map
@ -690,9 +690,9 @@ Feature: Collapse
| restriction | bc | dc | c | no_right_turn | | restriction | bc | dc | c | no_right_turn |
When I route I should get When I route I should get
| waypoints | route | turns | locations | | waypoints | route | turns | locations |
| a,g | road,cross,cross | depart,turn left,arrive | a,b,g | | a,g | road,road,cross,cross | depart,continue slight left,turn left,arrive | a,b,c,g |
| a,e | road,road | depart,arrive | a,e | | a,e | road,road | depart,arrive | a,e |
Scenario: On-Off on Highway Scenario: On-Off on Highway
Given the node map Given the node map
@ -996,8 +996,8 @@ Feature: Collapse
a . . b .' a . . b .'
` d. ` d.
f e f e
""" """
#Check collapse.detail for a similar case (shorter) that does not classify these turns as a sliproad anymore #Check collapse.detail for a similar case (shorter) that does not classify these turns as a sliproad anymore
And the ways And the ways
| nodes | name | oneway | highway | | nodes | name | oneway | highway |
@ -1016,9 +1016,9 @@ Feature: Collapse
When I route I should get When I route I should get
| waypoints | route | turns | locations | | waypoints | route | turns | locations |
| a,g | road,cross,cross | depart,fork left,arrive | a,b,g | | a,g | road,road,cross,cross | depart,fork slight left,turn left,arrive | a,b,c,g |
| a,e | road,road,road | depart,fork slight right,arrive | a,b,e | | a,e | road,road,road | depart,fork slight right,arrive | a,b,e |
| a,f | road,road,cross,cross | depart,fork slight right,turn right,arrive | a,b,d,f | | a,f | road,road,cross,cross | depart,fork slight right,turn right,arrive | a,b,d,f |
# http://www.openstreetmap.org/way/92415447 #3933 # http://www.openstreetmap.org/way/92415447 #3933
@ -1055,3 +1055,22 @@ Feature: Collapse
When I route I should get When I route I should get
| waypoints | route | turns | locations | | waypoints | route | turns | locations |
| a,i | President Avenue,Princes Highway,Princes Highway | depart,turn left,arrive | a,b,i | | a,i | President Avenue,Princes Highway,Princes Highway | depart,turn left,arrive | a,b,i |
Scenario: Don't combine uturns
Given the node map
"""
2 d
a - - b - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - c
1
"""
And the ways
| nodes | highway |
| ab | tertiary |
| bc | tertiary |
| bd | service |
When I route I should get
| waypoints | bearings | route | turns | locations |
| 1,2 | 90 270 | ab,bd,bd,ab,ab | depart,turn left,continue uturn,turn right,arrive | _,b,d,b,_ |

View File

@ -0,0 +1,48 @@
@driveway @guidance
Feature: Driveways intersections
Background:
Given the profile "car"
Given a grid size of 5 meters
Scenario: Road with a turn to service road
Given the node map
"""
a
~.
b----c----d
|
e
"""
And the ways
| nodes | highway | name | oneway |
| abc | trunk | first | yes |
| cd | trunk | second | yes |
| be | service | parking | yes |
When I route I should get
| waypoints | route | turns | locations |
| a,d | first,second | depart,arrive | a,d |
Scenario: Turn Instead of Ramp
Given the node map
"""
a
~.
b----c----d
|
e
"""
And the ways
| nodes | highway | name | oneway |
| ab | trunk | | yes |
| bc | trunk | | yes |
| cd | trunk | second | yes |
| be | service | parking | yes |
When I route I should get
| waypoints | route | turns | locations |
| a,d | ,second | depart,arrive | a,d |

View File

@ -201,14 +201,14 @@ Feature: Simple Turns
| ef | residential | road | 2 | yes | | ef | residential | road | 2 | yes |
When I route I should get When I route I should get
| waypoints | route | turns | locations | | waypoints | route | turns | locations |
| a,c | road,road | depart,arrive | a,c | | a,c | road,road | depart,arrive | a,c |
| c,a | road,road | depart,arrive | c,a | | c,a | road,road | depart,arrive | c,a |
| g,a | turn,road,road | depart,turn left,arrive | g,b,a | | g,a | turn,road,road | depart,turn left,arrive | g,b,a |
| g,c | turn,road,road | depart,turn right,arrive | g,b,c | | g,c | turn,road,road | depart,turn right,arrive | g,b,c |
| g,f | turn,road,road | depart,turn left,arrive | g,e,f | | g,f | turn,road,road | depart,end of road left,arrive | g,e,f |
| c,f | road,road,road | depart,continue right,arrive | c,b,f | | c,f | road,road,road | depart,turn right,arrive | c,b,f |
| a,f | road,road,road | depart,continue uturn,arrive | a,b,f | | a,f | road,road,road | depart,continue uturn,arrive | a,b,f |
# http://www.openstreetmap.org/#map=19/52.48753/13.52838 # http://www.openstreetmap.org/#map=19/52.48753/13.52838
Scenario: Traffic Circle Scenario: Traffic Circle
@ -1312,8 +1312,8 @@ Feature: Simple Turns
# we don't care for turn instructions, this is a coordinate extraction bug check # we don't care for turn instructions, this is a coordinate extraction bug check
When I route I should get When I route I should get
| waypoints | route | intersections | | waypoints | route | intersections |
| a,g | ab,bcdefgh | true:90,true:45 false:180 false:270;true:180 | | a,g | ab,bcdefgh,bcdefgh | true:90;true:45 false:180 false:270;true:180 |
#https://github.com/Project-OSRM/osrm-backend/pull/3469#issuecomment-270806580 #https://github.com/Project-OSRM/osrm-backend/pull/3469#issuecomment-270806580
Scenario: Oszillating Lower Priority Road Scenario: Oszillating Lower Priority Road

View File

@ -1215,3 +1215,32 @@ Feature: Turn Lane Guidance
| waypoints | route | turns | lanes | | waypoints | route | turns | lanes |
| a,d | road,cross,cross | depart,turn left,arrive | ,none:true none:false right:false, | | a,d | road,cross,cross | depart,turn left,arrive | ,none:true none:false right:false, |
| a,c | road,road | depart,arrive | , | | a,c | road,road | depart,arrive | , |
@4189
Scenario: U-turn after a traffic light
Given the node map
"""
j k
: :
f---g-h-i
: :
a-b-c-d-e
: :
l m
"""
And the nodes
| node | highway |
| b | traffic_signals |
And the ways
| nodes | name | lanes | turn:lanes | oneway |
| ab | road1 | 3 | left\|through\|through;right | yes |
| bcde | road1 | 2 | | yes |
| ihgf | road1 | 2 | | yes |
| jgcl | road2 | 2 | | yes |
| mdhk | road2 | 2 | | yes |
When I route I should get
| waypoints | route | turns | lanes | locations |
| a,f | road1,road1,road1 | depart,continue uturn,arrive | ,left:true straight:false straight;right:false, | a,d,f |

View File

@ -1319,3 +1319,33 @@ Feature: Simple Turns
When I route I should get When I route I should get
| waypoints | route | ref | turns | | waypoints | route | ref | turns |
| a,h | Road,,, | C 42,,C 42,C 42 | depart,on ramp right,merge slight left,arrive | | a,h | Road,,, | C 42,,C 42,C 42 | depart,on ramp right,merge slight left,arrive |
Scenario: End of road, T-intersection, no obvious turn, only one road allowed
Given the node map
"""
d
.
a . b . . c
' .
'e
.
f
"""
And the ways
| nodes | highway | oneway | ref |
| ab | primary | | B 191 |
| bc | primary | | B 191 |
| be | primary_link | yes | |
| dc | primary | | B 4;B 191 |
| ce | primary | | B 4 |
| ef | primary | | B 4 |
And the relations
| type | way:from | way:to | node:via | restriction |
| restriction | bc | ce | c | no_right_turn |
| restriction | be | ef | e | only_right_turn |
When I route I should get
| waypoints | route | turns |
| a,d | ab,dc,dc | depart,turn left,arrive |

View File

@ -0,0 +1,40 @@
#ifndef OSRM_EXTRACTOR_GUIDANCE_DRIVEWAY_HANDLER_HPP
#define OSRM_EXTRACTOR_GUIDANCE_DRIVEWAY_HANDLER_HPP
#include "extractor/guidance/intersection_handler.hpp"
namespace osrm
{
namespace extractor
{
namespace guidance
{
// Intersection handlers deal with all issues related to intersections.
class DrivewayHandler final : public IntersectionHandler
{
public:
DrivewayHandler(const IntersectionGenerator &intersection_generator,
const util::NodeBasedDynamicGraph &node_based_graph,
const std::vector<util::Coordinate> &coordinates,
const util::NameTable &name_table,
const SuffixTable &street_name_suffix_table);
~DrivewayHandler() override final = default;
// check whether the handler can actually handle the intersection
bool canProcess(const NodeID nid,
const EdgeID via_eid,
const Intersection &intersection) const override final;
// process the intersection
Intersection operator()(const NodeID nid,
const EdgeID via_eid,
Intersection intersection) const override final;
};
} // namespace guidance
} // namespace extractor
} // namespace osrm
#endif /* OSRM_EXTRACTOR_GUIDANCE_DRIVEWAY_HANDLER_HPP */

View File

@ -27,7 +27,6 @@ namespace guidance
{ {
// Intersection handlers deal with all issues related to intersections. // Intersection handlers deal with all issues related to intersections.
// They assign appropriate turn operations to the TurnOperations.
// This base class provides both the interface and implementations for // This base class provides both the interface and implementations for
// common functions. // common functions.
class IntersectionHandler class IntersectionHandler
@ -114,6 +113,8 @@ class IntersectionHandler
// For this scenario returns intersection at `b` and `b`. // For this scenario returns intersection at `b` and `b`.
boost::optional<IntersectionHandler::IntersectionViewAndNode> boost::optional<IntersectionHandler::IntersectionViewAndNode>
getNextIntersection(const NodeID at, const EdgeID via) const; getNextIntersection(const NodeID at, const EdgeID via) const;
bool isSameName(const EdgeID source_edge_id, const EdgeID target_edge_id) const;
}; };
// Impl. // Impl.
@ -410,14 +411,11 @@ std::size_t IntersectionHandler::findObviousTurn(const EdgeID via_edge,
const auto &best_option_data = const auto &best_option_data =
node_based_graph.GetEdgeData(intersection[best_option].eid); node_based_graph.GetEdgeData(intersection[best_option].eid);
const auto adjusted_distinction_ratio = [&]() { const auto adjusted_distinction_ratio = [&]() {
// not allowed competitors are easily distinct // obviousness by road classes
if (!intersection[index].entry_allowed) if (in_way_data.road_classification == best_option_data.road_classification &&
return 0.7 * DISTINCTION_RATIO; best_option_data.road_classification.GetPriority() <
// a bit less obvious are road classes node_based_graph.GetEdgeData(intersection[index].eid)
else if (in_way_data.road_classification == best_option_data.road_classification && .road_classification.GetPriority())
best_option_data.road_classification.GetPriority() <
node_based_graph.GetEdgeData(intersection[index].eid)
.road_classification.GetPriority())
return 0.8 * DISTINCTION_RATIO; return 0.8 * DISTINCTION_RATIO;
// if road classes are the same, we use the full ratio // if road classes are the same, we use the full ratio
else else

View File

@ -20,7 +20,6 @@ namespace guidance
{ {
// Intersection handlers deal with all issues related to intersections. // Intersection handlers deal with all issues related to intersections.
// They assign appropriate turn operations to the TurnOperations.
class MotorwayHandler : public IntersectionHandler class MotorwayHandler : public IntersectionHandler
{ {
public: public:

View File

@ -21,7 +21,6 @@ namespace guidance
{ {
// Intersection handlers deal with all issues related to intersections. // Intersection handlers deal with all issues related to intersections.
// They assign appropriate turn operations to the TurnOperations.
class SliproadHandler final : public IntersectionHandler class SliproadHandler final : public IntersectionHandler
{ {
public: public:

View File

@ -2,6 +2,7 @@
#define OSRM_EXTRACTOR_TURN_ANALYSIS #define OSRM_EXTRACTOR_TURN_ANALYSIS
#include "extractor/compressed_edge_container.hpp" #include "extractor/compressed_edge_container.hpp"
#include "extractor/guidance/driveway_handler.hpp"
#include "extractor/guidance/intersection.hpp" #include "extractor/guidance/intersection.hpp"
#include "extractor/guidance/intersection_generator.hpp" #include "extractor/guidance/intersection_generator.hpp"
#include "extractor/guidance/intersection_normalization_operation.hpp" #include "extractor/guidance/intersection_normalization_operation.hpp"
@ -87,6 +88,7 @@ class TurnAnalysis
const TurnHandler turn_handler; const TurnHandler turn_handler;
const SliproadHandler sliproad_handler; const SliproadHandler sliproad_handler;
const SuppressModeHandler suppress_mode_handler; const SuppressModeHandler suppress_mode_handler;
const DrivewayHandler driveway_handler;
// Utility function, setting basic turn types. Prepares for normal turn handling. // Utility function, setting basic turn types. Prepares for normal turn handling.
Intersection Intersection

View File

@ -24,7 +24,6 @@ namespace guidance
{ {
// Intersection handlers deal with all issues related to intersections. // Intersection handlers deal with all issues related to intersections.
// They assign appropriate turn operations to the TurnOperations.
class TurnHandler : public IntersectionHandler class TurnHandler : public IntersectionHandler
{ {
public: public:

View File

@ -10,6 +10,7 @@
#include <boost/iterator/iterator_facade.hpp> #include <boost/iterator/iterator_facade.hpp>
#include <boost/iterator/reverse_iterator.hpp> #include <boost/iterator/reverse_iterator.hpp>
#include <tbb/atomic.h>
#include <array> #include <array>
#include <cmath> #include <cmath>
@ -348,7 +349,7 @@ template <typename T, std::size_t Bits, storage::Ownership Ownership> class Pack
fill(initial_value); fill(initial_value);
} }
PackedVector(util::ViewOrVector<std::uint64_t, Ownership> vec_, std::size_t num_elements) PackedVector(util::ViewOrVector<WordT, Ownership> vec_, std::size_t num_elements)
: vec(std::move(vec_)), num_elements(num_elements) : vec(std::move(vec_)), num_elements(num_elements)
{ {
initialize(); initialize();
@ -497,20 +498,39 @@ template <typename T, std::size_t Bits, storage::Ownership Ownership> class Pack
inline void set_value(const InternalIndex internal_index, const T value) inline void set_value(const InternalIndex internal_index, const T value)
{ {
// ⚠ The method uses CAS spinlocks to prevent data races in parallel calls
// TBB internal atomic's are used for CAS on non-atomic data
// Parallel read and write access is not allowed
auto &lower_word = vec[internal_index.lower_word]; auto &lower_word = vec[internal_index.lower_word];
auto &upper_word = vec[internal_index.lower_word + 1]; auto &upper_word = vec[internal_index.lower_word + 1];
lower_word = set_lower_value<WordT, T>(lower_word, // Lock-free update of the lower word
lower_mask[internal_index.element], WordT local_lower_word, new_lower_word;
lower_offset[internal_index.element], do
value); {
upper_word = set_upper_value<WordT, T>(upper_word, local_lower_word = lower_word;
upper_mask[internal_index.element], new_lower_word = set_lower_value<WordT, T>(local_lower_word,
upper_offset[internal_index.element], lower_mask[internal_index.element],
value); lower_offset[internal_index.element],
value);
} while (tbb::internal::as_atomic(lower_word)
.compare_and_swap(new_lower_word, local_lower_word) != local_lower_word);
// Lock-free update of the upper word
WordT local_upper_word, new_upper_word;
do
{
local_upper_word = upper_word;
new_upper_word = set_upper_value<WordT, T>(local_upper_word,
upper_mask[internal_index.element],
upper_offset[internal_index.element],
value);
} while (tbb::internal::as_atomic(upper_word)
.compare_and_swap(new_upper_word, local_upper_word) != local_upper_word);
} }
util::ViewOrVector<std::uint64_t, Ownership> vec; util::ViewOrVector<WordT, Ownership> vec;
std::uint64_t num_elements = 0; std::uint64_t num_elements = 0;
}; };
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "osrm", "name": "osrm",
"version": "5.8.0-latest.1", "version": "5.8.1",
"private": false, "private": false,
"description": "The Open Source Routing Machine is a high performance routing engine written in C++14 designed to run on OpenStreetMap data.", "description": "The Open Source Routing Machine is a high performance routing engine written in C++14 designed to run on OpenStreetMap data.",
"dependencies": { "dependencies": {

View File

@ -61,6 +61,22 @@ bool isShortAndUndisturbed(const RouteStep &step)
return is_short && noIntermediaryIntersections(step); return is_short && noIntermediaryIntersections(step);
} }
// On dual carriageways, we might want to use u-turns in combination with new-name instructions.
// Otherwise a u-turn should never be part of a collapsing instructions.
bool noBadUTurnCombination(const RouteStepIterator first, const RouteStepIterator second)
{
auto has_uturn = hasModifier(*first, DirectionModifier::UTurn) ||
hasModifier(*second, DirectionModifier::UTurn);
auto const from_name_change_into_uturn =
hasTurnType(*first, TurnType::NewName) && hasModifier(*second, DirectionModifier::UTurn);
auto const uturn_into_name_change =
hasTurnType(*second, TurnType::NewName) && hasModifier(*first, DirectionModifier::UTurn);
return !has_uturn || from_name_change_into_uturn || uturn_into_name_change;
}
} // namespace } // namespace
bool basicCollapsePreconditions(const RouteStepIterator first, const RouteStepIterator second) bool basicCollapsePreconditions(const RouteStepIterator first, const RouteStepIterator second)
@ -70,7 +86,10 @@ bool basicCollapsePreconditions(const RouteStepIterator first, const RouteStepIt
const auto waypoint_type = hasWaypointType(*first) || hasWaypointType(*second); const auto waypoint_type = hasWaypointType(*first) || hasWaypointType(*second);
return !has_roundabout_type && !waypoint_type && haveSameMode(*first, *second); const auto contains_bad_uturn = !noBadUTurnCombination(first, second);
return !has_roundabout_type && !waypoint_type && haveSameMode(*first, *second) &&
!contains_bad_uturn;
} }
bool basicCollapsePreconditions(const RouteStepIterator first, bool basicCollapsePreconditions(const RouteStepIterator first,
@ -81,8 +100,11 @@ bool basicCollapsePreconditions(const RouteStepIterator first,
hasRoundaboutType(second->maneuver.instruction) || hasRoundaboutType(second->maneuver.instruction) ||
hasRoundaboutType(third->maneuver.instruction); hasRoundaboutType(third->maneuver.instruction);
const auto contains_bad_uturn =
!noBadUTurnCombination(first, second) && !noBadUTurnCombination(second, third);
// require modes to match up // require modes to match up
return !has_roundabout_type && haveSameMode(*first, *second, *third); return !has_roundabout_type && haveSameMode(*first, *second, *third) && !contains_bad_uturn;
} }
bool isStaggeredIntersection(const RouteStepIterator step_prior_to_intersection, bool isStaggeredIntersection(const RouteStepIterator step_prior_to_intersection,

View File

@ -831,6 +831,51 @@ void encodeVectorTile(const datafacade::ContiguousInternalMemoryDataFacadeBase &
values_writer.add_float(util::vector_tile::VARIANT_TYPE_FLOAT, value); values_writer.add_float(util::vector_tile::VARIANT_TYPE_FLOAT, value);
} }
} }
// OSM Node tile layer
{
protozero::pbf_writer point_layer_writer(tile_writer, util::vector_tile::LAYER_TAG);
point_layer_writer.add_uint32(util::vector_tile::VERSION_TAG, 2); // version
point_layer_writer.add_string(util::vector_tile::NAME_TAG, "osmnodes"); // name
point_layer_writer.add_uint32(util::vector_tile::EXTENT_TAG,
util::vector_tile::EXTENT); // extent
std::vector<NodeID> internal_nodes;
internal_nodes.reserve(edges.size() * 2);
for (const auto &edge : edges)
{
internal_nodes.push_back(edge.u);
internal_nodes.push_back(edge.v);
}
std::sort(internal_nodes.begin(), internal_nodes.end());
auto new_end = std::unique(internal_nodes.begin(), internal_nodes.end());
internal_nodes.resize(new_end - internal_nodes.begin());
for (const auto &internal_node : internal_nodes)
{
const auto coord = facade.GetCoordinateOfNode(internal_node);
const auto tile_point = coordinatesToTilePoint(coord, tile_bbox);
if (!boost::geometry::within(point_t(tile_point.x, tile_point.y), clip_box))
{
continue;
}
protozero::pbf_writer feature_writer(point_layer_writer,
util::vector_tile::FEATURE_TAG);
// Field 3 is the "geometry type" field. Value 1 is "point"
feature_writer.add_enum(util::vector_tile::GEOMETRY_TAG,
util::vector_tile::GEOMETRY_TYPE_POINT); // geometry type
const auto osmid =
static_cast<OSMNodeID::value_type>(facade.GetOSMNodeIDOfNode(internal_node));
feature_writer.add_uint64(util::vector_tile::ID_TAG, osmid); // id
// There are no additional properties, just the ID and the geometry
{
// Add the geometry as the last field in this feature
protozero::packed_field_uint32 geometry(
feature_writer, util::vector_tile::FEATURE_GEOMETRIES_TAG);
encodePoint(tile_point, geometry);
}
}
}
} }
// protozero serializes data during object destructors, so once the scope closes, // protozero serializes data during object destructors, so once the scope closes,
// our result buffer will have all the tile data encoded into it. // our result buffer will have all the tile data encoded into it.

View File

@ -111,43 +111,6 @@ void GraphCompressor::Compress(const std::unordered_set<NodeID> &barrier_nodes,
BOOST_ASSERT(graph.GetEdgeData(forward_e2).name_id == BOOST_ASSERT(graph.GetEdgeData(forward_e2).name_id ==
graph.GetEdgeData(reverse_e2).name_id); graph.GetEdgeData(reverse_e2).name_id);
// Do not compress edge if it crosses a traffic signal.
// This can't be done in CanCombineWith, becase we only store the
// traffic signals in the `traffic_lights` list, which EdgeData
// doesn't have access to.
const bool has_node_penalty = traffic_lights.find(node_v) != traffic_lights.end();
if (has_node_penalty)
continue;
// Get weights before graph is modified
const auto forward_weight1 = fwd_edge_data1.weight;
const auto forward_weight2 = fwd_edge_data2.weight;
const auto forward_duration1 = fwd_edge_data1.duration;
const auto forward_duration2 = fwd_edge_data2.duration;
BOOST_ASSERT(0 != forward_weight1);
BOOST_ASSERT(0 != forward_weight2);
const auto reverse_weight1 = rev_edge_data1.weight;
const auto reverse_weight2 = rev_edge_data2.weight;
const auto reverse_duration1 = rev_edge_data1.duration;
const auto reverse_duration2 = rev_edge_data2.duration;
BOOST_ASSERT(0 != reverse_weight1);
BOOST_ASSERT(0 != reverse_weight2);
// add weight of e2's to e1
graph.GetEdgeData(forward_e1).weight += forward_weight2;
graph.GetEdgeData(reverse_e1).weight += reverse_weight2;
// add duration of e2's to e1
graph.GetEdgeData(forward_e1).duration += forward_duration2;
graph.GetEdgeData(reverse_e1).duration += reverse_duration2;
// extend e1's to targets of e2's
graph.SetTarget(forward_e1, node_w);
graph.SetTarget(reverse_e1, node_u);
/* /*
* Remember Lane Data for compressed parts. This handles scenarios where lane-data * Remember Lane Data for compressed parts. This handles scenarios where lane-data
* is * is
@ -185,12 +148,51 @@ void GraphCompressor::Compress(const std::unordered_set<NodeID> &barrier_nodes,
return front; return front;
return back; return back;
}; };
graph.GetEdgeData(forward_e1).lane_description_id = graph.GetEdgeData(forward_e1).lane_description_id = selectLaneID(
selectLaneID(graph.GetEdgeData(forward_e1).lane_description_id, fwd_edge_data1.lane_description_id, fwd_edge_data2.lane_description_id);
fwd_edge_data2.lane_description_id); graph.GetEdgeData(reverse_e1).lane_description_id = selectLaneID(
graph.GetEdgeData(reverse_e1).lane_description_id = rev_edge_data1.lane_description_id, rev_edge_data2.lane_description_id);
selectLaneID(graph.GetEdgeData(reverse_e1).lane_description_id, graph.GetEdgeData(forward_e2).lane_description_id = selectLaneID(
rev_edge_data2.lane_description_id); fwd_edge_data2.lane_description_id, fwd_edge_data1.lane_description_id);
graph.GetEdgeData(reverse_e2).lane_description_id = selectLaneID(
rev_edge_data2.lane_description_id, rev_edge_data1.lane_description_id);
// Do not compress edge if it crosses a traffic signal.
// This can't be done in CanCombineWith, becase we only store the
// traffic signals in the `traffic_lights` list, which EdgeData
// doesn't have access to.
const bool has_node_penalty = traffic_lights.find(node_v) != traffic_lights.end();
if (has_node_penalty)
continue;
// Get weights before graph is modified
const auto forward_weight1 = fwd_edge_data1.weight;
const auto forward_weight2 = fwd_edge_data2.weight;
const auto forward_duration1 = fwd_edge_data1.duration;
const auto forward_duration2 = fwd_edge_data2.duration;
BOOST_ASSERT(0 != forward_weight1);
BOOST_ASSERT(0 != forward_weight2);
const auto reverse_weight1 = rev_edge_data1.weight;
const auto reverse_weight2 = rev_edge_data2.weight;
const auto reverse_duration1 = rev_edge_data1.duration;
const auto reverse_duration2 = rev_edge_data2.duration;
BOOST_ASSERT(0 != reverse_weight1);
BOOST_ASSERT(0 != reverse_weight2);
// add weight of e2's to e1
graph.GetEdgeData(forward_e1).weight += forward_weight2;
graph.GetEdgeData(reverse_e1).weight += reverse_weight2;
// add duration of e2's to e1
graph.GetEdgeData(forward_e1).duration += forward_duration2;
graph.GetEdgeData(reverse_e1).duration += reverse_duration2;
// extend e1's to targets of e2's
graph.SetTarget(forward_e1, node_w);
graph.SetTarget(reverse_e1, node_u);
// remove e2's (if bidir, otherwise only one) // remove e2's (if bidir, otherwise only one)
graph.DeleteEdge(node_v, forward_e2); graph.DeleteEdge(node_v, forward_e2);

View File

@ -0,0 +1,80 @@
#include "extractor/guidance/driveway_handler.hpp"
#include "util/assert.hpp"
using osrm::extractor::guidance::getTurnDirection;
using osrm::util::angularDeviation;
namespace osrm
{
namespace extractor
{
namespace guidance
{
DrivewayHandler::DrivewayHandler(const IntersectionGenerator &intersection_generator,
const util::NodeBasedDynamicGraph &node_based_graph,
const std::vector<util::Coordinate> &coordinates,
const util::NameTable &name_table,
const SuffixTable &street_name_suffix_table)
: IntersectionHandler(node_based_graph,
coordinates,
name_table,
street_name_suffix_table,
intersection_generator)
{
}
// The intersection without major roads needs to pass by service roads (bd, be)
// d
// .
// a--->b--->c
// .
// e
bool DrivewayHandler::canProcess(const NodeID /*nid*/,
const EdgeID /*via_eid*/,
const Intersection &intersection) const
{
const auto from_eid = intersection.getUTurnRoad().eid;
if (intersection.size() <= 2 ||
node_based_graph.GetEdgeData(from_eid).road_classification.IsLowPriorityRoadClass())
return false;
auto low_priority_count =
std::count_if(intersection.begin(), intersection.end(), [this](const auto &road) {
return node_based_graph.GetEdgeData(road.eid)
.road_classification.IsLowPriorityRoadClass();
});
// Process intersection if it has two edges with normal priority and one is the entry edge,
// and also has at least one edge with lower priority
return static_cast<std::size_t>(low_priority_count) + 2 == intersection.size();
}
Intersection DrivewayHandler::
operator()(const NodeID nid, const EdgeID source_edge_id, Intersection intersection) const
{
auto road =
std::find_if(intersection.begin() + 1, intersection.end(), [this](const auto &road) {
return !node_based_graph.GetEdgeData(road.eid)
.road_classification.IsLowPriorityRoadClass();
});
(void)nid;
OSRM_ASSERT(road != intersection.end(), coordinates[nid]);
if (road->instruction == TurnInstruction::INVALID())
return intersection;
OSRM_ASSERT(road->instruction.type == TurnType::Turn, coordinates[nid]);
road->instruction.type =
isSameName(source_edge_id, road->eid) ? TurnType::NoTurn : TurnType::NewName;
return intersection;
}
} // namespace guidance
} // namespace extractor
} // namespace osrm

View File

@ -436,6 +436,19 @@ IntersectionHandler::getNextIntersection(const NodeID at, const EdgeID via) cons
IntersectionViewAndNode{std::move(intersection), intersection_node}); IntersectionViewAndNode{std::move(intersection), intersection_node});
} }
bool IntersectionHandler::isSameName(const EdgeID source_edge_id, const EdgeID target_edge_id) const
{
const auto &source_edge_data = node_based_graph.GetEdgeData(source_edge_id);
const auto &target_edge_data = node_based_graph.GetEdgeData(target_edge_id);
return source_edge_data.name_id != EMPTY_NAMEID && //
target_edge_data.name_id != EMPTY_NAMEID && //
!util::guidance::requiresNameAnnounced(source_edge_data.name_id,
target_edge_data.name_id,
name_table,
street_name_suffix_table); //
}
} // namespace guidance } // namespace guidance
} // namespace extractor } // namespace extractor
} // namespace osrm } // namespace osrm

View File

@ -473,17 +473,7 @@ operator()(const NodeID /*nid*/, const EdgeID source_edge_id, Intersection inter
// In those cases the obvious non-Sliproad is now obvious and we discard the Fork turn type. // In those cases the obvious non-Sliproad is now obvious and we discard the Fork turn type.
if (sliproad_found && main_road.instruction.type == TurnType::Fork) if (sliproad_found && main_road.instruction.type == TurnType::Fork)
{ {
const auto &source_edge_data = node_based_graph.GetEdgeData(source_edge_id); if (isSameName(source_edge_id, main_road.eid))
const auto &main_road_data = node_based_graph.GetEdgeData(main_road.eid);
const auto same_name = source_edge_data.name_id != EMPTY_NAMEID && //
main_road_data.name_id != EMPTY_NAMEID && //
!util::guidance::requiresNameAnnounced(source_edge_data.name_id,
main_road_data.name_id,
name_table,
street_name_suffix_table); //
if (same_name)
{ {
if (angularDeviation(main_road.angle, STRAIGHT_ANGLE) < 5) if (angularDeviation(main_road.angle, STRAIGHT_ANGLE) < 5)
intersection[*obvious].instruction.type = TurnType::Suppressed; intersection[*obvious].instruction.type = TurnType::Suppressed;
@ -492,7 +482,7 @@ operator()(const NodeID /*nid*/, const EdgeID source_edge_id, Intersection inter
intersection[*obvious].instruction.direction_modifier = intersection[*obvious].instruction.direction_modifier =
getTurnDirection(intersection[*obvious].angle); getTurnDirection(intersection[*obvious].angle);
} }
else if (main_road_data.name_id != EMPTY_NAMEID) else if (node_based_graph.GetEdgeData(main_road.eid).name_id != EMPTY_NAMEID)
{ {
intersection[*obvious].instruction.type = TurnType::NewName; intersection[*obvious].instruction.type = TurnType::NewName;
intersection[*obvious].instruction.direction_modifier = intersection[*obvious].instruction.direction_modifier =

View File

@ -68,7 +68,12 @@ TurnAnalysis::TurnAnalysis(const util::NodeBasedDynamicGraph &node_based_graph,
node_based_graph, node_based_graph,
coordinates, coordinates,
name_table, name_table,
street_name_suffix_table) street_name_suffix_table),
driveway_handler(intersection_generator,
node_based_graph,
coordinates,
name_table,
street_name_suffix_table)
{ {
} }
@ -132,8 +137,14 @@ Intersection TurnAnalysis::AssignTurnTypes(const NodeID node_prior_to_intersecti
// set initial defaults for normal turns and modifier based on angle // set initial defaults for normal turns and modifier based on angle
intersection = intersection =
setTurnTypes(node_prior_to_intersection, entering_via_edge, std::move(intersection)); setTurnTypes(node_prior_to_intersection, entering_via_edge, std::move(intersection));
if (motorway_handler.canProcess( if (driveway_handler.canProcess(
node_prior_to_intersection, entering_via_edge, intersection)) node_prior_to_intersection, entering_via_edge, intersection))
{
intersection = driveway_handler(
node_prior_to_intersection, entering_via_edge, std::move(intersection));
}
else if (motorway_handler.canProcess(
node_prior_to_intersection, entering_via_edge, intersection))
{ {
intersection = motorway_handler( intersection = motorway_handler(
node_prior_to_intersection, entering_via_edge, std::move(intersection)); node_prior_to_intersection, entering_via_edge, std::move(intersection));

View File

@ -180,7 +180,7 @@ TurnLaneScenario TurnLaneHandler::deduceScenario(const NodeID at,
(intersection.size() == 2 && (intersection.size() == 2 &&
((lane_description_id != INVALID_LANE_DESCRIPTIONID && ((lane_description_id != INVALID_LANE_DESCRIPTIONID &&
lane_description_id == lane_description_id ==
node_based_graph.GetEdgeData(intersection[1].eid).lane_description_id) || node_based_graph.GetEdgeData(intersection[1].eid).lane_description_id) &&
angularDeviation(intersection[1].angle, STRAIGHT_ANGLE) < FUZZY_ANGLE_DIFFERENCE)); angularDeviation(intersection[1].angle, STRAIGHT_ANGLE) < FUZZY_ANGLE_DIFFERENCE));
if (is_going_straight_and_turns_continue) if (is_going_straight_and_turns_continue)

View File

@ -11,6 +11,7 @@
#include "osrm/osrm.hpp" #include "osrm/osrm.hpp"
#include "osrm/status.hpp" #include "osrm/status.hpp"
#include "util/typedefs.hpp"
#include "util/vector_tile.hpp" #include "util/vector_tile.hpp"
#include <protozero/pbf_reader.hpp> #include <protozero/pbf_reader.hpp>
@ -20,23 +21,38 @@
BOOST_AUTO_TEST_SUITE(tile) BOOST_AUTO_TEST_SUITE(tile)
template <typename algorithm> void test_tile(algorithm &osrm) void validate_value(protozero::pbf_reader value)
{ {
using namespace osrm; using namespace osrm;
while (value.next())
{
switch (value.tag())
{
case util::vector_tile::VARIANT_TYPE_BOOL:
value.get_bool();
break;
case util::vector_tile::VARIANT_TYPE_DOUBLE:
value.get_double();
break;
case util::vector_tile::VARIANT_TYPE_FLOAT:
value.get_float();
break;
case util::vector_tile::VARIANT_TYPE_STRING:
value.get_string();
break;
case util::vector_tile::VARIANT_TYPE_UINT64:
value.get_uint64();
break;
case util::vector_tile::VARIANT_TYPE_SINT64:
value.get_sint64();
break;
}
}
}
// This tile should contain most of monaco void validate_feature_layer(protozero::pbf_reader &layer_message)
TileParameters params{17059, 11948, 15}; {
using namespace osrm;
std::string result;
const auto rc = osrm.Tile(params, result);
BOOST_CHECK(rc == Status::Ok);
BOOST_CHECK(result.size() > 114000);
protozero::pbf_reader tile_message(result);
tile_message.next();
BOOST_CHECK_EQUAL(tile_message.tag(), util::vector_tile::LAYER_TAG); // must be a layer
protozero::pbf_reader layer_message = tile_message.get_message();
const auto check_feature = [](protozero::pbf_reader feature_message) { const auto check_feature = [](protozero::pbf_reader feature_message) {
feature_message.next(); // advance parser to first entry feature_message.next(); // advance parser to first entry
@ -81,33 +97,6 @@ template <typename algorithm> void test_tile(algorithm &osrm)
BOOST_CHECK_GT(std::distance(geometry_iter_pair.begin(), geometry_iter_pair.end()), 1); BOOST_CHECK_GT(std::distance(geometry_iter_pair.begin(), geometry_iter_pair.end()), 1);
}; };
const auto check_value = [](protozero::pbf_reader value) {
while (value.next())
{
switch (value.tag())
{
case util::vector_tile::VARIANT_TYPE_BOOL:
value.get_bool();
break;
case util::vector_tile::VARIANT_TYPE_DOUBLE:
value.get_double();
break;
case util::vector_tile::VARIANT_TYPE_FLOAT:
value.get_float();
break;
case util::vector_tile::VARIANT_TYPE_STRING:
value.get_string();
break;
case util::vector_tile::VARIANT_TYPE_UINT64:
value.get_uint64();
break;
case util::vector_tile::VARIANT_TYPE_SINT64:
value.get_sint64();
break;
}
}
};
auto number_of_speed_keys = 0u; auto number_of_speed_keys = 0u;
auto number_of_speed_values = 0u; auto number_of_speed_values = 0u;
@ -132,7 +121,7 @@ template <typename algorithm> void test_tile(algorithm &osrm)
number_of_speed_keys++; number_of_speed_keys++;
break; break;
case util::vector_tile::VARIANT_TAG: case util::vector_tile::VARIANT_TAG:
check_value(layer_message.get_message()); validate_value(layer_message.get_message());
number_of_speed_values++; number_of_speed_values++;
break; break;
default: default:
@ -143,9 +132,11 @@ template <typename algorithm> void test_tile(algorithm &osrm)
BOOST_CHECK_EQUAL(number_of_speed_keys, 7); BOOST_CHECK_EQUAL(number_of_speed_keys, 7);
BOOST_CHECK_GT(number_of_speed_values, 128); // speed value resolution BOOST_CHECK_GT(number_of_speed_values, 128); // speed value resolution
}
tile_message.next(); void validate_turn_layer(protozero::pbf_reader &layer_message)
layer_message = tile_message.get_message(); {
using namespace osrm;
const auto check_turn_feature = [](protozero::pbf_reader feature_message) { const auto check_turn_feature = [](protozero::pbf_reader feature_message) {
feature_message.next(); // advance parser to first entry feature_message.next(); // advance parser to first entry
@ -202,7 +193,7 @@ template <typename algorithm> void test_tile(algorithm &osrm)
number_of_turn_keys++; number_of_turn_keys++;
break; break;
case util::vector_tile::VARIANT_TAG: case util::vector_tile::VARIANT_TAG:
check_value(layer_message.get_message()); validate_value(layer_message.get_message());
break; break;
default: default:
BOOST_CHECK(false); // invalid tag BOOST_CHECK(false); // invalid tag
@ -214,11 +205,95 @@ template <typename algorithm> void test_tile(algorithm &osrm)
BOOST_CHECK(number_of_turns_found > 700); BOOST_CHECK(number_of_turns_found > 700);
} }
void validate_node_layer(protozero::pbf_reader &layer_message)
{
using namespace osrm;
auto number_of_nodes_found = 0u;
const auto check_osmnode_feature = [](protozero::pbf_reader feature_message) {
feature_message.next(); // advance parser to first entry
BOOST_CHECK_EQUAL(feature_message.tag(), util::vector_tile::GEOMETRY_TAG);
BOOST_CHECK_EQUAL(feature_message.get_enum(), util::vector_tile::GEOMETRY_TYPE_POINT);
feature_message.next(); // advance to next entry
BOOST_CHECK_EQUAL(feature_message.tag(), util::vector_tile::ID_TAG);
feature_message.get_uint64(); // id
feature_message.next(); // advance to next entry
// Note - on this layer, there should be no feature attributes, the next thing
// we get should be the geometry
BOOST_CHECK_EQUAL(feature_message.tag(), util::vector_tile::FEATURE_GEOMETRIES_TAG);
auto geometry_iter_pair = feature_message.get_packed_uint32();
BOOST_CHECK_GT(std::distance(geometry_iter_pair.begin(), geometry_iter_pair.end()), 1);
};
while (layer_message.next())
{
switch (layer_message.tag())
{
case util::vector_tile::VERSION_TAG:
BOOST_CHECK_EQUAL(layer_message.get_uint32(), 2);
break;
case util::vector_tile::NAME_TAG:
BOOST_CHECK_EQUAL(layer_message.get_string(), "osmnodes");
break;
case util::vector_tile::EXTENT_TAG:
BOOST_CHECK_EQUAL(layer_message.get_uint32(), util::vector_tile::EXTENT);
break;
case util::vector_tile::FEATURE_TAG:
check_osmnode_feature(layer_message.get_message());
number_of_nodes_found++;
break;
case util::vector_tile::KEY_TAG:
BOOST_CHECK(false); // There should be no properties on node features
break;
case util::vector_tile::VARIANT_TAG:
BOOST_CHECK(false); // There should be no properties on node features
break;
default:
BOOST_CHECK(false); // invalid tag
break;
}
}
BOOST_CHECK_EQUAL(number_of_nodes_found, 1791);
}
void validate_tile(const osrm::OSRM &osrm)
{
using namespace osrm;
// This tile should contain most of monaco
TileParameters params{17059, 11948, 15};
std::string result;
const auto rc = osrm.Tile(params, result);
BOOST_CHECK(rc == Status::Ok);
BOOST_CHECK(result.size() > 114000);
protozero::pbf_reader tile_message(result);
tile_message.next();
BOOST_CHECK_EQUAL(tile_message.tag(), util::vector_tile::LAYER_TAG); // must be a layer
protozero::pbf_reader layer_message = tile_message.get_message();
validate_feature_layer(layer_message);
tile_message.next();
BOOST_CHECK_EQUAL(tile_message.tag(), util::vector_tile::LAYER_TAG); // must be a layer
layer_message = tile_message.get_message();
validate_turn_layer(layer_message);
tile_message.next();
BOOST_CHECK_EQUAL(tile_message.tag(), util::vector_tile::LAYER_TAG); // must be a layer
layer_message = tile_message.get_message();
validate_node_layer(layer_message);
}
BOOST_AUTO_TEST_CASE(test_tile_ch) BOOST_AUTO_TEST_CASE(test_tile_ch)
{ {
using namespace osrm; using namespace osrm;
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm", osrm::EngineConfig::Algorithm::CH); auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm", osrm::EngineConfig::Algorithm::CH);
test_tile(osrm); validate_tile(osrm);
} }
BOOST_AUTO_TEST_CASE(test_tile_corech) BOOST_AUTO_TEST_CASE(test_tile_corech)
@ -226,17 +301,17 @@ BOOST_AUTO_TEST_CASE(test_tile_corech)
using namespace osrm; using namespace osrm;
auto osrm = auto osrm =
getOSRM(OSRM_TEST_DATA_DIR "/corech/monaco.osrm", osrm::EngineConfig::Algorithm::CoreCH); getOSRM(OSRM_TEST_DATA_DIR "/corech/monaco.osrm", osrm::EngineConfig::Algorithm::CoreCH);
test_tile(osrm); validate_tile(osrm);
} }
BOOST_AUTO_TEST_CASE(test_tile_mld) BOOST_AUTO_TEST_CASE(test_tile_mld)
{ {
using namespace osrm; using namespace osrm;
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/mld/monaco.osrm", osrm::EngineConfig::Algorithm::MLD); auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/mld/monaco.osrm", osrm::EngineConfig::Algorithm::MLD);
test_tile(osrm); validate_tile(osrm);
} }
template <typename algorithm> void test_tile_turns(algorithm &osrm) void test_tile_turns(const osrm::OSRM &osrm)
{ {
using namespace osrm; using namespace osrm;
@ -423,7 +498,7 @@ BOOST_AUTO_TEST_CASE(test_tile_turns_mld)
test_tile_turns(osrm); test_tile_turns(osrm);
} }
template <typename algorithm> void test_tile_speeds(algorithm &osrm) void test_tile_speeds(const osrm::OSRM &osrm)
{ {
using namespace osrm; using namespace osrm;
@ -613,4 +688,109 @@ BOOST_AUTO_TEST_CASE(test_tile_speeds_mld)
test_tile_speeds(osrm); test_tile_speeds(osrm);
} }
void test_tile_nodes(const osrm::OSRM &osrm)
{
using namespace osrm;
// Small tile so we can test all the values
// TileParameters params{272953, 191177, 19};
// TileParameters params{136477, 95580, 18};
// Small tile where we can test all the values
TileParameters params{272953, 191177, 19};
std::string result;
const auto rc = osrm.Tile(params, result);
BOOST_CHECK(rc == Status::Ok);
BOOST_CHECK_GT(result.size(), 128);
protozero::pbf_reader tile_message(result);
tile_message.next();
BOOST_CHECK_EQUAL(tile_message.tag(), util::vector_tile::LAYER_TAG); // must be a layer
// Skip the segments and turns layers
tile_message.skip();
tile_message.next();
tile_message.skip();
// Get the osmnodes layer
tile_message.next();
protozero::pbf_reader layer_message = tile_message.get_message();
std::vector<OSMNodeID::value_type> found_node_ids;
const auto check_feature = [&](protozero::pbf_reader feature_message) {
feature_message.next(); // advance parser to first entry
BOOST_CHECK_EQUAL(feature_message.tag(), util::vector_tile::GEOMETRY_TAG);
BOOST_CHECK_EQUAL(feature_message.get_enum(), util::vector_tile::GEOMETRY_TYPE_POINT);
feature_message.next(); // advance to next entry
BOOST_CHECK_EQUAL(feature_message.tag(), util::vector_tile::ID_TAG);
found_node_ids.push_back(feature_message.get_uint64()); // id
feature_message.next(); // advance to next entry
BOOST_CHECK_EQUAL(feature_message.tag(), util::vector_tile::FEATURE_GEOMETRIES_TAG);
auto geometry_iter_pair = feature_message.get_packed_uint32();
BOOST_CHECK_GT(std::distance(geometry_iter_pair.begin(), geometry_iter_pair.end()), 1);
};
while (layer_message.next())
{
switch (layer_message.tag())
{
case util::vector_tile::VERSION_TAG:
BOOST_CHECK_EQUAL(layer_message.get_uint32(), 2);
break;
case util::vector_tile::NAME_TAG:
BOOST_CHECK_EQUAL(layer_message.get_string(), "osmnodes");
break;
case util::vector_tile::EXTENT_TAG:
BOOST_CHECK_EQUAL(layer_message.get_uint32(), util::vector_tile::EXTENT);
break;
case util::vector_tile::FEATURE_TAG:
check_feature(layer_message.get_message());
break;
case util::vector_tile::KEY_TAG:
BOOST_CHECK(false); // There should be no keys
break;
case util::vector_tile::VARIANT_TAG:
BOOST_CHECK(false); // There should be no values
break;
default:
BOOST_CHECK(false); // invalid tag
break;
}
}
std::sort(found_node_ids.begin(), found_node_ids.end());
const std::vector<OSMNodeID::value_type> expected_node_ids = {
25191722, 25191725, 357300400, 1737389138, 1737389140, 2241375220};
BOOST_CHECK(found_node_ids == expected_node_ids);
}
BOOST_AUTO_TEST_CASE(test_tile_nodes_ch)
{
using namespace osrm;
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm", osrm::EngineConfig::Algorithm::CH);
test_tile_nodes(osrm);
}
BOOST_AUTO_TEST_CASE(test_tile_nodes_corech)
{
using namespace osrm;
auto osrm =
getOSRM(OSRM_TEST_DATA_DIR "/corech/monaco.osrm", osrm::EngineConfig::Algorithm::CoreCH);
test_tile_nodes(osrm);
}
BOOST_AUTO_TEST_CASE(test_tile_nodes_mld)
{
using namespace osrm;
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/mld/monaco.osrm", osrm::EngineConfig::Algorithm::MLD);
test_tile_nodes(osrm);
}
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()