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 90 -
(show annotations)
(download)
(as text)
Thu Jan 29 19:31:52 2009 UTC (16 years, 2 months ago) by amb
File MIME type: text/x-csrc
File size: 6609 byte(s)
Thu Jan 29 19:31:52 2009 UTC (16 years, 2 months ago) by amb
File MIME type: text/x-csrc
File size: 6609 byte(s)
Intermediate version while transitioning data format for nodes and segments.
1 | /*************************************** |
2 | $Header: /home/amb/CVS/routino/src/router.c,v 1.21 2009-01-29 19:31:52 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 "nodes.h" |
20 | #include "segments.h" |
21 | #include "ways.h" |
22 | #include "functions.h" |
23 | #include "profiles.h" |
24 | |
25 | |
26 | int main(int argc,char** argv) |
27 | { |
28 | Nodes *OSMNodes,*SuperNodes; |
29 | Segments *OSMSegments,*SuperSegments; |
30 | Ways *OSMWays,*SuperWays; |
31 | node_t start,finish; |
32 | int help_profile=0,all=0,only_super=0,no_print=0; |
33 | Transport transport=Transport_None; |
34 | Profile profile; |
35 | int i; |
36 | |
37 | /* Parse the command line arguments */ |
38 | |
39 | if(argc<3) |
40 | { |
41 | usage: |
42 | |
43 | fprintf(stderr,"Usage: router <start-node> <finish-node>\n" |
44 | " [-help] [-help-profile]\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 start and finish */ |
65 | |
66 | start=atoll(argv[1]); |
67 | finish=atoll(argv[2]); |
68 | |
69 | /* Get the transport type if specified and fill in the profile */ |
70 | |
71 | for(i=3;i<argc;i++) |
72 | if(!strncmp(argv[i],"-transport=",11)) |
73 | { |
74 | transport=TransportType(&argv[i][11]); |
75 | |
76 | 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 | while(--argc>=3) |
88 | { |
89 | if(!strcmp(argv[argc],"-help")) |
90 | goto usage; |
91 | else if(!strcmp(argv[argc],"-help-profile")) |
92 | help_profile=1; |
93 | else if(!strcmp(argv[argc],"-all")) |
94 | all=1; |
95 | else if(!strcmp(argv[argc],"-only-super")) |
96 | only_super=1; |
97 | else if(!strcmp(argv[argc],"-no-print")) |
98 | no_print=1; |
99 | else if(!strncmp(argv[argc],"-transport=",11)) |
100 | ; /* Done this already*/ |
101 | else if(!strncmp(argv[argc],"-not-highway=",13)) |
102 | { |
103 | Highway highway=HighwayType(&argv[argc][13]); |
104 | |
105 | if(highway==Way_Unknown) |
106 | goto usage; |
107 | |
108 | profile.highways[highway]=0; |
109 | } |
110 | else if(!strncmp(argv[argc],"-speed-",7)) |
111 | { |
112 | Highway highway; |
113 | char *equal=strchr(argv[argc],'='); |
114 | char *string; |
115 | |
116 | if(!equal) |
117 | goto usage; |
118 | |
119 | string=strcpy((char*)malloc(strlen(argv[argc])),argv[argc]+7); |
120 | string[equal-argv[argc]]=0; |
121 | |
122 | highway=HighwayType(string); |
123 | |
124 | free(string); |
125 | |
126 | if(highway==Way_Unknown) |
127 | goto usage; |
128 | |
129 | profile.speed[highway]=atoi(equal+1); |
130 | } |
131 | else if(!strcmp(argv[argc],"-ignore-oneway")) |
132 | profile.oneway=0; |
133 | else |
134 | goto usage; |
135 | } |
136 | |
137 | if(help_profile) |
138 | { |
139 | PrintProfile(&profile); |
140 | |
141 | return(0); |
142 | } |
143 | |
144 | /* Load in the data */ |
145 | |
146 | OSMNodes=LoadNodeList("data/nodes.mem"); |
147 | SuperNodes=LoadNodeList("data/super-nodes.mem"); |
148 | |
149 | OSMSegments=LoadSegmentList("data/segments.mem"); |
150 | SuperSegments=LoadSegmentList("data/super-segments.mem"); |
151 | |
152 | OSMWays=LoadWayList("data/ways.mem"); |
153 | SuperWays=LoadWayList("data/super-ways.mem"); |
154 | |
155 | if(all) |
156 | { |
157 | Results *results; |
158 | |
159 | /* Calculate the route */ |
160 | |
161 | results=FindRoute(OSMNodes,OSMSegments,OSMWays,start,finish,&profile,all); |
162 | |
163 | /* Print the route */ |
164 | |
165 | if(!results) |
166 | { |
167 | fprintf(stderr,"No route found.\n"); |
168 | return(1); |
169 | } |
170 | else if(!no_print) |
171 | PrintRoute(results,OSMNodes,OSMSegments,OSMWays,start,finish,&profile); |
172 | } |
173 | else |
174 | { |
175 | Results *begin,*end; |
176 | |
177 | #if 0 |
178 | |
179 | /* Calculate the beginning of the route */ |
180 | |
181 | if(FindNode(SuperNodes,start)) |
182 | { |
183 | Result *result; |
184 | |
185 | begin=NewResultsList(1); |
186 | |
187 | result=InsertResult(begin,start); |
188 | |
189 | result->node=start; |
190 | result->shortest.prev=0; |
191 | result->shortest.next=0; |
192 | result->shortest.distance=0; |
193 | result->shortest.duration=0; |
194 | result->quickest.prev=0; |
195 | result->quickest.next=0; |
196 | result->quickest.distance=0; |
197 | result->quickest.duration=0; |
198 | } |
199 | else |
200 | begin=FindRoutes(OSMNodes,OSMSegments,OSMWays,start,SuperNodes,&profile); |
201 | |
202 | if(FindResult(begin,finish)) |
203 | { |
204 | /* Print the route */ |
205 | |
206 | if(!no_print) |
207 | PrintRoute(begin,OSMNodes,OSMSegments,OSMWays,NULL,start,finish,&profile); |
208 | } |
209 | else |
210 | { |
211 | Results *superresults; |
212 | |
213 | /* Calculate the end of the route */ |
214 | |
215 | if(FindNode(SuperNodes,finish)) |
216 | { |
217 | Result *result; |
218 | |
219 | end=NewResultsList(1); |
220 | |
221 | result=InsertResult(end,finish); |
222 | |
223 | result->node=finish; |
224 | result->shortest.prev=0; |
225 | result->shortest.next=0; |
226 | result->shortest.distance=0; |
227 | result->shortest.duration=0; |
228 | result->quickest.prev=0; |
229 | result->quickest.next=0; |
230 | result->quickest.distance=0; |
231 | result->quickest.duration=0; |
232 | } |
233 | else |
234 | end=FindReverseRoutes(OSMNodes,OSMSegments,OSMWays,SuperNodes,finish,&profile); |
235 | |
236 | /* Calculate the middle of the route */ |
237 | |
238 | superresults=FindRoute3(SuperNodes,SuperSegments,SuperWays,start,finish,begin,end,&profile); |
239 | |
240 | /* Print the route */ |
241 | |
242 | if(!superresults) |
243 | { |
244 | fprintf(stderr,"No route found.\n"); |
245 | return(1); |
246 | } |
247 | else if(!no_print) |
248 | { |
249 | if(only_super) |
250 | { |
251 | PrintRoute(superresults,SuperNodes,SuperSegments,SuperWays,NULL,start,finish,&profile); |
252 | } |
253 | else |
254 | { |
255 | Results *results=CombineRoutes(superresults,OSMNodes,OSMSegments,OSMWays,start,finish,&profile); |
256 | |
257 | PrintRoute(results,OSMNodes,OSMSegments,OSMWays,SuperNodes,start,finish,&profile); |
258 | } |
259 | } |
260 | } |
261 | |
262 | #endif |
263 | } |
264 | |
265 | return(0); |
266 | } |
Properties
Name | Value |
---|---|
cvs:description | Router. |