Merge pull request #973 from DennisOSRM/fix/clean_profile_indentation
cleanup indentation of lua profiles
This commit is contained in:
		
						commit
						05c33bee78
					
				| @ -1,8 +1,8 @@ | |||||||
| require("lib/access") | require("lib/access") | ||||||
| 
 | 
 | ||||||
| -- Begin of globals | -- Begin of globals | ||||||
| barrier_whitelist = { [""] = true, ["cycle_barrier"] = true, ["bollard"] = true, ["entrance"] = true, ["cattle_grid"] = true, ["border_control"] = true, ["toll_booth"] = true, ["sally_port"] = true, ["gate"] = true, ["no"] = true} | barrier_whitelist = { [""] = true, ["cycle_barrier"] = true, ["bollard"] = true, ["entrance"] = true, ["cattle_grid"] = true, ["border_control"] = true, ["toll_booth"] = true, ["sally_port"] = true, ["gate"] = true, ["no"] = true } | ||||||
| access_tag_whitelist = { ["yes"] = true, ["permissive"] = true, ["designated"] = true	} | access_tag_whitelist = { ["yes"] = true, ["permissive"] = true, ["designated"] = true } | ||||||
| access_tag_blacklist = { ["no"] = true, ["private"] = true, ["agricultural"] = true, ["forestery"] = true } | access_tag_blacklist = { ["no"] = true, ["private"] = true, ["agricultural"] = true, ["forestery"] = true } | ||||||
| access_tag_restricted = { ["destination"] = true, ["delivery"] = true } | access_tag_restricted = { ["destination"] = true, ["delivery"] = true } | ||||||
| access_tags_hierachy = { "bicycle", "vehicle", "access" } | access_tags_hierachy = { "bicycle", "vehicle", "access" } | ||||||
| @ -15,349 +15,348 @@ default_speed = 15 | |||||||
| walking_speed = 6 | walking_speed = 6 | ||||||
| 
 | 
 | ||||||
| bicycle_speeds = { | bicycle_speeds = { | ||||||
| 	["cycleway"] = default_speed, |   ["cycleway"] = default_speed, | ||||||
| 	["primary"] = default_speed, |   ["primary"] = default_speed, | ||||||
| 	["primary_link"] = default_speed, |   ["primary_link"] = default_speed, | ||||||
| 	["secondary"] = default_speed, |   ["secondary"] = default_speed, | ||||||
| 	["secondary_link"] = default_speed, |   ["secondary_link"] = default_speed, | ||||||
| 	["tertiary"] = default_speed, |   ["tertiary"] = default_speed, | ||||||
| 	["tertiary_link"] = default_speed, |   ["tertiary_link"] = default_speed, | ||||||
| 	["residential"] = default_speed, |   ["residential"] = default_speed, | ||||||
| 	["unclassified"] = default_speed, |   ["unclassified"] = default_speed, | ||||||
| 	["living_street"] = default_speed, |   ["living_street"] = default_speed, | ||||||
| 	["road"] = default_speed, |   ["road"] = default_speed, | ||||||
| 	["service"] = default_speed, |   ["service"] = default_speed, | ||||||
| 	["track"] = 12, |   ["track"] = 12, | ||||||
| 	["path"] = 12 |   ["path"] = 12 | ||||||
| 	--["footway"] = 12, |   --["footway"] = 12, | ||||||
| 	--["pedestrian"] = 12, |   --["pedestrian"] = 12, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| pedestrian_speeds = { | pedestrian_speeds = { | ||||||
| 	["footway"] = walking_speed, |   ["footway"] = walking_speed, | ||||||
| 	["pedestrian"] = walking_speed, |   ["pedestrian"] = walking_speed, | ||||||
| 	["steps"] = 2 |   ["steps"] = 2 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| railway_speeds = { | railway_speeds = { | ||||||
| 	["train"] = 10, |   ["train"] = 10, | ||||||
| 	["railway"] = 10, |   ["railway"] = 10, | ||||||
| 	["subway"] = 10, |   ["subway"] = 10, | ||||||
| 	["light_rail"] = 10, |   ["light_rail"] = 10, | ||||||
| 	["monorail"] = 10, |   ["monorail"] = 10, | ||||||
| 	["tram"] = 10 |   ["tram"] = 10 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| platform_speeds = { | platform_speeds = { | ||||||
| 	["platform"] = walking_speed |   ["platform"] = walking_speed | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| amenity_speeds = { | amenity_speeds = { | ||||||
| 	["parking"] = 10, |   ["parking"] = 10, | ||||||
| 	["parking_entrance"] = 10 |   ["parking_entrance"] = 10 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| man_made_speeds = { | man_made_speeds = { | ||||||
| 	["pier"] = walking_speed |   ["pier"] = walking_speed | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| route_speeds = { | route_speeds = { | ||||||
| 	["ferry"] = 5 |   ["ferry"] = 5 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| surface_speeds = { | surface_speeds = { | ||||||
| 	["asphalt"] = default_speed, |   ["asphalt"] = default_speed, | ||||||
| 	["cobblestone:flattened"] = 10, |   ["cobblestone:flattened"] = 10, | ||||||
| 	["paving_stones"] = 10, |   ["paving_stones"] = 10, | ||||||
| 	["compacted"] = 10, |   ["compacted"] = 10, | ||||||
| 	["cobblestone"] = 6, |   ["cobblestone"] = 6, | ||||||
| 	["unpaved"] = 6, |   ["unpaved"] = 6, | ||||||
| 	["fine_gravel"] = 6, |   ["fine_gravel"] = 6, | ||||||
| 	["gravel"] = 6, |   ["gravel"] = 6, | ||||||
| 	["fine_gravel"] = 6, |   ["fine_gravel"] = 6, | ||||||
| 	["pebbelstone"] = 6, |   ["pebbelstone"] = 6, | ||||||
| 	["ground"] = 6, |   ["ground"] = 6, | ||||||
| 	["dirt"] = 6, |   ["dirt"] = 6, | ||||||
| 	["earth"] = 6, |   ["earth"] = 6, | ||||||
| 	["grass"] = 6, |   ["grass"] = 6, | ||||||
| 	["mud"] = 3, |   ["mud"] = 3, | ||||||
| 	["sand"] = 3 |   ["sand"] = 3 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| take_minimum_of_speeds 	= true | take_minimum_of_speeds  = true | ||||||
| obey_oneway 			= true | obey_oneway       = true | ||||||
| obey_bollards 			= false | obey_bollards       = false | ||||||
| use_restrictions 		= true | use_restrictions    = true | ||||||
| ignore_areas 			= true -- future feature | ignore_areas      = true    -- future feature | ||||||
| traffic_signal_penalty 	= 5 | traffic_signal_penalty  = 5 | ||||||
| u_turn_penalty 			= 20 | u_turn_penalty      = 20 | ||||||
| use_turn_restrictions   = false | use_turn_restrictions   = false | ||||||
| turn_penalty 			= 60 | turn_penalty      = 60 | ||||||
| turn_bias               = 1.4 | turn_bias         = 1.4 | ||||||
| -- End of globals | -- End of globals | ||||||
| 
 | 
 | ||||||
| function get_exceptions(vector) | function get_exceptions(vector) | ||||||
| 	for i,v in ipairs(restriction_exception_tags) do |   for i,v in ipairs(restriction_exception_tags) do | ||||||
| 		vector:Add(v) |     vector:Add(v) | ||||||
| 	end |   end | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
| function node_function (node) | function node_function (node) | ||||||
| 	local barrier = node.tags:Find ("barrier") |   local barrier = node.tags:Find ("barrier") | ||||||
| 	local access = Access.find_access_tag(node, access_tags_hierachy) |   local access = Access.find_access_tag(node, access_tags_hierachy) | ||||||
| 	local traffic_signal = node.tags:Find("highway") |   local traffic_signal = node.tags:Find("highway") | ||||||
| 
 | 
 | ||||||
| 	-- flag node if it carries a traffic light |   -- flag node if it carries a traffic light | ||||||
| 	if traffic_signal == "traffic_signals" then |   if traffic_signal == "traffic_signals" then | ||||||
| 		node.traffic_light = true |     node.traffic_light = true | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	-- parse access and barrier tags |   -- parse access and barrier tags | ||||||
| 	if access and access ~= "" then |   if access and access ~= "" then | ||||||
| 		if access_tag_blacklist[access] then |     if access_tag_blacklist[access] then | ||||||
| 			node.bollard = true |       node.bollard = true | ||||||
| 		else |     else | ||||||
| 			node.bollard = false |       node.bollard = false | ||||||
| 		end |     end | ||||||
| 	elseif barrier and barrier ~= "" then |   elseif barrier and barrier ~= "" then | ||||||
| 		if barrier_whitelist[barrier] then |     if barrier_whitelist[barrier] then | ||||||
| 			node.bollard = false |       node.bollard = false | ||||||
| 		else |     else | ||||||
| 			node.bollard = true |       node.bollard = true | ||||||
| 		end |     end | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	return 1 |   return 1 | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
| function way_function (way) | function way_function (way) | ||||||
| 	-- initial routability check, filters out buildings, boundaries, etc |   -- initial routability check, filters out buildings, boundaries, etc | ||||||
| 	local highway = way.tags:Find("highway") |   local highway = way.tags:Find("highway") | ||||||
| 	local route = way.tags:Find("route") |   local route = way.tags:Find("route") | ||||||
| 	local man_made = way.tags:Find("man_made") |   local man_made = way.tags:Find("man_made") | ||||||
| 	local railway = way.tags:Find("railway") |   local railway = way.tags:Find("railway") | ||||||
| 	local amenity = way.tags:Find("amenity") |   local amenity = way.tags:Find("amenity") | ||||||
| 	local public_transport = way.tags:Find("public_transport") |   local public_transport = way.tags:Find("public_transport") | ||||||
|     if (not highway or highway == '') and |   if (not highway or highway == '') and | ||||||
| 		(not route or route == '') and |   (not route or route == '') and | ||||||
| 		(not railway or railway=='') and |   (not railway or railway=='') and | ||||||
| 		(not amenity or amenity=='') and |   (not amenity or amenity=='') and | ||||||
| 		(not man_made or man_made=='') and |   (not man_made or man_made=='') and | ||||||
|     	(not public_transport or public_transport=='') |   (not public_transport or public_transport=='') | ||||||
|     	then |   then | ||||||
|     	return 0 |     return 0 | ||||||
|  |   end | ||||||
|  | 
 | ||||||
|  |   -- don't route on ways or railways that are still under construction | ||||||
|  |   if highway=='construction' or railway=='construction' 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 maxspeed = parseMaxspeed(way.tags:Find ( "maxspeed") ) | ||||||
|  |   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") | ||||||
|  |   local cycleway = way.tags:Find("cycleway") | ||||||
|  |   local cycleway_left = way.tags:Find("cycleway:left") | ||||||
|  |   local cycleway_right = way.tags:Find("cycleway:right") | ||||||
|  |   local duration = way.tags:Find("duration") | ||||||
|  |   local service = way.tags:Find("service") | ||||||
|  |   local area = way.tags:Find("area") | ||||||
|  |   local foot = way.tags:Find("foot") | ||||||
|  |   local surface = way.tags:Find("surface") | ||||||
|  | 
 | ||||||
|  |   -- name | ||||||
|  |   if "" ~= ref and "" ~= name then | ||||||
|  |     way.name = name .. ' / ' .. ref | ||||||
|  |   elseif "" ~= ref then | ||||||
|  |     way.name = ref | ||||||
|  |   elseif "" ~= name then | ||||||
|  |     way.name = name | ||||||
|  |   else | ||||||
|  |     -- if no name exists, use way type | ||||||
|  |     -- this encoding scheme is excepted to be a temporary solution | ||||||
|  |     way.name = "{highway:"..highway.."}" | ||||||
|  |   end | ||||||
|  | 
 | ||||||
|  |   -- roundabout handling | ||||||
|  |   if "roundabout" == junction then | ||||||
|  |     way.roundabout = true; | ||||||
|  |   end | ||||||
|  | 
 | ||||||
|  |   -- speed | ||||||
|  |   if route_speeds[route] then | ||||||
|  |     -- ferries (doesn't cover routes tagged using relations) | ||||||
|  |     way.direction = Way.bidirectional | ||||||
|  |     way.ignore_in_grid = true | ||||||
|  |     if durationIsValid(duration) then | ||||||
|  |       way.duration = math.max( 1, parseDuration(duration) ) | ||||||
|  |     else | ||||||
|  |        way.speed = route_speeds[route] | ||||||
|     end |     end | ||||||
| 
 |   elseif railway and platform_speeds[railway] then | ||||||
|     -- don't route on ways or railways that are still under construction |     -- railway platforms (old tagging scheme) | ||||||
|     if highway=='construction' or railway=='construction' then |     way.speed = platform_speeds[railway] | ||||||
|         return 0 |   elseif platform_speeds[public_transport] then | ||||||
|     end |     -- public_transport platforms (new tagging platform) | ||||||
| 
 |     way.speed = platform_speeds[public_transport] | ||||||
| 	-- 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 maxspeed = parseMaxspeed(way.tags:Find ( "maxspeed") ) |  | ||||||
| 	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") |  | ||||||
| 	local cycleway = way.tags:Find("cycleway") |  | ||||||
| 	local cycleway_left = way.tags:Find("cycleway:left") |  | ||||||
| 	local cycleway_right = way.tags:Find("cycleway:right") |  | ||||||
| 	local duration	= way.tags:Find("duration") |  | ||||||
| 	local service	= way.tags:Find("service") |  | ||||||
| 	local area = way.tags:Find("area") |  | ||||||
| 	local foot = way.tags:Find("foot") |  | ||||||
| 	local surface = way.tags:Find("surface") |  | ||||||
| 
 |  | ||||||
| 	-- name |  | ||||||
| 	if "" ~= ref and "" ~= name then |  | ||||||
| 		way.name = name .. ' / ' .. ref |  | ||||||
|     elseif "" ~= ref then |  | ||||||
|     	way.name = ref |  | ||||||
| 	elseif "" ~= name then |  | ||||||
| 		way.name = name |  | ||||||
| 	else |  | ||||||
| 		way.name = "{highway:"..highway.."}"	-- if no name exists, use way type |  | ||||||
| 		                                        -- this encoding scheme is excepted to be a temporary solution |  | ||||||
| 	end |  | ||||||
| 
 |  | ||||||
|     -- roundabout handling |  | ||||||
| 	if "roundabout" == junction then |  | ||||||
| 	  way.roundabout = true; |  | ||||||
| 	end |  | ||||||
| 
 |  | ||||||
| 	-- speed |  | ||||||
|     if route_speeds[route] then |  | ||||||
| 		-- ferries (doesn't cover routes tagged using relations) |  | ||||||
| 		way.direction = Way.bidirectional |  | ||||||
| 		way.ignore_in_grid = true |  | ||||||
| 		if durationIsValid(duration) then |  | ||||||
| 			way.duration = math.max( 1, parseDuration(duration) ) |  | ||||||
| 		else |  | ||||||
| 		 	way.speed = route_speeds[route] |  | ||||||
| 		end |  | ||||||
| 	elseif railway and platform_speeds[railway] then |  | ||||||
| 		-- railway platforms (old tagging scheme) |  | ||||||
| 		way.speed = platform_speeds[railway] |  | ||||||
| 	elseif platform_speeds[public_transport] then |  | ||||||
| 		-- public_transport platforms (new tagging platform) |  | ||||||
| 		way.speed = platform_speeds[public_transport] |  | ||||||
|     elseif railway and railway_speeds[railway] then |     elseif railway and railway_speeds[railway] then | ||||||
| 	 	-- railways |      -- railways | ||||||
| 		if access and access_tag_whitelist[access] then |     if access and access_tag_whitelist[access] then | ||||||
| 			way.speed = railway_speeds[railway] |       way.speed = railway_speeds[railway] | ||||||
| 			way.direction = Way.bidirectional |       way.direction = Way.bidirectional | ||||||
| 		end |  | ||||||
| 	elseif amenity and amenity_speeds[amenity] then |  | ||||||
| 		-- parking areas |  | ||||||
| 		way.speed = amenity_speeds[amenity] |  | ||||||
| 	elseif bicycle_speeds[highway] then |  | ||||||
| 		-- regular ways |  | ||||||
|       	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 |     end | ||||||
| 
 |   elseif amenity and amenity_speeds[amenity] then | ||||||
| 	-- direction |     -- parking areas | ||||||
| 	way.direction = Way.bidirectional |     way.speed = amenity_speeds[amenity] | ||||||
| 	local impliedOneway = false |   elseif bicycle_speeds[highway] then | ||||||
| 	if junction == "roundabout" or highway == "motorway_link" or highway == "motorway" then |     -- regular ways | ||||||
| 		way.direction = Way.oneway |     way.speed = bicycle_speeds[highway] | ||||||
| 		impliedOneway = true |   elseif access and access_tag_whitelist[access] then | ||||||
| 	end |     -- unknown way, but valid access tag | ||||||
| 
 |     way.speed = default_speed | ||||||
| 	if onewayClass == "yes" or onewayClass == "1" or onewayClass == "true" then |   else | ||||||
| 		way.direction = Way.oneway |     -- biking not allowed, maybe we can push our bike? | ||||||
| 	elseif onewayClass == "no" or onewayClass == "0" or onewayClass == "false" then |     -- essentially requires pedestrian profiling, for example foot=no mean we can't push a bike | ||||||
| 		way.direction = Way.bidirectional |     -- TODO: if we can push, the way should be marked as pedestrion mode, but there's no way to do it yet from lua.. | ||||||
| 	elseif onewayClass == "-1" then |     if foot ~= 'no' then | ||||||
| 		way.direction = Way.opposite |       if pedestrian_speeds[highway] then | ||||||
| 	elseif oneway == "no" or oneway == "0" or oneway == "false" then |         -- pedestrian-only ways and areas | ||||||
| 		way.direction = Way.bidirectional |         way.speed = pedestrian_speeds[highway] | ||||||
| 	elseif cycleway and string.find(cycleway, "opposite") == 1 then |       elseif man_made and man_made_speeds[man_made] then | ||||||
| 		if impliedOneway then |         -- man made structures | ||||||
| 			way.direction = Way.opposite |         way.speed = man_made_speeds[man_made] | ||||||
| 		else |       elseif foot == 'yes' then | ||||||
| 			way.direction = Way.bidirectional |         way.speed = walking_speed | ||||||
| 		end |       end | ||||||
| 	elseif cycleway_left and cycleway_tags[cycleway_left] and cycleway_right and cycleway_tags[cycleway_right] then |  | ||||||
| 		way.direction = Way.bidirectional |  | ||||||
| 	elseif cycleway_left and cycleway_tags[cycleway_left] then |  | ||||||
| 		if impliedOneway then |  | ||||||
| 			way.direction = Way.opposite |  | ||||||
| 		else |  | ||||||
| 			way.direction = Way.bidirectional |  | ||||||
| 		end |  | ||||||
| 	elseif cycleway_right and cycleway_tags[cycleway_right] then |  | ||||||
| 		if impliedOneway then |  | ||||||
| 			way.direction = Way.oneway |  | ||||||
| 		else |  | ||||||
| 			way.direction = Way.bidirectional |  | ||||||
| 		end |  | ||||||
| 	elseif oneway == "-1" then |  | ||||||
| 		way.direction = Way.opposite |  | ||||||
| 	elseif oneway == "yes" or oneway == "1" or oneway == "true" then |  | ||||||
| 		way.direction = Way.oneway |  | ||||||
| 	end |  | ||||||
| 
 |  | ||||||
| 	-- pushing bikes |  | ||||||
| 	if bicycle_speeds[highway] or pedestrian_speeds[highway] then |  | ||||||
| 	    if foot ~= 'no' then |  | ||||||
| 	        if junction ~= "roundabout" 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 |  | ||||||
|         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 |     end | ||||||
|  |   end | ||||||
| 
 | 
 | ||||||
|  |   -- direction | ||||||
|  |   way.direction = Way.bidirectional | ||||||
|  |   local impliedOneway = false | ||||||
|  |   if junction == "roundabout" or highway == "motorway_link" or highway == "motorway" then | ||||||
|  |     way.direction = Way.oneway | ||||||
|  |     impliedOneway = true | ||||||
|  |   end | ||||||
| 
 | 
 | ||||||
| 	-- cycleways |   if onewayClass == "yes" or onewayClass == "1" or onewayClass == "true" then | ||||||
| 	if cycleway and cycleway_tags[cycleway] then |     way.direction = Way.oneway | ||||||
| 		way.speed = bicycle_speeds["cycleway"] |   elseif onewayClass == "no" or onewayClass == "0" or onewayClass == "false" then | ||||||
| 	elseif cycleway_left and cycleway_tags[cycleway_left] then |     way.direction = Way.bidirectional | ||||||
| 		way.speed = bicycle_speeds["cycleway"] |   elseif onewayClass == "-1" then | ||||||
| 	elseif cycleway_right and cycleway_tags[cycleway_right] then |     way.direction = Way.opposite | ||||||
| 		way.speed = bicycle_speeds["cycleway"] |   elseif oneway == "no" or oneway == "0" or oneway == "false" then | ||||||
| 	end |     way.direction = Way.bidirectional | ||||||
| 
 |   elseif cycleway and string.find(cycleway, "opposite") == 1 then | ||||||
|     -- surfaces |     if impliedOneway then | ||||||
|     if surface then |       way.direction = Way.opposite | ||||||
|         surface_speed = surface_speeds[surface] |     else | ||||||
|         if surface_speed then |       way.direction = Way.bidirectional | ||||||
|             if way.speed > 0 then |  | ||||||
|                 way.speed = surface_speed |  | ||||||
|             end |  | ||||||
|             if way.backward_speed > 0 then |  | ||||||
|               way.backward_speed  = surface_speed |  | ||||||
|             end |  | ||||||
|         end |  | ||||||
|     end |     end | ||||||
|  |   elseif cycleway_left and cycleway_tags[cycleway_left] and cycleway_right and cycleway_tags[cycleway_right] then | ||||||
|  |     way.direction = Way.bidirectional | ||||||
|  |   elseif cycleway_left and cycleway_tags[cycleway_left] then | ||||||
|  |     if impliedOneway then | ||||||
|  |       way.direction = Way.opposite | ||||||
|  |     else | ||||||
|  |       way.direction = Way.bidirectional | ||||||
|  |     end | ||||||
|  |   elseif cycleway_right and cycleway_tags[cycleway_right] then | ||||||
|  |     if impliedOneway then | ||||||
|  |       way.direction = Way.oneway | ||||||
|  |     else | ||||||
|  |       way.direction = Way.bidirectional | ||||||
|  |     end | ||||||
|  |   elseif oneway == "-1" then | ||||||
|  |     way.direction = Way.opposite | ||||||
|  |   elseif oneway == "yes" or oneway == "1" or oneway == "true" then | ||||||
|  |     way.direction = Way.oneway | ||||||
|  |   end | ||||||
| 
 | 
 | ||||||
| 	-- maxspeed |   -- pushing bikes | ||||||
| 	-- TODO: maxspeed of backward direction |   if bicycle_speeds[highway] or pedestrian_speeds[highway] then | ||||||
| 	if take_minimum_of_speeds then |     if foot ~= 'no' then | ||||||
| 		if maxspeed and maxspeed>0 then |       if junction ~= "roundabout" then | ||||||
| 			way.speed = math.min(way.speed, maxspeed) |         if way.direction == Way.oneway then | ||||||
| 		end |           way.backward_speed = walking_speed | ||||||
| 	end |         elseif way.direction == Way.opposite then | ||||||
|  |           way.backward_speed = walking_speed | ||||||
|  |           way.speed = way.speed | ||||||
|  |         end | ||||||
|  |       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 = bicycle_speeds["cycleway"] | ||||||
|  |   elseif cycleway_left and cycleway_tags[cycleway_left] then | ||||||
|  |     way.speed = bicycle_speeds["cycleway"] | ||||||
|  |   elseif cycleway_right and cycleway_tags[cycleway_right] then | ||||||
|  |     way.speed = bicycle_speeds["cycleway"] | ||||||
|  |   end | ||||||
|  | 
 | ||||||
|  |   -- surfaces | ||||||
|  |   if surface then | ||||||
|  |     surface_speed = surface_speeds[surface] | ||||||
|  |     if surface_speed then | ||||||
|  |       if way.speed > 0 then | ||||||
|  |         way.speed = surface_speed | ||||||
|  |       end | ||||||
|  |       if way.backward_speed > 0 then | ||||||
|  |         way.backward_speed  = surface_speed | ||||||
|  |       end | ||||||
|  |     end | ||||||
|  |   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 |   -- Override speed settings if explicit forward/backward maxspeeds are given | ||||||
|     if way.speed > 0 and maxspeed_forward ~= nil and maxspeed_forward > 0 then |   if way.speed > 0 and maxspeed_forward ~= nil and maxspeed_forward > 0 then | ||||||
| 	if Way.bidirectional == way.direction then |     if Way.bidirectional == way.direction then | ||||||
|           way.backward_speed = way.speed |       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 |     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 | ||||||
| 	way.type = 1 |  | ||||||
| 	return 1 |  | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
| function turn_function (angle) | function turn_function (angle) | ||||||
|     -- compute turn penalty as angle^2, with a left/right bias |   -- compute turn penalty as angle^2, with a left/right bias | ||||||
|     k = turn_penalty/(90.0*90.0) |   k = turn_penalty/(90.0*90.0) | ||||||
| 	if angle>=0 then |   if angle>=0 then | ||||||
| 	    return angle*angle*k/turn_bias |     return angle*angle*k/turn_bias | ||||||
| 	else |   else | ||||||
| 	    return angle*angle*k*turn_bias |     return angle*angle*k*turn_bias | ||||||
|     end |   end | ||||||
| end | end | ||||||
|  | |||||||
							
								
								
									
										104
									
								
								profiles/car.lua
									
									
									
									
									
								
							
							
						
						
									
										104
									
								
								profiles/car.lua
									
									
									
									
									
								
							| @ -1,8 +1,8 @@ | |||||||
| -- Begin of globals | -- Begin of globals | ||||||
| --require("lib/access") --function temporarily inlined | --require("lib/access") --function temporarily inlined | ||||||
| 
 | 
 | ||||||
| barrier_whitelist = { ["cattle_grid"] = true, ["border_control"] = true, ["toll_booth"] = true, ["sally_port"] = true, ["gate"] = true, ["no"] = true, ["entrance"] = true} | barrier_whitelist = { ["cattle_grid"] = true, ["border_control"] = true, ["toll_booth"] = true, ["sally_port"] = true, ["gate"] = true, ["no"] = true, ["entrance"] = true } | ||||||
| access_tag_whitelist = { ["yes"] = true, ["motorcar"] = true, ["motor_vehicle"] = true, ["vehicle"] = true, ["permissive"] = true, ["designated"] = true  } | access_tag_whitelist = { ["yes"] = true, ["motorcar"] = true, ["motor_vehicle"] = true, ["vehicle"] = true, ["permissive"] = true, ["designated"] = true } | ||||||
| access_tag_blacklist = { ["no"] = true, ["private"] = true, ["agricultural"] = true, ["forestry"] = true, ["emergency"] = true } | access_tag_blacklist = { ["no"] = true, ["private"] = true, ["agricultural"] = true, ["forestry"] = true, ["emergency"] = true } | ||||||
| access_tag_restricted = { ["destination"] = true, ["delivery"] = true } | access_tag_restricted = { ["destination"] = true, ["delivery"] = true } | ||||||
| access_tags = { "motorcar", "motor_vehicle", "vehicle" } | access_tags = { "motorcar", "motor_vehicle", "vehicle" } | ||||||
| @ -32,13 +32,13 @@ speed_profile = { | |||||||
|   ["default"] = 10 |   ["default"] = 10 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| local take_minimum_of_speeds  = false | local take_minimum_of_speeds    = false | ||||||
| local obey_oneway 			      = true | local obey_oneway               = true | ||||||
| local obey_bollards           = true | local obey_bollards             = true | ||||||
| local use_turn_restrictions   = true | local use_turn_restrictions     = true | ||||||
| local ignore_areas 			      = true -- future feature | local ignore_areas              = true     -- future feature | ||||||
| local traffic_signal_penalty  = 2 | local traffic_signal_penalty    = 2 | ||||||
| local u_turn_penalty 			    = 20 | local u_turn_penalty            = 20 | ||||||
| 
 | 
 | ||||||
| local abs = math.abs | local abs = math.abs | ||||||
| local min = math.min | local min = math.min | ||||||
| @ -58,23 +58,23 @@ local function find_access_tag(source,access_tags_hierachy) | |||||||
| end | end | ||||||
| 
 | 
 | ||||||
| function get_exceptions(vector) | function get_exceptions(vector) | ||||||
| 	for i,v in ipairs(restriction_exception_tags) do |   for i,v in ipairs(restriction_exception_tags) do | ||||||
| 		vector:Add(v) |     vector:Add(v) | ||||||
| 	end |   end | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
| local function parse_maxspeed(source) | local function parse_maxspeed(source) | ||||||
| 	if not source then |   if not source then | ||||||
| 		return 0 |     return 0 | ||||||
| 	end |   end | ||||||
| 	local n = tonumber(source:match("%d*")) |   local n = tonumber(source:match("%d*")) | ||||||
| 	if not n then |   if not n then | ||||||
| 		n = 0 |     n = 0 | ||||||
| 	end |   end | ||||||
| 	if string.match(source, "mph") or string.match(source, "mp/h") then |   if string.match(source, "mph") or string.match(source, "mp/h") then | ||||||
| 		n = (n*1609)/1000; |     n = (n*1609)/1000; | ||||||
| 	end |   end | ||||||
| 	return n |   return n | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
| function node_function (node) | function node_function (node) | ||||||
| @ -87,19 +87,19 @@ function node_function (node) | |||||||
|     end |     end | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
| 	-- parse access and barrier tags |   -- parse access and barrier tags | ||||||
| 	if access and access ~= "" then |   if access and access ~= "" then | ||||||
| 		if access_tag_blacklist[access] then |     if access_tag_blacklist[access] then | ||||||
| 			node.bollard = true |       node.bollard = true | ||||||
| 		end |     end | ||||||
| 	elseif node.tags:Holds("barrier") then |   elseif node.tags:Holds("barrier") then | ||||||
|     local barrier = node.tags:Find("barrier") |     local barrier = node.tags:Find("barrier") | ||||||
| 		if barrier_whitelist[barrier] then |     if barrier_whitelist[barrier] then | ||||||
| 			return |       return | ||||||
| 		else |     else | ||||||
| 			node.bollard = true |       node.bollard = true | ||||||
| 		end |     end | ||||||
| 	end |   end | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
| function way_function (way) | function way_function (way) | ||||||
| @ -202,7 +202,7 @@ function way_function (way) | |||||||
|   elseif "" ~= name then |   elseif "" ~= name then | ||||||
|     way.name = name |     way.name = name | ||||||
| --  else | --  else | ||||||
| --      way.name = highway    -- if no name exists, use way type |       --    way.name = highway  -- if no name exists, use way type | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   if "roundabout" == junction then |   if "roundabout" == junction then | ||||||
| @ -216,22 +216,21 @@ function way_function (way) | |||||||
| 
 | 
 | ||||||
|   -- Set access restriction flag if service is allowed under certain restrictions only |   -- Set access restriction flag if service is allowed under certain restrictions only | ||||||
|   if service ~= "" and service_tag_restricted[service] then |   if service ~= "" and service_tag_restricted[service] then | ||||||
| 	  way.is_access_restricted = true |     way.is_access_restricted = true | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   -- Set direction according to tags on way |   -- Set direction according to tags on way | ||||||
|   way.direction = Way.bidirectional |   way.direction = Way.bidirectional | ||||||
|   if obey_oneway  then |   if obey_oneway  then | ||||||
| 	  if oneway == "-1" then |     if oneway == "-1" then | ||||||
| 	    way.direction = Way.opposite |       way.direction = Way.opposite | ||||||
|     elseif oneway == "yes" or |     elseif oneway == "yes" or | ||||||
|       oneway == "1" or |     oneway == "1" or | ||||||
|       oneway == "true" or |     oneway == "true" or | ||||||
|       junction == "roundabout" or |     junction == "roundabout" or | ||||||
|       (highway == "motorway_link" and oneway ~="no") or |     (highway == "motorway_link" and oneway ~="no") or | ||||||
|       (highway == "motorway" and oneway ~= "no") |     (highway == "motorway" and oneway ~= "no") then | ||||||
|       then |       way.direction = Way.oneway | ||||||
| 	     way.direction = Way.oneway |  | ||||||
|     end |     end | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
| @ -250,16 +249,15 @@ function way_function (way) | |||||||
| 
 | 
 | ||||||
|   -- Override general direction settings of there is a specific one for our mode of travel |   -- Override general direction settings of there is a specific one for our mode of travel | ||||||
|   if ignore_in_grid[highway] then |   if ignore_in_grid[highway] then | ||||||
| 		way.ignore_in_grid = true |     way.ignore_in_grid = true | ||||||
| 	end |   end | ||||||
| 	way.type = 1 |   way.type = 1 | ||||||
|   return |   return | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
| -- These are wrappers to parse vectors of nodes and ways and thus to speed up any tracing JIT | -- These are wrappers to parse vectors of nodes and ways and thus to speed up any tracing JIT | ||||||
| 
 |  | ||||||
| function node_vector_function(vector) | function node_vector_function(vector) | ||||||
|  for v in vector.nodes do |   for v in vector.nodes do | ||||||
|   node_function(v) |     node_function(v) | ||||||
|  end |   end | ||||||
| end | end | ||||||
| @ -2,106 +2,106 @@ | |||||||
| 
 | 
 | ||||||
| -- Moves at fixed, well-known speeds, practical for testing speed and travel times: | -- Moves at fixed, well-known speeds, practical for testing speed and travel times: | ||||||
| 
 | 
 | ||||||
| -- Primary road:	36km/h = 36000m/3600s = 100m/10s | -- Primary road:  36km/h = 36000m/3600s = 100m/10s | ||||||
| -- Secondary road:	18km/h = 18000m/3600s = 100m/20s | -- Secondary road:  18km/h = 18000m/3600s = 100m/20s | ||||||
| -- Tertiary road:	12km/h = 12000m/3600s = 100m/30s | -- Tertiary road:  12km/h = 12000m/3600s = 100m/30s | ||||||
| 
 | 
 | ||||||
| speed_profile = { | speed_profile = { | ||||||
| 	["primary"] = 36, |   ["primary"] = 36, | ||||||
| 	["secondary"] = 18, |   ["secondary"] = 18, | ||||||
| 	["tertiary"] = 12, |   ["tertiary"] = 12, | ||||||
| 	["default"] = 24 |   ["default"] = 24 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| -- these settings are read directly by osrm | -- these settings are read directly by osrm | ||||||
| 
 | 
 | ||||||
| take_minimum_of_speeds 	= true | take_minimum_of_speeds  = true | ||||||
| obey_oneway 			= true | obey_oneway             = true | ||||||
| obey_barriers 			= true | obey_barriers           = true | ||||||
| use_turn_restrictions 	= true | use_turn_restrictions   = true | ||||||
| ignore_areas 			= true	-- future feature | ignore_areas            = true  -- future feature | ||||||
| traffic_signal_penalty 	= 7		-- seconds | traffic_signal_penalty  = 7     -- seconds | ||||||
| u_turn_penalty 			= 20 | u_turn_penalty          = 20 | ||||||
| 
 | 
 | ||||||
| function limit_speed(speed, limits) | function limit_speed(speed, limits) | ||||||
|     -- don't use ipairs(), since it stops at the first nil value |   -- don't use ipairs(), since it stops at the first nil value | ||||||
|     for i=1, #limits do |   for i=1, #limits do | ||||||
|         limit = limits[i] |     limit = limits[i] | ||||||
|         if limit ~= nil and limit > 0 then |     if limit ~= nil and limit > 0 then | ||||||
|             if limit < speed then |       if limit < speed then | ||||||
|                 return limit        -- stop at first speedlimit that's smaller than speed |         return limit        -- stop at first speedlimit that's smaller than speed | ||||||
|             end |       end | ||||||
|         end |  | ||||||
|     end |     end | ||||||
|     return speed |   end | ||||||
|  |   return speed | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
| function node_function (node) | function node_function (node) | ||||||
| 	local traffic_signal = node.tags:Find("highway") |   local traffic_signal = node.tags:Find("highway") | ||||||
| 
 | 
 | ||||||
| 	if traffic_signal == "traffic_signals" then |   if traffic_signal == "traffic_signals" then | ||||||
| 		node.traffic_light = true; |     node.traffic_light = true; | ||||||
| 		-- TODO: a way to set the penalty value |     -- TODO: a way to set the penalty value | ||||||
| 	end |   end | ||||||
| 	return 1 |   return 1 | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
| function way_function (way) | function way_function (way) | ||||||
| 	local highway = way.tags:Find("highway") |   local highway = way.tags:Find("highway") | ||||||
| 	local name = way.tags:Find("name") |   local name = way.tags:Find("name") | ||||||
| 	local oneway = way.tags:Find("oneway") |   local oneway = way.tags:Find("oneway") | ||||||
| 	local route = way.tags:Find("route") |   local route = way.tags:Find("route") | ||||||
| 	local duration = way.tags:Find("duration") |   local duration = way.tags:Find("duration") | ||||||
|     local maxspeed = tonumber(way.tags:Find ( "maxspeed")) |   local maxspeed = tonumber(way.tags:Find ( "maxspeed")) | ||||||
|     local maxspeed_forward = tonumber(way.tags:Find( "maxspeed:forward")) |   local maxspeed_forward = tonumber(way.tags:Find( "maxspeed:forward")) | ||||||
|     local maxspeed_backward = tonumber(way.tags:Find( "maxspeed:backward")) |   local maxspeed_backward = tonumber(way.tags:Find( "maxspeed:backward")) | ||||||
| 
 | 
 | ||||||
| 	way.name = name |   way.name = name | ||||||
| 
 | 
 | ||||||
|   	if route ~= nil and durationIsValid(duration) then |   if route ~= nil and durationIsValid(duration) then | ||||||
| 		way.duration = math.max( 1, parseDuration(duration) ) |     way.duration = math.max( 1, parseDuration(duration) ) | ||||||
| 	else |   else | ||||||
| 	    local speed_forw = speed_profile[highway] or speed_profile['default'] |     local speed_forw = speed_profile[highway] or speed_profile['default'] | ||||||
| 	    local speed_back = speed_forw |     local speed_back = speed_forw | ||||||
| 
 | 
 | ||||||
|     	if highway == "river" then |     if highway == "river" then | ||||||
|     		local temp_speed = speed_forw; |       local temp_speed = speed_forw; | ||||||
|     		speed_forw = temp_speed*1.5 |       speed_forw = temp_speed*1.5 | ||||||
|     		speed_back = temp_speed/1.5 |       speed_back = temp_speed/1.5 | ||||||
|    	end |     end | ||||||
| 
 | 
 | ||||||
|         if maxspeed_forward ~= nil and maxspeed_forward > 0 then |     if maxspeed_forward ~= nil and maxspeed_forward > 0 then | ||||||
| 			speed_forw = maxspeed_forward |       speed_forw = maxspeed_forward | ||||||
| 		else |     else | ||||||
| 			if maxspeed ~= nil and maxspeed > 0 and speed_forw > maxspeed then |       if maxspeed ~= nil and maxspeed > 0 and speed_forw > maxspeed then | ||||||
| 				speed_forw = maxspeed |         speed_forw = maxspeed | ||||||
| 			end |       end | ||||||
| 		end |     end | ||||||
| 
 | 
 | ||||||
| 		if maxspeed_backward ~= nil and maxspeed_backward > 0 then |     if maxspeed_backward ~= nil and maxspeed_backward > 0 then | ||||||
| 			speed_back = maxspeed_backward |       speed_back = maxspeed_backward | ||||||
| 		else |     else | ||||||
| 			if maxspeed ~=nil and maxspeed > 0 and speed_back > maxspeed then |       if maxspeed ~=nil and maxspeed > 0 and speed_back > maxspeed then | ||||||
| 				speed_back = maxspeed |         speed_back = maxspeed | ||||||
| 			end |       end | ||||||
| 		end |     end | ||||||
| 
 | 
 | ||||||
|         way.speed = speed_forw |     way.speed = speed_forw | ||||||
|         if speed_back ~= way_forw then |     if speed_back ~= way_forw then | ||||||
|             way.backward_speed = speed_back |       way.backward_speed = speed_back | ||||||
|         end |     end | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	if oneway == "no" or oneway == "0" or oneway == "false" then |   if oneway == "no" or oneway == "0" or oneway == "false" then | ||||||
| 		way.direction = Way.bidirectional |     way.direction = Way.bidirectional | ||||||
| 	elseif oneway == "-1" then |   elseif oneway == "-1" then | ||||||
| 		way.direction = Way.opposite |     way.direction = Way.opposite | ||||||
| 	elseif oneway == "yes" or oneway == "1" or oneway == "true" then |   elseif oneway == "yes" or oneway == "1" or oneway == "true" then | ||||||
| 		way.direction = Way.oneway |     way.direction = Way.oneway | ||||||
| 	else |   else | ||||||
| 		way.direction = Way.bidirectional |     way.direction = Way.bidirectional | ||||||
| 	end |   end | ||||||
| 
 | 
 | ||||||
| 	way.type = 1 |   way.type = 1 | ||||||
| 	return 1 |   return 1 | ||||||
| end | end | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user