Skip to content

Add configurable lane_markings=no penalty to car profile#7409

Merged
DennisOSRM merged 2 commits intomasterfrom
claude/update-car-profile-lane-markings
Mar 13, 2026
Merged

Add configurable lane_markings=no penalty to car profile#7409
DennisOSRM merged 2 commits intomasterfrom
claude/update-car-profile-lane-markings

Conversation

@Claude
Copy link
Copy Markdown
Contributor

@Claude Claude AI commented Mar 8, 2026

Implements penalty for roads tagged with lane_markings=no to reduce routing preference for narrow streets without clear lane markings. Addresses request to avoid rat-run roads while applying a lighter penalty (0.75×) than the existing single-lane penalty (0.5×).

Implementation

  • Profile parameter: Added lane_markings_penalty = 0.75 to car.lua as globally configurable multiplier
  • Penalty logic: Extended WayHandlers.penalties() to check lane_markings=no tag and apply penalty only to bidirectional roads
  • Tag documentation: Added lane_markings entry to taginfo.json
  • Test coverage: Added 4 cucumber test scenarios (22 test cases) covering:
    • Basic penalty behavior with various maxspeed configurations
    • Directional constraints (bidirectional vs oneway)
    • Interaction with existing width and single-lane penalties

Behavior

-- profiles/car.lua
lane_markings_penalty = 0.75  -- Configurable multiplier

-- Applied in way_handlers.lua when:
-- 1. lane_markings=no tag is present
-- 2. Road is bidirectional
-- 3. No more restrictive penalty applies (width ≤ 3m or lanes ≤ 1)

Example routing impact on primary road (65 km/h base):

  • Without penalty: rate = 18.1 m/s
  • With lane_markings=no: rate = 13.5 m/s (0.75× multiplier)
  • With width=3 or lanes=1: rate = 9.0 m/s (0.5× multiplier takes precedence)

The penalty integrates with the existing penalty system via math.min(), ensuring the most restrictive penalty always applies.

Original prompt

This section details on the original issue you should resolve

<issue_title>car profile use lane_markings=no as indicator for narrow street</issue_title>
<issue_description>Hi,
i use OSRM for Routing quality assurance in a part of Germany since 2013. I typically find unwanted Rat Race roads and changes in routing over time done by accident e.g. broken turn restrictions, deleted segments etc.

I typically tune the relative weight between roads by tagging maxspeed and lanes. E.g. the smaller rural roads get lane count 1 if they are to narrow for overtaking.

In the end this is not a 100% correct as most of the time there are no lane markings so noone could actualy count the lanes. Still they are narrow.

The OSRM car profile uses the lane count to reduce the assumed speed by half based on maxspeed or road type.

I would suggest doing something similiar when looking at the tag/value lane_markings=no

I'd like to reduce the speed not to 0.5 but something like 0.75 - just a smaller penalty.

Something like this. Just tested on real live data with ~50k routes and compared them with their originals and this looks pretty promising. Of 50K routes ~400 have changed. Most of them to the better e.g. avoiding small narrow roads for through traffic.

diff --git a/profiles/lib/way_handlers.lua b/profiles/lib/way_handlers.lua
index b13410235..5c3528d5d 100644
--- a/profiles/lib/way_handlers.lua
+++ b/profiles/lib/way_handlers.lua
@@ -397,6 +397,11 @@ function WayHandlers.penalties(profile,way,result,data)
   local is_bidirectional = result.forward_mode ~= mode.inaccessible and
                            result.backward_mode ~= mode.inaccessible
 
+  local lanemarkings = way:get_value_by_key("lane_markings")
+  if (lanemarkings and lanemarkings == 'no' and is_bidirectional) then
+    width_penalty = 0.75
+  end
+
   if width <= 3 or (lanes <= 1 and is_bidirectional) then
     width_penalty = 0.5
   end

Flo </issue_description>

<agent_instructions>Implement this feature request with a globally configurable parameter. Use the suggested 0.75 as a starting point. Update taginfo json and provide thorough test coverage for the feature in cucumber tests. </agent_instructions>

Comments on the Issue (you are @claude[agent] in this section)

- Add configurable lane_markings_penalty parameter (default 0.75)
- Implement penalty logic for bidirectional roads with lane_markings=no
- Document lane_markings tag in taginfo.json
- Add comprehensive cucumber tests for feature

Co-authored-by: DennisOSRM <1067895+DennisOSRM@users.noreply.github.com>
@Claude Claude AI changed the title [WIP] Update car profile to adjust speed for lane_markings=no Add configurable lane_markings=no penalty to car profile Mar 8, 2026
@DennisOSRM DennisOSRM marked this pull request as ready for review March 11, 2026 20:25
@DennisOSRM DennisOSRM merged commit 508dcd1 into master Mar 13, 2026
23 checks passed
@DennisOSRM DennisOSRM deleted the claude/update-car-profile-lane-markings branch March 13, 2026 07:05
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.

car profile use lane_markings=no as indicator for narrow street

2 participants