Skip to content

Commit

Permalink
commit bo-e
Browse files Browse the repository at this point in the history
  • Loading branch information
ocivelo committed Jan 4, 2014
1 parent 81d0437 commit 47d68b3
Show file tree
Hide file tree
Showing 19 changed files with 679 additions and 46 deletions.
6 changes: 4 additions & 2 deletions src/Makefile
Expand Up @@ -71,7 +71,8 @@ PLANETSPLITTER_OBJ=planetsplitter.o \
files.o logging.o logerror.o errorlogx.o \
results.o queue.o sorting.o \
xmlparse.o tagging.o \
uncompress.o osmxmlparse.o osmpbfparse.o osmo5mparse.o osmparser.o
uncompress.o osmxmlparse.o osmpbfparse.o osmo5mparse.o osmparser.o \
srtmHgtReader.o

planetsplitter : $(PLANETSPLITTER_OBJ)
$(LD) $(PLANETSPLITTER_OBJ) -o $@ $(LDFLAGS)
Expand All @@ -84,7 +85,8 @@ PLANETSPLITTER_SLIM_OBJ=planetsplitter-slim.o \
files.o logging.o logerror-slim.o errorlogx-slim.o \
results.o queue.o sorting.o \
xmlparse.o tagging.o \
uncompress.o osmxmlparse.o osmpbfparse.o osmo5mparse.o osmparser.o
uncompress.o osmxmlparse.o osmpbfparse.o osmo5mparse.o osmparser.o \
srtmHgtReader.o

planetsplitter-slim : $(PLANETSPLITTER_SLIM_OBJ)
$(LD) $(PLANETSPLITTER_SLIM_OBJ) -o $@ $(LDFLAGS)
Expand Down
98 changes: 81 additions & 17 deletions src/optimiser.c
Expand Up @@ -33,7 +33,7 @@


/*+ To help when debugging +*/
#define DEBUG 0
//#define DEBUG 0


/* Global variables */
Expand Down Expand Up @@ -170,7 +170,15 @@ Results *FindNormalRoute(Nodes *nodes,Segments *segments,Ways *ways,Relations *r

/* must obey one-way restrictions (unless profile allows) */
if(profile->oneway && IsOnewayTo(segmentp,node1))
goto endloop;
{
if (profile->allow != Transports_Bicycle)
goto endloop;
wayp=LookupWay(ways,segmentp->way,1);

if (!(wayp->props & Properties_DoubleSens))
goto endloop;
printf(" FindNormalRoute(...,start_node=%"Pindex_t" prev_segment=%"Pindex_t" finish_node=%"Pindex_t") props=%d DoubleSens=%d \n",start_node,prev_segment,finish_node,wayp->props, Properties_DoubleSens);
}

if(IsFakeNode(node1) || IsFakeNode(node2))
{
Expand Down Expand Up @@ -247,7 +255,7 @@ Results *FindNormalRoute(Nodes *nodes,Segments *segments,Ways *ways,Relations *r
if(option_quickest==0)
segment_score=(score_t)DISTANCE(segmentp->distance)/segment_pref;
else
segment_score=(score_t)Duration(segmentp,wayp,profile)/segment_pref;
segment_score=(score_t)Duration(node1,segmentp,wayp,profile)/segment_pref;

cumulative_score=result1->score+segment_score;

Expand Down Expand Up @@ -358,7 +366,7 @@ Results *FindMiddleRoute(Nodes *nodes,Segments *segments,Ways *ways,Relations *r
int force_uturn=0;

#if DEBUG
printf(" FindMiddleRoute(...,[begin has %d nodes],[end has %d nodes])\n",begin->number,end->number);
printf(" FindMiddleRoute(...,[begin has %d nodes],[end has %d nodes] finish_node=%"Pindex_t " )\n",begin->number,end->number,end->finish_node);
#endif

#if !DEBUG
Expand Down Expand Up @@ -463,6 +471,10 @@ Results *FindMiddleRoute(Nodes *nodes,Segments *segments,Ways *ways,Relations *r
index_t node1,seg1;
index_t turnrelation=NO_RELATION;

#if DEBUG
printf("A Pop result1->node=%"Pindex_t" seg1=%"Pindex_t" score=%f finish_score=%f \n",result1->node,result1->segment,result1->score,finish_score);
#endif

/* score must be better than current best score */
if(result1->score>=finish_score)
continue;
Expand Down Expand Up @@ -494,7 +506,16 @@ Results *FindMiddleRoute(Nodes *nodes,Segments *segments,Ways *ways,Relations *r

/* must obey one-way restrictions (unless profile allows) */
if(profile->oneway && IsOnewayTo(segmentp,node1))
goto endloop;
{
if (profile->allow != Transports_Bicycle)
goto endloop;
wayp=LookupWay(ways,segmentp->way,1);
if (!(wayp->props & Properties_DoubleSens))
goto endloop;
#if DEBUG
printf("B FindMiddleRoute() node1=%"Pindex_t" node2=%"Pindex_t" props=%d DoubleSens=%d \n",segmentp->node1,segmentp->node2,wayp->props, Properties_DoubleSens);
#endif
}

seg2=IndexSegment(segments,segmentp); /* segment cannot be a fake segment (must be a super-segment) */

Expand Down Expand Up @@ -559,14 +580,20 @@ Results *FindMiddleRoute(Nodes *nodes,Segments *segments,Ways *ways,Relations *r
if(option_quickest==0)
segment_score=(score_t)DISTANCE(segmentp->distance)/segment_pref;
else
segment_score=(score_t)Duration(segmentp,wayp,profile)/segment_pref;
segment_score=(score_t)Duration(node1,segmentp,wayp,profile)/segment_pref;

cumulative_score=result1->score+segment_score;

#if DEBUG
printf("BTestsok node1=%"Pindex_t" node2=%"Pindex_t" seg2=%"Pindex_t" dist=%08x segment_pref=%f segment_score=%f cumulative_score=%f finish_score=%f\n",node1,node2,seg2,DISTANCE(segmentp->distance),segment_pref,segment_score,cumulative_score,finish_score);
#endif
/* score must be better than current best score */
if(cumulative_score>=finish_score)
{
#if DEBUG
printf("Bcum>finish segmentp->node1=%"Pindex_t" node2=%"Pindex_t" seg1=%"Pindex_t" seg2=%"Pindex_t"\n",segmentp->node1,segmentp->node2,seg1,seg2);
#endif
goto endloop;

}
result2=FindResult(results,node2,seg2);

if(!result2) /* New end node/segment pair */
Expand All @@ -581,15 +608,25 @@ Results *FindMiddleRoute(Nodes *nodes,Segments *segments,Ways *ways,Relations *r
result2->score=cumulative_score;
}
else
{
#if DEBUG
printf("Bcum>=score prec result2->node=%"Pindex_t" seg=%"Pindex_t" result2->score=%f cumulative_score=%f\n",result2->node,result2->segment,result2->score,cumulative_score);
#endif
goto endloop;

}
if((result3=FindResult(end,node2,seg2)))
{
#if DEBUG
printf("Cend result3->node=%"Pindex_t" seg=%"Pindex_t" score=%f result2->node=%"Pindex_t "seg=%"Pindex_t" score=%f finish_score=%f\n",result3->node,result3->segment,result3->score,result2->node,result2->segment,result2->score,finish_score);
#endif
if((result2->score+result3->score)<finish_score)
{
finish_score=result2->score+result3->score;
finish_result=result2;
}
#if DEBUG
printf("Cend finish_result->node=%"Pindex_t" seg=%"Pindex_t" finish_score=%f\n",finish_result->node,finish_result->segment,finish_score);
#endif
}
}
else
{
Expand All @@ -605,6 +642,9 @@ Results *FindMiddleRoute(Nodes *nodes,Segments *segments,Ways *ways,Relations *r
potential_score=result2->score+(score_t)direct/profile->max_pref;
else
potential_score=result2->score+(score_t)distance_speed_to_duration(direct,profile->max_speed)/profile->max_pref;
#if DEBUG
printf("Cpot result2->node=%"Pindex_t "seg=%"Pindex_t" potential_score=%f <? finish_score=%f\n",result2->node,result2->segment,potential_score,finish_score);
#endif

if(potential_score<finish_score)
InsertInQueue(queue,result2,potential_score);
Expand Down Expand Up @@ -809,8 +849,11 @@ static Results *FindSuperRoute(Nodes *nodes,Segments *segments,Ways *ways,Relati

/* must obey one-way restrictions */
if(IsOnewayTo(segmentp,node1))
{
printf(" FindSuperRoute(...,start_node=%"Pindex_t" finish_node=%"Pindex_t") IsOnewayTo\n",start_node,finish_node);

goto endloop;

}
seg2=IndexSegment(segments,segmentp);

/* must not perform U-turn */
Expand Down Expand Up @@ -973,7 +1016,14 @@ Results *FindStartRoutes(Nodes *nodes,Segments *segments,Ways *ways,Relations *r

/* must obey one-way restrictions (unless profile allows) */
if(profile->oneway && IsOnewayTo(segmentp,node1))
goto endloop;
{
if (profile->allow != Transports_Bicycle)
goto endloop;
wayp=LookupWay(ways,segmentp->way,1);
if (!(wayp->props & Properties_DoubleSens))
goto endloop;
printf(" FindStartRoutes(...,start_node=%"Pindex_t" prev_segment=%"Pindex_t" finish_node=%"Pindex_t") props=%d DoubleSens=%d\n",start_node,prev_segment,finish_node,wayp->props,Properties_DoubleSens);
}

if(IsFakeNode(node1) || IsFakeNode(node2))
{
Expand Down Expand Up @@ -1046,7 +1096,7 @@ Results *FindStartRoutes(Nodes *nodes,Segments *segments,Ways *ways,Relations *r
if(option_quickest==0)
segment_score=(score_t)DISTANCE(segmentp->distance)/segment_pref;
else
segment_score=(score_t)Duration(segmentp,wayp,profile)/segment_pref;
segment_score=(score_t)Duration(node1,segmentp,wayp,profile)/segment_pref;

cumulative_score=result1->score+segment_score;

Expand Down Expand Up @@ -1268,7 +1318,14 @@ Results *ExtendStartRoutes(Nodes *nodes,Segments *segments,Ways *ways,Relations

/* must obey one-way restrictions (unless profile allows) */
if(profile->oneway && IsOnewayTo(segmentp,node1))
goto endloop;
{
if (profile->allow != Transports_Bicycle)
goto endloop;
wayp=LookupWay(ways,segmentp->way,1);
if (!(wayp->props & Properties_DoubleSens))
goto endloop;
printf(" ExtendStartRoutes(...,[begin has %d nodes],finish_node=%"Pindex_t") props=%d DoubleSens=%d\n",begin->number,finish_node, wayp->props,Properties_DoubleSens);
}

if(IsFakeNode(node1) || IsFakeNode(node2))
{
Expand Down Expand Up @@ -1334,7 +1391,7 @@ Results *ExtendStartRoutes(Nodes *nodes,Segments *segments,Ways *ways,Relations
if(option_quickest==0)
segment_score=(score_t)DISTANCE(segmentp->distance)/segment_pref;
else
segment_score=(score_t)Duration(segmentp,wayp,profile)/segment_pref;
segment_score=(score_t)Duration(node1,segmentp,wayp,profile)/segment_pref;

cumulative_score=result1->score+segment_score;

Expand Down Expand Up @@ -1492,7 +1549,14 @@ Results *FindFinishRoutes(Nodes *nodes,Segments *segments,Ways *ways,Relations *

/* must obey one-way restrictions (unless profile allows) */
if(profile->oneway && IsOnewayFrom(segmentp,node1)) /* working backwards => disallow oneway *from* node1 */
goto endloop;
{
if (profile->allow != Transports_Bicycle)
goto endloop;
wayp=LookupWay(ways,segmentp->way,1);
if (!(wayp->props & Properties_DoubleSens))
goto endloop;
printf(" FindFinishRoutes(...,finish_node=%"Pindex_t") props=%d DoubleSens=%d\n",finish_node,wayp->props,Properties_DoubleSens);
}

node2=OtherNode(segmentp,node1);

Expand Down Expand Up @@ -1565,7 +1629,7 @@ Results *FindFinishRoutes(Nodes *nodes,Segments *segments,Ways *ways,Relations *
if(option_quickest==0)
segment_score=(score_t)DISTANCE(segmentp->distance)/segment_pref;
else
segment_score=(score_t)Duration(segmentp,wayp,profile)/segment_pref;
segment_score=(score_t)Duration(node2,segmentp,wayp,profile)/segment_pref;

cumulative_score=result1->score+segment_score;

Expand Down
60 changes: 60 additions & 0 deletions src/osmparser.c
Expand Up @@ -69,6 +69,7 @@ static node_t relation_via=NO_NODE_ID;
static double parse_speed(way_t id,const char *k,const char *v);
static double parse_weight(way_t id,const char *k,const char *v);
static double parse_length(way_t id,const char *k,const char *v);
static double parse_incline(way_t id,const char *k,const char *v);


/*++++++++++++++++++++++++++++++++++++++
Expand Down Expand Up @@ -525,6 +526,15 @@ void ProcessWayTags(TagList *tags,int64_t way_id,int mode)

break;

case 'c':
if(!strcmp(k,"cycleway"))
{
if(!strcmp(v,"opposite_lane"))
way.props|=Properties_DoubleSens;
recognised=1; break;
}
break;

case 'f':
if(!strcmp(k,"foot"))
{
Expand Down Expand Up @@ -582,6 +592,16 @@ void ProcessWayTags(TagList *tags,int64_t way_id,int mode)

break;

case 'i':
if(!strcmp(k,"incline"))
{
/* logerror("Way %"Pway_t" has an 'incline' = '%s' \n",logerror_way(id),v); */
way.incline=pourcent_to_incline(parse_incline(id,k,v));
recognised=1; break;
}
break;


case 'l':
if(!strcmp(k,"lanes"))
{
Expand Down Expand Up @@ -1140,3 +1160,43 @@ static double parse_length(way_t id,const char *k,const char *v)

return(0);
}

/*++++++++++++++++++++++++++++++++++++++
Convert a string containing an inclination into a double precision.
double parse_incline Returns the inclination in % if it can be parsed.
way_t id The way being processed.
const char *k The tag key.
const char *v The tag value.
++++++++++++++++++++++++++++++++++++++*/

static double parse_incline(way_t id,const char *k,const char *v)
{
char *ev;
double value=strtod(v,&ev);

if(v==ev)
logerror("Way %"Pway_t" has an unrecognised tag '%s' = '%s' (after tagging rules); ignoring it.\n",logerror_way(id),k,v);
else
{
while(isspace(*ev)) ev++;

if(!strcmp(ev,"°"))
{
if (value > 0)
return(100*tan(value));
else
return(-100*tan(-value));
}

if(*ev==0 || !strcmp(ev,"%"))
return(value);

logerror("Way %"Pway_t" has an un-parseable tag '%s' = '%s' (after tagging rules); ignoring it.\n",logerror_way(id),k,v);
}

return(0);
}
7 changes: 5 additions & 2 deletions src/output.c
Expand Up @@ -383,8 +383,11 @@ void PrintRoute(Results **results,int nresults,Nodes *nodes,Segments *segments,W
resultwayp=LookupWay(ways,resultsegmentp->way,1);

seg_distance+=DISTANCE(resultsegmentp->distance);
seg_duration+=Duration(resultsegmentp,resultwayp,profile);

/* pour calcul en fonction de incline */
if (result->node == resultsegmentp->node1)
seg_duration+=Duration(resultsegmentp->node2,resultsegmentp,resultwayp,profile);
else
seg_duration+=Duration(resultsegmentp->node1,resultsegmentp,resultwayp,profile);
/* Calculate the cumulative distance/duration */

junc_distance+=seg_distance;
Expand Down
10 changes: 10 additions & 0 deletions src/prunex.c
Expand Up @@ -1288,10 +1288,20 @@ static void modify_segment(SegmentsX *segmentsx,SegmentX *segmentx,index_t newno

if(segmentx->distance&(ONEWAY_2TO1|ONEWAY_1TO2))
segmentx->distance^=ONEWAY_2TO1|ONEWAY_1TO2;
if(segmentx->distance&(INCLINEUP_2TO1|INCLINEUP_1TO2))
segmentx->distance^=INCLINEUP_2TO1|INCLINEUP_1TO2;

temp=newnode1;
newnode1=newnode2;
newnode2=temp;

float tmp;
tmp=segmentx->ascent;
segmentx->ascent=segmentx->descent;
segmentx->descent = tmp;
tmp=segmentx->ascentOn;
segmentx->ascentOn=segmentx->descentOn;
segmentx->descentOn=tmp;
}

if(newnode1!=segmentx->node1)
Expand Down
6 changes: 5 additions & 1 deletion src/results.c
Expand Up @@ -221,7 +221,11 @@ Result *InsertResult(Results *results,index_t node,index_t segment)

result->score=0;
result->sortby=0;

result->ascent=0;
result->descent=0;
result->ascentOn=0;
result->descentOn=0;

result->queued=NOT_QUEUED;

return(result);
Expand Down
5 changes: 5 additions & 0 deletions src/results.h
Expand Up @@ -49,6 +49,11 @@ struct _Result

score_t score; /*+ The best actual weighted distance or duration score from the start to the node. +*/
score_t sortby; /*+ The best possible weighted distance or duration score from the start to the finish. +*/

float ascent;
float descent;
float ascentOn;
float descentOn;

uint32_t queued; /*+ The position of this result in the queue. +*/

Expand Down

0 comments on commit 47d68b3

Please sign in to comment.