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 ################################################################################
35 ########################### Routino default profile ############################
36 ################################################################################
38 $routino={ # contains all default Routino options (generated using "--help-profile-perl").
40 # Default transport type
41 transport => 'motorcar',
44 transports => { foot => 1, horse => 2, wheelchair => 3, bicycle => 4, moped => 5, motorbike => 6, motorcar => 7, goods => 8, hgv => 9, psv => 10 },
47 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, ferry => 13 },
50 properties => { paved => 1, multilane => 2, bridge => 3, tunnel => 4, footroute => 5, bicycleroute => 6 },
53 restrictions => { oneway => 1, weight => 2, height => 3, width => 4, length => 5 },
57 motorway => { foot => 0, horse => 0, wheelchair => 0, bicycle => 0, moped => 0, motorbike => 100, motorcar => 100, goods => 100, hgv => 100, psv => 100 },
58 trunk => { foot => 40, horse => 25, wheelchair => 40, bicycle => 30, moped => 90, motorbike => 100, motorcar => 100, goods => 100, hgv => 100, psv => 100 },
59 primary => { foot => 50, horse => 50, wheelchair => 50, bicycle => 70, moped => 100, motorbike => 90, motorcar => 90, goods => 90, hgv => 90, psv => 90 },
60 secondary => { foot => 60, horse => 50, wheelchair => 60, bicycle => 80, moped => 90, motorbike => 80, motorcar => 80, goods => 80, hgv => 80, psv => 80 },
61 tertiary => { foot => 70, horse => 75, wheelchair => 70, bicycle => 90, moped => 80, motorbike => 70, motorcar => 70, goods => 70, hgv => 70, psv => 70 },
62 unclassified => { foot => 80, horse => 75, wheelchair => 80, bicycle => 90, moped => 70, motorbike => 60, motorcar => 60, goods => 60, hgv => 60, psv => 60 },
63 residential => { foot => 90, horse => 75, wheelchair => 90, bicycle => 90, moped => 60, motorbike => 50, motorcar => 50, goods => 50, hgv => 50, psv => 50 },
64 service => { foot => 90, horse => 75, wheelchair => 90, bicycle => 90, moped => 80, motorbike => 80, motorcar => 80, goods => 80, hgv => 80, psv => 80 },
65 track => { foot => 95, horse => 100, wheelchair => 95, bicycle => 90, moped => 0, motorbike => 0, motorcar => 0, goods => 0, hgv => 0, psv => 0 },
66 cycleway => { foot => 95, horse => 90, wheelchair => 95, bicycle => 100, moped => 0, motorbike => 0, motorcar => 0, goods => 0, hgv => 0, psv => 0 },
67 path => { foot => 100, horse => 100, wheelchair => 100, bicycle => 90, moped => 0, motorbike => 0, motorcar => 0, goods => 0, hgv => 0, psv => 0 },
68 steps => { foot => 80, horse => 0, wheelchair => 0, bicycle => 0, moped => 0, motorbike => 0, motorcar => 0, goods => 0, hgv => 0, psv => 0 },
69 ferry => { foot => 20, horse => 20, wheelchair => 20, bicycle => 20, moped => 20, motorbike => 20, motorcar => 20, goods => 20, hgv => 20, psv => 20 }
74 motorway => { foot => 0, horse => 0, wheelchair => 0, bicycle => 0, moped => 48, motorbike => 112, motorcar => 112, goods => 96, hgv => 89, psv => 89 },
75 trunk => { foot => 4, horse => 8, wheelchair => 4, bicycle => 20, moped => 48, motorbike => 96, motorcar => 96, goods => 96, hgv => 80, psv => 80 },
76 primary => { foot => 4, horse => 8, wheelchair => 4, bicycle => 20, moped => 48, motorbike => 96, motorcar => 96, goods => 96, hgv => 80, psv => 80 },
77 secondary => { foot => 4, horse => 8, wheelchair => 4, bicycle => 20, moped => 48, motorbike => 88, motorcar => 88, goods => 88, hgv => 80, psv => 80 },
78 tertiary => { foot => 4, horse => 8, wheelchair => 4, bicycle => 20, moped => 48, motorbike => 80, motorcar => 80, goods => 80, hgv => 80, psv => 80 },
79 unclassified => { foot => 4, horse => 8, wheelchair => 4, bicycle => 20, moped => 48, motorbike => 64, motorcar => 64, goods => 64, hgv => 64, psv => 64 },
80 residential => { foot => 4, horse => 8, wheelchair => 4, bicycle => 20, moped => 48, motorbike => 48, motorcar => 48, goods => 48, hgv => 48, psv => 48 },
81 service => { foot => 4, horse => 8, wheelchair => 4, bicycle => 20, moped => 32, motorbike => 32, motorcar => 32, goods => 32, hgv => 32, psv => 32 },
82 track => { foot => 4, horse => 8, wheelchair => 4, bicycle => 20, moped => 16, motorbike => 16, motorcar => 16, goods => 16, hgv => 16, psv => 16 },
83 cycleway => { foot => 4, horse => 8, wheelchair => 4, bicycle => 20, moped => 0, motorbike => 0, motorcar => 0, goods => 0, hgv => 0, psv => 0 },
84 path => { foot => 4, horse => 8, wheelchair => 4, bicycle => 20, moped => 0, motorbike => 0, motorcar => 0, goods => 0, hgv => 0, psv => 0 },
85 steps => { foot => 4, horse => 0, wheelchair => 4, bicycle => 0, moped => 0, motorbike => 0, motorcar => 0, goods => 0, hgv => 0, psv => 0 },
86 ferry => { foot => 10, horse => 10, wheelchair => 10, bicycle => 10, moped => 10, motorbike => 10, motorcar => 10, goods => 10, hgv => 10, psv => 10 }
91 paved => { foot => 50, horse => 20, wheelchair => 90, bicycle => 50, moped => 100, motorbike => 100, motorcar => 100, goods => 100, hgv => 100, psv => 100 },
92 multilane => { foot => 25, horse => 25, wheelchair => 25, bicycle => 25, moped => 35, motorbike => 60, motorcar => 60, goods => 60, hgv => 60, psv => 60 },
93 bridge => { foot => 50, horse => 50, wheelchair => 50, bicycle => 50, moped => 50, motorbike => 50, motorcar => 50, goods => 50, hgv => 50, psv => 50 },
94 tunnel => { foot => 50, horse => 50, wheelchair => 50, bicycle => 50, moped => 50, motorbike => 50, motorcar => 50, goods => 50, hgv => 50, psv => 50 },
95 footroute => { foot => 55, horse => 50, wheelchair => 55, bicycle => 50, moped => 50, motorbike => 50, motorcar => 45, goods => 45, hgv => 45, psv => 45 },
96 bicycleroute => { foot => 55, horse => 50, wheelchair => 55, bicycle => 60, moped => 50, motorbike => 50, motorcar => 45, goods => 45, hgv => 45, psv => 45 }
100 profile_restrictions => {
101 oneway => { foot => 0, horse => 1, wheelchair => 0, bicycle => 1, moped => 1, motorbike => 1, motorcar => 1, goods => 1, hgv => 1, psv => 1 },
102 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 },
103 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 },
104 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 },
105 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 }
108 }; # end of routino variable
112 # Fill in the default parameters using the ones above (don't use executable compiled in defaults)
119 $params{transport}=$routino->{transport} if(!defined $params{transport});
121 my($transport)=$params{transport};
123 foreach $highway (keys %{$routino->{highways}})
125 $key="highway-$highway";
126 $value=$routino->{profile_highway}->{$highway}->{$transport};
127 $params{$key}=$value if(!defined $params{$key});
129 $key="speed-$highway";
130 $value=$routino->{profile_speed}->{$highway}->{$transport};
131 $params{$key}=$value if(!defined $params{$key});
134 foreach $property (keys %{$routino->{properties}})
136 $key="property-$property";
137 $value=$routino->{profile_property}->{$property}->{$transport};
138 $params{$key}=$value if(!defined $params{$key});
141 $params{oneway} =~ s/(true|on)/1/;
142 $params{oneway} =~ s/(false|off)/0/;
144 foreach $restriction (keys %{$routino->{restrictions}})
147 $value=$routino->{profile_restrictions}->{$restriction}->{$transport};
148 $params{$key}=$value if(!defined $params{$key});
161 my($optimise,%params)=@_;
163 # Combine all of the parameters together
165 my($params)="--$optimise";
167 foreach $key (keys %params)
169 $params.=" --$key=$params{$key}";
174 mkdir $results_dir,0755 if(! -d $results_dir);
177 # Create a unique output directory
179 chomp($uuid=`echo '$params' $$ | md5sum | cut -f1 '-d '`);
187 $params.=" --dir=$data_dir" if($data_dir);
188 $params.=" --prefix=$data_prefix" if($data_prefix);
191 $message=`$bin_dir/$router_exe $params 2>&1`;
193 (undef,undef,$cuser,$csystem) = times;
194 $time=sprintf "time: %.3f CPU / %.3f elapsed",$cuser+$csystem,tv_interval($t0);
196 if(-f "$optimise.txt")
198 $result=`tail -1 $optimise.txt`;
199 @result=split(/\t/,$result);
200 $result = $result[4]." , ".$result[5];
205 return($uuid,$time,$result,$message);
210 # Return the output file
213 # Possible file formats
217 "gpx-route" => "-route.gpx",
218 "gpx-track" => "-track.gpx",
220 "text-all" => "-all.txt"
223 # Possible MIME types
226 "html" => "text/html",
227 "gpx-route" => "text/xml",
228 "gpx-track" => "text/xml",
229 "text" => "text/plain",
230 "text-all" => "text/plain"
235 my($uuid,$type,$format)=@_;
237 $suffix=$suffixes{$format};
238 $mime =$mimetypes{$format};
240 $file="$results_dir/$uuid/$type$suffix";
244 if(!$type || !$uuid || !$format || ! -f $file)
246 print header('text/plain','404 Not found');
247 print "Not Found!\n";