1 /***************************************
2 $Header: /home/amb/routino/src/RCS/profiles.c,v 1.47 2010/10/18 17:40:34 amb Exp $
4 Load the profiles from a file and the functions for handling them.
6 Part of the Routino routing software.
7 ******************/ /******************
8 This file Copyright 2008-2010 Andrew M. Bishop
10 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.
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.
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 ***************************************/
34 #include "functions.h"
38 /*+ The profiles that have been loaded from file. +*/
39 static Profile **loaded_profiles=NULL;
41 /*+ The number of profiles that have been loaded from file. +*/
42 static int nloaded_profiles=0;
45 /* The XML tag processing function prototypes */
47 //static int xmlDeclaration_function(const char *_tag_,int _type_,const char *version,const char *encoding);
48 //static int RoutinoProfilesType_function(const char *_tag_,int _type_);
49 static int profileType_function(const char *_tag_,int _type_,const char *name,const char *transport);
50 //static int restrictionsType_function(const char *_tag_,int _type_);
51 static int lengthType_function(const char *_tag_,int _type_,const char *limit);
52 static int widthType_function(const char *_tag_,int _type_,const char *limit);
53 static int heightType_function(const char *_tag_,int _type_,const char *limit);
54 static int weightType_function(const char *_tag_,int _type_,const char *limit);
55 //static int propertiesType_function(const char *_tag_,int _type_);
56 static int onewayType_function(const char *_tag_,int _type_,const char *obey);
57 static int propertyType_function(const char *_tag_,int _type_,const char *type,const char *percent);
58 //static int preferencesType_function(const char *_tag_,int _type_);
59 static int preferenceType_function(const char *_tag_,int _type_,const char *highway,const char *percent);
60 //static int speedsType_function(const char *_tag_,int _type_);
61 static int speedType_function(const char *_tag_,int _type_,const char *highway,const char *kph);
64 /* The XML tag definitions */
66 /*+ The speedType type tag. +*/
67 static xmltag speedType_tag=
73 /*+ The speedsType type tag. +*/
74 static xmltag speedsType_tag=
78 {&speedType_tag,NULL}};
80 /*+ The preferenceType type tag. +*/
81 static xmltag preferenceType_tag=
83 2, {"highway","percent"},
84 preferenceType_function,
87 /*+ The preferencesType type tag. +*/
88 static xmltag preferencesType_tag=
92 {&preferenceType_tag,NULL}};
94 /*+ The propertyType type tag. +*/
95 static xmltag propertyType_tag=
97 2, {"type","percent"},
98 propertyType_function,
101 /*+ The onewayType type tag. +*/
102 static xmltag onewayType_tag=
108 /*+ The propertiesType type tag. +*/
109 static xmltag propertiesType_tag=
113 {&propertyType_tag,NULL}};
115 /*+ The weightType type tag. +*/
116 static xmltag weightType_tag=
122 /*+ The heightType type tag. +*/
123 static xmltag heightType_tag=
129 /*+ The widthType type tag. +*/
130 static xmltag widthType_tag=
136 /*+ The lengthType type tag. +*/
137 static xmltag lengthType_tag=
143 /*+ The restrictionsType type tag. +*/
144 static xmltag restrictionsType_tag=
148 {&onewayType_tag,&weightType_tag,&heightType_tag,&widthType_tag,&lengthType_tag,NULL}};
150 /*+ The profileType type tag. +*/
151 static xmltag profileType_tag=
153 2, {"name","transport"},
154 profileType_function,
155 {&speedsType_tag,&preferencesType_tag,&propertiesType_tag,&restrictionsType_tag,NULL}};
157 /*+ The RoutinoProfilesType type tag. +*/
158 static xmltag RoutinoProfilesType_tag=
162 {&profileType_tag,NULL}};
164 /*+ The xmlDeclaration type tag. +*/
165 static xmltag xmlDeclaration_tag=
167 2, {"version","encoding"},
172 /*+ The complete set of tags at the top level. +*/
173 static xmltag *xml_toplevel_tags[]={&xmlDeclaration_tag,&RoutinoProfilesType_tag,NULL};
176 /* The XML tag processing functions */
179 /*++++++++++++++++++++++++++++++++++++++
180 The function that is called when the speedType XSD type is seen
182 int speedType_function Returns 0 if no error occured or something else otherwise.
184 const char *_tag_ Set to the name of the element tag that triggered this function call.
186 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
188 const char *highway The contents of the 'highway' attribute (or NULL if not defined).
190 const char *kph The contents of the 'kph' attribute (or NULL if not defined).
191 ++++++++++++++++++++++++++++++++++++++*/
193 static int speedType_function(const char *_tag_,int _type_,const char *highway,const char *kph)
195 if(_type_&XMLPARSE_TAG_START)
200 XMLPARSE_ASSERT_STRING(_tag_,highway);
202 highwaytype=HighwayType(highway);
204 if(highwaytype==Way_Count)
205 XMLPARSE_INVALID(_tag_,highway);
207 XMLPARSE_ASSERT_FLOATING(_tag_,kph,speed);
209 loaded_profiles[nloaded_profiles-1]->speed[highwaytype]=kph_to_speed(speed);
216 /*++++++++++++++++++++++++++++++++++++++
217 The function that is called when the speedsType XSD type is seen
219 int speedsType_function Returns 0 if no error occured or something else otherwise.
221 const char *_tag_ Set to the name of the element tag that triggered this function call.
223 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
224 ++++++++++++++++++++++++++++++++++++++*/
226 //static int speedsType_function(const char *_tag_,int _type_)
232 /*++++++++++++++++++++++++++++++++++++++
233 The function that is called when the preferenceType XSD type is seen
235 int preferenceType_function Returns 0 if no error occured or something else otherwise.
237 const char *_tag_ Set to the name of the element tag that triggered this function call.
239 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
241 const char *highway The contents of the 'highway' attribute (or NULL if not defined).
243 const char *percent The contents of the 'percent' attribute (or NULL if not defined).
244 ++++++++++++++++++++++++++++++++++++++*/
246 static int preferenceType_function(const char *_tag_,int _type_,const char *highway,const char *percent)
248 if(_type_&XMLPARSE_TAG_START)
253 XMLPARSE_ASSERT_STRING(_tag_,highway);
255 highwaytype=HighwayType(highway);
257 if(highwaytype==Way_Count)
258 XMLPARSE_INVALID(_tag_,highway);
260 XMLPARSE_ASSERT_FLOATING(_tag_,percent,p);
262 loaded_profiles[nloaded_profiles-1]->highway[highwaytype]=p;
269 /*++++++++++++++++++++++++++++++++++++++
270 The function that is called when the preferencesType XSD type is seen
272 int preferencesType_function Returns 0 if no error occured or something else otherwise.
274 const char *_tag_ Set to the name of the element tag that triggered this function call.
276 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
277 ++++++++++++++++++++++++++++++++++++++*/
279 //static int preferencesType_function(const char *_tag_,int _type_)
285 /*++++++++++++++++++++++++++++++++++++++
286 The function that is called when the propertyType XSD type is seen
288 int propertyType_function Returns 0 if no error occured or something else otherwise.
290 const char *_tag_ Set to the name of the element tag that triggered this function call.
292 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
294 const char *type The contents of the 'type' attribute (or NULL if not defined).
296 const char *percent The contents of the 'percent' attribute (or NULL if not defined).
297 ++++++++++++++++++++++++++++++++++++++*/
299 static int propertyType_function(const char *_tag_,int _type_,const char *type,const char *percent)
301 if(_type_&XMLPARSE_TAG_START)
306 XMLPARSE_ASSERT_STRING(_tag_,type);
308 property=PropertyType(type);
310 if(property==Property_Count)
311 XMLPARSE_INVALID(_tag_,type);
313 XMLPARSE_ASSERT_FLOATING(_tag_,percent,p);
315 loaded_profiles[nloaded_profiles-1]->props_yes[property]=p;
322 /*++++++++++++++++++++++++++++++++++++++
323 The function that is called when the onewayType XSD type is seen
325 int onewayType_function Returns 0 if no error occured or something else otherwise.
327 const char *_tag_ Set to the name of the element tag that triggered this function call.
329 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
331 const char *obey The contents of the 'obey' attribute (or NULL if not defined).
332 ++++++++++++++++++++++++++++++++++++++*/
334 static int onewayType_function(const char *_tag_,int _type_,const char *obey)
336 if(_type_&XMLPARSE_TAG_START)
340 XMLPARSE_ASSERT_INTEGER(_tag_,obey,o);
342 loaded_profiles[nloaded_profiles-1]->oneway=!!o;
349 /*++++++++++++++++++++++++++++++++++++++
350 The function that is called when the propertiesType XSD type is seen
352 int propertiesType_function Returns 0 if no error occured or something else otherwise.
354 const char *_tag_ Set to the name of the element tag that triggered this function call.
356 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
357 ++++++++++++++++++++++++++++++++++++++*/
359 //static int propertiesType_function(const char *_tag_,int _type_)
365 /*++++++++++++++++++++++++++++++++++++++
366 The function that is called when the weightType XSD type is seen
368 int weightType_function Returns 0 if no error occured or something else otherwise.
370 const char *_tag_ Set to the name of the element tag that triggered this function call.
372 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
374 const char *limit The contents of the 'limit' attribute (or NULL if not defined).
375 ++++++++++++++++++++++++++++++++++++++*/
377 static int weightType_function(const char *_tag_,int _type_,const char *limit)
379 if(_type_&XMLPARSE_TAG_START)
383 XMLPARSE_ASSERT_FLOATING(_tag_,limit,l);
385 loaded_profiles[nloaded_profiles-1]->weight=tonnes_to_weight(l);
392 /*++++++++++++++++++++++++++++++++++++++
393 The function that is called when the heightType XSD type is seen
395 int heightType_function Returns 0 if no error occured or something else otherwise.
397 const char *_tag_ Set to the name of the element tag that triggered this function call.
399 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
401 const char *limit The contents of the 'limit' attribute (or NULL if not defined).
402 ++++++++++++++++++++++++++++++++++++++*/
404 static int heightType_function(const char *_tag_,int _type_,const char *limit)
406 if(_type_&XMLPARSE_TAG_START)
410 XMLPARSE_ASSERT_FLOATING(_tag_,limit,l);
412 loaded_profiles[nloaded_profiles-1]->height=metres_to_height(l);
419 /*++++++++++++++++++++++++++++++++++++++
420 The function that is called when the widthType XSD type is seen
422 int widthType_function Returns 0 if no error occured or something else otherwise.
424 const char *_tag_ Set to the name of the element tag that triggered this function call.
426 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
428 const char *limit The contents of the 'limit' attribute (or NULL if not defined).
429 ++++++++++++++++++++++++++++++++++++++*/
431 static int widthType_function(const char *_tag_,int _type_,const char *limit)
433 if(_type_&XMLPARSE_TAG_START)
437 XMLPARSE_ASSERT_FLOATING(_tag_,limit,l);
439 loaded_profiles[nloaded_profiles-1]->width=metres_to_width(l);
446 /*++++++++++++++++++++++++++++++++++++++
447 The function that is called when the lengthType XSD type is seen
449 int lengthType_function Returns 0 if no error occured or something else otherwise.
451 const char *_tag_ Set to the name of the element tag that triggered this function call.
453 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
455 const char *limit The contents of the 'limit' attribute (or NULL if not defined).
456 ++++++++++++++++++++++++++++++++++++++*/
458 static int lengthType_function(const char *_tag_,int _type_,const char *limit)
460 if(_type_&XMLPARSE_TAG_START)
464 XMLPARSE_ASSERT_FLOATING(_tag_,limit,l);
466 loaded_profiles[nloaded_profiles-1]->length=metres_to_length(l);
473 /*++++++++++++++++++++++++++++++++++++++
474 The function that is called when the restrictionsType XSD type is seen
476 int restrictionsType_function Returns 0 if no error occured or something else otherwise.
478 const char *_tag_ Set to the name of the element tag that triggered this function call.
480 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
481 ++++++++++++++++++++++++++++++++++++++*/
483 //static int restrictionsType_function(const char *_tag_,int _type_)
489 /*++++++++++++++++++++++++++++++++++++++
490 The function that is called when the profileType XSD type is seen
492 int profileType_function Returns 0 if no error occured or something else otherwise.
494 const char *_tag_ Set to the name of the element tag that triggered this function call.
496 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
498 const char *name The contents of the 'name' attribute (or NULL if not defined).
500 const char *transport The contents of the 'transport' attribute (or NULL if not defined).
501 ++++++++++++++++++++++++++++++++++++++*/
503 static int profileType_function(const char *_tag_,int _type_,const char *name,const char *transport)
505 if(_type_&XMLPARSE_TAG_START)
507 Transport transporttype;
510 XMLPARSE_ASSERT_STRING(_tag_,name);
511 XMLPARSE_ASSERT_STRING(_tag_,transport);
513 for(i=0;i<nloaded_profiles;i++)
514 if(!strcmp(name,loaded_profiles[i]->name))
515 XMLPARSE_MESSAGE(_tag_,"profile name must be unique");
517 transporttype=TransportType(transport);
519 if(transporttype==Transport_None)
520 XMLPARSE_INVALID(_tag_,transport);
522 if((nloaded_profiles%16)==0)
523 loaded_profiles=(Profile**)realloc((void*)loaded_profiles,(nloaded_profiles+16)*sizeof(Profile*));
527 loaded_profiles[nloaded_profiles-1]=(Profile*)calloc(1,sizeof(Profile));
529 loaded_profiles[nloaded_profiles-1]->name=strcpy(malloc(strlen(name)+1),name);
530 loaded_profiles[nloaded_profiles-1]->transport=transporttype;
537 /*++++++++++++++++++++++++++++++++++++++
538 The function that is called when the RoutinoProfilesType XSD type is seen
540 int RoutinoProfilesType_function Returns 0 if no error occured or something else otherwise.
542 const char *_tag_ Set to the name of the element tag that triggered this function call.
544 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
545 ++++++++++++++++++++++++++++++++++++++*/
547 //static int RoutinoProfilesType_function(const char *_tag_,int _type_)
553 /*++++++++++++++++++++++++++++++++++++++
554 The function that is called when the XML declaration is seen
556 int xmlDeclaration_function Returns 0 if no error occured or something else otherwise.
558 const char *_tag_ Set to the name of the element tag that triggered this function call.
560 int _type_ Set to XMLPARSE_TAG_START at the start of a tag and/or XMLPARSE_TAG_END at the end of a tag.
562 const char *version The contents of the 'version' attribute (or NULL if not defined).
564 const char *encoding The contents of the 'encoding' attribute (or NULL if not defined).
565 ++++++++++++++++++++++++++++++++++++++*/
567 //static int xmlDeclaration_function(const char *_tag_,int _type_,const char *version,const char *encoding)
573 /*++++++++++++++++++++++++++++++++++++++
574 The XML profile parser.
576 int ParseXMLProfiles Returns 0 if OK or something else in case of an error.
578 const char *filename The name of the file to read.
579 ++++++++++++++++++++++++++++++++++++++*/
581 int ParseXMLProfiles(const char *filename)
585 if(!ExistsFile(filename))
587 fprintf(stderr,"Error: Specified profiles file '%s' does not exist.\n",filename);
591 FILE *file=fopen(filename,"r");
595 fprintf(stderr,"Error: Cannot open profiles file '%s' for reading.\n",filename);
599 retval=ParseXML(file,xml_toplevel_tags,XMLPARSE_UNKNOWN_ATTR_ERRNONAME);
607 for(i=0;i<nloaded_profiles;i++)
608 free(loaded_profiles[i]);
609 free(loaded_profiles);
620 /*++++++++++++++++++++++++++++++++++++++
621 Get the profile for a type of transport.
623 Profile *GetProfile Returns a pointer to the profile.
625 const char *name The name of the profile.
626 ++++++++++++++++++++++++++++++++++++++*/
628 Profile *GetProfile(const char *name)
632 for(i=0;i<nloaded_profiles;i++)
633 if(!strcmp(loaded_profiles[i]->name,name))
634 return(loaded_profiles[i]);
640 /*++++++++++++++++++++++++++++++++++++++
641 Update a profile with highway preference scaling factor.
643 int UpdateProfile Returns 1 in case of a problem.
645 Profile *profile The profile to be updated.
647 Ways *ways The set of ways to use.
648 ++++++++++++++++++++++++++++++++++++++*/
650 int UpdateProfile(Profile *profile,Ways *ways)
655 /* Fix up the allowed transport types. */
657 profile->allow=ALLOWED(profile->transport);
659 if(!(profile->allow & ways->file.allow))
662 /* Normalise the highway preferences into the range ~0 -> 1 */
664 for(i=1;i<Way_Count;i++)
666 if(profile->highway[i]<0)
667 profile->highway[i]=0;
669 if(profile->highway[i]>hmax)
670 hmax=profile->highway[i];
676 for(i=1;i<Way_Count;i++)
678 profile->highway[i]/=hmax;
680 if(profile->highway[i]<0.0001)
681 profile->highway[i]=0.0001;
684 /* Normalise the property preferences into the range ~0 -> 1 */
686 for(i=1;i<Property_Count;i++)
688 if(profile->props_yes[i]<0)
689 profile->props_yes[i]=0;
691 if(profile->props_yes[i]>100)
692 profile->props_yes[i]=100;
694 profile->props_yes[i]/=100;
695 profile->props_no [i] =1-profile->props_yes[i];
697 /* Squash the properties; selecting 60% preference without the sqrt() allows
698 routes 50% longer on highways with the property compared to ones without.
699 With the sqrt() function the ratio is only 22% allowing finer control. */
701 profile->props_yes[i] =sqrt(profile->props_yes[i]);
702 profile->props_no [i] =sqrt(profile->props_no[i] );
704 if(profile->props_yes[i]<0.0001)
705 profile->props_yes[i]=0.0001;
707 if(profile->props_no[i]<0.0001)
708 profile->props_no[i]=0.0001;
711 /* Find the fastest preferred speed */
713 profile->max_speed=0;
715 for(i=1;i<Way_Count;i++)
716 if(profile->speed[i]>profile->max_speed)
717 profile->max_speed=profile->speed[i];
719 if(profile->max_speed==0)
722 /* Find the most preferred property combination */
724 profile->max_pref=1; /* since highway prefs were normalised to 1 */
726 for(i=1;i<Property_Count;i++)
727 if(ways->file.props & PROPERTIES(i))
729 if(profile->props_yes[i]>profile->props_no[i])
730 profile->max_pref*=profile->props_yes[i];
732 profile->max_pref*=profile->props_no[i];
739 /*++++++++++++++++++++++++++++++++++++++
742 const Profile *profile The profile to print.
743 ++++++++++++++++++++++++++++++++++++++*/
745 void PrintProfile(const Profile *profile)
749 printf("Profile\n=======\n");
753 printf("Transport: %s\n",TransportName(profile->transport));
757 for(i=1;i<Way_Count;i++)
758 printf("Highway %-12s: %3d%%\n",HighwayName(i),(int)profile->highway[i]);
762 for(i=1;i<Way_Count;i++)
763 if(profile->highway[i])
764 printf("Speed on %-12s: %3d km/h / %2.0f mph\n",HighwayName(i),profile->speed[i],(double)profile->speed[i]/1.6);
768 for(i=1;i<Property_Count;i++)
769 printf("Highway property %-12s: %3d%%\n",PropertyName(i),(int)profile->props_yes[i]);
773 printf("Obey one-way : %s\n",profile->oneway?"yes":"no");
774 printf("Minimum weight: %.1f tonnes\n",weight_to_tonnes(profile->weight));
775 printf("Minimum height: %.1f metres\n",height_to_metres(profile->height));
776 printf("Minimum width : %.1f metres\n",width_to_metres(profile->width));
777 printf("Minimum length: %.1f metres\n",length_to_metres(profile->length));
781 /*++++++++++++++++++++++++++++++++++++++
782 Print out the profiles as XML for use as program input.
783 ++++++++++++++++++++++++++++++++++++++*/
785 void PrintProfilesXML(void)
790 printf("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
793 printf("<routino-profiles xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"routino-profiles.xsd\">\n");
796 for(j=0;j<nloaded_profiles;j++)
798 printf(" <profile name=\"%s\" transport=\"%s\">\n",loaded_profiles[j]->name,TransportName(loaded_profiles[j]->transport));
800 printf(" <speeds>\n");
801 for(i=1;i<Way_Count;i++)
802 printf(" <speed highway=\"%s\"%s kph=\"%d\" />\n",HighwayName(i),padding+3+strlen(HighwayName(i)),loaded_profiles[j]->speed[i]);
803 printf(" </speeds>\n");
805 printf(" <preferences>\n");
806 for(i=1;i<Way_Count;i++)
807 printf(" <preference highway=\"%s\"%s percent=\"%.0f\" />\n",HighwayName(i),padding+3+strlen(HighwayName(i)),loaded_profiles[j]->highway[i]);
808 printf(" </preferences>\n");
810 printf(" <properties>\n");
811 for(i=1;i<Property_Count;i++)
812 printf(" <property type=\"%s\"%s percent=\"%.0f\" />\n",PropertyName(i),padding+6+strlen(PropertyName(i)),loaded_profiles[j]->props_yes[i]);
813 printf(" </properties>\n");
815 printf(" <restrictions>\n");
816 printf(" <oneway obey=\"%d\" /> \n",loaded_profiles[j]->oneway);
817 printf(" <weight limit=\"%.1f\" />\n",weight_to_tonnes(loaded_profiles[j]->weight));
818 printf(" <height limit=\"%.1f\" />\n",height_to_metres(loaded_profiles[j]->height));
819 printf(" <width limit=\"%.1f\" />\n",width_to_metres(loaded_profiles[j]->width));
820 printf(" <length limit=\"%.1f\" />\n",length_to_metres(loaded_profiles[j]->length));
821 printf(" </restrictions>\n");
823 printf(" </profile>\n");
827 printf("</routino-profiles>\n");
831 /*++++++++++++++++++++++++++++++++++++++
832 Print out the profiles as JavaScript Object Notation for use in a web form.
833 ++++++++++++++++++++++++++++++++++++++*/
835 void PrintProfilesJSON(void)
839 printf("var routino={ // contains all default Routino options (generated using \"--help-profile-json\").\n");
842 printf(" // Default transport type\n");
843 printf(" transport: 'motorcar',\n");
846 printf(" // Transport types\n");
847 printf(" transports: { ");
848 for(j=0;j<nloaded_profiles;j++)
849 printf("%s%s: %d",j==0?"":", ",TransportName(loaded_profiles[j]->transport),j+1);
853 printf(" // Highway types\n");
854 printf(" highways: { ");
855 for(i=1;i<Way_Count;i++)
856 printf("%s%s: %d",i==1?"":", ",HighwayName(i),i);
860 printf(" // Property types\n");
861 printf(" properties: { ");
862 for(i=1;i<Property_Count;i++)
863 printf("%s%s: %d",i==1?"":", ",PropertyName(i),i);
867 printf(" // Restriction types\n");
868 printf(" restrictions: { oneway: 1, weight: 2, height: 3, width: 4, length: 5 },\n");
871 printf(" // Allowed highways\n");
872 printf(" profile_highway: {\n");
873 for(i=1;i<Way_Count;i++)
875 printf(" %12s: { ",HighwayName(i));
876 for(j=0;j<nloaded_profiles;j++)
877 printf("%s%s: %3d",j==0?"":", ",TransportName(loaded_profiles[j]->transport),(int)loaded_profiles[j]->highway[i]);
878 printf(" }%s\n",i==(Way_Count-1)?"":",");
883 printf(" // Speed limits\n");
884 printf(" profile_speed: {\n");
885 for(i=1;i<Way_Count;i++)
887 printf(" %12s: { ",HighwayName(i));
888 for(j=0;j<nloaded_profiles;j++)
889 printf("%s%s: %3d",j==0?"":", ",TransportName(loaded_profiles[j]->transport),loaded_profiles[j]->speed[i]);
890 printf(" }%s\n",i==(Way_Count-1)?"":",");
895 printf(" // Highway properties\n");
896 printf(" profile_property: {\n");
897 for(i=1;i<Property_Count;i++)
899 printf(" %12s: { ",PropertyName(i));
900 for(j=0;j<nloaded_profiles;j++)
901 printf("%s%s: %3d",j==0?"":", ",TransportName(loaded_profiles[j]->transport),(int)loaded_profiles[j]->props_yes[i]);
902 printf(" }%s\n",i==(Property_Count-1)?"":",");
907 printf(" // Restrictions\n");
908 printf(" profile_restrictions: {\n");
909 printf(" %12s: { ","oneway");
910 for(j=0;j<nloaded_profiles;j++)
911 printf("%s%s: %4d",j==0?"":", ",TransportName(loaded_profiles[j]->transport),loaded_profiles[j]->oneway);
913 printf(" %12s: { ","weight");
914 for(j=0;j<nloaded_profiles;j++)
915 printf("%s%s: %4.1f",j==0?"":", ",TransportName(loaded_profiles[j]->transport),weight_to_tonnes(loaded_profiles[j]->weight));
917 printf(" %12s: { ","height");
918 for(j=0;j<nloaded_profiles;j++)
919 printf("%s%s: %4.1f",j==0?"":", ",TransportName(loaded_profiles[j]->transport),height_to_metres(loaded_profiles[j]->height));
921 printf(" %12s: { ","width");
922 for(j=0;j<nloaded_profiles;j++)
923 printf("%s%s: %4.1f",j==0?"":", ",TransportName(loaded_profiles[j]->transport),width_to_metres(loaded_profiles[j]->width));
925 printf(" %12s: { ","length");
926 for(j=0;j<nloaded_profiles;j++)
927 printf("%s%s: %4.1f",j==0?"":", ",TransportName(loaded_profiles[j]->transport),length_to_metres(loaded_profiles[j]->length));
932 printf("}; // end of routino variable\n");
936 /*++++++++++++++++++++++++++++++++++++++
937 Print out the profiles as Perl for use in a web CGI.
938 ++++++++++++++++++++++++++++++++++++++*/
940 void PrintProfilesPerl(void)
944 printf("$routino={ # contains all default Routino options (generated using \"--help-profile-perl\").\n");
947 printf(" # Default transport type\n");
948 printf(" transport => 'motorcar',\n");
951 printf(" # Transport types\n");
952 printf(" transports => { ");
953 for(j=0;j<nloaded_profiles;j++)
954 printf("%s%s => %d",j==0?"":", ",TransportName(loaded_profiles[j]->transport),j+1);
958 printf(" # Highway types\n");
959 printf(" highways => { ");
960 for(i=1;i<Way_Count;i++)
961 printf("%s%s => %d",i==1?"":", ",HighwayName(i),i);
965 printf(" # Property types\n");
966 printf(" properties => { ");
967 for(i=1;i<Property_Count;i++)
968 printf("%s%s => %d",i==1?"":", ",PropertyName(i),i);
972 printf(" # Restriction types\n");
973 printf(" restrictions => { oneway => 1, weight => 2, height => 3, width => 4, length => 5 },\n");
976 printf(" # Allowed highways\n");
977 printf(" profile_highway => {\n");
978 for(i=1;i<Way_Count;i++)
980 printf(" %12s => {",HighwayName(i));
981 for(j=0;j<nloaded_profiles;j++)
982 printf("%s %s => %3d",j==0?"":", ",TransportName(loaded_profiles[j]->transport),(int)loaded_profiles[j]->highway[i]);
983 printf(" }%s\n",i==(Way_Count-1)?"":",");
988 printf(" # Speed limits\n");
989 printf(" profile_speed => {\n");
990 for(i=1;i<Way_Count;i++)
992 printf(" %12s => {",HighwayName(i));
993 for(j=0;j<nloaded_profiles;j++)
994 printf("%s %s => %3d",j==0?"":", ",TransportName(loaded_profiles[j]->transport),loaded_profiles[j]->speed[i]);
995 printf(" }%s\n",i==(Way_Count-1)?"":",");
1000 printf(" # Highway properties\n");
1001 printf(" profile_property => {\n");
1002 for(i=1;i<Property_Count;i++)
1004 printf(" %12s => {",PropertyName(i));
1005 for(j=0;j<nloaded_profiles;j++)
1006 printf("%s %s => %3d",j==0?"":", ",TransportName(loaded_profiles[j]->transport),(int)loaded_profiles[j]->props_yes[i]);
1007 printf(" }%s\n",i==(Property_Count-1)?"":",");
1012 printf(" # Restrictions\n");
1013 printf(" profile_restrictions => {\n");
1014 printf(" %12s => {","oneway");
1015 for(j=0;j<nloaded_profiles;j++)
1016 printf("%s %s => %4d",j==0?"":", ",TransportName(loaded_profiles[j]->transport),loaded_profiles[j]->oneway);
1018 printf(" %12s => {","weight");
1019 for(j=0;j<nloaded_profiles;j++)
1020 printf("%s %s => %4.1f",j==0?"":", ",TransportName(loaded_profiles[j]->transport),weight_to_tonnes(loaded_profiles[j]->weight));
1022 printf(" %12s => {","height");
1023 for(j=0;j<nloaded_profiles;j++)
1024 printf("%s %s => %4.1f",j==0?"":", ",TransportName(loaded_profiles[j]->transport),height_to_metres(loaded_profiles[j]->height));
1026 printf(" %12s => {","width");
1027 for(j=0;j<nloaded_profiles;j++)
1028 printf("%s %s => %4.1f",j==0?"":", ",TransportName(loaded_profiles[j]->transport),width_to_metres(loaded_profiles[j]->width));
1030 printf(" %12s => {","length");
1031 for(j=0;j<nloaded_profiles;j++)
1032 printf("%s %s => %4.1f",j==0?"":", ",TransportName(loaded_profiles[j]->transport),length_to_metres(loaded_profiles[j]->length));
1037 printf("}; # end of routino variable\n");