Routino SVN Repository Browser

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

ViewVC logotype

Annotation of /trunk/src/supersegments.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (hide annotations) (download) (as text)
Sun Jan 11 09:28:31 2009 UTC (16 years, 2 months ago) by amb
File MIME type: text/x-csrc
File size: 4104 byte(s)
Working version with supersegments and junctions.

1 amb 16 /***************************************
2 amb 31 $Header: /home/amb/CVS/routino/src/supersegments.c,v 1.3 2009-01-11 09:28:31 amb Exp $
3 amb 16
4     Super-Segment data type functions.
5     ******************/ /******************
6     Written by Andrew M. Bishop
7    
8     This file Copyright 2008,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 <assert.h>
16     #include <math.h>
17     #include <stdlib.h>
18    
19 amb 26 #include "nodes.h"
20     #include "ways.h"
21     #include "segments.h"
22 amb 16 #include "functions.h"
23    
24    
25     /*++++++++++++++++++++++++++++++++++++++
26     Select the super-segments from the list of segments.
27    
28 amb 31 NodesMem *ChooseJunctions Returns the list of junctions.
29 amb 16
30 amb 26 Nodes *nodes The nodes.
31 amb 16
32 amb 26 Segments *segments The existing segments.
33 amb 16
34 amb 26 Ways *ways The ways.
35 amb 16 ++++++++++++++++++++++++++++++++++++++*/
36    
37 amb 31 NodesMem *ChooseJunctions(Nodes *nodes,Segments *segments,Ways *ways)
38 amb 16 {
39 amb 31 int i;
40     int count_oneway=0,count_twoway=0;
41     node_t node=0;
42     NodesMem *junctions;
43 amb 16
44 amb 31 /* Find junctions */
45    
46     junctions=NewNodeList();
47    
48     for(i=0;i<segments->number;i++)
49     {
50     Way *way;
51    
52     if(i>0 && segments->segments[i].node1!=node)
53     {
54     if((count_oneway*2+count_twoway)>2)
55     {
56     Node *oldnode=FindNode(nodes,node);
57    
58     AppendNode(junctions,node,oldnode->latitude,oldnode->longitude);
59     }
60    
61     count_oneway=0;
62     count_twoway=0;
63     }
64    
65     way=FindWay(ways,segments->segments[i].way);
66    
67     if(way->type&Way_ONEWAY)
68     count_oneway++;
69     else
70     count_twoway++;
71    
72     node=segments->segments[i].node1;
73    
74     if(!(i%10000))
75     {
76     printf("\rFinding Junctions: Segments=%d Junctions=%d",i,junctions->number);
77     fflush(stdout);
78     }
79     }
80    
81     printf("\rFound Junctions: Segments=%d Junctions=%d \n",segments->number,junctions->number);
82     fflush(stdout);
83    
84     return(junctions);
85 amb 16 }
86 amb 31
87    
88     /*++++++++++++++++++++++++++++++++++++++
89     Create the super-segments.
90    
91     SegmentsMem *CreateSuperSegments Returns the set of super-segments.
92    
93     Nodes *nodes The list of nodes.
94    
95     Segments *segments The list of segments.
96    
97     Ways *ways The list of ways.
98    
99     Nodes *junctions The list of junctions.
100     ++++++++++++++++++++++++++++++++++++++*/
101    
102     SegmentsMem *CreateSuperSegments(Nodes *nodes,Segments *segments,Ways *ways,Nodes *junctions)
103     {
104     SegmentsMem *supersegments;
105     int i,j,k;
106    
107     /* Create super-segments */
108    
109     supersegments=NewSegmentList();
110    
111     for(i=0;i<junctions->number;i++)
112     {
113     Results *results;
114    
115     results=FindRoutes(nodes,segments,junctions->nodes[i].id,junctions);
116    
117     for(j=0;j<NBINS_RESULTS;j++)
118     for(k=0;k<results->number[j];k++)
119     if(FindNode(junctions,results->results[j][k]->node))
120     {
121     distance_t distance;
122     duration_t duration;
123     Segment *segment=AppendSegment(supersegments,junctions->nodes[i].id,results->results[j][k]->node,0);
124    
125     distance=results->results[j][k]->shortest.distance;
126     duration=results->results[j][k]->quickest.duration;
127    
128     if(distance>(distance_short_t)~0)
129     {
130     fprintf(stderr,"\nSuper-Segment too long (%d->%d) = %.1f km\n",segment->node1,segment->node2,distance_to_km(distance));
131     distance=(distance_short_t)~0;
132     }
133    
134     if(duration>(duration_short_t)~0)
135     {
136     fprintf(stderr,"\nSuper-Segment too long (%d->%d) = %.1f mins\n",segment->node1,segment->node2,duration_to_minutes(duration));
137     duration=(duration_short_t)~0;
138     }
139    
140     segment->distance=distance;
141     segment->duration=duration;
142     }
143    
144     FreeResultsList(results);
145    
146     if(!(i%1000))
147     {
148     printf("\rFinding Super-Segments: Junctions=%d Super-Segments=%d",i,supersegments->number);
149     fflush(stdout);
150     }
151     }
152    
153     printf("\rFound Super-Segments: Junctions=%d Super-Segments=%d \n",junctions->number,supersegments->number);
154     fflush(stdout);
155    
156     return(supersegments);
157     }

Properties

Name Value
cvs:description SuperSegments data type.