X-Git-Url: http://git.maemo.org/git/?p=routino;a=blobdiff_plain;f=src%2Fprofiles.c;fp=src%2Fprofiles.c;h=8c89d9032a9f2f9b7c8b80e97500216240cc99b2;hp=e27a0678f8ef9bb4065031563555c8afcd64b0c3;hb=a5b34ad069a52ff6cf981f01667d102292988811;hpb=20283c6cf5c6951cc1f2787492c67a7fb72aee9a;ds=sidebyside diff --git a/src/profiles.c b/src/profiles.c index e27a067..8c89d90 100644 --- a/src/profiles.c +++ b/src/profiles.c @@ -1,5 +1,5 @@ /*************************************** - $Header: /home/amb/routino/src/RCS/profiles.c,v 1.42 2010/05/29 10:37:12 amb Exp $ + $Header: /home/amb/routino/src/RCS/profiles.c,v 1.47 2010/10/18 17:40:34 amb Exp $ Load the profiles from a file and the functions for handling them. @@ -26,11 +26,13 @@ #include #include -#include "profiles.h" #include "types.h" #include "ways.h" -#include "xmlparse.h" + +#include "files.h" +#include "profiles.h" #include "functions.h" +#include "xmlparse.h" /*+ The profiles that have been loaded from file. +*/ @@ -654,10 +656,10 @@ int UpdateProfile(Profile *profile,Ways *ways) profile->allow=ALLOWED(profile->transport); - if(!(profile->allow & ways->allow)) + if(!(profile->allow & ways->file.allow)) return(1); - /* Normalise the highway preferences into the range 0 -> 1 */ + /* Normalise the highway preferences into the range ~0 -> 1 */ for(i=1;ihighway[i]/=hmax; - /* Normalise the property preferences into the range 0 -> 2 */ + if(profile->highway[i]<0.0001) + profile->highway[i]=0.0001; + } + + /* Normalise the property preferences into the range ~0 -> 1 */ for(i=1;iprops_yes[i]>100) profile->props_yes[i]=100; - profile->props_yes[i]/=50; - profile->props_no [i] =2-profile->props_yes[i]; + profile->props_yes[i]/=100; + profile->props_no [i] =1-profile->props_yes[i]; + + /* Squash the properties; selecting 60% preference without the sqrt() allows + routes 50% longer on highways with the property compared to ones without. + With the sqrt() function the ratio is only 22% allowing finer control. */ + + profile->props_yes[i] =sqrt(profile->props_yes[i]); + profile->props_no [i] =sqrt(profile->props_no[i] ); + + if(profile->props_yes[i]<0.0001) + profile->props_yes[i]=0.0001; + + if(profile->props_no[i]<0.0001) + profile->props_no[i]=0.0001; } /* Find the fastest preferred speed */ @@ -704,7 +724,7 @@ int UpdateProfile(Profile *profile,Ways *ways) profile->max_pref=1; /* since highway prefs were normalised to 1 */ for(i=1;iprops & PROPERTIES(i)) + if(ways->file.props & PROPERTIES(i)) { if(profile->props_yes[i]>profile->props_no[i]) profile->max_pref*=profile->props_yes[i]; @@ -824,38 +844,38 @@ void PrintProfilesJSON(void) printf("\n"); printf(" // Transport types\n"); - printf(" transports: {"); + printf(" transports: { "); for(j=0;jtransport),j); - printf("},\n"); + printf("%s%s: %d",j==0?"":", ",TransportName(loaded_profiles[j]->transport),j+1); + printf(" },\n"); printf("\n"); printf(" // Highway types\n"); - printf(" highways: {"); + printf(" highways: { "); for(i=1;itransport),(int)loaded_profiles[j]->highway[i]); - printf("}%s\n",i==(Way_Count-1)?"":","); + printf("%s%s: %3d",j==0?"":", ",TransportName(loaded_profiles[j]->transport),(int)loaded_profiles[j]->highway[i]); + printf(" }%s\n",i==(Way_Count-1)?"":","); } printf(" },\n"); printf("\n"); @@ -864,10 +884,10 @@ void PrintProfilesJSON(void) printf(" profile_speed: {\n"); for(i=1;itransport),loaded_profiles[j]->speed[i]); - printf("}%s\n",i==(Way_Count-1)?"":","); + printf("%s%s: %3d",j==0?"":", ",TransportName(loaded_profiles[j]->transport),loaded_profiles[j]->speed[i]); + printf(" }%s\n",i==(Way_Count-1)?"":","); } printf(" },\n"); printf("\n"); @@ -876,36 +896,36 @@ void PrintProfilesJSON(void) printf(" profile_property: {\n"); for(i=1;itransport),(int)loaded_profiles[j]->props_yes[i]); - printf("}%s\n",i==(Property_Count-1)?"":","); + printf("%s%s: %3d",j==0?"":", ",TransportName(loaded_profiles[j]->transport),(int)loaded_profiles[j]->props_yes[i]); + printf(" }%s\n",i==(Property_Count-1)?"":","); } printf(" },\n"); printf("\n"); printf(" // Restrictions\n"); printf(" profile_restrictions: {\n"); - printf(" %12s: {","oneway"); + printf(" %12s: { ","oneway"); for(j=0;jtransport),loaded_profiles[j]->oneway); - printf("},\n"); - printf(" %12s: {","weight"); + printf("%s%s: %4d",j==0?"":", ",TransportName(loaded_profiles[j]->transport),loaded_profiles[j]->oneway); + printf(" },\n"); + printf(" %12s: { ","weight"); for(j=0;jtransport),weight_to_tonnes(loaded_profiles[j]->weight)); - printf("},\n"); - printf(" %12s: {","height"); + printf("%s%s: %4.1f",j==0?"":", ",TransportName(loaded_profiles[j]->transport),weight_to_tonnes(loaded_profiles[j]->weight)); + printf(" },\n"); + printf(" %12s: { ","height"); for(j=0;jtransport),height_to_metres(loaded_profiles[j]->height)); - printf("},\n"); - printf(" %12s: {","width"); + printf("%s%s: %4.1f",j==0?"":", ",TransportName(loaded_profiles[j]->transport),height_to_metres(loaded_profiles[j]->height)); + printf(" },\n"); + printf(" %12s: { ","width"); for(j=0;jtransport),width_to_metres(loaded_profiles[j]->width)); - printf("},\n"); - printf(" %12s: {","length"); + printf("%s%s: %4.1f",j==0?"":", ",TransportName(loaded_profiles[j]->transport),width_to_metres(loaded_profiles[j]->width)); + printf(" },\n"); + printf(" %12s: { ","length"); for(j=0;jtransport),length_to_metres(loaded_profiles[j]->length)); - printf("}\n"); + printf("%s%s: %4.1f",j==0?"":", ",TransportName(loaded_profiles[j]->transport),length_to_metres(loaded_profiles[j]->length)); + printf(" }\n"); printf(" }\n"); printf("\n"); @@ -929,28 +949,28 @@ void PrintProfilesPerl(void) printf("\n"); printf(" # Transport types\n"); - printf(" transports => {"); + printf(" transports => { "); for(j=0;j %d",j==1?"":", ",TransportName(loaded_profiles[j]->transport),j); - printf("},\n"); + printf("%s%s => %d",j==0?"":", ",TransportName(loaded_profiles[j]->transport),j+1); + printf(" },\n"); printf("\n"); printf(" # Highway types\n"); - printf(" highways => {"); + printf(" highways => { "); for(i=1;i %d",i==1?"":", ",HighwayName(i),i); - printf("},\n"); + printf(" },\n"); printf("\n"); printf(" # Property types\n"); - printf(" properties => {"); + printf(" properties => { "); for(i=1;i %d",i==1?"":", ",PropertyName(i),i); - printf("},\n"); + printf(" },\n"); printf("\n"); printf(" # Restriction types\n"); - printf(" restrictions => {oneway => 1, weight => 2, height => 3, width => 4, length => 5},\n"); + printf(" restrictions => { oneway => 1, weight => 2, height => 3, width => 4, length => 5 },\n"); printf("\n"); printf(" # Allowed highways\n"); @@ -959,8 +979,8 @@ void PrintProfilesPerl(void) { printf(" %12s => {",HighwayName(i)); for(j=0;j %3d",j==1?"":", ",TransportName(loaded_profiles[j]->transport),(int)loaded_profiles[j]->highway[i]); - printf("}%s\n",i==(Way_Count-1)?"":","); + printf("%s %s => %3d",j==0?"":", ",TransportName(loaded_profiles[j]->transport),(int)loaded_profiles[j]->highway[i]); + printf(" }%s\n",i==(Way_Count-1)?"":","); } printf(" },\n"); printf("\n"); @@ -971,8 +991,8 @@ void PrintProfilesPerl(void) { printf(" %12s => {",HighwayName(i)); for(j=0;j %3d",j==1?"":", ",TransportName(loaded_profiles[j]->transport),loaded_profiles[j]->speed[i]); - printf("}%s\n",i==(Way_Count-1)?"":","); + printf("%s %s => %3d",j==0?"":", ",TransportName(loaded_profiles[j]->transport),loaded_profiles[j]->speed[i]); + printf(" }%s\n",i==(Way_Count-1)?"":","); } printf(" },\n"); printf("\n"); @@ -983,8 +1003,8 @@ void PrintProfilesPerl(void) { printf(" %12s => {",PropertyName(i)); for(j=0;j %3d",j==1?"":", ",TransportName(loaded_profiles[j]->transport),(int)loaded_profiles[j]->props_yes[i]); - printf("}%s\n",i==(Property_Count-1)?"":","); + printf("%s %s => %3d",j==0?"":", ",TransportName(loaded_profiles[j]->transport),(int)loaded_profiles[j]->props_yes[i]); + printf(" }%s\n",i==(Property_Count-1)?"":","); } printf(" },\n"); printf("\n"); @@ -993,25 +1013,25 @@ void PrintProfilesPerl(void) printf(" profile_restrictions => {\n"); printf(" %12s => {","oneway"); for(j=0;j %4d",j==1?"":", ",TransportName(loaded_profiles[j]->transport),loaded_profiles[j]->oneway); - printf("},\n"); + printf("%s %s => %4d",j==0?"":", ",TransportName(loaded_profiles[j]->transport),loaded_profiles[j]->oneway); + printf(" },\n"); printf(" %12s => {","weight"); for(j=0;j %4.1f",j==1?"":", ",TransportName(loaded_profiles[j]->transport),weight_to_tonnes(loaded_profiles[j]->weight)); - printf("},\n"); + printf("%s %s => %4.1f",j==0?"":", ",TransportName(loaded_profiles[j]->transport),weight_to_tonnes(loaded_profiles[j]->weight)); + printf(" },\n"); printf(" %12s => {","height"); for(j=0;j %4.1f",j==1?"":", ",TransportName(loaded_profiles[j]->transport),height_to_metres(loaded_profiles[j]->height)); - printf("},\n"); + printf("%s %s => %4.1f",j==0?"":", ",TransportName(loaded_profiles[j]->transport),height_to_metres(loaded_profiles[j]->height)); + printf(" },\n"); printf(" %12s => {","width"); for(j=0;j %4.1f",j==1?"":", ",TransportName(loaded_profiles[j]->transport),width_to_metres(loaded_profiles[j]->width)); - printf("},\n"); + printf("%s %s => %4.1f",j==0?"":", ",TransportName(loaded_profiles[j]->transport),width_to_metres(loaded_profiles[j]->width)); + printf(" },\n"); printf(" %12s => {","length"); for(j=0;j %4.1f",j==1?"":", ",TransportName(loaded_profiles[j]->transport),length_to_metres(loaded_profiles[j]->length)); - printf("}\n"); - printf(" },\n"); + printf("%s %s => %4.1f",j==0?"":", ",TransportName(loaded_profiles[j]->transport),length_to_metres(loaded_profiles[j]->length)); + printf(" }\n"); + printf(" }\n"); printf("\n"); printf("}; # end of routino variable\n");