Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Contents of /trunk/web/www/routino/router.pl
Parent Directory
|
Revision Log
Revision 998 -
(show annotations)
(download)
(as text)
Mon Jun 4 15:37:33 2012 UTC (12 years, 10 months ago) by amb
File MIME type: text/x-perl
File size: 4610 byte(s)
Mon Jun 4 15:37:33 2012 UTC (12 years, 10 months ago) by amb
File MIME type: text/x-perl
File size: 4610 byte(s)
Move the filename prefix parameter to the paths.pl script with the other user-editable parameters.
1 | # |
2 | # Routino generic router Perl script |
3 | # |
4 | # Part of the Routino routing software. |
5 | # |
6 | # This file Copyright 2008-2012 Andrew M. Bishop |
7 | # |
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. |
12 | # |
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. |
17 | # |
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/>. |
20 | # |
21 | |
22 | # Use the directory paths script |
23 | require "paths.pl"; |
24 | |
25 | # Load the profiles variables |
26 | require "profiles.pl"; |
27 | |
28 | # Use the perl Time::HiRes module |
29 | use Time::HiRes qw(gettimeofday tv_interval); |
30 | |
31 | $t0 = [gettimeofday]; |
32 | |
33 | |
34 | # |
35 | # Fill in the default parameters using the ones above (don't use executable compiled in defaults) |
36 | # |
37 | |
38 | sub FillInDefaults |
39 | { |
40 | my(%params)=@_; |
41 | |
42 | $params{transport}=$routino->{transport} if(!defined $params{transport}); |
43 | |
44 | my($transport)=$params{transport}; |
45 | |
46 | foreach $highway (keys %{$routino->{highways}}) |
47 | { |
48 | $key="highway-$highway"; |
49 | $value=$routino->{profile_highway}->{$highway}->{$transport}; |
50 | $params{$key}=$value if(!defined $params{$key}); |
51 | |
52 | $key="speed-$highway"; |
53 | $value=$routino->{profile_speed}->{$highway}->{$transport}; |
54 | $params{$key}=$value if(!defined $params{$key}); |
55 | } |
56 | |
57 | foreach $property (keys %{$routino->{properties}}) |
58 | { |
59 | $key="property-$property"; |
60 | $value=$routino->{profile_property}->{$property}->{$transport}; |
61 | $params{$key}=$value if(!defined $params{$key}); |
62 | } |
63 | |
64 | $params{oneway} =~ s/(true|on)/1/; |
65 | $params{oneway} =~ s/(false|off)/0/; |
66 | |
67 | $params{turns} =~ s/(true|on)/1/; |
68 | $params{turns} =~ s/(false|off)/0/; |
69 | |
70 | foreach $restriction (keys %{$routino->{restrictions}}) |
71 | { |
72 | $key="$restriction"; |
73 | $value=$routino->{profile_restrictions}->{$restriction}->{$transport}; |
74 | $params{$key}=$value if(!defined $params{$key}); |
75 | } |
76 | |
77 | return %params; |
78 | } |
79 | |
80 | |
81 | # |
82 | # Run the router |
83 | # |
84 | |
85 | sub RunRouter |
86 | { |
87 | my($optimise,%params)=@_; |
88 | |
89 | # Combine all of the parameters together |
90 | |
91 | my($params)="--$optimise"; |
92 | |
93 | foreach $key (keys %params) |
94 | { |
95 | $params.=" --$key=$params{$key}"; |
96 | } |
97 | |
98 | # Change directory |
99 | |
100 | mkdir $results_dir,0755 if(! -d $results_dir); |
101 | chdir $results_dir; |
102 | |
103 | # Create a unique output directory |
104 | |
105 | if($^O eq "darwin") |
106 | { |
107 | chomp($uuid=`echo '$params' $$ | md5 | cut -f1 '-d '`); |
108 | } |
109 | else |
110 | { |
111 | chomp($uuid=`echo '$params' $$ | md5sum | cut -f1 '-d '`); |
112 | } |
113 | |
114 | mkdir $uuid; |
115 | chmod 0775, $uuid; |
116 | chdir $uuid; |
117 | |
118 | # Run the router |
119 | |
120 | $params.=" --dir=$data_dir" if($data_dir); |
121 | $params.=" --prefix=$data_prefix" if($data_prefix); |
122 | $params.=" --loggable"; |
123 | |
124 | system "$bin_dir/$router_exe $params > router.log 2>&1"; |
125 | |
126 | (undef,undef,$cuser,$csystem) = times; |
127 | $time=sprintf "time: %.3f CPU / %.3f elapsed",$cuser+$csystem,tv_interval($t0); |
128 | |
129 | $message=""; |
130 | |
131 | if($? != 0) |
132 | { |
133 | $message=`tail -1 router.log`; |
134 | } |
135 | |
136 | $result=""; |
137 | |
138 | if(-f "$optimise.txt") |
139 | { |
140 | $result=`tail -1 $optimise.txt`; |
141 | @result=split(/\t/,$result); |
142 | $result = $result[4]." , ".$result[5]; |
143 | } |
144 | |
145 | # Return the results |
146 | |
147 | return($uuid,$time,$result,$message); |
148 | } |
149 | |
150 | |
151 | # |
152 | # Return the output file |
153 | # |
154 | |
155 | # Possible file formats |
156 | |
157 | %suffixes=( |
158 | "html" => ".html", |
159 | "gpx-route" => "-route.gpx", |
160 | "gpx-track" => "-track.gpx", |
161 | "text" => ".txt", |
162 | "text-all" => "-all.txt", |
163 | "log" => ".log" |
164 | ); |
165 | |
166 | # Possible MIME types |
167 | |
168 | %mimetypes=( |
169 | "html" => "text/html", |
170 | "gpx-route" => "text/xml", |
171 | "gpx-track" => "text/xml", |
172 | "text" => "text/plain", |
173 | "text-all" => "text/plain", |
174 | "log" => "text/plain" |
175 | ); |
176 | |
177 | sub ReturnOutput |
178 | { |
179 | my($uuid,$type,$format)=@_; |
180 | |
181 | if($type eq "router") { $format="log" } |
182 | |
183 | $suffix=$suffixes{$format}; |
184 | $mime =$mimetypes{$format}; |
185 | |
186 | $file="$results_dir/$uuid/$type$suffix"; |
187 | |
188 | # Return the output |
189 | |
190 | if(!$type || !$uuid || !$format || ! -f $file) |
191 | { |
192 | print header('text/plain','404 Not found'); |
193 | print "Not Found!\n"; |
194 | } |
195 | else |
196 | { |
197 | print header($mime); |
198 | |
199 | system "cat $file"; |
200 | } |
201 | } |
202 | |
203 | 1; |