/***************************************
- $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.
#include <string.h>
#include <stdlib.h>
-#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. +*/
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;i<Way_Count;i++)
{
return(1);
for(i=1;i<Way_Count;i++)
+ {
profile->highway[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;i<Property_Count;i++)
{
if(profile->props_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 */
profile->max_pref=1; /* since highway prefs were normalised to 1 */
for(i=1;i<Property_Count;i++)
- if(ways->props & PROPERTIES(i))
+ if(ways->file.props & PROPERTIES(i))
{
if(profile->props_yes[i]>profile->props_no[i])
profile->max_pref*=profile->props_yes[i];
printf("\n");
printf(" // Transport types\n");
- printf(" transports: {");
+ printf(" transports: { ");
for(j=0;j<nloaded_profiles;j++)
- printf("%s%s: %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<Way_Count;i++)
printf("%s%s: %d",i==1?"":", ",HighwayName(i),i);
- printf("},\n");
+ printf(" },\n");
printf("\n");
printf(" // Property types\n");
- printf(" properties: {");
+ printf(" properties: { ");
for(i=1;i<Property_Count;i++)
printf("%s%s: %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");
printf(" profile_highway: {\n");
for(i=1;i<Way_Count;i++)
{
- printf(" %12s: {",HighwayName(i));
+ printf(" %12s: { ",HighwayName(i));
for(j=0;j<nloaded_profiles;j++)
- printf("%s%s: %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");
printf(" profile_speed: {\n");
for(i=1;i<Way_Count;i++)
{
- printf(" %12s: {",HighwayName(i));
+ printf(" %12s: { ",HighwayName(i));
for(j=0;j<nloaded_profiles;j++)
- printf("%s%s: %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");
printf(" profile_property: {\n");
for(i=1;i<Property_Count;i++)
{
- printf(" %12s: {",PropertyName(i));
+ printf(" %12s: { ",PropertyName(i));
for(j=0;j<nloaded_profiles;j++)
- printf("%s%s: %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");
printf(" // Restrictions\n");
printf(" profile_restrictions: {\n");
- printf(" %12s: {","oneway");
+ printf(" %12s: { ","oneway");
for(j=0;j<nloaded_profiles;j++)
- printf("%s%s: %4d",j==1?"":", ",TransportName(loaded_profiles[j]->transport),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;j<nloaded_profiles;j++)
- printf("%s%s: %4.1f",j==1?"":", ",TransportName(loaded_profiles[j]->transport),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;j<nloaded_profiles;j++)
- printf("%s%s: %4.1f",j==1?"":", ",TransportName(loaded_profiles[j]->transport),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;j<nloaded_profiles;j++)
- printf("%s%s: %4.1f",j==1?"":", ",TransportName(loaded_profiles[j]->transport),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;j<nloaded_profiles;j++)
- printf("%s%s: %4.1f",j==1?"":", ",TransportName(loaded_profiles[j]->transport),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");
printf("\n");
printf(" # Transport types\n");
- printf(" transports => {");
+ printf(" transports => { ");
for(j=0;j<nloaded_profiles;j++)
- printf("%s%s => %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<Way_Count;i++)
printf("%s%s => %d",i==1?"":", ",HighwayName(i),i);
- printf("},\n");
+ printf(" },\n");
printf("\n");
printf(" # Property types\n");
- printf(" properties => {");
+ printf(" properties => { ");
for(i=1;i<Property_Count;i++)
printf("%s%s => %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");
{
printf(" %12s => {",HighwayName(i));
for(j=0;j<nloaded_profiles;j++)
- printf("%s %s => %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");
{
printf(" %12s => {",HighwayName(i));
for(j=0;j<nloaded_profiles;j++)
- printf("%s %s => %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");
{
printf(" %12s => {",PropertyName(i));
for(j=0;j<nloaded_profiles;j++)
- printf("%s %s => %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");
printf(" profile_restrictions => {\n");
printf(" %12s => {","oneway");
for(j=0;j<nloaded_profiles;j++)
- printf("%s %s => %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<nloaded_profiles;j++)
- printf("%s %s => %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<nloaded_profiles;j++)
- printf("%s %s => %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<nloaded_profiles;j++)
- printf("%s %s => %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<nloaded_profiles;j++)
- printf("%s %s => %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");