Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Contents of /trunk/src/router.c
Parent Directory
|
Revision Log
Revision 100 -
(show annotations)
(download)
(as text)
Wed Feb 4 18:26:29 2009 UTC (16 years, 2 months ago) by amb
File MIME type: text/x-csrc
File size: 7446 byte(s)
Wed Feb 4 18:26:29 2009 UTC (16 years, 2 months ago) by amb
File MIME type: text/x-csrc
File size: 7446 byte(s)
Make sure that nodes, segments and ways could be loaded.
1 | /*************************************** |
2 | $Header: /home/amb/CVS/routino/src/router.c,v 1.27 2009-02-04 18:26:29 amb Exp $ |
3 | |
4 | OSM router. |
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 <stdio.h> |
16 | #include <string.h> |
17 | #include <stdlib.h> |
18 | |
19 | #include "types.h" |
20 | #include "functions.h" |
21 | #include "profiles.h" |
22 | |
23 | |
24 | int main(int argc,char** argv) |
25 | { |
26 | Nodes *OSMNodes; |
27 | Segments *OSMSegments; |
28 | Ways *OSMWays; |
29 | node_t start,finish; |
30 | int help_profile=0,all=0,only_super=0,no_print=0; |
31 | char *dirname=NULL,*prefix=NULL,*filename; |
32 | Transport transport=Transport_None; |
33 | Profile profile; |
34 | int i; |
35 | |
36 | /* Parse the command line arguments */ |
37 | |
38 | if(argc<5) |
39 | { |
40 | usage: |
41 | |
42 | fprintf(stderr,"Usage: router <start-lat> <start-lon> <finish-lat> <finish-lon>\n" |
43 | " [-help] [-help-profile]\n" |
44 | " [-dir=<name>] [-prefix=<name>]\n" |
45 | " [-all] [-only-super]\n" |
46 | " [-no-print]\n" |
47 | " [-transport=<transport>]\n" |
48 | " [-not-highway=<highway> ...]\n" |
49 | " [-speed-<highway>=<speed> ...]\n" |
50 | " [-ignore-oneway]\n" |
51 | "\n" |
52 | "<transport> defaults to motorcar but can be set to:\n" |
53 | "%s" |
54 | "\n" |
55 | "<highway> can be selected from:\n" |
56 | "%s" |
57 | "<speed> is a speed in km/hour\n" |
58 | "\n", |
59 | TransportList(),HighwayList()); |
60 | |
61 | return(1); |
62 | } |
63 | |
64 | /* Get the transport type if specified and fill in the profile */ |
65 | |
66 | for(i=3;i<argc;i++) |
67 | if(!strncmp(argv[i],"-transport=",11)) |
68 | { |
69 | transport=TransportType(&argv[i][11]); |
70 | |
71 | if(transport==Transport_None) |
72 | goto usage; |
73 | } |
74 | |
75 | if(transport==Transport_None) |
76 | transport=Transport_Motorcar; |
77 | |
78 | profile=*GetProfile(transport); |
79 | |
80 | /* Parse the other command line arguments */ |
81 | |
82 | while(--argc>=5) |
83 | { |
84 | if(!strcmp(argv[argc],"-help")) |
85 | goto usage; |
86 | else if(!strcmp(argv[argc],"-help-profile")) |
87 | help_profile=1; |
88 | else if(!strncmp(argv[argc],"-dir=",5)) |
89 | dirname=&argv[argc][5]; |
90 | else if(!strncmp(argv[argc],"-prefix=",8)) |
91 | prefix=&argv[argc][8]; |
92 | else if(!strcmp(argv[argc],"-all")) |
93 | all=1; |
94 | else if(!strcmp(argv[argc],"-only-super")) |
95 | only_super=1; |
96 | else if(!strcmp(argv[argc],"-no-print")) |
97 | no_print=1; |
98 | else if(!strncmp(argv[argc],"-transport=",11)) |
99 | ; /* Done this already*/ |
100 | else if(!strncmp(argv[argc],"-not-highway=",13)) |
101 | { |
102 | Highway highway=HighwayType(&argv[argc][13]); |
103 | |
104 | if(highway==Way_Unknown) |
105 | goto usage; |
106 | |
107 | profile.highways[highway]=0; |
108 | } |
109 | else if(!strncmp(argv[argc],"-speed-",7)) |
110 | { |
111 | Highway highway; |
112 | char *equal=strchr(argv[argc],'='); |
113 | char *string; |
114 | |
115 | if(!equal) |
116 | goto usage; |
117 | |
118 | string=strcpy((char*)malloc(strlen(argv[argc])),argv[argc]+7); |
119 | string[equal-argv[argc]]=0; |
120 | |
121 | highway=HighwayType(string); |
122 | |
123 | free(string); |
124 | |
125 | if(highway==Way_Unknown) |
126 | goto usage; |
127 | |
128 | profile.speed[highway]=atoi(equal+1); |
129 | } |
130 | else if(!strcmp(argv[argc],"-ignore-oneway")) |
131 | profile.oneway=0; |
132 | else |
133 | goto usage; |
134 | } |
135 | |
136 | if(help_profile) |
137 | { |
138 | PrintProfile(&profile); |
139 | |
140 | return(0); |
141 | } |
142 | |
143 | /* Load in the data */ |
144 | |
145 | filename=(char*)malloc((dirname?strlen(dirname):0)+(prefix?strlen(prefix):0)+16); |
146 | |
147 | sprintf(filename,"%s%s%s%snodes.mem",dirname?dirname:"",dirname?"/":"",prefix?prefix:"",prefix?"-":""); |
148 | OSMNodes=LoadNodeList(filename); |
149 | |
150 | if(!OSMNodes) |
151 | { |
152 | fprintf(stderr,"Cannot open nodes file '%s'.\n",filename); |
153 | return(1); |
154 | } |
155 | |
156 | sprintf(filename,"%s%s%s%ssegments.mem",dirname?dirname:"",dirname?"/":"",prefix?prefix:"",prefix?"-":""); |
157 | OSMSegments=LoadSegmentList(filename); |
158 | |
159 | if(!OSMSegments) |
160 | { |
161 | fprintf(stderr,"Cannot open segments file '%s'.\n",filename); |
162 | return(1); |
163 | } |
164 | |
165 | sprintf(filename,"%s%s%s%sways.mem",dirname?dirname:"",dirname?"/":"",prefix?prefix:"",prefix?"-":""); |
166 | OSMWays=LoadWayList(filename); |
167 | |
168 | if(!OSMWays) |
169 | { |
170 | fprintf(stderr,"Cannot open ways file '%s'.\n",filename); |
171 | return(1); |
172 | } |
173 | |
174 | /* Get the start and finish */ |
175 | |
176 | start=IndexNode(OSMNodes,FindNode(OSMNodes,atof(argv[1]),atof(argv[2]))); |
177 | finish=IndexNode(OSMNodes,FindNode(OSMNodes,atof(argv[3]),atof(argv[4]))); |
178 | |
179 | /* Calculate the route. */ |
180 | |
181 | if(all) |
182 | { |
183 | Results *results; |
184 | |
185 | /* Calculate the route */ |
186 | |
187 | results=FindRoute(OSMNodes,OSMSegments,OSMWays,start,finish,&profile,all); |
188 | |
189 | /* Print the route */ |
190 | |
191 | if(!results) |
192 | { |
193 | fprintf(stderr,"No route found.\n"); |
194 | return(1); |
195 | } |
196 | else if(!no_print) |
197 | PrintRoute(results,OSMNodes,OSMSegments,OSMWays,start,finish,&profile); |
198 | } |
199 | else |
200 | { |
201 | Results *begin,*end; |
202 | |
203 | /* Calculate the beginning of the route */ |
204 | |
205 | if(IsSuperNode(LookupNode(OSMNodes,start))) |
206 | { |
207 | Result *result; |
208 | |
209 | begin=NewResultsList(1); |
210 | |
211 | result=InsertResult(begin,start); |
212 | |
213 | result->node=start; |
214 | result->shortest.prev=0; |
215 | result->shortest.next=0; |
216 | result->shortest.distance=0; |
217 | result->shortest.duration=0; |
218 | result->quickest.prev=0; |
219 | result->quickest.next=0; |
220 | result->quickest.distance=0; |
221 | result->quickest.duration=0; |
222 | } |
223 | else |
224 | begin=FindRoutes(OSMNodes,OSMSegments,OSMWays,start,&profile); |
225 | |
226 | if(FindResult(begin,finish)) |
227 | { |
228 | /* Print the route */ |
229 | |
230 | if(!no_print) |
231 | PrintRoute(begin,OSMNodes,OSMSegments,OSMWays,start,finish,&profile); |
232 | } |
233 | else |
234 | { |
235 | Results *superresults; |
236 | |
237 | /* Calculate the end of the route */ |
238 | |
239 | if(IsSuperNode(LookupNode(OSMNodes,finish))) |
240 | { |
241 | Result *result; |
242 | |
243 | end=NewResultsList(1); |
244 | |
245 | result=InsertResult(end,finish); |
246 | |
247 | result->node=finish; |
248 | result->shortest.prev=0; |
249 | result->shortest.next=0; |
250 | result->shortest.distance=0; |
251 | result->shortest.duration=0; |
252 | result->quickest.prev=0; |
253 | result->quickest.next=0; |
254 | result->quickest.distance=0; |
255 | result->quickest.duration=0; |
256 | } |
257 | else |
258 | end=FindReverseRoutes(OSMNodes,OSMSegments,OSMWays,finish,&profile); |
259 | |
260 | /* Calculate the middle of the route */ |
261 | |
262 | superresults=FindRoute3(OSMNodes,OSMSegments,OSMWays,start,finish,begin,end,&profile); |
263 | |
264 | /* Print the route */ |
265 | |
266 | if(!superresults) |
267 | { |
268 | fprintf(stderr,"No route found.\n"); |
269 | return(1); |
270 | } |
271 | else if(!no_print) |
272 | { |
273 | if(only_super) |
274 | { |
275 | PrintRoute(superresults,OSMNodes,OSMSegments,OSMWays,start,finish,&profile); |
276 | } |
277 | else |
278 | { |
279 | Results *results=CombineRoutes(superresults,OSMNodes,OSMSegments,OSMWays,start,finish,&profile); |
280 | |
281 | PrintRoute(results,OSMNodes,OSMSegments,OSMWays,start,finish,&profile); |
282 | } |
283 | } |
284 | } |
285 | } |
286 | |
287 | return(0); |
288 | } |
Properties
Name | Value |
---|---|
cvs:description | Router. |