Merge branch 'feature/opposite_direction' into develop

This commit is contained in:
DennisOSRM
2013-02-04 18:38:15 +01:00
38 changed files with 1048 additions and 629 deletions
+106 -61
View File
@@ -12,7 +12,9 @@ restriction_exception_tags = { "bicycle", "vehicle", "access" }
default_speed = 16
main_speeds = {
walking_speed = 4
bicycle_speeds = {
["cycleway"] = 18,
["primary"] = 17,
["primary_link"] = 17,
@@ -26,17 +28,14 @@ main_speeds = {
["road"] = 16,
["service"] = 16,
["track"] = 13,
["path"] = 13,
["footway"] = 12,
["pedestrian"] = 12,
["pier"] = 12,
["steps"] = 2
["path"] = 13
--["footway"] = 12,
--["pedestrian"] = 12,
}
pedestrian_speeds = {
["footway"] = 5,
["pedestrian"] = 5,
["pier"] = 5,
["footway"] = walking_speed,
["pedestrian"] = walking_speed,
["steps"] = 2
}
@@ -50,7 +49,7 @@ railway_speeds = {
}
platform_speeds = {
["platform"] = 5
["platform"] = walking_speed
}
amenity_speeds = {
@@ -58,6 +57,10 @@ amenity_speeds = {
["parking_entrance"] = 10
}
man_made_speeds = {
["pier"] = walking_speed
}
route_speeds = {
["ferry"] = 5
}
@@ -110,17 +113,38 @@ function way_function (way, numberOfNodesInWay)
if(numberOfNodesInWay < 2) then
return 0;
end
-- First, get the properties of each way that we come across
-- initial routability check, filters out buildings, boundaries, etc
local highway = way.tags:Find("highway")
local route = way.tags:Find("route")
local man_made = way.tags:Find("man_made")
local railway = way.tags:Find("railway")
local amenity = way.tags:Find("amenity")
local public_transport = way.tags:Find("public_transport")
if (not highway or highway == '') and
(not route or route == '') and
(not railway or railway=='') and
(not amenity or amenity=='') and
(not man_made or man_made=='') and
(not public_transport or public_transport=='')
then
return 0
end
-- access
local access = Access.find_access_tag(way, access_tags_hierachy)
if access_tag_blacklist[access] then
return 0
end
-- other tags
local name = way.tags:Find("name")
local ref = way.tags:Find("ref")
local junction = way.tags:Find("junction")
local route = way.tags:Find("route")
local railway = way.tags:Find("railway")
local public_transport = way.tags:Find("public_transport")
local maxspeed = parseMaxspeed(way.tags:Find ( "maxspeed") )
local man_made = way.tags:Find("man_made")
local maxspeed_forward = parseMaxspeed(way.tags:Find( "maxspeed:forward"))
local maxspeed_backward = parseMaxspeed(way.tags:Find( "maxspeed:backward"))
local barrier = way.tags:Find("barrier")
local oneway = way.tags:Find("oneway")
local onewayClass = way.tags:Find("oneway:bicycle")
@@ -130,23 +154,7 @@ function way_function (way, numberOfNodesInWay)
local duration = way.tags:Find("duration")
local service = way.tags:Find("service")
local area = way.tags:Find("area")
local amenity = way.tags:Find("amenity")
local access = Access.find_access_tag(way, access_tags_hierachy)
-- initial routability check, filters out buildings, boundaries, etc
if (not highway or highway == '') and
(not route or route == '') and
(not railway or railway=='') and
(not amenity or amenity=='') and
(not public_transport or public_transport=='')
then
return 0
end
-- access
if access_tag_blacklist[access] then
return 0
end
local foot = way.tags:Find("foot")
-- name
if "" ~= ref then
@@ -157,8 +165,9 @@ function way_function (way, numberOfNodesInWay)
way.name = highway -- if no name exists, use way type
end
-- speed
if route_speeds[route] then
-- ferries
-- ferries (doesn't cover routes tagged using relations)
way.direction = Way.bidirectional
way.ignore_in_grid = true
if durationIsValid(duration) then
@@ -178,34 +187,32 @@ function way_function (way, numberOfNodesInWay)
way.speed = railway_speeds[railway]
way.direction = Way.bidirectional
end
elseif pedestrian_speeds[highway] and main_speeds[highway] then
-- pedestrian areas
if access_tag_whitelist[access] then
way.speed = main_speeds[highway] -- biking
else
way.speed = pedestrian_speeds[highway] -- pushing bikes
end
elseif amenity and amenity_speeds[amenity] then
-- parking areas
way.speed = amenity_speeds[amenity]
else
elseif bicycle_speeds[highway] then
-- regular ways
if main_speeds[highway] then
way.speed = main_speeds[highway]
elseif main_speeds[man_made] then
way.speed = main_speeds[man_made]
elseif access_tag_whitelist[access] then
way.speed = default_speed
end
end
-- maxspeed
if take_minimum_of_speeds then
if maxspeed and maxspeed>0 then
way.speed = math.min(way.speed, maxspeed)
end
end
way.speed = bicycle_speeds[highway]
elseif access and access_tag_whitelist[access] then
-- unknown way, but valid access tag
way.speed = default_speed
else
-- biking not allowed, maybe we can push our bike?
-- essentially requires pedestrian profiling, for example foot=no mean we can't push a bike
-- TODO: if we can push, the way should be marked as pedestrion mode, but there's no way to do it yet from lua..
if foot ~= 'no' then
if pedestrian_speeds[highway] then
-- pedestrian-only ways and areas
way.speed = pedestrian_speeds[highway]
elseif man_made and man_made_speeds[man_made] then
-- man made structures
way.speed = man_made_speeds[man_made]
elseif foot == 'yes' then
way.speed = walking_speed
end
end
end
-- direction
way.direction = Way.bidirectional
local impliedOneway = false
@@ -248,15 +255,53 @@ function way_function (way, numberOfNodesInWay)
way.direction = Way.oneway
end
-- pushing bikes
if bicycle_speeds[highway] or pedestrian_speeds[highway] then
if foot ~= 'no' then
if way.direction == Way.oneway then
way.backward_speed = walking_speed
elseif way.direction == Way.opposite then
way.backward_speed = walking_speed
way.speed = way.speed
end
end
if way.backward_speed == way.speed then
-- TODO: no way yet to mark a way as pedestrian mode if forward/backward speeds are equal
way.direction = Way.bidirectional
end
end
-- cycleways
if cycleway and cycleway_tags[cycleway] then
way.speed = main_speeds["cycleway"]
way.speed = bicycle_speeds["cycleway"]
elseif cycleway_left and cycleway_tags[cycleway_left] then
way.speed = main_speeds["cycleway"]
way.speed = bicycle_speeds["cycleway"]
elseif cycleway_right and cycleway_tags[cycleway_right] then
way.speed = main_speeds["cycleway"]
way.speed = bicycle_speeds["cycleway"]
end
-- maxspeed
-- TODO: maxspeed of backward direction
if take_minimum_of_speeds then
if maxspeed and maxspeed>0 then
way.speed = math.min(way.speed, maxspeed)
end
end
-- Override speed settings if explicit forward/backward maxspeeds are given
if maxspeed_forward ~= nil and maxspeed_forward > 0 then
if Way.bidirectional == way.direction then
way.backward_speed = way.speed
end
way.speed = maxspeed_forward
end
if maxspeed_backward ~= nil and maxspeed_backward > 0 then
way.backward_speed = maxspeed_backward
end
way.type = 1
return 1
end
+156 -131
View File
@@ -12,24 +12,24 @@ ignore_in_grid = { ["ferry"] = true }
restriction_exception_tags = { "motorcar", "motor_vehicle", "vehicle" }
speed_profile = {
["motorway"] = 90,
["motorway_link"] = 75,
["trunk"] = 85,
["trunk_link"] = 70,
["primary"] = 65,
["primary_link"] = 60,
["secondary"] = 55,
["secondary_link"] = 50,
["tertiary"] = 40,
["tertiary_link"] = 30,
["unclassified"] = 25,
["residential"] = 25,
["living_street"] = 10,
["service"] = 15,
["motorway"] = 90,
["motorway_link"] = 75,
["trunk"] = 85,
["trunk_link"] = 70,
["primary"] = 65,
["primary_link"] = 60,
["secondary"] = 55,
["secondary_link"] = 50,
["tertiary"] = 40,
["tertiary_link"] = 30,
["unclassified"] = 25,
["residential"] = 25,
["living_street"] = 10,
["service"] = 15,
-- ["track"] = 5,
["ferry"] = 5,
["shuttle_train"] = 10,
["default"] = 50
["ferry"] = 5,
["shuttle_train"] = 10,
["default"] = 50
}
take_minimum_of_speeds = false
@@ -43,85 +43,101 @@ u_turn_penalty = 20
-- End of globals
function get_exceptions(vector)
for i,v in ipairs(restriction_exception_tags) do
vector:Add(v)
end
for i,v in ipairs(restriction_exception_tags) do
vector:Add(v)
end
end
local function parse_maxspeed(source)
if source == nil then
return 0
end
local n = tonumber(source:match("%d*"))
if n == nil then
n = 0
end
if string.match(source, "mph") or string.match(source, "mp/h") then
n = (n*1609)/1000;
end
return math.abs(n)
end
function node_function (node)
local barrier = node.tags:Find ("barrier")
local access = Access.find_access_tag(node, access_tags_hierachy)
local traffic_signal = node.tags:Find("highway")
--flag node if it carries a traffic light
if traffic_signal == "traffic_signals" then
node.traffic_light = true;
end
-- parse access and barrier tags
if access and access ~= "" then
if access_tag_blacklist[access] then
node.bollard = true
end
elseif barrier and barrier ~= "" then
if barrier_whitelist[barrier] then
return
else
node.bollard = true
end
local barrier = node.tags:Find ("barrier")
local access = Access.find_access_tag(node, access_tags_hierachy)
local traffic_signal = node.tags:Find("highway")
--flag node if it carries a traffic light
if traffic_signal == "traffic_signals" then
node.traffic_light = true;
end
return 1
-- parse access and barrier tags
if access and access ~= "" then
if access_tag_blacklist[access] then
node.bollard = true
end
elseif barrier and barrier ~= "" then
if barrier_whitelist[barrier] then
return
else
node.bollard = true
end
end
return 1
end
function way_function (way, numberOfNodesInWay)
-- A way must have two nodes or more
if(numberOfNodesInWay < 2) then
return 0;
end
-- First, get the properties of each way that we come across
local highway = way.tags:Find("highway")
local name = way.tags:Find("name")
local ref = way.tags:Find("ref")
local junction = way.tags:Find("junction")
local route = way.tags:Find("route")
local maxspeed = parseMaxspeed(way.tags:Find ( "maxspeed") )
local barrier = way.tags:Find("barrier")
local oneway = way.tags:Find("oneway")
local cycleway = way.tags:Find("cycleway")
local duration = way.tags:Find("duration")
local service = way.tags:Find("service")
local area = way.tags:Find("area")
local access = Access.find_access_tag(way, access_tags_hierachy)
-- Second, parse the way according to these properties
if ignore_areas and ("yes" == area) then
return 0
end
-- Check if we are allowed to access the way
if access_tag_blacklist[access] then
return 0
end
-- Set the name that will be used for instructions
if "" ~= ref then
way.name = ref
elseif "" ~= name then
way.name = name
-- else
-- way.name = highway -- if no name exists, use way type
-- A way must have two nodes or more
if(numberOfNodesInWay < 2) then
return 0;
end
if "roundabout" == junction then
way.roundabout = true;
end
-- First, get the properties of each way that we come across
local highway = way.tags:Find("highway")
local name = way.tags:Find("name")
local ref = way.tags:Find("ref")
local junction = way.tags:Find("junction")
local route = way.tags:Find("route")
local maxspeed = parse_maxspeed(way.tags:Find ( "maxspeed") )
local maxspeed_forward = tonumber(way.tags:Find( "maxspeed:forward"))
local maxspeed_backward = tonumber(way.tags:Find( "maxspeed:backward"))
local barrier = way.tags:Find("barrier")
local oneway = way.tags:Find("oneway")
local cycleway = way.tags:Find("cycleway")
local duration = way.tags:Find("duration")
local service = way.tags:Find("service")
local area = way.tags:Find("area")
local access = Access.find_access_tag(way, access_tags_hierachy)
-- Handling ferries and piers
-- Second, parse the way according to these properties
if ignore_areas and ("yes" == area) then
return 0
end
-- Check if we are allowed to access the way
if access_tag_blacklist[access] then
return 0
end
-- Set the name that will be used for instructions
if "" ~= ref then
way.name = ref
elseif "" ~= name then
way.name = name
-- else
-- way.name = highway -- if no name exists, use way type
end
if "roundabout" == junction then
way.roundabout = true;
end
-- Handling ferries and piers
if (speed_profile[route] ~= nil and speed_profile[route] > 0) then
if durationIsValid(duration) then
way.duration = math.max( parseDuration(duration), 1 );
@@ -134,9 +150,9 @@ function way_function (way, numberOfNodesInWay)
way.speed = speed_profile[highway]
end
end
-- Set the avg speed on the way if it is accessible by road class
if (speed_profile[highway] ~= nil and way.speed == -1 ) then
-- Set the avg speed on the way if it is accessible by road class
if (speed_profile[highway] ~= nil and way.speed == -1 ) then
if maxspeed > speed_profile[highway] then
way.speed = maxspeed
else
@@ -146,55 +162,64 @@ function way_function (way, numberOfNodesInWay)
way.speed = math.min(speed_profile[highway], maxspeed)
end
end
-- Set the avg speed on ways that are marked accessible
if "" ~= highway and access_tag_whitelist[access] and way.speed == -1 then
if 0 == maxspeed then
maxspeed = math.huge
end
way.speed = math.min(speed_profile["default"], maxspeed)
end
if durationIsValid(duration) then
way.duration = math.max( parseDuration(duration), 1 );
end
-- Set access restriction flag if access is allowed under certain restrictions only
if access ~= "" and access_tag_restricted[access] then
way.is_access_restricted = true
end
-- Set the avg speed on ways that are marked accessible
if "" ~= highway and access_tag_whitelist[access] and way.speed == -1 then
if 0 == maxspeed then
maxspeed = math.huge
end
way.speed = math.min(speed_profile["default"], maxspeed)
end
-- Set access restriction flag if service is allowed under certain restrictions only
if service ~= "" and service_tag_restricted[service] then
way.is_access_restricted = true
end
-- Set access restriction flag if access is allowed under certain restrictions only
if access ~= "" and access_tag_restricted[access] then
way.is_access_restricted = true
end
-- Set access restriction flag if service is allowed under certain restrictions only
if service ~= "" and service_tag_restricted[service] then
way.is_access_restricted = true
end
-- Set direction according to tags on way
if obey_oneway then
if oneway == "no" or oneway == "0" or oneway == "false" then
way.direction = Way.bidirectional
elseif oneway == "-1" then
way.direction = Way.opposite
elseif oneway == "yes" or oneway == "1" or oneway == "true" or junction == "roundabout" or highway == "motorway_link" or highway == "motorway" then
way.direction = Way.oneway
else
way.direction = Way.bidirectional
end
else
way.direction = Way.bidirectional
end
-- Override speed settings if explicit forward/backward maxspeeds are given
if maxspeed_forward ~= nil and maxspeed_forward > 0 then
if Way.bidirectional == way.direction then
way.backward_speed = way.speed
end
way.speed = maxspeed_forward
end
if maxspeed_backward ~= nil and maxspeed_backward > 0 then
way.backward_speed = maxspeed_backward
end
-- Override general direction settings of there is a specific one for our mode of travel
-- Set direction according to tags on way
if obey_oneway then
if oneway == "no" or oneway == "0" or oneway == "false" then
way.direction = Way.bidirectional
elseif oneway == "-1" then
way.direction = Way.opposite
elseif oneway == "yes" or oneway == "1" or oneway == "true" or junction == "roundabout" or highway == "motorway_link" or highway == "motorway" then
way.direction = Way.oneway
else
way.direction = Way.bidirectional
end
else
way.direction = Way.bidirectional
end
-- Override general direction settings of there is a specific one for our mode of travel
if ignore_in_grid[highway] ~= nil and ignore_in_grid[highway] then
way.ignore_in_grid = true
end
way.type = 1
return 1
if ignore_in_grid[highway] ~= nil and ignore_in_grid[highway] then
way.ignore_in_grid = true
end
way.type = 1
return 1
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
for v in vector.nodes do
node_function(v)
end
end
+44 -1
View File
@@ -23,6 +23,18 @@ ignore_areas = true -- future feature
traffic_signal_penalty = 7 -- seconds
u_turn_penalty = 20
function limit_speed(speed, limits)
-- don't use ipairs(), since it stops at the first nil value
for i=1, #limits do
limit = limits[i]
if limit ~= nil and limit > 0 then
if limit < speed then
return limit -- stop at first speedlimit that's smaller than speed
end
end
end
return speed
end
function node_function (node)
local traffic_signal = node.tags:Find("highway")
@@ -45,13 +57,44 @@ function way_function (way, numberOfNodesInWay)
local oneway = way.tags:Find("oneway")
local route = way.tags:Find("route")
local duration = way.tags:Find("duration")
local maxspeed = tonumber(way.tags:Find ( "maxspeed"))
local maxspeed_forward = tonumber(way.tags:Find( "maxspeed:forward"))
local maxspeed_backward = tonumber(way.tags:Find( "maxspeed:backward"))
way.name = name
if route ~= nil and durationIsValid(duration) then
way.duration = math.max( 1, parseDuration(duration) )
else
way.speed = speed_profile[highway] or speed_profile['default']
local speed_forw = speed_profile[highway] or speed_profile['default']
local speed_back = speed_forw
if highway == "river" then
local temp_speed = speed_forw;
speed_forw = temp_speed*1.5
speed_back = temp_speed/1.5
end
if maxspeed_forward ~= nil and maxspeed_forward > 0 then
speed_forw = maxspeed_forward
else
if maxspeed ~= nil and maxspeed > 0 and speed_forw > maxspeed then
speed_forw = maxspeed
end
end
if maxspeed_backward ~= nil and maxspeed_backward > 0 then
speed_back = maxspeed_backward
else
if maxspeed ~=nil and maxspeed > 0 and speed_back > maxspeed then
speed_back = maxspeed
end
end
way.speed = speed_forw
if speed_back ~= way_forw then
way.backward_speed = speed_back
end
end
if oneway == "no" or oneway == "0" or oneway == "false" then