-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
DennisOSRM
committed
Feb 14, 2012
1 parent
84b35f4
commit b210b22
Showing
28 changed files
with
1,818 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
source "http://rubygems.org" | ||
|
||
gem "cucumber" | ||
gem "rake" | ||
gem "osmlib-base" | ||
gem "sys-proctable" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
GEM | ||
remote: http://rubygems.org/ | ||
specs: | ||
builder (3.0.0) | ||
cucumber (1.1.4) | ||
builder (>= 2.1.2) | ||
diff-lcs (>= 1.1.2) | ||
gherkin (~> 2.7.1) | ||
json (>= 1.4.6) | ||
term-ansicolor (>= 1.0.6) | ||
diff-lcs (1.1.3) | ||
gherkin (2.7.6) | ||
json (>= 1.4.6) | ||
json (1.6.5) | ||
osmlib-base (0.1.4) | ||
rake (0.9.2.2) | ||
sys-proctable (0.9.1) | ||
term-ansicolor (1.0.7) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
cucumber | ||
osmlib-base | ||
rake | ||
sys-proctable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
require 'OSM/StreamParser' | ||
require 'socket' | ||
require 'digest/sha1' | ||
require 'cucumber/rake/task' | ||
require 'sys/proctable' | ||
|
||
SANDBOX = 'sandbox' | ||
DATA_FOLDER = 'osm_data' | ||
|
||
Cucumber::Rake::Task.new do |t| | ||
t.cucumber_opts = %w{--format pretty} | ||
end | ||
|
||
areas = { | ||
:kbh => { :country => 'denmark', :bbox => 'top=55.6972 left=12.5222 right=12.624 bottom=55.6376' }, | ||
:frd => { :country => 'denmark', :bbox => 'top=55.7007 left=12.4765 bottom=55.6576 right=12.5698' }, | ||
:regh => { :country => 'denmark', :bbox => 'top=56.164 left=11.792 bottom=55.403 right=12.731' }, | ||
:dk => { :country => 'denmark', :bbox => nil }, | ||
:skaane => { :counry => 'sweden', :bbox => 'top=56.55 left=12.4 bottom=55.3 right=14.6' } | ||
} | ||
|
||
|
||
|
||
osm_data_area_name = ARGV[1] ? ARGV[1].to_s.to_sym : :kbh | ||
raise "Unknown data area." unless areas[osm_data_area_name] | ||
osm_data_country = areas[osm_data_area_name][:country] | ||
osm_data_area_bbox = areas[osm_data_area_name][:bbox] | ||
|
||
|
||
task osm_data_area_name.to_sym {} #define empty task to prevent rake from whining. will break if area has same name as a task | ||
|
||
|
||
def each_process name, &block | ||
Sys::ProcTable.ps do |process| | ||
if process.comm.strip == name.strip | ||
yield process.pid.to_i, process.state.strip | ||
end | ||
end | ||
end | ||
|
||
def up? | ||
find_pid('osrm-routed') != nil | ||
end | ||
|
||
def find_pid name | ||
each_process(name) { |pid,state| return pid.to_i } | ||
return nil | ||
end | ||
|
||
def wait_for_shutdown name | ||
timeout = 10 | ||
(timeout*10).times do | ||
return if find_pid(name) == nil | ||
sleep 0.1 | ||
end | ||
raise "*** Could not terminate #{name}." | ||
end | ||
|
||
def write_server_ini osm_file | ||
s=<<-EOF | ||
Threads = 1 | ||
IP = 0.0.0.0 | ||
Port = 5000 | ||
hsgrData=#{DATA_FOLDER}/#{osm_file}.osrm.hsgr | ||
nodesData=#{DATA_FOLDER}/#{osm_file}.osrm.nodes | ||
ramIndex=#{DATA_FOLDER}/#{osm_file}.osrm.ramIndex | ||
fileIndex=#{DATA_FOLDER}/#{osm_file}.osrm.fileIndex | ||
namesData=#{DATA_FOLDER}/#{osm_file}.osrm.names | ||
EOF | ||
File.open( 'server.ini', 'w') {|f| f.write( s ) } | ||
end | ||
|
||
|
||
desc "Rebuild and run tests." | ||
task :default => [:build, :cucumber] | ||
|
||
desc "Build using SConsstruct." | ||
task :build do | ||
system "scons" | ||
end | ||
|
||
desc "Setup config files." | ||
task :setup do | ||
Dir.mkdir "#{SANDBOX}/#{DATA_FOLDER}" unless File.exist? "#{SANDBOX}/#{DATA_FOLDER}" | ||
['server.ini','speedprofile.ini','extractor.ini','contractor.ini'].each do |file| | ||
unless File.exist? "#{SANDBOX}/#{file}" | ||
puts "Copying #{file} template to sandbox/#{file}" | ||
FileUtils.cp file, "#{SANDBOX}/#{file}" | ||
end | ||
end | ||
end | ||
|
||
desc "Download OSM data." | ||
task :download => :setup do | ||
puts "Downloading..." | ||
raise "Error while downloading data." unless system "curl http://download.geofabrik.de/osm/europe/#{osm_data_country}.osm.pbf -o #{SANDBOX}/#{DATA_FOLDER}/#{osm_data_country}.osm.pbf" | ||
if osm_data_area_bbox | ||
puts "Cropping and converting to protobuffer..." | ||
raise "Error while cropping data." unless system "osmosis --read-pbf file=#{SANDBOX}/#{DATA_FOLDER}/#{osm_data_country}.osm.pbf --bounding-box #{osm_data_area_bbox} --write-pbf file=#{SANDBOX}/#{DATA_FOLDER}/#{osm_data_area_name}.osm.pbf omitmetadata=true" | ||
end | ||
end | ||
|
||
desc "Crop OSM data" | ||
task :crop do | ||
if osm_data_area_bbox | ||
raise "Error while cropping data." unless system "osmosis --read-pbf file=#{SANDBOX}/#{DATA_FOLDER}/#{osm_data_country}.osm.pbf --bounding-box #{osm_data_area_bbox} --write-pbf file=#{SANDBOX}/#{DATA_FOLDER}/#{osm_data_area_name}.osm.pbf omitmetadata=true" | ||
end | ||
end | ||
|
||
desc "Reprocess OSM data." | ||
task :process => :setup do | ||
Dir.chdir SANDBOX do | ||
raise "Error while extracting data." unless system "../osrm-extract #{DATA_FOLDER}/#{osm_data_area_name}.osm.pbf" | ||
puts | ||
raise "Error while preparing data." unless system "../osrm-prepare #{DATA_FOLDER}/#{osm_data_area_name}.osrm #{DATA_FOLDER}/#{osm_data_area_name}.osrm.restrictions" | ||
puts | ||
end | ||
end | ||
|
||
desc "Delete preprocessing files." | ||
task :clean do | ||
File.delete *Dir.glob("#{SANDBOX}/#{DATA_FOLDER}/*.osrm") | ||
File.delete *Dir.glob("#{SANDBOX}/#{DATA_FOLDER}/*.osrm.*") | ||
end | ||
|
||
desc "Run all cucumber test" | ||
task :test do | ||
system "cucumber" | ||
puts | ||
end | ||
|
||
desc "Run the routing server in the terminal. Press Ctrl-C to stop." | ||
task :run => :setup do | ||
Dir.chdir SANDBOX do | ||
write_server_ini osm_data_area_name | ||
system "../osrm-routed" | ||
end | ||
end | ||
|
||
desc "Launch the routing server in the background. Use rake:down to stop it." | ||
task :up => :setup do | ||
Dir.chdir SANDBOX do | ||
abort("Already up.") if up? | ||
write_server_ini osm_data_area_name | ||
pipe = IO.popen('../osrm-routed 1>>osrm-routed.log 2>>osrm-routed.log') | ||
timeout = 5 | ||
(timeout*10).times do | ||
begin | ||
socket = TCPSocket.new('localhost', 5000) | ||
socket.puts 'ping' | ||
rescue Errno::ECONNREFUSED | ||
sleep 0.1 | ||
end | ||
end | ||
end | ||
end | ||
|
||
desc "Stop the routing server." | ||
task :down do | ||
pid = find_pid 'osrm-routed' | ||
abort("Already down.") unless pid | ||
Process.kill 'TERM', pid | ||
end | ||
|
||
desc "Kill all osrm-extract, osrm-prepare and osrm-routed processes." | ||
task :kill do | ||
each_process('osrm-routed') { |pid,state| Process.kill 'KILL', pid } | ||
each_process('osrm-prepare') { |pid,state| Process.kill 'KILL', pid } | ||
each_process('osrm-extract') { |pid,state| Process.kill 'KILL', pid } | ||
wait_for_shutdown 'osrm-routed' | ||
wait_for_shutdown 'osrm-prepare' | ||
wait_for_shutdown 'osrm-extract' | ||
end | ||
|
||
desc "Get PIDs of all osrm-extract, osrm-prepare and osrm-routed processes." | ||
task :pid do | ||
each_process 'osrm-routed' do |pid,state| | ||
puts "#{pid}\t#{state}" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
@routing @access | ||
Feature: Oneway streets | ||
Basic accessability of various way types. | ||
|
||
Scenario: Basic access for cars | ||
Given the speedprofile "car" | ||
Then routability should be | ||
| highway | forw | | ||
| motorway | x | | ||
| motorway_link | x | | ||
| trunk | x | | ||
| trunk_link | x | | ||
| primary | x | | ||
| secondary | x | | ||
| tertiary | x | | ||
| residential | x | | ||
| service | x | | ||
| unclassified | x | | ||
| living_street | x | | ||
| road | x | | ||
| track | | | ||
| path | | | ||
| footway | | | ||
| pedestrian | | | ||
| steps | | | ||
| pier | | | ||
| cycleway | | | ||
| bridleway | | | ||
|
||
Scenario: Basic access for bicycles | ||
Bikes are allowed on footways etc because you can pull your bike at a lower speed. | ||
Given the speedprofile "bicycle" | ||
Then routability should be | ||
| highway | forw | | ||
| motorway | | | ||
| motorway_link | | | ||
| trunk | | | ||
| trunk_link | | | ||
| primary | x | | ||
| secondary | x | | ||
| tertiary | x | | ||
| residential | x | | ||
| service | x | | ||
| unclassified | x | | ||
| living_street | x | | ||
| road | x | | ||
| track | x | | ||
| path | x | | ||
| footway | x | | ||
| pedestrian | x | | ||
| steps | x | | ||
| pier | x | | ||
| cycleway | x | | ||
| bridleway | | | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
@routing @bad | ||
Feature: Handle bad data in a graceful manner | ||
|
||
Scenario: Empty dataset | ||
Given the nodes | ||
| a | b | | ||
|
||
Given the ways | ||
| nodes | | ||
|
||
When I route I should get | ||
| from | to | route | | ||
| a | b | | | ||
|
||
Scenario: Start/end point at the same location | ||
Given the nodes | ||
| a | b | | ||
| 1 | 2 | | ||
|
||
Given the ways | ||
| nodes | | ||
| ab | | ||
|
||
When I route I should get | ||
| from | to | route | | ||
| a | a | | | ||
| b | b | | | ||
| 1 | 1 | | | ||
| 2 | 2 | | | ||
|
||
Scenario: Start/end point far outside data area | ||
Given the nodes | ||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 1 | | ||
| a | b | | | | | | | | | | | | | | | | | | | | | | | | | | | 2 | | ||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 3 | | ||
|
||
Given the ways | ||
| nodes | | ||
| ab | | ||
|
||
When I route I should get | ||
| from | to | route | | ||
| 1 | a | ab | | ||
| 2 | a | ab | | ||
| 3 | a | ab | | ||
| 1 | b | | | ||
| 2 | b | | | ||
| 3 | b | | | ||
| 1 | 2 | | | ||
| 1 | 3 | | | ||
| 2 | 1 | | | ||
| 2 | 3 | | | ||
| 3 | 1 | | | ||
| 3 | 2 | | | ||
|
Oops, something went wrong.
b210b22
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
happy you find this useful and merged it to master.
one thing - i notice that the author was changed on all files, and i'm getting git conflicts for all the modified files when i try to merge your master to my repo, which is quite impractical. it's probably related to the method you used to merge my additions?
b210b22
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, sorry about that. Did not mean to cloud your contributions, but the automatic merge did not work. I merged it more or less manually. At times Git troubles me.
b210b22
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, other contributors might be quite displeased to see their names replaced. so it's important to find a good workflow moving forward.
what conflicts did you get when merging? it was rebased on your latest master.
http://help.github.com/send-pull-requests/
https://github.com/blog/843-the-merge-button
b210b22
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the last commit message and attached your name as author. I hope this fixes that. Again, sorry for the trouble. The next beer will be on my tap.
I was not able to properly resolve the conflicts occuring in ExtractorCallbacks.h. After about 15 minutes of unsuccessful tries to resolve that I got impatient and copied the changes into the directory. I'll do better next time.
b210b22
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks. i resolved conflicts manually and pushed my master branch to github.
github is powerful, but can be complicted. i'm still learning too :-)
b210b22
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems your master doesn't include any of the changes needed to compile on mac.
b210b22
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Working on that at the moment. Just booted the MacBook.