Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Road Priorities: Stop Signs, Give Ways #3009

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion include/extractor/extraction_node.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef EXTRACTION_NODE_HPP
#define EXTRACTION_NODE_HPP

#include <cstdint>

namespace osrm
{
namespace extractor
Expand All @@ -9,7 +11,13 @@ namespace extractor
struct ExtractionNode
{
ExtractionNode() : traffic_lights(false), barrier(false) {}
void clear() { traffic_lights = barrier = false; }

void clear()
{
traffic_lights = false;
barrier = false;
}

bool traffic_lights;
bool barrier;
};
Expand Down
4 changes: 4 additions & 0 deletions include/extractor/extraction_way.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ struct ExtractionWay
duration = -1;
roundabout = false;
is_startpoint = true;
is_priority_road_forward = false;
is_priority_road_backward = false;
is_access_restricted = false;
name.clear();
ref.clear();
Expand Down Expand Up @@ -62,6 +64,8 @@ struct ExtractionWay
bool roundabout;
bool is_access_restricted;
bool is_startpoint;
bool is_priority_road_forward;
bool is_priority_road_backward;
TravelMode forward_travel_mode : 4;
TravelMode backward_travel_mode : 4;
guidance::RoadClassification road_classification;
Expand Down
10 changes: 10 additions & 0 deletions include/extractor/internal_extractor_edge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ struct InternalExtractorEdge
false,
false,
true,
false, // road_priority_forward
false, // road_priority_backward
TRAVEL_MODE_INACCESSIBLE,
false,
guidance::TurnLaneType::empty,
Expand All @@ -64,6 +66,8 @@ struct InternalExtractorEdge
bool roundabout,
bool access_restricted,
bool startpoint,
bool road_priority_forward,
bool road_priority_backward,
TravelMode travel_mode,
bool is_split,
LaneDescriptionID lane_description,
Expand All @@ -77,6 +81,8 @@ struct InternalExtractorEdge
roundabout,
access_restricted,
startpoint,
road_priority_forward,
road_priority_backward,
travel_mode,
is_split,
lane_description,
Expand Down Expand Up @@ -104,6 +110,8 @@ struct InternalExtractorEdge
false,
false,
true,
false, // road_priority_forward
false, // road_priority_backward
TRAVEL_MODE_INACCESSIBLE,
false,
INVALID_LANE_DESCRIPTIONID,
Expand All @@ -120,6 +128,8 @@ struct InternalExtractorEdge
false,
false,
true,
false, // road_priority_forward
false, // road_priority_backward
TRAVEL_MODE_INACCESSIBLE,
false,
INVALID_LANE_DESCRIPTIONID,
Expand Down
18 changes: 16 additions & 2 deletions include/extractor/node_based_edge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ struct NodeBasedEdge
bool roundabout,
bool access_restricted,
bool startpoint,
bool priority_road_forward,
bool priority_road_backward,
TravelMode travel_mode,
bool is_split,
const LaneDescriptionID lane_description_id,
Expand All @@ -40,6 +42,8 @@ struct NodeBasedEdge
bool roundabout : 1;
bool access_restricted : 1;
bool startpoint : 1;
bool priority_road_forward : 1;
bool priority_road_backward : 1;
bool is_split : 1;
TravelMode travel_mode : 4;
LaneDescriptionID lane_description_id;
Expand All @@ -57,6 +61,8 @@ struct NodeBasedEdgeWithOSM : NodeBasedEdge
bool roundabout,
bool access_restricted,
bool startpoint,
bool priority_road_forward,
bool priority_road_backward,
TravelMode travel_mode,
bool is_split,
const LaneDescriptionID lane_description_id,
Expand All @@ -71,7 +77,8 @@ struct NodeBasedEdgeWithOSM : NodeBasedEdge
inline NodeBasedEdge::NodeBasedEdge()
: source(SPECIAL_NODEID), target(SPECIAL_NODEID), name_id(0), weight(0), forward(false),
backward(false), roundabout(false), access_restricted(false), startpoint(true),
is_split(false), travel_mode(false), lane_description_id(INVALID_LANE_DESCRIPTIONID)
priority_road_forward(false), priority_road_backward(false), is_split(false),
travel_mode(false), lane_description_id(INVALID_LANE_DESCRIPTIONID)
{
}

Expand All @@ -84,13 +91,16 @@ inline NodeBasedEdge::NodeBasedEdge(NodeID source,
bool roundabout,
bool access_restricted,
bool startpoint,
bool priority_road_forward,
bool priority_road_backward,
TravelMode travel_mode,
bool is_split,
const LaneDescriptionID lane_description_id,
guidance::RoadClassification road_classification)
: source(source), target(target), name_id(name_id), weight(weight), forward(forward),
backward(backward), roundabout(roundabout), access_restricted(access_restricted),
startpoint(startpoint), is_split(is_split), travel_mode(travel_mode),
startpoint(startpoint), priority_road_forward(priority_road_forward),
priority_road_backward(priority_road_backward), is_split(is_split), travel_mode(travel_mode),
lane_description_id(lane_description_id), road_classification(std::move(road_classification))
{
}
Expand Down Expand Up @@ -121,6 +131,8 @@ inline NodeBasedEdgeWithOSM::NodeBasedEdgeWithOSM(OSMNodeID source,
bool roundabout,
bool access_restricted,
bool startpoint,
bool priority_road_forward,
bool priority_road_backward,
TravelMode travel_mode,
bool is_split,
const LaneDescriptionID lane_description_id,
Expand All @@ -134,6 +146,8 @@ inline NodeBasedEdgeWithOSM::NodeBasedEdgeWithOSM(OSMNodeID source,
roundabout,
access_restricted,
startpoint,
priority_road_forward,
priority_road_backward,
travel_mode,
is_split,
lane_description_id,
Expand Down
15 changes: 13 additions & 2 deletions include/util/node_based_graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@ struct NodeBasedEdgeData
bool reversed,
bool roundabout,
bool startpoint,
bool priority_road_forward,
bool priority_road_backward,
extractor::TravelMode travel_mode,
const LaneDescriptionID lane_description_id)
: distance(distance), edge_id(edge_id), name_id(name_id),
access_restricted(access_restricted), reversed(reversed), roundabout(roundabout),
startpoint(startpoint), travel_mode(travel_mode), lane_description_id(lane_description_id)
startpoint(startpoint), priority_road_forward(priority_road_forward),
priority_road_backward(priority_road_backward), travel_mode(travel_mode),
lane_description_id(lane_description_id)
{
}

Expand All @@ -47,14 +51,19 @@ struct NodeBasedEdgeData
bool reversed : 1;
bool roundabout : 1;
bool startpoint : 1;
bool priority_road_forward : 1;
bool priority_road_backward : 1;
extractor::TravelMode travel_mode : 4;
LaneDescriptionID lane_description_id;
extractor::guidance::RoadClassification road_classification;

bool IsCompatibleTo(const NodeBasedEdgeData &other) const
{
return (reversed == other.reversed) && (roundabout == other.roundabout) &&
(startpoint == other.startpoint) && (access_restricted == other.access_restricted) &&
(startpoint == other.startpoint) &&
(priority_road_forward == other.priority_road_forward) &&
(priority_road_backward == other.priority_road_backward) &&
(access_restricted == other.access_restricted) &&
(travel_mode == other.travel_mode) &&
(road_classification == other.road_classification);
}
Expand Down Expand Up @@ -86,6 +95,8 @@ NodeBasedDynamicGraphFromEdges(NodeID number_of_nodes,
output_edge.data.access_restricted = input_edge.access_restricted;
output_edge.data.travel_mode = input_edge.travel_mode;
output_edge.data.startpoint = input_edge.startpoint;
output_edge.data.priority_road_forward = input_edge.priority_road_forward;
output_edge.data.priority_road_backward = input_edge.priority_road_backward;
output_edge.data.road_classification = input_edge.road_classification;
output_edge.data.lane_description_id = input_edge.lane_description_id;
});
Expand Down
58 changes: 44 additions & 14 deletions profiles/car.lua
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,16 @@ function way_function (way, result)
return
end

local oneway = way:get_value_by_key("oneway")
local oneway_reverse = oneway and oneway == "-1"

-- Reversible oneways change direction with low frequency (think twice a day):
-- do not route over these at all at the moment because of time dependence.
-- Note: alternating (high frequency) oneways are handled below with penalty.
if oneway and "reversible" == oneway then
return
end

-- default to driving mode, may get overwritten below
result.forward_mode = mode.driving
result.backward_mode = mode.driving
Expand All @@ -251,6 +261,37 @@ function way_function (way, result)
return
end

-- priority roads, signposted or not
local priority_road = way:get_value_by_key("priority_road")
local priority_road_forward = way:get_value_by_key("priority_road:forward")
local priority_road_backward = way:get_value_by_key("priority_road:backward")

if priority_road and ("designated" == priority_road or "yes_unposted" == priority_road) then
if oneway_reverse then
way.is_priority_road_backward = true
else
way.is_priority_road_forward = true
end
end

if priority_road_forward and ("designated" == priority_road_forward or "yes_unposted" == priority_road_forward) then
if oneway_reverse then
way.is_priority_road_backward = true
else
way.is_priority_road_forward = true
end
end

if priority_road_backward and ("designated" == priority_road_backward or "yes_unposted" == priority_road_backward) then
if oneway_reverse then
way.is_priority_road_forward = true
else
way.is_priority_road_backward = true
end
end
-- end priority roads


-- respect user-preference for HOV-only ways
if ignore_hov_ways then
local hov = way:get_value_by_key("hov")
Expand Down Expand Up @@ -284,19 +325,16 @@ function way_function (way, result)
and has_all_designated_hov_lanes(hov_lanes_backward)

-- forward/backward lane depend on a way's direction
local oneway = way:get_value_by_key("oneway")
local reverse = oneway and oneway == "-1"

if hov_all_designated or hov_all_designated_forward then
if reverse then
if oneway_reverse then
result.backward_mode = mode.inaccessible
else
result.forward_mode = mode.inaccessible
end
end

if hov_all_designated_backward then
if reverse then
if oneway_reverse then
result.forward_mode = mode.inaccessible
else
result.backward_mode = mode.inaccessible
Expand All @@ -311,14 +349,6 @@ function way_function (way, result)
return
end

-- Reversible oneways change direction with low frequency (think twice a day):
-- do not route over these at all at the moment because of time dependence.
-- Note: alternating (high frequency) oneways are handled below with penalty.
local oneway = way:get_value_by_key("oneway")
if oneway and "reversible" == oneway then
return
end

local impassable = way:get_value_by_key("impassable")
if impassable and "yes" == impassable then
return
Expand Down Expand Up @@ -497,7 +527,7 @@ function way_function (way, result)

-- Set direction according to tags on way
if obey_oneway then
if oneway == "-1" then
if oneway_reverse then
result.forward_mode = mode.inaccessible

local is_forward = false
Expand Down
7 changes: 7 additions & 0 deletions src/extractor/edge_based_graph_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,13 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
distance += profile_properties.traffic_signal_penalty;
}

// Success - if this compiles!
// TODO: Adapt GetTurnPenalty function and pass those flags on
(void)edge_data1.priority_road_forward;
(void)edge_data1.priority_road_backward;
(void)edge_data2.priority_road_forward;
(void)edge_data2.priority_road_backward;

const int32_t turn_penalty =
scripting_environment.GetTurnPenalty(180. - turn.angle);
const auto turn_instruction = turn.instruction;
Expand Down
6 changes: 6 additions & 0 deletions src/extractor/extractor_callbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti
parsed_way.roundabout,
parsed_way.is_access_restricted,
parsed_way.is_startpoint,
parsed_way.is_priority_road_forward,
parsed_way.is_priority_road_backward,
parsed_way.backward_travel_mode,
false,
turn_lane_id_backward,
Expand Down Expand Up @@ -361,6 +363,8 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti
parsed_way.roundabout,
parsed_way.is_access_restricted,
parsed_way.is_startpoint,
parsed_way.is_priority_road_forward,
parsed_way.is_priority_road_backward,
parsed_way.forward_travel_mode,
split_edge,
turn_lane_id_forward,
Expand All @@ -383,6 +387,8 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti
parsed_way.roundabout,
parsed_way.is_access_restricted,
parsed_way.is_startpoint,
parsed_way.is_priority_road_forward,
parsed_way.is_priority_road_backward,
parsed_way.backward_travel_mode,
true,
turn_lane_id_backward,
Expand Down
2 changes: 2 additions & 0 deletions src/extractor/scripting_environment_lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ void LuaScriptingEnvironment::InitContext(LuaScriptingContext &context)
.def_readwrite("roundabout", &ExtractionWay::roundabout)
.def_readwrite("is_access_restricted", &ExtractionWay::is_access_restricted)
.def_readwrite("is_startpoint", &ExtractionWay::is_startpoint)
.def_readwrite("is_priority_road_forward", &ExtractionWay::is_priority_road_forward)
.def_readwrite("is_priority_road_backward", &ExtractionWay::is_priority_road_backward)
.def_readwrite("duration", &ExtractionWay::duration)
.def_readwrite("turn_lanes_forward", &ExtractionWay::turn_lanes_forward)
.def_readwrite("turn_lanes_backward", &ExtractionWay::turn_lanes_backward)
Expand Down