Add road priority class to turn function (#4858)

* expose road priority class to turn function

* update docs
This commit is contained in:
Huyen Chau Nguyen 2018-02-07 11:39:02 +01:00 committed by GitHub
parent 92b7d581ce
commit fa8d788bb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 64 additions and 32 deletions

View File

@ -208,33 +208,35 @@ The `process_turn` function is called for every possible turn in the network. Ba
The following attributes can be read and set on the result in `process_turn`: The following attributes can be read and set on the result in `process_turn`:
Attribute | Read/write? | Type | Notes Attribute | Read/write? | Type | Notes
--------------------- | ------------- | --------- | ------------------------------------------------------ --------------------- | ------------- | --------- | ------------------------------------------------------
angle | Read | Float | Angle of turn in degrees (`[-179, 180]`: `0`=straight, `180`=u turn, `+x`=x degrees to the right, `-x`= x degrees to the left) angle | Read | Float | Angle of turn in degrees (`[-179, 180]`: `0`=straight, `180`=u turn, `+x`=x degrees to the right, `-x`= x degrees to the left)
number_of_roads | Read | Integer | Number of ways at the intersection of the turn number_of_roads | Read | Integer | Number of ways at the intersection of the turn
is_u_turn | Read | Boolean | Is the turn a u-turn? is_u_turn | Read | Boolean | Is the turn a u-turn?
has_traffic_light | Read | Boolean | Is a traffic light present at this turn? has_traffic_light | Read | Boolean | Is a traffic light present at this turn?
is_left_hand_driving | Read | Boolean | Is left-hand traffic? is_left_hand_driving | Read | Boolean | Is left-hand traffic?
source_restricted | Read | Boolean | Is it from a restricted access road? (See definition in `process_way`) source_restricted | Read | Boolean | Is it from a restricted access road? (See definition in `process_way`)
source_mode | Read | Enum | Travel mode before the turn. Defined in `include/extractor/travel_mode.hpp` source_mode | Read | Enum | Travel mode before the turn. Defined in `include/extractor/travel_mode.hpp`
source_is_motorway | Read | Boolean | Is the source road a motorway? source_is_motorway | Read | Boolean | Is the source road a motorway?
source_is_link | Read | Boolean | Is the source road a link? source_is_link | Read | Boolean | Is the source road a link?
source_number_of_lanes | Read | Integer | How many lanes does the source road have? (default when not tagged: 0) source_number_of_lanes | Read | Integer | How many lanes does the source road have? (default when not tagged: 0)
source_highway_turn_classification | Read | Integer | Classification based on highway tag defined by user during setup. (default when not set: 0, allowed classification values are: 0-15)) source_highway_turn_classification | Read | Integer | Classification based on highway tag defined by user during setup. (default when not set: 0, allowed classification values are: 0-15))
source_access_turn_classification | Read | Integer | Classification based on access tag defined by user during setup. (default when not set: 0, allowed classification values are: 0-15)) source_access_turn_classification | Read | Integer | Classification based on access tag defined by user during setup. (default when not set: 0, allowed classification values are: 0-15))
source_speed | Read | Integer | Speed on this source road in km/h source_speed | Read | Integer | Speed on this source road in km/h
target_restricted | Read | Boolean | Is it from a restricted access road? (See definition in `process_way`) source_priority_class | Read | Enum | The type of road priority class of the source. Defined in `include/extractor/guidance/road_classification.hpp`
target_mode | Read | Enum | Travel mode before the turn. Defined in `include/extractor/travel_mode.hpp` target_restricted | Read | Boolean | Is it from a restricted access road? (See definition in `process_way`)
target_is_motorway | Read | Boolean | Is the target road a motorway? target_mode | Read | Enum | Travel mode before the turn. Defined in `include/extractor/travel_mode.hpp`
target_is_link | Read | Boolean | Is the target road a link? target_is_motorway | Read | Boolean | Is the target road a motorway?
target_number_of_lanes | Read | Integer | How many lanes does the target road have? (default when not tagged: 0) target_is_link | Read | Boolean | Is the target road a link?
target_highway_turn_classification | Read | Integer | Classification based on highway tag defined by user during setup. (default when not set: 0, allowed classification values are: 0-15)) target_number_of_lanes | Read | Integer | How many lanes does the target road have? (default when not tagged: 0)
target_access_turn_classification | Read | Integer | Classification based on access tag defined by user during setup. (default when not set: 0, allowed classification values are: 0-15)) target_highway_turn_classification | Read | Integer | Classification based on highway tag defined by user during setup. (default when not set: 0, allowed classification values are: 0-15))
target_speed | Read | Integer | Speed on this target road in km/h target_access_turn_classification | Read | Integer | Classification based on access tag defined by user during setup. (default when not set: 0, allowed classification values are: 0-15))
roads_on_the_right | Read | Vector<ExtractionTurnLeg> | Vector with information about other roads on the right of the turn that are also connected at the intersection target_speed | Read | Integer | Speed on this target road in km/h
roads_on_the_left | Read | Vector<ExtractionTurnLeg> | Vector with information about other roads on the left of the turn that are also connected at the intersection. If turn is a u turn, this is empty. target_priority_class | Read | Enum | The type of road priority class of the target. Defined in `include/extractor/guidance/road_classification.hpp`
weight | Read/write | Float | Penalty to be applied for this turn (routing weight) roads_on_the_right | Read | Vector<ExtractionTurnLeg> | Vector with information about other roads on the right of the turn that are also connected at the intersection
duration | Read/write | Float | Penalty to be applied for this turn (duration in deciseconds) roads_on_the_left | Read | Vector<ExtractionTurnLeg> | Vector with information about other roads on the left of the turn that are also connected at the intersection. If turn is a u turn, this is empty.
weight | Read/write | Float | Penalty to be applied for this turn (routing weight)
duration | Read/write | Float | Penalty to be applied for this turn (duration in deciseconds)
#### `roads_on_the_right` and `roads_on_the_left` #### `roads_on_the_right` and `roads_on_the_left`
@ -250,6 +252,7 @@ number_of_lanes | Read | Integer | How many lanes does th
highway_turn_classification | Read | Integer | Classification based on highway tag defined by user during setup. (default when not set: 0, allowed classification values are: 0-15) highway_turn_classification | Read | Integer | Classification based on highway tag defined by user during setup. (default when not set: 0, allowed classification values are: 0-15)
access_turn_classification | Read | Integer | Classification based on access tag defined by user during setup. (default when not set: 0, allowed classification values are: 0-15) access_turn_classification | Read | Integer | Classification based on access tag defined by user during setup. (default when not set: 0, allowed classification values are: 0-15)
speed | Read | Integer | Speed on this road in km/h speed | Read | Integer | Speed on this road in km/h
priority_class | Read | Enum | The type of road priority class of the leg. Defined in `include/extractor/guidance/road_classification.hpp`
is_incoming | Read | Boolean | Is the road an incoming road of the intersection is_incoming | Read | Boolean | Is the road an incoming road of the intersection
is_outgoing | Read | Boolean | Is the road an outgoing road of the intersection is_outgoing | Read | Boolean | Is the road an outgoing road of the intersection

View File

@ -40,6 +40,7 @@ Feature: Turn Function Information
.. ', is_outgoing: ' .. tostring(leg.is_outgoing) .. ', is_outgoing: ' .. tostring(leg.is_outgoing)
.. ', highway_turn_classification: ' .. tostring(leg.highway_turn_classification) .. ', highway_turn_classification: ' .. tostring(leg.highway_turn_classification)
.. ', access_turn_classification: ' .. tostring(leg.access_turn_classification) .. ', access_turn_classification: ' .. tostring(leg.access_turn_classification)
.. ', priority_class: ' .. tostring(leg.priority_class)
end end
function print_turn (profile, turn) function print_turn (profile, turn)
@ -50,6 +51,8 @@ Feature: Turn Function Information
print ('source_highway_turn_classification ' .. string.format("%s", tostring(turn.source_highway_turn_classification))) print ('source_highway_turn_classification ' .. string.format("%s", tostring(turn.source_highway_turn_classification)))
print ('source_access_turn_classification ' .. string.format("%s", tostring(turn.source_access_turn_classification))) print ('source_access_turn_classification ' .. string.format("%s", tostring(turn.source_access_turn_classification)))
print ('source_speed ' .. string.format("%s", tostring(turn.source_speed))) print ('source_speed ' .. string.format("%s", tostring(turn.source_speed)))
print ('source_priority_class ' .. string.format("%s", tostring(turn.source_priority_class)))
print ('source_mode ' .. string.format("%s", tostring(turn.source_mode)))
print ('target_restricted ' .. string.format("%s", tostring(turn.target_restricted))) print ('target_restricted ' .. string.format("%s", tostring(turn.target_restricted)))
print ('target_is_motorway ' .. string.format("%s", tostring(turn.target_is_motorway))) print ('target_is_motorway ' .. string.format("%s", tostring(turn.target_is_motorway)))
@ -58,6 +61,8 @@ Feature: Turn Function Information
print ('target_highway_turn_classification ' .. string.format("%s", tostring(turn.target_highway_turn_classification))) print ('target_highway_turn_classification ' .. string.format("%s", tostring(turn.target_highway_turn_classification)))
print ('target_access_turn_classification ' .. string.format("%s", tostring(turn.target_access_turn_classification))) print ('target_access_turn_classification ' .. string.format("%s", tostring(turn.target_access_turn_classification)))
print ('target_speed ' .. string.format("%s", tostring(turn.target_speed))) print ('target_speed ' .. string.format("%s", tostring(turn.target_speed)))
print ('target_priority_class ' .. string.format("%s", tostring(turn.target_priority_class)))
print ('target_mode ' .. string.format("%s", tostring(turn.target_mode)))
print ('number_of_roads ' .. string.format("%s", tostring(turn.number_of_roads))) print ('number_of_roads ' .. string.format("%s", tostring(turn.number_of_roads)))
if not turn.is_u_turn then if not turn.is_u_turn then
@ -97,8 +102,10 @@ Feature: Turn Function Information
And stdout should contain "source_is_motorway true" And stdout should contain "source_is_motorway true"
And stdout should contain "target_is_motorway true" And stdout should contain "target_is_motorway true"
And stdout should contain "source_is_link false" And stdout should contain "source_is_link false"
And stdout should contain "source_priority_class 0"
And stdout should contain "target_is_motorway true" And stdout should contain "target_is_motorway true"
And stdout should contain "target_is_link false" And stdout should contain "target_is_link false"
And stdout should contain "target_priority_class 0"
Scenario: Turns should detect when turn is leaving highway Scenario: Turns should detect when turn is leaving highway
@ -143,6 +150,9 @@ Feature: Turn Function Information
When I run "osrm-extract --profile {profile_file} {osm_file}" When I run "osrm-extract --profile {profile_file} {osm_file}"
Then it should exit successfully Then it should exit successfully
And stdout should contain "number_of_roads 3" And stdout should contain "number_of_roads 3"
And stdout should contain "source_priority_class 4"
And stdout should contain "target_priority_class 0"
And stdout should contain "target_priority_class 11"
# turning abd, give information about bc # turning abd, give information about bc
And stdout should contain /roads_on_the_right \[1\] speed: [0-9]+, is_incoming: false, is_outgoing: true, highway_turn_classification: 4, access_turn_classification: 0/ And stdout should contain /roads_on_the_right \[1\] speed: [0-9]+, is_incoming: false, is_outgoing: true, highway_turn_classification: 4, access_turn_classification: 0/
# turning abc, give information about bd # turning abc, give information about bd

View File

@ -1,7 +1,8 @@
#ifndef OSRM_EXTRACTION_TURN_HPP #ifndef OSRM_EXTRACTION_TURN_HPP
#define OSRM_EXTRACTION_TURN_HPP #define OSRM_EXTRACTION_TURN_HPP
#include <extractor/travel_mode.hpp> #include "extractor/road_classification.hpp"
#include "extractor/travel_mode.hpp"
#include <boost/numeric/conversion/cast.hpp> #include <boost/numeric/conversion/cast.hpp>
@ -21,13 +22,14 @@ struct ExtractionTurnLeg
int highway_turn_classification, int highway_turn_classification,
int access_turn_classification, int access_turn_classification,
int speed, int speed,
RoadPriorityClass::Enum priority_class,
bool is_incoming, bool is_incoming,
bool is_outgoing) bool is_outgoing)
: is_restricted(is_restricted), is_motorway(is_motorway), is_link(is_link), : is_restricted(is_restricted), is_motorway(is_motorway), is_link(is_link),
number_of_lanes(number_of_lanes), number_of_lanes(number_of_lanes),
highway_turn_classification(highway_turn_classification), highway_turn_classification(highway_turn_classification),
access_turn_classification(access_turn_classification), speed(speed), access_turn_classification(access_turn_classification), speed(speed),
is_incoming(is_incoming), is_outgoing(is_outgoing) priority_class(priority_class), is_incoming(is_incoming), is_outgoing(is_outgoing)
{ {
} }
@ -38,6 +40,7 @@ struct ExtractionTurnLeg
const int highway_turn_classification; const int highway_turn_classification;
const int access_turn_classification; const int access_turn_classification;
const int speed; const int speed;
const RoadPriorityClass::Enum priority_class;
const bool is_incoming; const bool is_incoming;
const bool is_outgoing; const bool is_outgoing;
}; };
@ -53,11 +56,12 @@ struct ExtractionTurn
TravelMode source_mode, TravelMode source_mode,
bool source_is_motorway, bool source_is_motorway,
bool source_is_link, bool source_is_link,
int source_number_of_lanes, int source_number_of_lanes,
int source_highway_turn_classification, int source_highway_turn_classification,
int source_access_turn_classification, int source_access_turn_classification,
int source_speed, int source_speed,
RoadPriorityClass::Enum source_priority_class,
bool target_restricted, bool target_restricted,
TravelMode target_mode, TravelMode target_mode,
bool target_is_motorway, bool target_is_motorway,
@ -66,6 +70,8 @@ struct ExtractionTurn
int target_highway_turn_classification, int target_highway_turn_classification,
int target_access_turn_classification, int target_access_turn_classification,
int target_speed, int target_speed,
RoadPriorityClass::Enum target_priority_class,
const std::vector<ExtractionTurnLeg> &roads_on_the_right, const std::vector<ExtractionTurnLeg> &roads_on_the_right,
const std::vector<ExtractionTurnLeg> &roads_on_the_left) const std::vector<ExtractionTurnLeg> &roads_on_the_left)
: angle(180. - angle), number_of_roads(number_of_roads), is_u_turn(is_u_turn), : angle(180. - angle), number_of_roads(number_of_roads), is_u_turn(is_u_turn),
@ -76,14 +82,14 @@ struct ExtractionTurn
source_number_of_lanes(source_number_of_lanes), source_number_of_lanes(source_number_of_lanes),
source_highway_turn_classification(source_highway_turn_classification), source_highway_turn_classification(source_highway_turn_classification),
source_access_turn_classification(source_access_turn_classification), source_access_turn_classification(source_access_turn_classification),
source_speed(source_speed), source_speed(source_speed), source_priority_class(source_priority_class),
target_restricted(target_restricted), target_mode(target_mode), target_restricted(target_restricted), target_mode(target_mode),
target_is_motorway(target_is_motorway), target_is_link(target_is_link), target_is_motorway(target_is_motorway), target_is_link(target_is_link),
target_number_of_lanes(target_number_of_lanes), target_number_of_lanes(target_number_of_lanes),
target_highway_turn_classification(target_highway_turn_classification), target_highway_turn_classification(target_highway_turn_classification),
target_access_turn_classification(target_access_turn_classification), target_access_turn_classification(target_access_turn_classification),
target_speed(target_speed), target_speed(target_speed), target_priority_class(target_priority_class),
roads_on_the_right(roads_on_the_right), roads_on_the_left(roads_on_the_left), weight(0.), roads_on_the_right(roads_on_the_right), roads_on_the_left(roads_on_the_left), weight(0.),
duration(0.) duration(0.)
@ -105,6 +111,7 @@ struct ExtractionTurn
const int source_highway_turn_classification; const int source_highway_turn_classification;
const int source_access_turn_classification; const int source_access_turn_classification;
const int source_speed; const int source_speed;
const RoadPriorityClass::Enum source_priority_class;
// target info // target info
const bool target_restricted; const bool target_restricted;
@ -115,6 +122,7 @@ struct ExtractionTurn
const int target_highway_turn_classification; const int target_highway_turn_classification;
const int target_access_turn_classification; const int target_access_turn_classification;
const int target_speed; const int target_speed;
const RoadPriorityClass::Enum target_priority_class;
const std::vector<ExtractionTurnLeg> roads_on_the_right; const std::vector<ExtractionTurnLeg> roads_on_the_right;
const std::vector<ExtractionTurnLeg> roads_on_the_left; const std::vector<ExtractionTurnLeg> roads_on_the_left;

View File

@ -585,6 +585,7 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
((double)intersection::findEdgeLength(edge_geometries, node_based_edge_from) / ((double)intersection::findEdgeLength(edge_geometries, node_based_edge_from) /
edge_data1.duration) * edge_data1.duration) *
36, 36,
edge_data1.flags.road_classification.GetPriority(),
// target info // target info
edge_data2.flags.restricted, edge_data2.flags.restricted,
m_edge_based_node_container.GetAnnotation(edge_data2.annotation_data).travel_mode, m_edge_based_node_container.GetAnnotation(edge_data2.annotation_data).travel_mode,
@ -596,6 +597,7 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
((double)intersection::findEdgeLength(edge_geometries, node_based_edge_to) / ((double)intersection::findEdgeLength(edge_geometries, node_based_edge_to) /
edge_data2.duration) * edge_data2.duration) *
36, 36,
edge_data2.flags.road_classification.GetPriority(),
// connected roads // connected roads
road_legs_on_the_right, road_legs_on_the_right,
road_legs_on_the_left); road_legs_on_the_left);
@ -763,6 +765,7 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
connected_edge.eid) / connected_edge.eid) /
edge_data.duration) * edge_data.duration) *
36, 36,
edge_data.flags.road_classification.GetPriority(),
!connected_edge.entry_allowed || !connected_edge.entry_allowed ||
(edge_data.flags.forward && (edge_data.flags.forward &&
edge_data.flags.backward), // is incoming edge_data.flags.backward), // is incoming

View File

@ -235,6 +235,7 @@ void GraphCompressor::Compress(
0, 0,
0, 0,
0, 0,
0,
false, false,
TRAVEL_MODE_DRIVING, TRAVEL_MODE_DRIVING,
false, false,
@ -243,6 +244,7 @@ void GraphCompressor::Compress(
0, 0,
0, 0,
0, 0,
0,
roads_on_the_right, roads_on_the_right,
roads_on_the_left); roads_on_the_left);
scripting_environment.ProcessTurn(extraction_turn); scripting_environment.ProcessTurn(extraction_turn);

View File

@ -692,6 +692,8 @@ void Sol2ScriptingEnvironment::InitContext(LuaScriptingContext &context)
&ExtractionTurnLeg::access_turn_classification, &ExtractionTurnLeg::access_turn_classification,
"speed", "speed",
&ExtractionTurnLeg::speed, &ExtractionTurnLeg::speed,
"priority_class",
&ExtractionTurnLeg::priority_class,
"is_incoming", "is_incoming",
&ExtractionTurnLeg::is_incoming, &ExtractionTurnLeg::is_incoming,
"is_outgoing", "is_outgoing",
@ -726,6 +728,8 @@ void Sol2ScriptingEnvironment::InitContext(LuaScriptingContext &context)
&ExtractionTurn::source_access_turn_classification, &ExtractionTurn::source_access_turn_classification,
"source_speed", "source_speed",
&ExtractionTurn::source_speed, &ExtractionTurn::source_speed,
"source_priority_class",
&ExtractionTurn::source_priority_class,
"target_restricted", "target_restricted",
&ExtractionTurn::target_restricted, &ExtractionTurn::target_restricted,
@ -743,6 +747,8 @@ void Sol2ScriptingEnvironment::InitContext(LuaScriptingContext &context)
&ExtractionTurn::target_access_turn_classification, &ExtractionTurn::target_access_turn_classification,
"target_speed", "target_speed",
&ExtractionTurn::target_speed, &ExtractionTurn::target_speed,
"target_priority_class",
&ExtractionTurn::target_priority_class,
"roads_on_the_right", "roads_on_the_right",
&ExtractionTurn::roads_on_the_right, &ExtractionTurn::roads_on_the_right,