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