Skip to content

feat(profiles): handle priority=forward/backward way tag in car profile#7541

Open
DennisOSRM wants to merge 2 commits intomasterfrom
priority_tag
Open

feat(profiles): handle priority=forward/backward way tag in car profile#7541
DennisOSRM wants to merge 2 commits intomasterfrom
priority_tag

Conversation

@DennisOSRM
Copy link
Copy Markdown
Collaborator

Summary

Closes #4387.

Adds support for the OSM priority=* tag in the car profile. This tag records the right-of-way direction on narrow road sections, allowing routing algorithms to account for the delay a driver faces when travelling against the priority direction (e.g. having to yield or slow down).

Functional change

New config knob – priority_penalty (default 0.7)

Added to profiles/car.lua. Controls how much the non-priority direction is penalised relative to the priority direction. A value of 0.7 means the routing weight for the disadvantaged direction is multiplied by 0.7× (making it less attractive).

Tag handling – WayHandlers.penalties()

profiles/lib/way_handlers.lua now reads the priority key from each way:

Tag value Effect
priority=forward backward direction gets priority_penalty multiplied into its weight/speed rate
priority=backward forward direction gets priority_penalty multiplied
(absent / other) no change – both directions unaffected

The penalty is applied via math.min() alongside the existing service, width, alternating, and sideroad penalties, so it stacks correctly with other factors without exceeding a 1.0× factor.

Profiles that do not set profile.priority_penalty are unaffected (guarded by a nil check).

taginfo.json

Documents the two new tag values (priority=forward and priority=backward) so they appear in the taginfo registry.

Tests

Added features/car/priority.feature with two Cucumber scenarios:

  1. Directional penalty is applied to the non-priority direction on bidirectional roads.
  2. On oneways the penalty correctly targets the single permitted direction.

Implements support for the OSM `priority=*` tag (closes #4387).
When a way is tagged `priority=forward` the backward direction receives
a configurable speed/weight penalty (default 0.7×); `priority=backward`
applies the same penalty to the forward direction.

Changes:
- profiles/car.lua: add `priority_penalty = 0.7` config knob
- profiles/lib/way_handlers.lua: read `priority` tag and apply
  per-direction penalty inside WayHandlers.penalties()
- taginfo.json: document the two new priority tag values

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 7, 2026 18:31

This comment was marked as outdated.

- Remove inaccurate 'narrow roads' qualifier from priority_penalty comment;
  the penalty applies to any way tagged priority=forward/backward regardless
  of road width
- Fix misleading scenario title: penalty does apply to oneways when the
  permitted direction lacks priority, rename accordingly
- Fix feature file description that incorrectly said 'narrow sections'

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment on lines +451 to 455
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 thread profiles/car.lua
Comment on lines +45 to +46
-- Penalty multiplier for the non-priority direction on ways tagged priority=forward/backward
priority_penalty = 0.7,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handle priority= way tag to scale forward or backward weight and speed

2 participants