diff --git a/features/car/priority.feature b/features/car/priority.feature new file mode 100644 index 0000000000..ea8d3e659e --- /dev/null +++ b/features/car/priority.feature @@ -0,0 +1,24 @@ +@routing @priority @car +Feature: Car - Priority tag handling +The priority tag indicates traffic right-of-way direction on a way. +priority=forward means forward traffic has right-of-way, penalizing backward. +priority=backward means backward traffic has right-of-way, penalizing forward. + + Background: Use specific speeds + Given the profile "car" + Given a grid size of 1000 meters + + Scenario: Car - Priority tag applies directional penalty + Then routability should be + | highway | maxspeed | priority | forw | backw | forw_rate | backw_rate | + | primary | 60 | | 48 km/h | 48 km/h | 13.3 | 13.3 | + | primary | 60 | forward | 48 km/h | 48 km/h | 13.3 | 9.3 | + | primary | 60 | backward | 48 km/h | 48 km/h | 9.3 | 13.3 | + + Scenario: Car - Priority penalty applies to the permitted direction on oneways when it lacks priority + Then routability should be + | highway | maxspeed | priority | oneway | forw | backw | forw_rate | backw_rate | + | primary | 60 | forward | yes | 48 km/h | | 13.3 | | + | primary | 60 | backward | yes | 48 km/h | | 9.3 | | + | primary | 60 | forward | -1 | | 48 km/h | | 9.3 | + | primary | 60 | backward | -1 | | 48 km/h | | 13.3 | diff --git a/profiles/car.lua b/profiles/car.lua index ebbc77d143..f165a60351 100644 --- a/profiles/car.lua +++ b/profiles/car.lua @@ -42,6 +42,9 @@ function setup() -- Applied to bidirectional roads to prefer roads with clear lane markings lane_markings_penalty = 0.75, + -- Penalty multiplier for the non-priority direction on ways tagged priority=forward/backward + priority_penalty = 0.7, + -- Size of the vehicle, to be limited by physical restriction of the way vehicle_height = 2.0, -- in meters, 2.0m is the height slightly above biggest SUVs vehicle_width = 1.9, -- in meters, ways with narrow tag are considered narrower than 2.2m diff --git a/profiles/lib/way_handlers.lua b/profiles/lib/way_handlers.lua index f6809ed282..02b6e2de12 100644 --- a/profiles/lib/way_handlers.lua +++ b/profiles/lib/way_handlers.lua @@ -437,8 +437,19 @@ function WayHandlers.penalties(profile,way,result,data) sideroad_penalty = profile.side_road_multiplier end - local forward_penalty = math.min(service_penalty, width_penalty, alternating_penalty, sideroad_penalty) - local backward_penalty = math.min(service_penalty, width_penalty, alternating_penalty, sideroad_penalty) + local priority_forward_penalty = 1.0 + local priority_backward_penalty = 1.0 + if profile.priority_penalty then + local priority = way:get_value_by_key("priority") + if priority == "forward" then + priority_backward_penalty = profile.priority_penalty + elseif priority == "backward" then + priority_forward_penalty = profile.priority_penalty + end + end + + local forward_penalty = math.min(service_penalty, width_penalty, alternating_penalty, sideroad_penalty, priority_forward_penalty) + local backward_penalty = math.min(service_penalty, width_penalty, alternating_penalty, sideroad_penalty, priority_backward_penalty) if profile.properties.weight_name == 'routability' then if result.forward_speed > 0 then diff --git a/taginfo.json b/taginfo.json index 8783d83597..d167106026 100644 --- a/taginfo.json +++ b/taginfo.json @@ -258,6 +258,8 @@ {"key": "lanes:forward", "description": "Lanes in forward direction"}, {"key": "lanes:backward", "description": "Lanes in backward direction"}, {"key": "lane_markings", "value": "no", "description": "Penalty for roads without lane markings on bidirectional streets"}, + {"key": "priority", "value": "forward", "object_types": ["way"], "description": "Traffic priority in forward direction; non-priority direction gets a penalty"}, + {"key": "priority", "value": "backward", "object_types": ["way"], "description": "Traffic priority in backward direction; non-priority direction gets a penalty"}, {"key": "surface", "value": "asphalt"}, {"key": "surface", "value": "concrete"}, {"key": "surface", "value": "concrete:plates"},