Skip to content

Commit

Permalink
Merge pull request #1534 from Project-OSRM/profile/lane-penalty
Browse files Browse the repository at this point in the history
Profile/lane penalty
  • Loading branch information
TheMarex committed Jun 18, 2015
2 parents ce152b2 + 1445f11 commit bbe1211
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
19 changes: 19 additions & 0 deletions features/car/maxspeed.feature
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,22 @@ OSRM will use 4/5 of the projected free-flow speed.
| primary | 15 | | 30 | 60 | 34 km/h | 59 km/h |
| primary | 15 | 3 | 30 | 60 | 15 km/h | 30 km/h |

Scenario: Car - Single lane streets be ignored or incur a penalty
Then routability should be

| highway | maxspeed | lanes | maxspeed:forward | maxspeed:backward | forw | backw |
| primary | | | | | 63 km/h | 63 km/h |
| primary | | 1 | | | 32 km/h | 32 km/h |
| primary | 60 | | | | 59 km/h | 59 km/h |
| primary | 60 | 1 | | | 30 km/h | 30 km/h |
| primary | | | 60 | | 59 km/h | 63 km/h |
| primary | | 1 | 60 | | 30 km/h | 32 km/h |
| primary | | | | 60 | 63 km/h | 59 km/h |
| primary | | 1 | | 60 | 32 km/h | 30 km/h |
| primary | 15 | | 60 | | 59 km/h | 23 km/h |
| primary | 15 | 1 | 60 | | 30 km/h | 7 km/h |
| primary | 15 | | | 60 | 23 km/h | 59 km/h |
| primary | 15 | 1 | | 60 | 7 km/h | 30 km/h |
| primary | 15 | | 30 | 60 | 34 km/h | 59 km/h |
| primary | 15 | 1 | 30 | 60 | 15 km/h | 30 km/h |

23 changes: 15 additions & 8 deletions profiles/car.lua
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,6 @@ function way_function (way, result)
return
end

local width = math.huge
local width_string = way:get_value_by_key("width")
if width_string and tonumber(width_string:match("%d*")) then
width = tonumber(width_string:match("%d*"))
end

-- Check if we are allowed to access the way
local access = find_access_tag(way, access_tags_hierachy)
if access_tag_blacklist[access] then
Expand Down Expand Up @@ -404,12 +398,25 @@ function way_function (way, result)
result.ignore_in_grid = true
end

local width = math.huge
local lanes = math.huge
if result.forward_speed > 0 or result.backward_speed > 0 then
local width_string = way:get_value_by_key("width")
if width_string and tonumber(width_string:match("%d*")) then
width = tonumber(width_string:match("%d*"))
end

local lanes_string = way:get_value_by_key("lanes")
if lanes_string and tonumber(lanes_string:match("%d*")) then
lanes = tonumber(lanes_string:match("%d*"))
end
end

-- scale speeds to get better avg driving times
if result.forward_speed > 0 then
local scaled_speed = result.forward_speed*speed_reduction + 11;
local penalized_speed = math.huge
if width <= 3 then
if width <= 3 or lanes <= 1 then
penalized_speed = result.forward_speed / 2;
end
result.forward_speed = math.min(penalized_speed, scaled_speed)
Expand All @@ -418,7 +425,7 @@ function way_function (way, result)
if result.backward_speed > 0 then
local scaled_speed = result.backward_speed*speed_reduction + 11;
local penalized_speed = math.huge
if width <= 3 then
if width <= 3 or lanes <= 1 then
penalized_speed = result.backward_speed / 2;
end
result.backward_speed = math.min(penalized_speed, scaled_speed)
Expand Down

0 comments on commit bbe1211

Please sign in to comment.