2 # Routino generic router Perl script
4 # Part of the Routino routing software.
6 # This file Copyright 2008-2010 Andrew M. Bishop
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU Affero General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU Affero General Public License for more details.
18 # You should have received a copy of the GNU Affero General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 # Use the directory paths script
25 # Use the perl Time::HiRes module
26 use Time::HiRes qw(gettimeofday tv_interval);
34 $routino={ # contains all default Routino options (generated using "--help-profile-pl").
36 # Default transport type
37 transport => 'motorcar',
40 transports => {foot => 1, horse => 2, wheelchair => 3, bicycle => 4, moped => 5, motorbike => 6, motorcar => 7, goods => 8, hgv => 9, psv => 10},
43 highways => {motorway => 1, trunk => 2, primary => 3, secondary => 4, tertiary => 5, unclassified => 6, residential => 7, service => 8, track => 9, cycleway => 10, path => 11, steps => 12},
46 properties => {paved => 1, multilane => 2, bridge => 3, tunnel => 4},
49 restrictions => {oneway => 1, weight => 2, height => 3, width => 4, length => 5},
53 motorway => { foot => 0, horse => 0, wheelchair => 0, bicycle => 0, moped => 0, motorbike => 100, motorcar => 100, goods => 100, hgv => 100, psv => 100},
54 trunk => { foot => 40, horse => 25, wheelchair => 40, bicycle => 30, moped => 90, motorbike => 100, motorcar => 100, goods => 100, hgv => 100, psv => 100},
55 primary => { foot => 50, horse => 50, wheelchair => 50, bicycle => 70, moped => 100, motorbike => 90, motorcar => 90, goods => 90, hgv => 90, psv => 90},
56 secondary => { foot => 60, horse => 50, wheelchair => 60, bicycle => 80, moped => 90, motorbike => 80, motorcar => 80, goods => 80, hgv => 80, psv => 80},
57 tertiary => { foot => 70, horse => 75, wheelchair => 70, bicycle => 90, moped => 80, motorbike => 70, motorcar => 70, goods => 70, hgv => 70, psv => 70},
58 unclassified => { foot => 80, horse => 75, wheelchair => 80, bicycle => 90, moped => 70, motorbike => 60, motorcar => 60, goods => 60, hgv => 60, psv => 60},
59 residential => { foot => 90, horse => 75, wheelchair => 90, bicycle => 90, moped => 60, motorbike => 50, motorcar => 50, goods => 50, hgv => 50, psv => 50},
60 service => { foot => 90, horse => 75, wheelchair => 90, bicycle => 90, moped => 80, motorbike => 80, motorcar => 80, goods => 80, hgv => 80, psv => 80},
61 track => { foot => 95, horse => 100, wheelchair => 95, bicycle => 90, moped => 0, motorbike => 0, motorcar => 0, goods => 0, hgv => 0, psv => 0},
62 cycleway => { foot => 95, horse => 90, wheelchair => 95, bicycle => 100, moped => 0, motorbike => 0, motorcar => 0, goods => 0, hgv => 0, psv => 0},
63 path => { foot => 100, horse => 100, wheelchair => 100, bicycle => 90, moped => 0, motorbike => 0, motorcar => 0, goods => 0, hgv => 0, psv => 0},
64 steps => { foot => 80, horse => 0, wheelchair => 0, bicycle => 0, moped => 0, motorbike => 0, motorcar => 0, goods => 0, hgv => 0, psv => 0}
69 motorway => { foot => 0, horse => 0, wheelchair => 0, bicycle => 0, moped => 48, motorbike => 112, motorcar => 112, goods => 96, hgv => 89, psv => 89},
70 trunk => { foot => 4, horse => 8, wheelchair => 4, bicycle => 20, moped => 48, motorbike => 96, motorcar => 96, goods => 96, hgv => 80, psv => 80},
71 primary => { foot => 4, horse => 8, wheelchair => 4, bicycle => 20, moped => 48, motorbike => 96, motorcar => 96, goods => 96, hgv => 80, psv => 80},
72 secondary => { foot => 4, horse => 8, wheelchair => 4, bicycle => 20, moped => 48, motorbike => 88, motorcar => 88, goods => 88, hgv => 80, psv => 80},
73 tertiary => { foot => 4, horse => 8, wheelchair => 4, bicycle => 20, moped => 48, motorbike => 80, motorcar => 80, goods => 80, hgv => 80, psv => 80},
74 unclassified => { foot => 4, horse => 8, wheelchair => 4, bicycle => 20, moped => 48, motorbike => 64, motorcar => 64, goods => 64, hgv => 64, psv => 64},
75 residential => { foot => 4, horse => 8, wheelchair => 4, bicycle => 20, moped => 48, motorbike => 48, motorcar => 48, goods => 48, hgv => 48, psv => 48},
76 service => { foot => 4, horse => 8, wheelchair => 4, bicycle => 20, moped => 32, motorbike => 32, motorcar => 32, goods => 32, hgv => 32, psv => 32},
77 track => { foot => 4, horse => 8, wheelchair => 4, bicycle => 20, moped => 16, motorbike => 16, motorcar => 16, goods => 16, hgv => 16, psv => 16},
78 cycleway => { foot => 4, horse => 8, wheelchair => 4, bicycle => 20, moped => 0, motorbike => 0, motorcar => 0, goods => 0, hgv => 0, psv => 0},
79 path => { foot => 4, horse => 8, wheelchair => 4, bicycle => 20, moped => 0, motorbike => 0, motorcar => 0, goods => 0, hgv => 0, psv => 0},
80 steps => { foot => 4, horse => 0, wheelchair => 4, bicycle => 0, moped => 0, motorbike => 0, motorcar => 0, goods => 0, hgv => 0, psv => 0}
85 paved => { foot => 50, horse => 20, wheelchair => 90, bicycle => 50, moped => 100, motorbike => 100, motorcar => 100, goods => 100, hgv => 100, psv => 100},
86 multilane => { foot => 25, horse => 25, wheelchair => 25, bicycle => 25, moped => 25, motorbike => 75, motorcar => 75, goods => 75, hgv => 75, psv => 75},
87 bridge => { foot => 50, horse => 50, wheelchair => 50, bicycle => 50, moped => 50, motorbike => 50, motorcar => 50, goods => 50, hgv => 50, psv => 50},
88 tunnel => { foot => 50, horse => 50, wheelchair => 50, bicycle => 50, moped => 50, motorbike => 50, motorcar => 50, goods => 50, hgv => 50, psv => 50}
92 profile_restrictions => {
93 oneway => { foot => 0, horse => 1, wheelchair => 0, bicycle => 1, moped => 1, motorbike => 1, motorcar => 1, goods => 1, hgv => 1, psv => 1},
94 weight => { foot => 0.0, horse => 0.0, wheelchair => 0.0, bicycle => 0.0, moped => 0.0, motorbike => 0.0, motorcar => 0.0, goods => 5.0, hgv => 10.0, psv => 15.0},
95 height => { foot => 0.0, horse => 0.0, wheelchair => 0.0, bicycle => 0.0, moped => 0.0, motorbike => 0.0, motorcar => 0.0, goods => 2.5, hgv => 3.0, psv => 3.0},
96 width => { foot => 0.0, horse => 0.0, wheelchair => 0.0, bicycle => 0.0, moped => 0.0, motorbike => 0.0, motorcar => 0.0, goods => 2.0, hgv => 2.5, psv => 2.5},
97 length => { foot => 0.0, horse => 0.0, wheelchair => 0.0, bicycle => 0.0, moped => 0.0, motorbike => 0.0, motorcar => 0.0, goods => 5.0, hgv => 6.0, psv => 6.0}
100 }; # end of routino variable
104 # Fill in the default parameters using the ones above (don't use executable compiled in defaults)
111 $params{transport}=$routino->{transport} if(!defined $params{transport});
113 my($transport)=$params{transport};
115 foreach $highway (keys %{$routino->{highways}})
117 $key="highway-$highway";
118 $value=$routino->{profile_highway}->{$highway}->{$transport};
119 $params{$key}=$value if(!defined $params{$key});
121 $key="speed-$highway";
122 $value=$routino->{profile_speed}->{$highway}->{$transport};
123 $params{$key}=$value if(!defined $params{$key});
126 foreach $property (keys %{$routino->{properties}})
128 $key="property-$property";
129 $value=$routino->{profile_property}->{$property}->{$transport};
130 $params{$key}=$value if(!defined $params{$key});
133 $params{oneway} =~ s/(true|on)/1/;
134 $params{oneway} =~ s/(false|off)/0/;
136 foreach $restriction (keys %{$routino->{restrictions}})
139 $value=$routino->{profile_restrictions}->{$restriction}->{$transport};
140 $params{$key}=$value if(!defined $params{$key});
153 my($optimise,%params)=@_;
155 # Combine all of the parameters together
157 my($params)="--$optimise";
159 foreach $key (keys %params)
161 $params.=" --$key=$params{$key}";
166 mkdir $results_dir,0755 if(! -d $results_dir);
169 # Create a unique output directory
171 chomp($uuid=`echo '$params' $$ | md5sum | cut -f1 '-d '`);
179 $params.=" --dir=$data_dir" if($data_dir);
180 $params.=" --prefix=$data_prefix" if($data_prefix);
183 $message=`$bin_dir/router $params 2>&1`;
185 (undef,undef,$cuser,$csystem) = times;
186 $time=sprintf "time: %.3f CPU / %.3f elapsed",$cuser+$csystem,tv_interval($t0);
188 if(-f "$optimise.txt")
190 $result=`tail -1 $optimise.txt`;
191 @result=split(/\t/,$result);
192 $result = $result[4]." , ".$result[5];
197 return($uuid,$time,$result,$message);
202 # Return the output file
205 # Possible file formats
209 "gpx-route" => "-route.gpx",
210 "gpx-track" => "-track.gpx",
212 "text-all" => "-all.txt"
215 # Possible MIME types
218 "html" => "text/html",
219 "gpx-route" => "text/xml",
220 "gpx-track" => "text/xml",
221 "text" => "text/plain",
222 "text-all" => "text/plain"
227 my($uuid,$type,$format)=@_;
229 $suffix=$suffixes{$format};
230 $mime =$mimetypes{$format};
232 $file="$results_dir/$uuid/$type$suffix";
236 if(!$type || !$uuid || !$format || ! -f $file)
238 print header('text/plain','404 Not found');
239 print "Not Found!\n";