Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Annotation of /trunk/src/segments.c
Parent Directory
|
Revision Log
Revision 459 -
(hide annotations)
(download)
(as text)
Fri Jul 23 14:35:27 2010 UTC (14 years, 7 months ago) by amb
File MIME type: text/x-csrc
File size: 4940 byte(s)
Fri Jul 23 14:35:27 2010 UTC (14 years, 7 months ago) by amb
File MIME type: text/x-csrc
File size: 4940 byte(s)
Added slim mode to the router for segments.
1 | amb | 2 | /*************************************** |
2 | amb | 459 | $Header: /home/amb/CVS/routino/src/segments.c,v 1.47 2010-07-23 14:35:27 amb Exp $ |
3 | amb | 2 | |
4 | Segment data type functions. | ||
5 | amb | 151 | |
6 | Part of the Routino routing software. | ||
7 | amb | 2 | ******************/ /****************** |
8 | amb | 328 | This file Copyright 2008-2010 Andrew M. Bishop |
9 | amb | 2 | |
10 | amb | 151 | 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. | ||
14 | |||
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. | ||
19 | |||
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 | amb | 2 | ***************************************/ |
23 | |||
24 | |||
25 | amb | 214 | #include <sys/types.h> |
26 | amb | 2 | #include <stdlib.h> |
27 | |||
28 | amb | 109 | #include "types.h" |
29 | amb | 39 | #include "nodes.h" |
30 | amb | 26 | #include "segments.h" |
31 | amb | 109 | #include "ways.h" |
32 | amb | 449 | |
33 | #include "files.h" | ||
34 | amb | 109 | #include "profiles.h" |
35 | amb | 2 | |
36 | |||
37 | amb | 23 | /*++++++++++++++++++++++++++++++++++++++ |
38 | amb | 2 | Load in a segment list from a file. |
39 | |||
40 | amb | 228 | Segments* LoadSegmentList Returns the segment list that has just been loaded. |
41 | amb | 23 | |
42 | amb | 2 | const char *filename The name of the file to load. |
43 | ++++++++++++++++++++++++++++++++++++++*/ | ||
44 | |||
45 | amb | 23 | Segments *LoadSegmentList(const char *filename) |
46 | amb | 2 | { |
47 | amb | 88 | Segments *segments; |
48 | |||
49 | segments=(Segments*)malloc(sizeof(Segments)); | ||
50 | |||
51 | amb | 459 | #if !SLIM |
52 | amb | 88 | |
53 | amb | 459 | segments->data=MapFile(filename); |
54 | amb | 88 | |
55 | amb | 459 | /* Copy the SegmentsFile structure from the loaded data */ |
56 | amb | 88 | |
57 | amb | 459 | segments->file=*((SegmentsFile*)segments->data); |
58 | amb | 88 | |
59 | amb | 459 | /* Set the pointers in the Segments structure. */ |
60 | amb | 88 | |
61 | amb | 459 | segments->segments=(Segment*)(segments->data+sizeof(SegmentsFile)); |
62 | |||
63 | #else | ||
64 | |||
65 | segments->fd=ReOpenFile(filename); | ||
66 | |||
67 | /* Copy the SegmentsFile header structure from the loaded data */ | ||
68 | |||
69 | ReadFile(segments->fd,&segments->file,sizeof(SegmentsFile)); | ||
70 | |||
71 | segments->incache[0]=NO_SEGMENT; | ||
72 | segments->incache[1]=NO_SEGMENT; | ||
73 | segments->incache[2]=NO_SEGMENT; | ||
74 | |||
75 | #endif | ||
76 | |||
77 | amb | 88 | return(segments); |
78 | amb | 2 | } |
79 | |||
80 | |||
81 | /*++++++++++++++++++++++++++++++++++++++ | ||
82 | Find the next segment with a particular starting node. | ||
83 | |||
84 | amb | 88 | Segment *NextSegment Returns a pointer to the next segment with the same id. |
85 | amb | 2 | |
86 | amb | 23 | Segments* segments The set of segments to process. |
87 | |||
88 | amb | 2 | Segment *segment The current segment. |
89 | amb | 228 | |
90 | index_t node The current node. | ||
91 | amb | 2 | ++++++++++++++++++++++++++++++++++++++*/ |
92 | |||
93 | amb | 104 | Segment *NextSegment(Segments* segments,Segment *segment,index_t node) |
94 | amb | 2 | { |
95 | amb | 208 | if(segment->node1==node) |
96 | amb | 128 | { |
97 | amb | 459 | #if SLIM |
98 | index_t index=IndexSegment(segments,segment); | ||
99 | index++; | ||
100 | |||
101 | if(index>=segments->file.number) | ||
102 | return(NULL); | ||
103 | segment=LookupSegment(segments,index,1); | ||
104 | if(segment->node1!=node) | ||
105 | return(NULL); | ||
106 | else | ||
107 | return(segment); | ||
108 | #else | ||
109 | amb | 128 | segment++; |
110 | amb | 459 | if(IndexSegment(segments,segment)>=segments->file.number || segment->node1!=node) |
111 | amb | 128 | return(NULL); |
112 | else | ||
113 | return(segment); | ||
114 | amb | 459 | #endif |
115 | amb | 128 | } |
116 | amb | 104 | else |
117 | amb | 128 | { |
118 | amb | 176 | if(segment->next2==NO_NODE) |
119 | amb | 128 | return(NULL); |
120 | else | ||
121 | amb | 459 | return(LookupSegment(segments,segment->next2,1)); |
122 | amb | 128 | } |
123 | amb | 89 | } |
124 | amb | 88 | |
125 | |||
126 | amb | 2 | /*++++++++++++++++++++++++++++++++++++++ |
127 | amb | 99 | Calculate the distance between two locations. |
128 | |||
129 | amb | 114 | distance_t Distance Returns the distance between the locations. |
130 | amb | 99 | |
131 | amb | 219 | double lat1 The latitude of the first location. |
132 | amb | 99 | |
133 | amb | 219 | double lon1 The longitude of the first location. |
134 | amb | 99 | |
135 | amb | 219 | double lat2 The latitude of the second location. |
136 | amb | 99 | |
137 | amb | 219 | double lon2 The longitude of the second location. |
138 | amb | 99 | ++++++++++++++++++++++++++++++++++++++*/ |
139 | |||
140 | amb | 219 | distance_t Distance(double lat1,double lon1,double lat2,double lon2) |
141 | amb | 99 | { |
142 | amb | 219 | double dlon = lon1 - lon2; |
143 | double dlat = lat1 - lat2; | ||
144 | amb | 99 | |
145 | amb | 219 | double a1,a2,a,sa,c,d; |
146 | amb | 99 | |
147 | if(dlon==0 && dlat==0) | ||
148 | return 0; | ||
149 | |||
150 | amb | 219 | a1 = sin (dlat / 2); |
151 | a2 = sin (dlon / 2); | ||
152 | a = (a1 * a1) + cos (lat1) * cos (lat2) * a2 * a2; | ||
153 | sa = sqrt (a); | ||
154 | amb | 99 | if (sa <= 1.0) |
155 | amb | 219 | {c = 2 * asin (sa);} |
156 | amb | 99 | else |
157 | amb | 219 | {c = 2 * asin (1.0);} |
158 | amb | 99 | d = 6378.137 * c; |
159 | |||
160 | amb | 114 | return km_to_distance(d); |
161 | amb | 99 | } |
162 | |||
163 | |||
164 | /*++++++++++++++++++++++++++++++++++++++ | ||
165 | amb | 63 | Calculate the duration of segment. |
166 | |||
167 | duration_t Duration Returns the duration of travel between the nodes. | ||
168 | |||
169 | Segment *segment The segment to traverse. | ||
170 | |||
171 | Way *way The way that the segment belongs to. | ||
172 | |||
173 | amb | 82 | Profile *profile The profile of the transport being used. |
174 | amb | 63 | ++++++++++++++++++++++++++++++++++++++*/ |
175 | |||
176 | amb | 82 | duration_t Duration(Segment *segment,Way *way,Profile *profile) |
177 | amb | 63 | { |
178 | amb | 137 | speed_t speed1=way->speed; |
179 | speed_t speed2=profile->speed[HIGHWAY(way->type)]; | ||
180 | amb | 90 | distance_t distance=DISTANCE(segment->distance); |
181 | amb | 63 | |
182 | amb | 137 | if(speed1==0) |
183 | { | ||
184 | if(speed2==0) | ||
185 | return(hours_to_duration(10)); | ||
186 | else | ||
187 | return distance_speed_to_duration(distance,speed2); | ||
188 | } | ||
189 | else /* if(speed1!=0) */ | ||
190 | { | ||
191 | if(speed2==0) | ||
192 | return distance_speed_to_duration(distance,speed1); | ||
193 | else if(speed1<=speed2) | ||
194 | return distance_speed_to_duration(distance,speed1); | ||
195 | else | ||
196 | return distance_speed_to_duration(distance,speed2); | ||
197 | } | ||
198 | amb | 63 | } |
Properties
Name | Value |
---|---|
cvs:description | Segment data type. |