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