Skip to content

Commit

Permalink
Merge pull request #1478 from Project-OSRM/fix/profiles-cleanup
Browse files Browse the repository at this point in the history
Cleanup the profiles
  • Loading branch information
TheMarex committed May 17, 2015
2 parents dd33a45 + 074c7a9 commit 6d9c3bc
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 56 deletions.
100 changes: 53 additions & 47 deletions profiles/bicycle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ access_tags_hierachy = { "bicycle", "vehicle", "access" }
cycleway_tags = {["track"]=true,["lane"]=true,["opposite"]=true,["opposite_lane"]=true,["opposite_track"]=true,["share_busway"]=true,["sharrow"]=true,["shared"]=true }
service_tag_restricted = { ["parking_aisle"] = true }
restriction_exception_tags = { "bicycle", "vehicle", "access" }
unsafe_highway_list = { ["primary"] = true, ["secondary"] = true, ["tertiary"] = true, ["primary_link"] = true, ["secondary_link"] = true, ["tertiary_link"] = true}

default_speed = 15

walking_speed = 6
local default_speed = 15
local walking_speed = 6

bicycle_speeds = {
["cycleway"] = default_speed,
Expand Down Expand Up @@ -91,24 +91,27 @@ surface_speeds = {
["sand"] = 3
}

take_minimum_of_speeds = true
obey_oneway = true
obey_bollards = false
use_restrictions = true
ignore_areas = true -- future feature
traffic_signal_penalty = 5
u_turn_penalty = 20
use_turn_restrictions = false
turn_penalty = 60
turn_bias = 1.4

traffic_signal_penalty = 2
use_turn_restrictions = false

local obey_oneway = true
local obey_bollards = false
local ignore_areas = true
local u_turn_penalty = 20
local turn_penalty = 60
local turn_bias = 1.4
-- reduce the driving speed by 30% for unsafe roads
-- local safety_penalty = 0.7
local safety_penalty = 1.0
local use_public_transport = true
local fallback_names = true

--modes
mode_normal = 1
mode_pushing = 2
mode_ferry = 3
mode_train = 4
mode_movable_bridge = 5
local mode_normal = 1
local mode_pushing = 2
local mode_ferry = 3
local mode_train = 4
local mode_movable_bridge = 5

local function parse_maxspeed(source)
if not source then
Expand All @@ -131,29 +134,26 @@ function get_exceptions(vector)
end

function node_function (node, result)
local barrier = node:get_value_by_key("barrier")
-- parse access and barrier tags
local access = find_access_tag(node, access_tags_hierachy)
local traffic_signal = node:get_value_by_key("highway")

-- flag node if it carries a traffic light
if traffic_signal and traffic_signal == "traffic_signals" then
result.traffic_lights = true
end

-- parse access and barrier tags
if access and access ~= "" then
if access_tag_blacklist[access] then
result.barrier = true
else
result.barrier = false
end
elseif barrier and barrier ~= "" then
if barrier_whitelist[barrier] then
result.barrier = false
else
result.barrier = true
end
end
if access and access ~= "" then
if access_tag_blacklist[access] then
result.barrier = true
end
else
local barrier = node:get_value_by_key("barrier")
if barrier and "" ~= barrier then
if not barrier_whitelist[barrier] then
result.barrier = true
end
end
end

-- check if node is a traffic light
local tag = node:get_value_by_key("highway")
if tag and "traffic_signals" == tag then
result.traffic_lights = true;
end
end

function way_function (way, result)
Expand All @@ -166,8 +166,8 @@ function way_function (way, result)
local public_transport = way:get_value_by_key("public_transport")
local bridge = way:get_value_by_key("bridge")
if (not highway or highway == '') and
(not route or route == '') and
(not railway or railway=='') and
(not use_public_transport or not route or route == '') and
(not use_public_transport or not railway or railway=='') and
(not amenity or amenity=='') and
(not man_made or man_made=='') and
(not public_transport or public_transport=='') and
Expand Down Expand Up @@ -214,7 +214,8 @@ function way_function (way, result)
result.name = ref
elseif name and "" ~= name then
result.name = name
elseif highway then
-- TODO find a better solution for encoding way type
elseif fallback_names and highway then
-- if no name exists, use way type
-- this encoding scheme is excepted to be a temporary solution
result.name = "{highway:"..highway.."}"
Expand Down Expand Up @@ -247,15 +248,16 @@ function way_function (way, result)
result.forward_speed = route_speeds[route]
result.backward_speed = route_speeds[route]
end
elseif railway and platform_speeds[railway] then
-- public transport
elseif use_public_transport and railway and platform_speeds[railway] then
-- railway platforms (old tagging scheme)
result.forward_speed = platform_speeds[railway]
result.backward_speed = platform_speeds[railway]
elseif platform_speeds[public_transport] then
elseif use_public_transport and platform_speeds[public_transport] then
-- public_transport platforms (new tagging platform)
result.forward_speed = platform_speeds[public_transport]
result.backward_speed = platform_speeds[public_transport]
elseif railway and railway_speeds[railway] then
elseif use_public_transport and railway and railway_speeds[railway] then
result.forward_mode = mode_train
result.backward_mode = mode_train
-- railways
Expand All @@ -271,6 +273,10 @@ function way_function (way, result)
-- regular ways
result.forward_speed = bicycle_speeds[highway]
result.backward_speed = bicycle_speeds[highway]
if safety_penalty < 1 and unsafe_highway_list[highway] then
result.forward_speed = result.forward_speed * safety_penalty
result.backward_speed = result.backward_speed * safety_penalty
end
elseif access and access_tag_whitelist[access] then
-- unknown way, but valid access tag
result.forward_speed = default_speed
Expand Down
12 changes: 3 additions & 9 deletions profiles/car.lua
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,9 @@ maxspeed_table = {
traffic_signal_penalty = 2
use_turn_restrictions = true

local take_minimum_of_speeds = false
local obey_oneway = true
local obey_bollards = true
local ignore_areas = true -- future feature
local ignore_areas = true
local u_turn_penalty = 20

local abs = math.abs
Expand Down Expand Up @@ -179,6 +178,7 @@ local function parse_maxspeed(source)
return n
end

-- FIXME Why was this commented out?
-- function turn_function (angle)
-- -- print ("called at angle " .. angle )
-- local index = math.abs(math.floor(angle/10+0.5))+1 -- +1 'coz LUA starts as idx 1
Expand All @@ -190,7 +190,7 @@ end
function node_function (node, result)
-- parse access and barrier tags
local access = find_access_tag(node, access_tags_hierachy)
if access ~= "" then
if access and access ~= "" then
if access_tag_blacklist[access] then
result.barrier = true
end
Expand Down Expand Up @@ -420,9 +420,3 @@ function way_function (way, result)
end
end

-- These are wrappers to parse vectors of nodes and ways and thus to speed up any tracing JIT
function node_vector_function(vector)
for v in vector.nodes do
node_function(v)
end
end

0 comments on commit 6d9c3bc

Please sign in to comment.