Skip to content
24 changes: 24 additions & 0 deletions features/car/priority.feature
Original file line number Diff line number Diff line change
@@ -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 |
3 changes: 3 additions & 0 deletions profiles/car.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 13 additions & 2 deletions profiles/lib/way_handlers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines +454 to 458
Expand Down
2 changes: 2 additions & 0 deletions taginfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
Loading