Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Annotation of /trunk/src/profiles.c
Parent Directory
|
Revision Log
Revision 308 -
(hide annotations)
(download)
(as text)
Fri Nov 27 11:03:41 2009 UTC (15 years, 4 months ago) by amb
File MIME type: text/x-csrc
File size: 31789 byte(s)
Fri Nov 27 11:03:41 2009 UTC (15 years, 4 months ago) by amb
File MIME type: text/x-csrc
File size: 31789 byte(s)
Add in "multilane" as a new highway property.
1 | amb | 83 | /*************************************** |
2 | amb | 308 | $Header: /home/amb/CVS/routino/src/profiles.c,v 1.27 2009-11-27 11:03:41 amb Exp $ |
3 | amb | 83 | |
4 | The pre-defined profiles and the functions for handling them. | ||
5 | amb | 151 | |
6 | Part of the Routino routing software. | ||
7 | amb | 83 | ******************/ /****************** |
8 | amb | 151 | This file Copyright 2008,2009 Andrew M. Bishop |
9 | amb | 83 | |
10 | amb | 151 | This program is free software: you can redistribute it and/or modify |
11 | it under the terms of the GNU Affero General Public License as published by | ||
12 | the Free Software Foundation, either version 3 of the License, or | ||
13 | (at your option) any later version. | ||
14 | |||
15 | This program is distributed in the hope that it will be useful, | ||
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | GNU Affero General Public License for more details. | ||
19 | |||
20 | You should have received a copy of the GNU Affero General Public License | ||
21 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
22 | amb | 83 | ***************************************/ |
23 | |||
24 | |||
25 | #include <stdio.h> | ||
26 | |||
27 | #include "profiles.h" | ||
28 | amb | 97 | #include "types.h" |
29 | amb | 83 | #include "ways.h" |
30 | |||
31 | |||
32 | amb | 228 | /*+ The set of built-in profiles for different transport types. +*/ |
33 | amb | 83 | static Profile builtin_profiles[]= |
34 | { | ||
35 | /* The profile for travel by Foot */ | ||
36 | |||
37 | [Transport_Foot] = { | ||
38 | .transport=Transport_Foot, | ||
39 | .allow =Allow_Foot, | ||
40 | amb | 166 | .highway = { |
41 | [Way_Motorway ] = 0, | ||
42 | [Way_Trunk ] = 40, | ||
43 | [Way_Primary ] = 50, | ||
44 | [Way_Secondary ] = 60, | ||
45 | [Way_Tertiary ] = 70, | ||
46 | [Way_Unclassified] = 80, | ||
47 | [Way_Residential ] = 90, | ||
48 | [Way_Service ] = 90, | ||
49 | [Way_Track ] = 95, | ||
50 | amb | 293 | [Way_Cycleway ] = 95, |
51 | amb | 166 | [Way_Path ] = 100, |
52 | amb | 306 | [Way_Steps ] = 80, |
53 | amb | 83 | }, |
54 | .speed = { | ||
55 | amb | 112 | [Way_Motorway ] = 0, |
56 | amb | 138 | [Way_Trunk ] = kph_to_speed(4), |
57 | [Way_Primary ] = kph_to_speed(4), | ||
58 | [Way_Secondary ] = kph_to_speed(4), | ||
59 | [Way_Tertiary ] = kph_to_speed(4), | ||
60 | [Way_Unclassified] = kph_to_speed(4), | ||
61 | [Way_Residential ] = kph_to_speed(4), | ||
62 | [Way_Service ] = kph_to_speed(4), | ||
63 | [Way_Track ] = kph_to_speed(4), | ||
64 | amb | 293 | [Way_Cycleway ] = kph_to_speed(4), |
65 | amb | 148 | [Way_Path ] = kph_to_speed(4), |
66 | amb | 306 | [Way_Steps ] = kph_to_speed(4), |
67 | amb | 83 | }, |
68 | amb | 298 | .props_yes= { |
69 | amb | 308 | [Property_Paved] = 50, |
70 | [Property_Multilane] = 25, | ||
71 | amb | 298 | }, |
72 | amb | 83 | .oneway = 0, |
73 | amb | 138 | .weight = 0, |
74 | .height = 0, | ||
75 | .width = 0, | ||
76 | .length = 0, | ||
77 | amb | 83 | }, |
78 | |||
79 | amb | 294 | /* The profile for travel by Horse */ |
80 | |||
81 | [Transport_Horse] = { | ||
82 | .transport=Transport_Horse, | ||
83 | .allow =Allow_Horse, | ||
84 | .highway = { | ||
85 | [Way_Motorway ] = 0, | ||
86 | [Way_Trunk ] = 25, | ||
87 | [Way_Primary ] = 50, | ||
88 | [Way_Secondary ] = 50, | ||
89 | [Way_Tertiary ] = 75, | ||
90 | [Way_Unclassified] = 75, | ||
91 | [Way_Residential ] = 75, | ||
92 | [Way_Service ] = 75, | ||
93 | [Way_Track ] = 100, | ||
94 | [Way_Cycleway ] = 90, | ||
95 | [Way_Path ] = 100, | ||
96 | amb | 306 | [Way_Steps ] = 0, |
97 | amb | 294 | }, |
98 | .speed = { | ||
99 | [Way_Motorway ] = 0, | ||
100 | amb | 295 | [Way_Trunk ] = kph_to_speed(8), |
101 | amb | 294 | [Way_Primary ] = kph_to_speed(8), |
102 | [Way_Secondary ] = kph_to_speed(8), | ||
103 | [Way_Tertiary ] = kph_to_speed(8), | ||
104 | [Way_Unclassified] = kph_to_speed(8), | ||
105 | [Way_Residential ] = kph_to_speed(8), | ||
106 | [Way_Service ] = kph_to_speed(8), | ||
107 | [Way_Track ] = kph_to_speed(8), | ||
108 | [Way_Cycleway ] = kph_to_speed(8), | ||
109 | [Way_Path ] = kph_to_speed(8), | ||
110 | amb | 306 | [Way_Steps ] = 0, |
111 | amb | 294 | }, |
112 | amb | 298 | .props_yes= { |
113 | amb | 308 | [Property_Paved] = 20, |
114 | [Property_Multilane] = 25, | ||
115 | amb | 298 | }, |
116 | amb | 294 | .oneway = 1, |
117 | .weight = 0, | ||
118 | .height = 0, | ||
119 | .width = 0, | ||
120 | .length = 0, | ||
121 | }, | ||
122 | |||
123 | amb | 83 | /* The profile for travel by Bicycle */ |
124 | |||
125 | [Transport_Bicycle] = { | ||
126 | .transport=Transport_Bicycle, | ||
127 | .allow =Allow_Bicycle, | ||
128 | amb | 166 | .highway = { |
129 | [Way_Motorway ] = 0, | ||
130 | [Way_Trunk ] = 30, | ||
131 | [Way_Primary ] = 70, | ||
132 | [Way_Secondary ] = 80, | ||
133 | [Way_Tertiary ] = 90, | ||
134 | [Way_Unclassified] = 90, | ||
135 | [Way_Residential ] = 90, | ||
136 | [Way_Service ] = 90, | ||
137 | [Way_Track ] = 90, | ||
138 | amb | 293 | [Way_Cycleway ] = 100, |
139 | amb | 166 | [Way_Path ] = 90, |
140 | amb | 306 | [Way_Steps ] = 0, |
141 | amb | 83 | }, |
142 | .speed = { | ||
143 | amb | 112 | [Way_Motorway ] = 0, |
144 | amb | 295 | [Way_Trunk ] = kph_to_speed(20), |
145 | amb | 138 | [Way_Primary ] = kph_to_speed(20), |
146 | [Way_Secondary ] = kph_to_speed(20), | ||
147 | [Way_Tertiary ] = kph_to_speed(20), | ||
148 | [Way_Unclassified] = kph_to_speed(20), | ||
149 | [Way_Residential ] = kph_to_speed(20), | ||
150 | [Way_Service ] = kph_to_speed(20), | ||
151 | [Way_Track ] = kph_to_speed(20), | ||
152 | amb | 293 | [Way_Cycleway ] = kph_to_speed(20), |
153 | amb | 148 | [Way_Path ] = kph_to_speed(20), |
154 | amb | 306 | [Way_Steps ] = 0, |
155 | amb | 83 | }, |
156 | amb | 298 | .props_yes= { |
157 | amb | 308 | [Property_Paved] = 50, |
158 | [Property_Multilane] = 25, | ||
159 | amb | 298 | }, |
160 | amb | 83 | .oneway = 1, |
161 | amb | 138 | .weight = 0, |
162 | .height = 0, | ||
163 | .width = 0, | ||
164 | .length = 0, | ||
165 | amb | 83 | }, |
166 | |||
167 | amb | 296 | /* The profile for travel by Moped */ |
168 | |||
169 | [Transport_Moped] = { | ||
170 | .transport=Transport_Moped, | ||
171 | .allow =Allow_Moped, | ||
172 | .highway = { | ||
173 | [Way_Motorway ] = 0, | ||
174 | [Way_Trunk ] = 90, | ||
175 | [Way_Primary ] = 100, | ||
176 | [Way_Secondary ] = 90, | ||
177 | [Way_Tertiary ] = 80, | ||
178 | [Way_Unclassified] = 70, | ||
179 | [Way_Residential ] = 60, | ||
180 | [Way_Service ] = 80, | ||
181 | [Way_Track ] = 0, | ||
182 | [Way_Cycleway ] = 0, | ||
183 | [Way_Path ] = 0, | ||
184 | amb | 306 | [Way_Steps ] = 0, |
185 | amb | 296 | }, |
186 | .speed = { | ||
187 | [Way_Motorway ] = kph_to_speed(30*1.6), | ||
188 | [Way_Trunk ] = kph_to_speed(30*1.6), | ||
189 | [Way_Primary ] = kph_to_speed(30*1.6), | ||
190 | [Way_Secondary ] = kph_to_speed(30*1.6), | ||
191 | [Way_Tertiary ] = kph_to_speed(30*1.6), | ||
192 | [Way_Unclassified] = kph_to_speed(30*1.6), | ||
193 | [Way_Residential ] = kph_to_speed(30*1.6), | ||
194 | [Way_Service ] = kph_to_speed(20*1.6), | ||
195 | [Way_Track ] = kph_to_speed(10*1.6), | ||
196 | [Way_Cycleway ] = 0, | ||
197 | [Way_Path ] = 0, | ||
198 | amb | 306 | [Way_Steps ] = 0, |
199 | amb | 296 | }, |
200 | amb | 298 | .props_yes= { |
201 | amb | 308 | [Property_Paved] = 100, |
202 | [Property_Multilane] = 25, | ||
203 | amb | 298 | }, |
204 | amb | 296 | .oneway = 1, |
205 | .weight = 0, | ||
206 | .height = 0, | ||
207 | .width = 0, | ||
208 | .length = 0, | ||
209 | }, | ||
210 | |||
211 | amb | 83 | /* The profile for travel by Motorbike */ |
212 | |||
213 | [Transport_Motorbike] = { | ||
214 | .transport=Transport_Motorbike, | ||
215 | .allow =Allow_Motorbike, | ||
216 | amb | 166 | .highway = { |
217 | [Way_Motorway ] = 100, | ||
218 | [Way_Trunk ] = 100, | ||
219 | [Way_Primary ] = 90, | ||
220 | [Way_Secondary ] = 80, | ||
221 | [Way_Tertiary ] = 70, | ||
222 | [Way_Unclassified] = 60, | ||
223 | [Way_Residential ] = 50, | ||
224 | [Way_Service ] = 80, | ||
225 | [Way_Track ] = 0, | ||
226 | amb | 293 | [Way_Cycleway ] = 0, |
227 | amb | 166 | [Way_Path ] = 0, |
228 | amb | 306 | [Way_Steps ] = 0, |
229 | amb | 83 | }, |
230 | .speed = { | ||
231 | amb | 138 | [Way_Motorway ] = kph_to_speed(70*1.6), |
232 | [Way_Trunk ] = kph_to_speed(60*1.6), | ||
233 | [Way_Primary ] = kph_to_speed(60*1.6), | ||
234 | [Way_Secondary ] = kph_to_speed(55*1.6), | ||
235 | [Way_Tertiary ] = kph_to_speed(50*1.6), | ||
236 | [Way_Unclassified] = kph_to_speed(40*1.6), | ||
237 | [Way_Residential ] = kph_to_speed(30*1.6), | ||
238 | [Way_Service ] = kph_to_speed(20*1.6), | ||
239 | amb | 178 | [Way_Track ] = kph_to_speed(10*1.6), |
240 | amb | 293 | [Way_Cycleway ] = 0, |
241 | amb | 148 | [Way_Path ] = 0, |
242 | amb | 306 | [Way_Steps ] = 0, |
243 | amb | 83 | }, |
244 | amb | 298 | .props_yes= { |
245 | amb | 308 | [Property_Paved] = 100, |
246 | [Property_Multilane] = 75, | ||
247 | amb | 298 | }, |
248 | amb | 83 | .oneway = 1, |
249 | amb | 138 | .weight = 0, |
250 | .height = 0, | ||
251 | .width = 0, | ||
252 | .length = 0, | ||
253 | amb | 83 | }, |
254 | |||
255 | /* The profile for travel by Motorcar */ | ||
256 | |||
257 | [Transport_Motorcar] = { | ||
258 | .transport=Transport_Motorcar, | ||
259 | .allow =Allow_Motorcar, | ||
260 | amb | 166 | .highway = { |
261 | [Way_Motorway ] = 100, | ||
262 | [Way_Trunk ] = 100, | ||
263 | [Way_Primary ] = 90, | ||
264 | [Way_Secondary ] = 80, | ||
265 | [Way_Tertiary ] = 70, | ||
266 | [Way_Unclassified] = 60, | ||
267 | [Way_Residential ] = 50, | ||
268 | [Way_Service ] = 80, | ||
269 | [Way_Track ] = 0, | ||
270 | amb | 293 | [Way_Cycleway ] = 0, |
271 | amb | 166 | [Way_Path ] = 0, |
272 | amb | 306 | [Way_Steps ] = 0, |
273 | amb | 83 | }, |
274 | .speed = { | ||
275 | amb | 138 | [Way_Motorway ] = kph_to_speed(70*1.6), |
276 | [Way_Trunk ] = kph_to_speed(60*1.6), | ||
277 | [Way_Primary ] = kph_to_speed(60*1.6), | ||
278 | [Way_Secondary ] = kph_to_speed(55*1.6), | ||
279 | [Way_Tertiary ] = kph_to_speed(50*1.6), | ||
280 | [Way_Unclassified] = kph_to_speed(40*1.6), | ||
281 | [Way_Residential ] = kph_to_speed(30*1.6), | ||
282 | [Way_Service ] = kph_to_speed(20*1.6), | ||
283 | amb | 178 | [Way_Track ] = kph_to_speed(10*1.6), |
284 | amb | 293 | [Way_Cycleway ] = 0, |
285 | amb | 148 | [Way_Path ] = 0, |
286 | amb | 306 | [Way_Steps ] = 0, |
287 | amb | 83 | }, |
288 | amb | 298 | .props_yes= { |
289 | amb | 308 | [Property_Paved] = 100, |
290 | [Property_Multilane] = 75, | ||
291 | amb | 298 | }, |
292 | amb | 83 | .oneway = 1, |
293 | amb | 138 | .weight = 0, |
294 | .height = 0, | ||
295 | .width = 0, | ||
296 | .length = 0, | ||
297 | amb | 83 | }, |
298 | |||
299 | /* The profile for travel by Goods */ | ||
300 | |||
301 | [Transport_Goods] = { | ||
302 | .transport=Transport_Goods, | ||
303 | .allow =Allow_Goods, | ||
304 | amb | 166 | .highway = { |
305 | [Way_Motorway ] = 100, | ||
306 | [Way_Trunk ] = 100, | ||
307 | [Way_Primary ] = 90, | ||
308 | [Way_Secondary ] = 80, | ||
309 | [Way_Tertiary ] = 70, | ||
310 | [Way_Unclassified] = 60, | ||
311 | [Way_Residential ] = 50, | ||
312 | [Way_Service ] = 80, | ||
313 | [Way_Track ] = 0, | ||
314 | amb | 293 | [Way_Cycleway ] = 0, |
315 | amb | 166 | [Way_Path ] = 0, |
316 | amb | 306 | [Way_Steps ] = 0, |
317 | amb | 83 | }, |
318 | .speed = { | ||
319 | amb | 138 | [Way_Motorway ] = kph_to_speed(60*1.6), |
320 | [Way_Trunk ] = kph_to_speed(60*1.6), | ||
321 | [Way_Primary ] = kph_to_speed(60*1.6), | ||
322 | [Way_Secondary ] = kph_to_speed(55*1.6), | ||
323 | [Way_Tertiary ] = kph_to_speed(50*1.6), | ||
324 | [Way_Unclassified] = kph_to_speed(40*1.6), | ||
325 | [Way_Residential ] = kph_to_speed(30*1.6), | ||
326 | [Way_Service ] = kph_to_speed(20*1.6), | ||
327 | amb | 178 | [Way_Track ] = kph_to_speed(10*1.6), |
328 | amb | 293 | [Way_Cycleway ] = 0, |
329 | amb | 148 | [Way_Path ] = 0, |
330 | amb | 306 | [Way_Steps ] = 0, |
331 | amb | 83 | }, |
332 | amb | 298 | .props_yes= { |
333 | amb | 308 | [Property_Paved] = 100, |
334 | [Property_Multilane] = 75, | ||
335 | amb | 298 | }, |
336 | amb | 83 | .oneway = 1, |
337 | amb | 138 | .weight = tonnes_to_weight(5), |
338 | .height = metres_to_height(2.5), | ||
339 | .width = metres_to_width (2), | ||
340 | .length = metres_to_length(5), | ||
341 | amb | 83 | }, |
342 | |||
343 | /* The profile for travel by HGV */ | ||
344 | |||
345 | [Transport_HGV] = { | ||
346 | .transport=Transport_HGV, | ||
347 | .allow =Allow_HGV, | ||
348 | amb | 166 | .highway = { |
349 | [Way_Motorway ] = 100, | ||
350 | [Way_Trunk ] = 100, | ||
351 | [Way_Primary ] = 90, | ||
352 | [Way_Secondary ] = 80, | ||
353 | [Way_Tertiary ] = 70, | ||
354 | [Way_Unclassified] = 60, | ||
355 | [Way_Residential ] = 50, | ||
356 | [Way_Service ] = 80, | ||
357 | [Way_Track ] = 0, | ||
358 | amb | 293 | [Way_Cycleway ] = 0, |
359 | amb | 166 | [Way_Path ] = 0, |
360 | amb | 306 | [Way_Steps ] = 0, |
361 | amb | 83 | }, |
362 | .speed = { | ||
363 | amb | 138 | [Way_Motorway ] = kph_to_speed(56*1.6), |
364 | [Way_Trunk ] = kph_to_speed(50*1.6), | ||
365 | [Way_Primary ] = kph_to_speed(50*1.6), | ||
366 | [Way_Secondary ] = kph_to_speed(50*1.6), | ||
367 | [Way_Tertiary ] = kph_to_speed(50*1.6), | ||
368 | [Way_Unclassified] = kph_to_speed(40*1.6), | ||
369 | [Way_Residential ] = kph_to_speed(30*1.6), | ||
370 | [Way_Service ] = kph_to_speed(20*1.6), | ||
371 | amb | 178 | [Way_Track ] = kph_to_speed(10*1.6), |
372 | amb | 293 | [Way_Cycleway ] = 0, |
373 | amb | 148 | [Way_Path ] = 0, |
374 | amb | 306 | [Way_Steps ] = 0, |
375 | amb | 83 | }, |
376 | amb | 298 | .props_yes= { |
377 | amb | 308 | [Property_Paved] = 100, |
378 | [Property_Multilane] = 75, | ||
379 | amb | 298 | }, |
380 | amb | 83 | .oneway = 1, |
381 | amb | 138 | .weight = tonnes_to_weight(10), |
382 | .height = metres_to_height(3), | ||
383 | .width = metres_to_width (2.5), | ||
384 | .length = metres_to_length(6), | ||
385 | amb | 83 | }, |
386 | |||
387 | /* The profile for travel by PSV */ | ||
388 | |||
389 | [Transport_PSV] = { | ||
390 | .transport=Transport_PSV, | ||
391 | .allow =Allow_PSV, | ||
392 | amb | 166 | .highway = { |
393 | [Way_Motorway ] = 100, | ||
394 | [Way_Trunk ] = 100, | ||
395 | [Way_Primary ] = 90, | ||
396 | [Way_Secondary ] = 80, | ||
397 | [Way_Tertiary ] = 70, | ||
398 | [Way_Unclassified] = 60, | ||
399 | [Way_Residential ] = 50, | ||
400 | [Way_Service ] = 80, | ||
401 | [Way_Track ] = 0, | ||
402 | amb | 293 | [Way_Cycleway ] = 0, |
403 | amb | 166 | [Way_Path ] = 0, |
404 | amb | 306 | [Way_Steps ] = 0, |
405 | amb | 83 | }, |
406 | .speed = { | ||
407 | amb | 138 | [Way_Motorway ] = kph_to_speed(56*1.6), |
408 | [Way_Trunk ] = kph_to_speed(50*1.6), | ||
409 | [Way_Primary ] = kph_to_speed(50*1.6), | ||
410 | [Way_Secondary ] = kph_to_speed(50*1.6), | ||
411 | [Way_Tertiary ] = kph_to_speed(50*1.6), | ||
412 | [Way_Unclassified] = kph_to_speed(40*1.6), | ||
413 | [Way_Residential ] = kph_to_speed(30*1.6), | ||
414 | [Way_Service ] = kph_to_speed(20*1.6), | ||
415 | amb | 178 | [Way_Track ] = kph_to_speed(10*1.6), |
416 | amb | 293 | [Way_Cycleway ] = 0, |
417 | amb | 148 | [Way_Path ] = 0, |
418 | amb | 306 | [Way_Steps ] = 0, |
419 | amb | 83 | }, |
420 | amb | 298 | .props_yes= { |
421 | amb | 308 | [Property_Paved] = 100, |
422 | [Property_Multilane] = 75, | ||
423 | amb | 298 | }, |
424 | amb | 83 | .oneway = 1, |
425 | amb | 138 | .weight = tonnes_to_weight(15), |
426 | .height = metres_to_height(3), | ||
427 | .width = metres_to_width (2.5), | ||
428 | .length = metres_to_length(6), | ||
429 | amb | 83 | }, |
430 | }; | ||
431 | |||
432 | |||
433 | /*++++++++++++++++++++++++++++++++++++++ | ||
434 | Get the profile for a type of transport. | ||
435 | |||
436 | Profile *GetProfile Returns a pointer to the profile. | ||
437 | |||
438 | Transport transport The type of transport. | ||
439 | ++++++++++++++++++++++++++++++++++++++*/ | ||
440 | |||
441 | Profile *GetProfile(Transport transport) | ||
442 | { | ||
443 | return(&builtin_profiles[transport]); | ||
444 | } | ||
445 | |||
446 | |||
447 | /*++++++++++++++++++++++++++++++++++++++ | ||
448 | amb | 166 | Update a profile with highway preference scaling factor. |
449 | |||
450 | Profile *profile The profile to be updated. | ||
451 | ++++++++++++++++++++++++++++++++++++++*/ | ||
452 | |||
453 | void UpdateProfile(Profile *profile) | ||
454 | { | ||
455 | amb | 168 | score_t hmax=0; |
456 | amb | 166 | int i; |
457 | |||
458 | amb | 173 | /* Normalise the highway preferences into the range 0 -> 1 */ |
459 | |||
460 | amb | 300 | for(i=1;i<Way_Count;i++) |
461 | amb | 298 | { |
462 | if(profile->highway[i]<0) | ||
463 | profile->highway[i]=0; | ||
464 | |||
465 | amb | 166 | if(profile->highway[i]>hmax) |
466 | hmax=profile->highway[i]; | ||
467 | amb | 298 | } |
468 | amb | 166 | |
469 | amb | 300 | for(i=1;i<Way_Count;i++) |
470 | amb | 298 | profile->highway[i]/=hmax; |
471 | amb | 173 | |
472 | amb | 298 | /* Normalise the attribute preferences into the range 0 -> 1 */ |
473 | |||
474 | for(i=1;i<Property_Count;i++) | ||
475 | { | ||
476 | if(profile->props_yes[i]<0) | ||
477 | profile->props_yes[i]=0; | ||
478 | |||
479 | if(profile->props_yes[i]>100) | ||
480 | profile->props_yes[i]=100; | ||
481 | |||
482 | profile->props_yes[i]/=100; | ||
483 | profile->props_no [i] =1-profile->props_yes[i]; | ||
484 | } | ||
485 | |||
486 | amb | 173 | /* Find the fastest and most preferred highway type */ |
487 | |||
488 | profile->max_speed=0; | ||
489 | |||
490 | amb | 300 | for(i=1;i<Way_Count;i++) |
491 | amb | 173 | if(profile->speed[i]>profile->max_speed) |
492 | profile->max_speed=profile->speed[i]; | ||
493 | |||
494 | amb | 298 | profile->max_pref=1; /* since highway prefs were normalised to 1 */ |
495 | amb | 173 | |
496 | amb | 298 | for(i=1;i<Property_Count;i++) |
497 | if(profile->props_yes[i]>profile->props_no[i]) | ||
498 | profile->max_pref*=profile->props_yes[i]; | ||
499 | else if(profile->props_no[i]>profile->props_yes[i]) | ||
500 | profile->max_pref*=profile->props_no[i]; | ||
501 | amb | 166 | } |
502 | |||
503 | |||
504 | /*++++++++++++++++++++++++++++++++++++++ | ||
505 | amb | 83 | Print out a profile. |
506 | |||
507 | const Profile *profile The profile to print. | ||
508 | ++++++++++++++++++++++++++++++++++++++*/ | ||
509 | |||
510 | void PrintProfile(const Profile *profile) | ||
511 | { | ||
512 | amb | 214 | unsigned int i; |
513 | amb | 83 | |
514 | printf("Profile\n=======\n"); | ||
515 | |||
516 | printf("\n"); | ||
517 | |||
518 | printf("Transport: %s\n",TransportName(profile->transport)); | ||
519 | |||
520 | printf("\n"); | ||
521 | |||
522 | amb | 300 | for(i=1;i<Way_Count;i++) |
523 | amb | 166 | printf("Highway %-12s: %3d%%\n",HighwayName(i),(int)profile->highway[i]); |
524 | amb | 83 | |
525 | printf("\n"); | ||
526 | |||
527 | amb | 300 | for(i=1;i<Way_Count;i++) |
528 | amb | 166 | if(profile->highway[i]) |
529 | amb | 85 | printf("Speed on %-12s: %3d km/h / %2.0f mph\n",HighwayName(i),profile->speed[i],(double)profile->speed[i]/1.6); |
530 | amb | 83 | |
531 | printf("\n"); | ||
532 | |||
533 | amb | 298 | for(i=1;i<Property_Count;i++) |
534 | printf("Highway property %-12s: %3d%%\n",PropertyName(i),(int)profile->props_yes[i]); | ||
535 | |||
536 | printf("\n"); | ||
537 | |||
538 | amb | 138 | printf("Obey one-way : %s\n",profile->oneway?"yes":"no"); |
539 | printf("Minimum weight: %.1f tonnes\n",weight_to_tonnes(profile->weight)); | ||
540 | printf("Minimum height: %.1f metres\n",height_to_metres(profile->height)); | ||
541 | printf("Minimum width : %.1f metres\n",width_to_metres(profile->width)); | ||
542 | printf("Minimum length: %.1f metres\n",length_to_metres(profile->length)); | ||
543 | amb | 83 | } |
544 | amb | 129 | |
545 | |||
546 | /*++++++++++++++++++++++++++++++++++++++ | ||
547 | Print out the profiles as Javascript for use in a web form. | ||
548 | ++++++++++++++++++++++++++++++++++++++*/ | ||
549 | |||
550 | void PrintProfilesJS(void) | ||
551 | { | ||
552 | amb | 214 | unsigned int i,j; |
553 | amb | 129 | |
554 | printf("// Transport types\n"); | ||
555 | amb | 163 | printf("var router_transports={"); |
556 | amb | 129 | for(j=1;j<sizeof(builtin_profiles)/sizeof(builtin_profiles[0]);j++) |
557 | amb | 292 | printf("%s%s: %d",j==1?"":", ",TransportName(j),j); |
558 | amb | 129 | printf("};\n"); |
559 | printf("\n"); | ||
560 | |||
561 | printf("// Highway types\n"); | ||
562 | amb | 163 | printf("var router_highways={"); |
563 | amb | 300 | for(i=1;i<Way_Count;i++) |
564 | amb | 292 | printf("%s%s: %d",i==1?"":", ",HighwayName(i),i); |
565 | amb | 129 | printf("};\n"); |
566 | printf("\n"); | ||
567 | |||
568 | amb | 298 | printf("// Property types\n"); |
569 | printf("var router_properties={"); | ||
570 | for(i=1;i<Property_Count;i++) | ||
571 | printf("%s%s: %d",i==1?"":", ",PropertyName(i),i); | ||
572 | printf("};\n"); | ||
573 | printf("\n"); | ||
574 | |||
575 | amb | 138 | printf("// Restriction types\n"); |
576 | amb | 163 | printf("var router_restrictions={oneway: 1, weight: 2, height: 3, width: 4, length: 5};\n"); |
577 | amb | 138 | printf("\n"); |
578 | |||
579 | amb | 129 | printf("// Allowed highways\n"); |
580 | amb | 163 | printf("var router_profile_highway={\n"); |
581 | amb | 300 | for(i=1;i<Way_Count;i++) |
582 | amb | 129 | { |
583 | amb | 148 | printf(" %12s: {",HighwayName(i)); |
584 | amb | 129 | for(j=1;j<sizeof(builtin_profiles)/sizeof(builtin_profiles[0]);j++) |
585 | amb | 166 | printf("%s%s: %3d",j==1?"":", ",TransportName(j),(int)builtin_profiles[j].highway[i]); |
586 | amb | 300 | printf("}%s\n",i==(Way_Count-1)?"":","); |
587 | amb | 129 | } |
588 | printf(" };\n"); | ||
589 | printf("\n"); | ||
590 | |||
591 | printf("// Speed limits\n"); | ||
592 | amb | 163 | printf("var router_profile_speed={\n"); |
593 | amb | 300 | for(i=1;i<Way_Count;i++) |
594 | amb | 129 | { |
595 | amb | 148 | printf(" %12s: {",HighwayName(i)); |
596 | amb | 129 | for(j=1;j<sizeof(builtin_profiles)/sizeof(builtin_profiles[0]);j++) |
597 | amb | 163 | printf("%s%s: %3d",j==1?"":", ",TransportName(j),builtin_profiles[j].speed[i]); |
598 | amb | 300 | printf("}%s\n",i==(Way_Count-1)?"":","); |
599 | amb | 129 | } |
600 | printf(" };\n"); | ||
601 | printf("\n"); | ||
602 | |||
603 | amb | 298 | printf("// Highway properties\n"); |
604 | printf("var router_profile_property={\n"); | ||
605 | for(i=1;i<Property_Count;i++) | ||
606 | { | ||
607 | printf(" %12s: {",PropertyName(i)); | ||
608 | for(j=1;j<sizeof(builtin_profiles)/sizeof(builtin_profiles[0]);j++) | ||
609 | printf("%s%s: %3d",j==1?"":", ",TransportName(j),(int)builtin_profiles[j].props_yes[i]); | ||
610 | printf("}%s\n",i==(Property_Count-1)?"":","); | ||
611 | } | ||
612 | printf(" };\n"); | ||
613 | printf("\n"); | ||
614 | |||
615 | amb | 138 | printf("// Restrictions\n"); |
616 | amb | 163 | printf("var router_profile_restrictions={\n"); |
617 | printf(" %12s: {","oneway"); | ||
618 | amb | 129 | for(j=1;j<sizeof(builtin_profiles)/sizeof(builtin_profiles[0]);j++) |
619 | amb | 163 | printf("%s%s: %4d",j==1?"":", ",TransportName(j),builtin_profiles[j].oneway); |
620 | amb | 138 | printf("},\n"); |
621 | amb | 148 | printf(" %12s: {","weight"); |
622 | amb | 138 | for(j=1;j<sizeof(builtin_profiles)/sizeof(builtin_profiles[0]);j++) |
623 | amb | 163 | printf("%s%s: %4.1f",j==1?"":", ",TransportName(j),weight_to_tonnes(builtin_profiles[j].weight)); |
624 | amb | 138 | printf("},\n"); |
625 | amb | 148 | printf(" %12s: {","height"); |
626 | amb | 138 | for(j=1;j<sizeof(builtin_profiles)/sizeof(builtin_profiles[0]);j++) |
627 | amb | 163 | printf("%s%s: %4.1f",j==1?"":", ",TransportName(j),height_to_metres(builtin_profiles[j].height)); |
628 | amb | 138 | printf("},\n"); |
629 | amb | 148 | printf(" %12s: {","width"); |
630 | amb | 138 | for(j=1;j<sizeof(builtin_profiles)/sizeof(builtin_profiles[0]);j++) |
631 | amb | 163 | printf("%s%s: %4.1f",j==1?"":", ",TransportName(j),width_to_metres(builtin_profiles[j].width)); |
632 | amb | 138 | printf("},\n"); |
633 | amb | 148 | printf(" %12s: {","length"); |
634 | amb | 138 | for(j=1;j<sizeof(builtin_profiles)/sizeof(builtin_profiles[0]);j++) |
635 | amb | 163 | printf("%s%s: %4.1f",j==1?"":", ",TransportName(j),length_to_metres(builtin_profiles[j].length)); |
636 | amb | 138 | printf("}\n"); |
637 | amb | 163 | printf(" };\n"); |
638 | amb | 129 | printf("\n"); |
639 | } | ||
640 | amb | 145 | |
641 | |||
642 | /*++++++++++++++++++++++++++++++++++++++ | ||
643 | Print out the profiles as Perl for use in a web CGI. | ||
644 | ++++++++++++++++++++++++++++++++++++++*/ | ||
645 | |||
646 | void PrintProfilesPerl(void) | ||
647 | { | ||
648 | amb | 214 | unsigned int i,j; |
649 | amb | 145 | |
650 | printf("# Transport types\n"); | ||
651 | printf("@router_transports=("); | ||
652 | for(j=1;j<sizeof(builtin_profiles)/sizeof(builtin_profiles[0]);j++) | ||
653 | printf("%s'%s'",j==1?"":", ",TransportName(j)); | ||
654 | printf(");\n"); | ||
655 | printf("\n"); | ||
656 | |||
657 | printf("# Highway types\n"); | ||
658 | printf("@router_highways=("); | ||
659 | amb | 300 | for(i=1;i<Way_Count;i++) |
660 | amb | 145 | printf("%s'%s'",i==1?"":", ",HighwayName(i)); |
661 | printf(");\n"); | ||
662 | printf("\n"); | ||
663 | |||
664 | amb | 298 | printf("# Property types\n"); |
665 | printf("@router_properties=("); | ||
666 | for(i=1;i<Property_Count;i++) | ||
667 | printf("%s'%s'",i==1?"":", ",PropertyName(i)); | ||
668 | printf(");\n"); | ||
669 | printf("\n"); | ||
670 | |||
671 | amb | 145 | printf("# Restriction types\n"); |
672 | printf("@router_restrictions=('oneway', 'weight', 'height', 'width', 'length');\n"); | ||
673 | printf("\n"); | ||
674 | |||
675 | printf("# Allowed highways\n"); | ||
676 | printf("%%router_profile_highway=(\n"); | ||
677 | amb | 300 | for(i=1;i<Way_Count;i++) |
678 | amb | 145 | { |
679 | amb | 148 | printf(" %12s => {",HighwayName(i)); |
680 | amb | 145 | for(j=1;j<sizeof(builtin_profiles)/sizeof(builtin_profiles[0]);j++) |
681 | amb | 166 | printf("%s %s => %3d",j==1?"":", ",TransportName(j),(int)builtin_profiles[j].highway[i]); |
682 | amb | 300 | printf("}%s\n",i==(Way_Count-1)?"":","); |
683 | amb | 145 | } |
684 | printf(" );\n"); | ||
685 | printf("\n"); | ||
686 | |||
687 | printf("# Speed limits\n"); | ||
688 | printf("%%router_profile_speed=(\n"); | ||
689 | amb | 300 | for(i=1;i<Way_Count;i++) |
690 | amb | 145 | { |
691 | amb | 148 | printf(" %12s => {",HighwayName(i)); |
692 | amb | 145 | for(j=1;j<sizeof(builtin_profiles)/sizeof(builtin_profiles[0]);j++) |
693 | amb | 163 | printf("%s %s => %3d",j==1?"":", ",TransportName(j),builtin_profiles[j].speed[i]); |
694 | amb | 300 | printf("}%s\n",i==(Way_Count-1)?"":","); |
695 | amb | 145 | } |
696 | printf(" );\n"); | ||
697 | printf("\n"); | ||
698 | |||
699 | amb | 298 | printf("# Highway properties\n"); |
700 | printf("%%router_profile_property=(\n"); | ||
701 | for(i=1;i<Property_Count;i++) | ||
702 | { | ||
703 | printf(" %12s => {",PropertyName(i)); | ||
704 | for(j=1;j<sizeof(builtin_profiles)/sizeof(builtin_profiles[0]);j++) | ||
705 | printf("%s %s => %3d",j==1?"":", ",TransportName(j),(int)builtin_profiles[j].props_yes[i]); | ||
706 | printf("}%s\n",i==(Property_Count-1)?"":","); | ||
707 | } | ||
708 | printf(" );\n"); | ||
709 | printf("\n"); | ||
710 | |||
711 | amb | 145 | printf("# Restrictions\n"); |
712 | printf("%%router_profile_restrictions=(\n"); | ||
713 | amb | 163 | printf(" %12s => {","oneway"); |
714 | amb | 145 | for(j=1;j<sizeof(builtin_profiles)/sizeof(builtin_profiles[0]);j++) |
715 | amb | 163 | printf("%s %s => %4d",j==1?"":", ",TransportName(j),builtin_profiles[j].oneway); |
716 | amb | 145 | printf("},\n"); |
717 | amb | 148 | printf(" %12s => {","weight"); |
718 | amb | 145 | for(j=1;j<sizeof(builtin_profiles)/sizeof(builtin_profiles[0]);j++) |
719 | amb | 163 | printf("%s %s => %4.1f",j==1?"":", ",TransportName(j),weight_to_tonnes(builtin_profiles[j].weight)); |
720 | amb | 145 | printf("},\n"); |
721 | amb | 148 | printf(" %12s => {","height"); |
722 | amb | 145 | for(j=1;j<sizeof(builtin_profiles)/sizeof(builtin_profiles[0]);j++) |
723 | amb | 163 | printf("%s %s => %4.1f",j==1?"":", ",TransportName(j),height_to_metres(builtin_profiles[j].height)); |
724 | amb | 145 | printf("},\n"); |
725 | amb | 148 | printf(" %12s => {","width"); |
726 | amb | 145 | for(j=1;j<sizeof(builtin_profiles)/sizeof(builtin_profiles[0]);j++) |
727 | amb | 163 | printf("%s %s => %4.1f",j==1?"":", ",TransportName(j),width_to_metres(builtin_profiles[j].width)); |
728 | amb | 145 | printf("},\n"); |
729 | amb | 148 | printf(" %12s => {","length"); |
730 | amb | 145 | for(j=1;j<sizeof(builtin_profiles)/sizeof(builtin_profiles[0]);j++) |
731 | amb | 163 | printf("%s %s => %4.1f",j==1?"":", ",TransportName(j),length_to_metres(builtin_profiles[j].length)); |
732 | amb | 145 | printf("}\n"); |
733 | amb | 163 | printf(" );\n"); |
734 | amb | 145 | printf("\n"); |
735 | } |
Properties
Name | Value |
---|---|
cvs:description | Definition of built-in profiles and other functions. |