Merge pull request #423 from ibikecph/cuke_lua

update cucumber test to work with lua profiles
This commit is contained in:
Project OSRM 2012-09-20 02:25:14 -07:00
commit 96ba31cc2b
15 changed files with 596 additions and 107 deletions

2
.gitignore vendored
View File

@ -79,3 +79,5 @@ win/bin-debug/
# Sandbox folder #
###################
sandbox/
test/profile.lua

View File

@ -78,20 +78,6 @@ Feature: Oneway streets
| motorway_link | | -1 | | x |
| trunk_link | | -1 | | x |
| primary | roundabout | -1 | | x |
Scenario: Disabling oneways in speedprofile
Given the speedprofile "car"
And the speedprofile settings
| obeyOneways | no |
Then routability should be
| highway | junction | oneway | forw | backw |
| primary | | yes | x | x |
| primary | | true | x | x |
| primary | | 1 | x | x |
| primary | | -1 | x | x |
| motorway_link | | | x | x |
| trunk_link | | | x | x |
| primary | roundabout | | x | x |
@bicycle
Scenario: Oneway:bicycle should override normal oneways tags

View File

@ -3,8 +3,6 @@ Feature: Penalties
Background:
Given the speedprofile "bicycle"
And the speedprofile settings
| trafficSignalPenalty | 20 |
Scenario: Passing a traffic signal should incur a delay
Given the node map

View File

@ -2,12 +2,6 @@ Given /^the speedprofile "([^"]*)"$/ do |profile|
read_speedprofile profile
end
Given /^the speedprofile settings$/ do |table|
table.raw.each do |row|
speedprofile[ row[0] ] = row[1]
end
end
Given /^a grid size of (\d+) meters$/ do |meters|
set_grid_size meters
end

View File

@ -252,7 +252,7 @@ When /^I route I should get$/ do |table|
ok = false
end
else
ok = row[key] == got[key].to_f
ok = row[key] == got[key]
end
end

View File

@ -3,25 +3,16 @@ def speedprofile
end
def reset_speedprofile
@speedprofile = {}
@speedprofile = nil
read_speedprofile DEFAULT_SPEEDPROFILE
end
def read_speedprofile profile
@speedprofile = {}
@speedprofile_str = nil
s = File.read "test/speedprofiles/#{profile}.ini"
s.scan /(.*)=(.*)/ do |option|
@speedprofile[option[0].strip] = option[1].strip
end
end
def speedprofile_str
@speedprofile_str ||= "[Scenario: #{@scenario_title}]\n" + @speedprofile.map { |k,v| " #{k} = #{v}" }.join("\n")
@speedprofile = profile
end
def write_speedprofile
File.open( 'speedprofile.ini', 'w') {|f| f.write( speedprofile_str ) }
FileUtils.copy_file "profiles/#{@speedprofile}.lua", "profile.lua"
end
def write_server_ini

View File

@ -14,7 +14,7 @@ DEFAULT_SPEEDPROFILE = 'bicycle'
WAY_SPACING = 100
DEFAULT_GRID_SIZE = 100 #meters
ORIGIN = [1,1]
ORIGIN = [12,55]
def set_grid_size meters
@zoom = 0.001*(meters.to_f/111.21)

View File

@ -12,11 +12,7 @@ def hash_of_file path
end
def speedprofile_hash
@speedprofile_hash ||= Digest::SHA1.hexdigest speedprofile_str
end
def osm_hash
@osm_hash ||= Digest::SHA1.hexdigest osm_str
@speedprofile_hash ||= hash_of_file "profile.lua"
end
def osm_hash

View File

@ -13,12 +13,13 @@ def log_scenario_fail_info
log "========================================="
log "Failed scenario: #{@scenario_title}"
log "Time: #{@scenario_time}"
log "Fingerprint: #{@fingerprint}"
log "Profile: #{@speedprofile}"
log
log '```xml' #so output can be posted directly to github comment fields
log osm_str.strip
log '```'
log
log speedprofile_str
log
@has_logged_scenario_info = true
end
@ -27,7 +28,7 @@ def log_fail expected,actual,failed
log_scenario_fail_info
log "== "
log "Expected: #{expected}"
log "Got: #{actual}"
log "Got: #{actual}"
log
failed.each do |fail|
log "Attempt: #{fail[:attempt]}"
@ -49,8 +50,8 @@ def log_preprocess_info
log osm_str, :preprocess
log '```', :preprocess
log '', :preprocess
log "== Speed profile:", :preprocess
log speedprofile_str.strip, :preprocess
log "== Profile:", :preprocess
log @speedprofile, :preprocess
log '', :preprocess
@has_logged_preprocess_info = true
end

193
test/profiles/bicycle.lua Normal file
View File

@ -0,0 +1,193 @@
-- Bicycle profile
-- Begin of globals
bollards_whitelist = { [""] = true, ["cattle_grid"] = true, ["border_control"] = true, ["toll_booth"] = true, ["no"] = true, ["sally_port"] = true, ["gate"] = true}
access_tag_whitelist = { ["yes"] = true, ["vehicle"] = true, ["permissive"] = true, ["designated"] = true }
access_tag_blacklist = { ["no"] = true, ["private"] = true, ["agricultural"] = true, ["forestery"] = true }
access_tag_restricted = { ["destination"] = true, ["delivery"] = true }
access_tags = { "bicycle", "vehicle" }
service_tag_restricted = { ["parking_aisle"] = true }
ignore_in_grid = { ["ferry"] = true }
speed_profile = {
["cycleway"] = 18,
["primary"] = 17,
["primary_link"] = 17,
["secondary"] = 18,
["secondary_link"] = 18,
["tertiary"] = 18,
["residential"] = 18,
["unclassified"] = 16,
["living_street"] = 16,
["road"] = 16,
["service"] = 16,
["track"] = 13,
["path"] = 13,
["footway"] = 5,
["pedestrian"] = 5,
["pier"] = 5,
["steps"] = 1,
["default"] = 18
}
take_minimum_of_speeds = true
obey_oneway = true
obey_bollards = false
use_restrictions = true
ignore_areas = true -- future feature
traffic_signal_penalty = 2
u_turn_penalty = 20
-- End of globals
function node_function (node)
local barrier = node.tags:Find ("barrier")
local access = node.tags:Find ("access")
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
if obey_bollards then
--flag node as unpassable if it black listed as unpassable
if access_tag_blacklist[barrier] then
node.bollard = true;
end
--reverse the previous flag if there is an access tag specifying entrance
if node.bollard and not bollards_whitelist[barrier] and not access_tag_whitelist[barrier] then
node.bollard = false;
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 man_made = way.tags:Find("man_made")
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 = way.tags:Find("access")
-- 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] ~=nil and access_tag_blacklist[access] then
return 0;
end
-- Check if our vehicle types are forbidden
for i,v in ipairs(access_tags) do
local mode_value = way.tags:Find(v)
if nil ~= mode_value and "no" == mode_value then
return 0;
end
end
-- Set the name that will be used for instructions
if "" ~= ref then
way.name = ref
elseif "" ~= name then
way.name = name
end
if "roundabout" == junction then
way.roundabout = true;
end
-- Handling ferries and piers
if (speed_profile[route] ~= nil and speed_profile[route] > 0) or
(speed_profile[man_made] ~= nil and speed_profile[man_made] > 0)
then
if durationIsValid(duration) then
way.speed = parseDuration / math.max(1, numberOfSegments-1);
way.is_duration_set = true;
end
way.direction = Way.bidirectional;
if speed_profile[route] ~= nil then
highway = route;
elseif speed_profile[man_made] ~= nil then
highway = man_made;
end
if not way.is_duration_set then
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
if (0 < maxspeed and not take_minimum_of_speeds) or (maxspeed == 0) then
maxspeed = math.huge
end
way.speed = math.min(speed_profile[highway], maxspeed)
end
-- Set the avg speed on ways that are marked accessible
if access_tag_whitelist[access] and way.speed == -1 then
if (0 < maxspeed and not take_minimum_of_speeds) or maxspeed == 0 then
maxspeed = math.huge
end
way.speed = math.min(speed_profile["default"], maxspeed)
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 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
end

194
test/profiles/car.lua Normal file
View File

@ -0,0 +1,194 @@
-- Car profile
-- Begin of globals
bollards_whitelist = { [""] = true, ["cattle_grid"] = true, ["border_control"] = true, ["toll_booth"] = true, ["no"] = true, ["sally_port"] = true, ["gate"] = 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, ["forestery"] = true }
access_tag_restricted = { ["destination"] = true, ["delivery"] = true }
access_tags = { "motorcar", "motor_vehicle", "vehicle" }
service_tag_restricted = { ["parking_aisle"] = true }
ignore_in_grid = { ["ferry"] = true, ["pier"] = true }
speed_profile = {
["motorway"] = 100,
["motorway_link"] = 90,
["trunk"] = 90,
["trunk_link"] = 90,
["primary"] = 70,
["primary_link"] = 60,
["secondary"] = 60,
["secondary_link"] = 50,
["tertiary"] = 50,
["tertiary_link"] = 40,
["unclassified"] = 30,
["residential"] = 40,
["road"] = 40,
["living_street"] = 10,
["service"] = 15,
-- ["track"] = 5,
["ferry"] = 5,
["pier"] = 5,
["default"] = 50
}
take_minimum_of_speeds = true
obey_oneway = true
obey_bollards = true
use_restrictions = true
ignore_areas = true -- future feature
traffic_signal_penalty = 2
u_turn_penalty = 20
-- End of globals
function node_function (node)
local barrier = node.tags:Find ("barrier")
local access = node.tags:Find ("access")
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
if obey_bollards then
--flag node as unpassable if it black listed as unpassable
if access_tag_blacklist[barrier] then
node.bollard = true;
end
--reverse the previous flag if there is an access tag specifying entrance
if node.bollard and not bollards_whitelist[barrier] and not access_tag_whitelist[barrier] then
node.bollard = false;
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 man_made = way.tags:Find("man_made")
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 = way.tags:Find("access")
-- 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] ~=nil and access_tag_blacklist[access] then
return 0;
end
-- Check if our vehicle types are forbidden
for i,v in ipairs(access_tags) do
local mode_value = way.tags:Find(v)
if nil ~= mode_value and "no" == mode_value then
return 0;
end
end
-- Set the name that will be used for instructions
if "" ~= ref then
way.name = ref
elseif "" ~= name then
way.name = name
end
if "roundabout" == junction then
way.roundabout = true;
end
-- Handling ferries and piers
if (speed_profile[route] ~= nil and speed_profile[route] > 0) or
(speed_profile[man_made] ~= nil and speed_profile[man_made] > 0)
then
if durationIsValid(duration) then
way.speed = parseDuration / math.max(1, numberOfSegments-1);
way.is_duration_set = true;
end
way.direction = Way.bidirectional;
if speed_profile[route] ~= nil then
highway = route;
elseif speed_profile[man_made] ~= nil then
highway = man_made;
end
if not way.is_duration_set then
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
if (0 < maxspeed and not take_minimum_of_speeds) or (maxspeed == 0) then
maxspeed = math.huge
end
way.speed = math.min(speed_profile[highway], maxspeed)
end
-- Set the avg speed on ways that are marked accessible
if access_tag_whitelist[access] and way.speed == -1 then
if (0 < maxspeed and not take_minimum_of_speeds) or maxspeed == 0 then
maxspeed = math.huge
end
way.speed = math.min(speed_profile["default"], maxspeed)
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 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
end

196
test/profiles/foot.lua Normal file
View File

@ -0,0 +1,196 @@
-- Foot profile
-- Begin of globals
bollards_whitelist = { [""] = true, ["cattle_grid"] = true, ["border_control"] = true, ["toll_booth"] = true, ["no"] = true, ["sally_port"] = true, ["gate"] = true}
access_tag_whitelist = { ["yes"] = true, ["foot"] = true, ["permissive"] = true, ["designated"] = true }
access_tag_blacklist = { ["no"] = true, ["private"] = true, ["agricultural"] = true, ["forestery"] = true }
access_tag_restricted = { ["destination"] = true, ["delivery"] = true }
access_tags = { "foot" }
service_tag_restricted = { ["parking_aisle"] = true }
ignore_in_grid = { ["ferry"] = true }
speed_profile = {
["trunk_link"] = 5,
["primary"] = 5,
["primary_link"] = 5,
["secondary"] = 5,
["secondary_link"] = 5,
["tertiary"] = 5,
["tertiary_link"] = 5,
["unclassified"] = 5,
["residential"] = 5,
["road"] = 5,
["living_street"] = 5,
["service"] = 5,
["track"] = 5,
["path"] = 5,
["steps"] = 5,
["ferry"] = 5,
["pedestrian"] = 5,
["footway"] = 5,
["cycleway"] = 5,
["pier"] = 5,
["default"] = 5
}
take_minimum_of_speeds = true
obey_oneway = false
obey_bollards = false
use_restrictions = false
ignore_areas = true -- future feature
traffic_signal_penalty = 2
u_turn_penalty = 2
-- End of globals
function node_function (node)
local barrier = node.tags:Find ("barrier")
local access = node.tags:Find ("access")
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
if obey_bollards then
--flag node as unpassable if it black listed as unpassable
if access_tag_blacklist[barrier] then
node.bollard = true;
end
--reverse the previous flag if there is an access tag specifying entrance
if node.bollard and not bollards_whitelist[barrier] and not access_tag_whitelist[barrier] then
node.bollard = false;
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 man_made = way.tags:Find("man_made")
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 = way.tags:Find("access")
-- 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] ~=nil and access_tag_blacklist[access] then
return 0;
end
-- Check if our vehicle types are forbidden
for i,v in ipairs(access_tags) do
local mode_value = way.tags:Find(v)
if nil ~= mode_value and "no" == mode_value then
return 0;
end
end
-- Set the name that will be used for instructions
if "" ~= ref then
way.name = ref
elseif "" ~= name then
way.name = name
end
if "roundabout" == junction then
way.roundabout = true;
end
-- Handling ferries and piers
if (speed_profile[route] ~= nil and speed_profile[route] > 0) or
(speed_profile[man_made] ~= nil and speed_profile[man_made] > 0)
then
if durationIsValid(duration) then
way.speed = parseDuration / math.max(1, numberOfSegments-1);
way.is_duration_set = true;
end
way.direction = Way.bidirectional;
if speed_profile[route] ~= nil then
highway = route;
elseif speed_profile[man_made] ~= nil then
highway = man_made;
end
if not way.is_duration_set then
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
if (0 < maxspeed and not take_minimum_of_speeds) or (maxspeed == 0) then
maxspeed = math.huge
end
way.speed = math.min(speed_profile[highway], maxspeed)
end
-- Set the avg speed on ways that are marked accessible
if access_tag_whitelist[access] and way.speed == -1 then
if (0 < maxspeed and not take_minimum_of_speeds) or maxspeed == 0 then
maxspeed = math.huge
end
way.speed = math.min(speed_profile["default"], maxspeed)
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 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
end

View File

@ -1,11 +0,0 @@
[bicycle]
accessTags = bicycle
obeyOneways = yes
obeyBollards = no
useRestrictions = yes
takeMinimumOfSpeeds = yes
defaultSpeed = 15
primary = 15
cycleway = 15
footway = 5
ferry = 5

View File

@ -1,23 +0,0 @@
[car]
accessTags = motorcar
defaultSpeed = 50
obeyOneways = yes
useRestrictions = yes
barrier = bollard
motorway = 100
motorway_link = 90
trunk = 90
trunk_link = 70
primary = 70
primary_link = 60
secondary = 60
secondary_link = 50
tertiary = 50
tertiary_link = 40
road = 40
residential = 40
unclassified = 30
service = 20
living_street = 10

View File

@ -1,28 +0,0 @@
[foot]
accessTags = foot
defaultSpeed = 5
obeyOneways = no
useRestrictions = no
obeyBollards = no
primary = 5
primary_link = 5
secondary = 5
secondary_link = 5
tertiary = 5
residential = 5
unclassified = 5
living_street = 5
road = 5
service = 5
track = 5
path = 5
cycleway = 5
footway = 5
pedestrian = 5
pier = 5
steps = 2
ferry = 5
excludeFromGrid = ferry