Routino SVN Repository Browser

Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino

ViewVC logotype

Contents of /trunk/src/profiles.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 145 - (show annotations) (download) (as text)
Mon Mar 23 18:47:18 2009 UTC (16 years ago) by amb
File MIME type: text/x-csrc
File size: 24176 byte(s)
Add a function to output default profiles as perl data structures.

1 /***************************************
2 $Header: /home/amb/CVS/routino/src/profiles.c,v 1.9 2009-03-23 18:47:17 amb Exp $
3
4 The pre-defined profiles and the functions for handling them.
5 ******************/ /******************
6 Written by Andrew M. Bishop
7
8 This file Copyright 2009 Andrew M. Bishop
9 It may be distributed under the GNU Public License, version 2, or
10 any higher version. See section COPYING of the GNU Public license
11 for conditions under which this file may be redistributed.
12 ***************************************/
13
14
15 #include <stdio.h>
16
17 #include "profiles.h"
18 #include "types.h"
19 #include "ways.h"
20
21
22 static Profile builtin_profiles[]=
23 {
24 /* The profile for travel by Foot */
25
26 [Transport_Foot] = {
27 .transport=Transport_Foot,
28 .allow =Allow_Foot,
29 .highways = {
30 [Way_Motorway ] = 0,
31 [Way_Trunk ] = 1,
32 [Way_Primary ] = 1,
33 [Way_Secondary ] = 1,
34 [Way_Tertiary ] = 1,
35 [Way_Unclassified] = 1,
36 [Way_Residential ] = 1,
37 [Way_Service ] = 1,
38 [Way_Track ] = 1,
39 [Way_Bridleway ] = 1,
40 [Way_Cycleway ] = 1,
41 [Way_Footway ] = 1,
42 },
43 .speed = {
44 [Way_Motorway ] = 0,
45 [Way_Trunk ] = kph_to_speed(4),
46 [Way_Primary ] = kph_to_speed(4),
47 [Way_Secondary ] = kph_to_speed(4),
48 [Way_Tertiary ] = kph_to_speed(4),
49 [Way_Unclassified] = kph_to_speed(4),
50 [Way_Residential ] = kph_to_speed(4),
51 [Way_Service ] = kph_to_speed(4),
52 [Way_Track ] = kph_to_speed(4),
53 [Way_Bridleway ] = kph_to_speed(4),
54 [Way_Cycleway ] = kph_to_speed(4),
55 [Way_Footway ] = kph_to_speed(4),
56 },
57 .oneway = 0,
58 .weight = 0,
59 .height = 0,
60 .width = 0,
61 .length = 0,
62 },
63
64 /* The profile for travel by Bicycle */
65
66 [Transport_Bicycle] = {
67 .transport=Transport_Bicycle,
68 .allow =Allow_Bicycle,
69 .highways = {
70 [Way_Motorway ] = 0,
71 [Way_Trunk ] = 0,
72 [Way_Primary ] = 1,
73 [Way_Secondary ] = 1,
74 [Way_Tertiary ] = 1,
75 [Way_Unclassified] = 1,
76 [Way_Residential ] = 1,
77 [Way_Service ] = 1,
78 [Way_Track ] = 1,
79 [Way_Bridleway ] = 1,
80 [Way_Cycleway ] = 1,
81 [Way_Footway ] = 0,
82 },
83 .speed = {
84 [Way_Motorway ] = 0,
85 [Way_Trunk ] = 0,
86 [Way_Primary ] = kph_to_speed(20),
87 [Way_Secondary ] = kph_to_speed(20),
88 [Way_Tertiary ] = kph_to_speed(20),
89 [Way_Unclassified] = kph_to_speed(20),
90 [Way_Residential ] = kph_to_speed(20),
91 [Way_Service ] = kph_to_speed(20),
92 [Way_Track ] = kph_to_speed(20),
93 [Way_Bridleway ] = kph_to_speed(20),
94 [Way_Cycleway ] = kph_to_speed(20),
95 [Way_Footway ] = 0,
96 },
97 .oneway = 1,
98 .weight = 0,
99 .height = 0,
100 .width = 0,
101 .length = 0,
102 },
103
104 /* The profile for travel by Horse */
105
106 [Transport_Horse] = {
107 .transport=Transport_Horse,
108 .allow =Allow_Horse,
109 .highways = {
110 [Way_Motorway ] = 0,
111 [Way_Trunk ] = 1,
112 [Way_Primary ] = 1,
113 [Way_Secondary ] = 1,
114 [Way_Tertiary ] = 1,
115 [Way_Unclassified] = 1,
116 [Way_Residential ] = 1,
117 [Way_Service ] = 1,
118 [Way_Track ] = 1,
119 [Way_Bridleway ] = 1,
120 [Way_Cycleway ] = 0,
121 [Way_Footway ] = 0,
122 },
123 .speed = {
124 [Way_Motorway ] = 0,
125 [Way_Trunk ] = 0,
126 [Way_Primary ] = kph_to_speed(10),
127 [Way_Secondary ] = kph_to_speed(10),
128 [Way_Tertiary ] = kph_to_speed(10),
129 [Way_Unclassified] = kph_to_speed(10),
130 [Way_Residential ] = kph_to_speed(10),
131 [Way_Service ] = kph_to_speed(10),
132 [Way_Track ] = kph_to_speed(10),
133 [Way_Bridleway ] = kph_to_speed(10),
134 [Way_Cycleway ] = 0,
135 [Way_Footway ] = 0,
136 },
137 .oneway = 1,
138 .weight = 0,
139 .height = 0,
140 .width = 0,
141 .length = 0,
142 },
143
144 /* The profile for travel by Motorbike */
145
146 [Transport_Motorbike] = {
147 .transport=Transport_Motorbike,
148 .allow =Allow_Motorbike,
149 .highways = {
150 [Way_Motorway ] = 1,
151 [Way_Trunk ] = 1,
152 [Way_Primary ] = 1,
153 [Way_Secondary ] = 1,
154 [Way_Tertiary ] = 1,
155 [Way_Unclassified] = 1,
156 [Way_Residential ] = 1,
157 [Way_Service ] = 1,
158 [Way_Track ] = 0,
159 [Way_Bridleway ] = 0,
160 [Way_Cycleway ] = 0,
161 [Way_Footway ] = 0,
162 },
163 .speed = {
164 [Way_Motorway ] = kph_to_speed(70*1.6),
165 [Way_Trunk ] = kph_to_speed(60*1.6),
166 [Way_Primary ] = kph_to_speed(60*1.6),
167 [Way_Secondary ] = kph_to_speed(55*1.6),
168 [Way_Tertiary ] = kph_to_speed(50*1.6),
169 [Way_Unclassified] = kph_to_speed(40*1.6),
170 [Way_Residential ] = kph_to_speed(30*1.6),
171 [Way_Service ] = kph_to_speed(20*1.6),
172 [Way_Track ] = 0,
173 [Way_Bridleway ] = 0,
174 [Way_Cycleway ] = 0,
175 [Way_Footway ] = 0,
176 },
177 .oneway = 1,
178 .weight = 0,
179 .height = 0,
180 .width = 0,
181 .length = 0,
182 },
183
184 /* The profile for travel by Motorcar */
185
186 [Transport_Motorcar] = {
187 .transport=Transport_Motorcar,
188 .allow =Allow_Motorcar,
189 .highways = {
190 [Way_Motorway ] = 1,
191 [Way_Trunk ] = 1,
192 [Way_Primary ] = 1,
193 [Way_Secondary ] = 1,
194 [Way_Tertiary ] = 1,
195 [Way_Unclassified] = 1,
196 [Way_Residential ] = 1,
197 [Way_Service ] = 1,
198 [Way_Track ] = 0,
199 [Way_Bridleway ] = 0,
200 [Way_Cycleway ] = 0,
201 [Way_Footway ] = 0,
202 },
203 .speed = {
204 [Way_Motorway ] = kph_to_speed(70*1.6),
205 [Way_Trunk ] = kph_to_speed(60*1.6),
206 [Way_Primary ] = kph_to_speed(60*1.6),
207 [Way_Secondary ] = kph_to_speed(55*1.6),
208 [Way_Tertiary ] = kph_to_speed(50*1.6),
209 [Way_Unclassified] = kph_to_speed(40*1.6),
210 [Way_Residential ] = kph_to_speed(30*1.6),
211 [Way_Service ] = kph_to_speed(20*1.6),
212 [Way_Track ] = 0,
213 [Way_Bridleway ] = 0,
214 [Way_Cycleway ] = 0,
215 [Way_Footway ] = 0,
216 },
217 .oneway = 1,
218 .weight = 0,
219 .height = 0,
220 .width = 0,
221 .length = 0,
222 },
223
224 /* The profile for travel by Goods */
225
226 [Transport_Goods] = {
227 .transport=Transport_Goods,
228 .allow =Allow_Goods,
229 .highways = {
230 [Way_Motorway ] = 1,
231 [Way_Trunk ] = 1,
232 [Way_Primary ] = 1,
233 [Way_Secondary ] = 1,
234 [Way_Tertiary ] = 1,
235 [Way_Unclassified] = 1,
236 [Way_Residential ] = 1,
237 [Way_Service ] = 1,
238 [Way_Track ] = 0,
239 [Way_Bridleway ] = 0,
240 [Way_Cycleway ] = 0,
241 [Way_Footway ] = 0,
242 },
243 .speed = {
244 [Way_Motorway ] = kph_to_speed(60*1.6),
245 [Way_Trunk ] = kph_to_speed(60*1.6),
246 [Way_Primary ] = kph_to_speed(60*1.6),
247 [Way_Secondary ] = kph_to_speed(55*1.6),
248 [Way_Tertiary ] = kph_to_speed(50*1.6),
249 [Way_Unclassified] = kph_to_speed(40*1.6),
250 [Way_Residential ] = kph_to_speed(30*1.6),
251 [Way_Service ] = kph_to_speed(20*1.6),
252 [Way_Track ] = 0,
253 [Way_Bridleway ] = 0,
254 [Way_Cycleway ] = 0,
255 [Way_Footway ] = 0,
256 },
257 .oneway = 1,
258 .weight = tonnes_to_weight(5),
259 .height = metres_to_height(2.5),
260 .width = metres_to_width (2),
261 .length = metres_to_length(5),
262 },
263
264 /* The profile for travel by HGV */
265
266 [Transport_HGV] = {
267 .transport=Transport_HGV,
268 .allow =Allow_HGV,
269 .highways = {
270 [Way_Motorway ] = 1,
271 [Way_Trunk ] = 1,
272 [Way_Primary ] = 1,
273 [Way_Secondary ] = 1,
274 [Way_Tertiary ] = 1,
275 [Way_Unclassified] = 1,
276 [Way_Residential ] = 1,
277 [Way_Service ] = 1,
278 [Way_Track ] = 0,
279 [Way_Bridleway ] = 0,
280 [Way_Cycleway ] = 0,
281 [Way_Footway ] = 0,
282 },
283 .speed = {
284 [Way_Motorway ] = kph_to_speed(56*1.6),
285 [Way_Trunk ] = kph_to_speed(50*1.6),
286 [Way_Primary ] = kph_to_speed(50*1.6),
287 [Way_Secondary ] = kph_to_speed(50*1.6),
288 [Way_Tertiary ] = kph_to_speed(50*1.6),
289 [Way_Unclassified] = kph_to_speed(40*1.6),
290 [Way_Residential ] = kph_to_speed(30*1.6),
291 [Way_Service ] = kph_to_speed(20*1.6),
292 [Way_Track ] = 0,
293 [Way_Bridleway ] = 0,
294 [Way_Cycleway ] = 0,
295 [Way_Footway ] = 0,
296 },
297 .oneway = 1,
298 .weight = tonnes_to_weight(10),
299 .height = metres_to_height(3),
300 .width = metres_to_width (2.5),
301 .length = metres_to_length(6),
302 },
303
304 /* The profile for travel by PSV */
305
306 [Transport_PSV] = {
307 .transport=Transport_PSV,
308 .allow =Allow_PSV,
309 .highways = {
310 [Way_Motorway ] = 1,
311 [Way_Trunk ] = 1,
312 [Way_Primary ] = 1,
313 [Way_Secondary ] = 1,
314 [Way_Tertiary ] = 1,
315 [Way_Unclassified] = 1,
316 [Way_Residential ] = 1,
317 [Way_Service ] = 1,
318 [Way_Track ] = 0,
319 [Way_Bridleway ] = 0,
320 [Way_Cycleway ] = 0,
321 [Way_Footway ] = 0,
322 },
323 .speed = {
324 [Way_Motorway ] = kph_to_speed(56*1.6),
325 [Way_Trunk ] = kph_to_speed(50*1.6),
326 [Way_Primary ] = kph_to_speed(50*1.6),
327 [Way_Secondary ] = kph_to_speed(50*1.6),
328 [Way_Tertiary ] = kph_to_speed(50*1.6),
329 [Way_Unclassified] = kph_to_speed(40*1.6),
330 [Way_Residential ] = kph_to_speed(30*1.6),
331 [Way_Service ] = kph_to_speed(20*1.6),
332 [Way_Track ] = 0,
333 [Way_Bridleway ] = 0,
334 [Way_Cycleway ] = 0,
335 [Way_Footway ] = 0,
336 },
337 .oneway = 1,
338 .weight = tonnes_to_weight(15),
339 .height = metres_to_height(3),
340 .width = metres_to_width (2.5),
341 .length = metres_to_length(6),
342 },
343 };
344
345
346 /*++++++++++++++++++++++++++++++++++++++
347 Get the profile for a type of transport.
348
349 Profile *GetProfile Returns a pointer to the profile.
350
351 Transport transport The type of transport.
352 ++++++++++++++++++++++++++++++++++++++*/
353
354 Profile *GetProfile(Transport transport)
355 {
356 return(&builtin_profiles[transport]);
357 }
358
359
360 /*++++++++++++++++++++++++++++++++++++++
361 Print out a profile.
362
363 const Profile *profile The profile to print.
364 ++++++++++++++++++++++++++++++++++++++*/
365
366 void PrintProfile(const Profile *profile)
367 {
368 int i;
369
370 printf("Profile\n=======\n");
371
372 printf("\n");
373
374 printf("Transport: %s\n",TransportName(profile->transport));
375
376 printf("\n");
377
378 for(i=1;i<Way_Unknown;i++)
379 printf("Highway %-12s: %s\n",HighwayName(i),profile->highways[i]?"yes":"no");
380
381 printf("\n");
382
383 for(i=1;i<Way_Unknown;i++)
384 if(profile->highways[i])
385 printf("Speed on %-12s: %3d km/h / %2.0f mph\n",HighwayName(i),profile->speed[i],(double)profile->speed[i]/1.6);
386
387 printf("\n");
388
389 printf("Obey one-way : %s\n",profile->oneway?"yes":"no");
390 printf("Minimum weight: %.1f tonnes\n",weight_to_tonnes(profile->weight));
391 printf("Minimum height: %.1f metres\n",height_to_metres(profile->height));
392 printf("Minimum width : %.1f metres\n",width_to_metres(profile->width));
393 printf("Minimum length: %.1f metres\n",length_to_metres(profile->length));
394 }
395
396
397 /*++++++++++++++++++++++++++++++++++++++
398 Print out the profiles as Javascript for use in a web form.
399 ++++++++++++++++++++++++++++++++++++++*/
400
401 void PrintProfilesJS(void)
402 {
403 int i,j;
404
405 printf("// Transport types\n");
406 printf("router_transports={");
407 for(j=1;j<sizeof(builtin_profiles)/sizeof(builtin_profiles[0]);j++)
408 printf("%s%s: %d",j==1?"":",",TransportName(j),j-1);
409 printf("};\n");
410 printf("\n");
411
412 printf("// Highway types\n");
413 printf("router_highways={\n");
414 for(i=1;i<Way_Unknown;i++)
415 printf("%s%s: %d",i==1?"":",",HighwayName(i),i-1);
416 printf("};\n");
417 printf("\n");
418
419 printf("// Restriction types\n");
420 printf("router_restrictions={oneway: 1, weight: 2, height: 3, width: 4, length: 5};\n");
421 printf("\n");
422
423 printf("// Allowed highways\n");
424 printf("router_profile_highway={\n");
425 for(i=1;i<Way_Unknown;i++)
426 {
427 printf(" %16s: {",HighwayName(i));
428 for(j=1;j<sizeof(builtin_profiles)/sizeof(builtin_profiles[0]);j++)
429 printf("%s%s: %d",j==1?"":",",TransportName(j),builtin_profiles[j].highways[i]);
430 printf("}%s\n",i==(Way_Unknown-1)?"":",");
431 }
432 printf(" };\n");
433 printf("\n");
434
435 printf("// Speed limits\n");
436 printf("router_profile_speed={\n");
437 for(i=1;i<Way_Unknown;i++)
438 {
439 printf(" %16s: {",HighwayName(i));
440 for(j=1;j<sizeof(builtin_profiles)/sizeof(builtin_profiles[0]);j++)
441 printf("%s%s: %3d",j==1?"":",",TransportName(j),builtin_profiles[j].speed[i]);
442 printf("}%s\n",i==(Way_Unknown-1)?"":",");
443 }
444 printf(" };\n");
445 printf("\n");
446
447 printf("// Restrictions\n");
448 printf("router_profile_restrictions={\n");
449 printf("oneway: {");
450 for(j=1;j<sizeof(builtin_profiles)/sizeof(builtin_profiles[0]);j++)
451 printf("%s%s: %d",j==1?"":",",TransportName(j),builtin_profiles[j].oneway);
452 printf("},\n");
453 printf("weight: {");
454 for(j=1;j<sizeof(builtin_profiles)/sizeof(builtin_profiles[0]);j++)
455 printf("%s%s: %.1f",j==1?"":",",TransportName(j),weight_to_tonnes(builtin_profiles[j].weight));
456 printf("},\n");
457 printf("height: {");
458 for(j=1;j<sizeof(builtin_profiles)/sizeof(builtin_profiles[0]);j++)
459 printf("%s%s: %.1f",j==1?"":",",TransportName(j),height_to_metres(builtin_profiles[j].height));
460 printf("},\n");
461 printf("width: {");
462 for(j=1;j<sizeof(builtin_profiles)/sizeof(builtin_profiles[0]);j++)
463 printf("%s%s: %.1f",j==1?"":",",TransportName(j),width_to_metres(builtin_profiles[j].width));
464 printf("},\n");
465 printf("length: {");
466 for(j=1;j<sizeof(builtin_profiles)/sizeof(builtin_profiles[0]);j++)
467 printf("%s%s: %.1f",j==1?"":",",TransportName(j),length_to_metres(builtin_profiles[j].length));
468 printf("}\n");
469 printf("};\n");
470 printf("\n");
471 }
472
473
474 /*++++++++++++++++++++++++++++++++++++++
475 Print out the profiles as Perl for use in a web CGI.
476 ++++++++++++++++++++++++++++++++++++++*/
477
478 void PrintProfilesPerl(void)
479 {
480 int i,j;
481
482 printf("# Transport types\n");
483 printf("@router_transports=(");
484 for(j=1;j<sizeof(builtin_profiles)/sizeof(builtin_profiles[0]);j++)
485 printf("%s'%s'",j==1?"":", ",TransportName(j));
486 printf(");\n");
487 printf("\n");
488
489 printf("# Highway types\n");
490 printf("@router_highways=(");
491 for(i=1;i<Way_Unknown;i++)
492 printf("%s'%s'",i==1?"":", ",HighwayName(i));
493 printf(");\n");
494 printf("\n");
495
496 printf("# Restriction types\n");
497 printf("@router_restrictions=('oneway', 'weight', 'height', 'width', 'length');\n");
498 printf("\n");
499
500 printf("# Allowed highways\n");
501 printf("%%router_profile_highway=(\n");
502 for(i=1;i<Way_Unknown;i++)
503 {
504 printf(" %16s => {",HighwayName(i));
505 for(j=1;j<sizeof(builtin_profiles)/sizeof(builtin_profiles[0]);j++)
506 printf("%s %s => %d",j==1?"":",",TransportName(j),builtin_profiles[j].highways[i]);
507 printf("}%s\n",i==(Way_Unknown-1)?"":",");
508 }
509 printf(" );\n");
510 printf("\n");
511
512 printf("# Speed limits\n");
513 printf("%%router_profile_speed=(\n");
514 for(i=1;i<Way_Unknown;i++)
515 {
516 printf(" %16s => {",HighwayName(i));
517 for(j=1;j<sizeof(builtin_profiles)/sizeof(builtin_profiles[0]);j++)
518 printf("%s %s => %3d",j==1?"":",",TransportName(j),builtin_profiles[j].speed[i]);
519 printf("}%s\n",i==(Way_Unknown-1)?"":",");
520 }
521 printf(" );\n");
522 printf("\n");
523
524 printf("# Restrictions\n");
525 printf("%%router_profile_restrictions=(\n");
526 printf("oneway => {");
527 for(j=1;j<sizeof(builtin_profiles)/sizeof(builtin_profiles[0]);j++)
528 printf("%s %s => %d",j==1?"":",",TransportName(j),builtin_profiles[j].oneway);
529 printf("},\n");
530 printf(" weight => {");
531 for(j=1;j<sizeof(builtin_profiles)/sizeof(builtin_profiles[0]);j++)
532 printf("%s %s => %.1f",j==1?"":",",TransportName(j),weight_to_tonnes(builtin_profiles[j].weight));
533 printf("},\n");
534 printf(" height => {");
535 for(j=1;j<sizeof(builtin_profiles)/sizeof(builtin_profiles[0]);j++)
536 printf("%s %s => %.1f",j==1?"":",",TransportName(j),height_to_metres(builtin_profiles[j].height));
537 printf("},\n");
538 printf(" width => {");
539 for(j=1;j<sizeof(builtin_profiles)/sizeof(builtin_profiles[0]);j++)
540 printf("%s %s => %.1f",j==1?"":",",TransportName(j),width_to_metres(builtin_profiles[j].width));
541 printf("},\n");
542 printf(" length => {");
543 for(j=1;j<sizeof(builtin_profiles)/sizeof(builtin_profiles[0]);j++)
544 printf("%s %s => %.1f",j==1?"":",",TransportName(j),length_to_metres(builtin_profiles[j].length));
545 printf("}\n");
546 printf(");\n");
547 printf("\n");
548 }

Properties

Name Value
cvs:description Definition of built-in profiles and other functions.