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/router.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 97 - (hide annotations) (download) (as text)
Sun Feb 1 17:11:08 2009 UTC (16 years, 1 month ago) by amb
File MIME type: text/x-csrc
File size: 7003 byte(s)
Rename some variable types.

1 amb 2 /***************************************
2 amb 97 $Header: /home/amb/CVS/routino/src/router.c,v 1.25 2009-02-01 17:11:08 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 97 /* Calculate the route. */
162    
163 amb 54 if(all)
164 amb 31 {
165 amb 34 Results *results;
166    
167 amb 31 /* Calculate the route */
168 amb 2
169 amb 82 results=FindRoute(OSMNodes,OSMSegments,OSMWays,start,finish,&profile,all);
170 amb 2
171 amb 31 /* Print the route */
172 amb 2
173 amb 77 if(!results)
174     {
175 amb 48 fprintf(stderr,"No route found.\n");
176 amb 77 return(1);
177     }
178 amb 82 else if(!no_print)
179 amb 90 PrintRoute(results,OSMNodes,OSMSegments,OSMWays,start,finish,&profile);
180 amb 31 }
181     else
182     {
183 amb 48 Results *begin,*end;
184 amb 2
185 amb 34 /* Calculate the beginning of the route */
186 amb 31
187 amb 95 if(IsSuperNode(LookupNode(OSMNodes,start)))
188 amb 34 {
189     Result *result;
190 amb 31
191 amb 71 begin=NewResultsList(1);
192 amb 34
193     result=InsertResult(begin,start);
194    
195     result->node=start;
196 amb 43 result->shortest.prev=0;
197     result->shortest.next=0;
198 amb 34 result->shortest.distance=0;
199     result->shortest.duration=0;
200 amb 43 result->quickest.prev=0;
201     result->quickest.next=0;
202 amb 34 result->quickest.distance=0;
203     result->quickest.duration=0;
204     }
205     else
206 amb 95 begin=FindRoutes(OSMNodes,OSMSegments,OSMWays,start,&profile);
207 amb 34
208     if(FindResult(begin,finish))
209     {
210     /* Print the route */
211    
212 amb 82 if(!no_print)
213 amb 95 PrintRoute(begin,OSMNodes,OSMSegments,OSMWays,start,finish,&profile);
214 amb 34 }
215     else
216     {
217 amb 55 Results *superresults;
218 amb 48
219 amb 34 /* Calculate the end of the route */
220    
221 amb 95 if(IsSuperNode(LookupNode(OSMNodes,finish)))
222 amb 34 {
223     Result *result;
224    
225 amb 71 end=NewResultsList(1);
226 amb 34
227     result=InsertResult(end,finish);
228    
229     result->node=finish;
230 amb 43 result->shortest.prev=0;
231     result->shortest.next=0;
232 amb 34 result->shortest.distance=0;
233     result->shortest.duration=0;
234 amb 43 result->quickest.prev=0;
235     result->quickest.next=0;
236 amb 34 result->quickest.distance=0;
237     result->quickest.duration=0;
238     }
239     else
240 amb 95 end=FindReverseRoutes(OSMNodes,OSMSegments,OSMWays,finish,&profile);
241 amb 34
242     /* Calculate the middle of the route */
243    
244 amb 95 superresults=FindRoute3(OSMNodes,OSMSegments,OSMWays,start,finish,begin,end,&profile);
245 amb 34
246     /* Print the route */
247    
248 amb 77 if(!superresults)
249     {
250 amb 48 fprintf(stderr,"No route found.\n");
251 amb 77 return(1);
252     }
253 amb 82 else if(!no_print)
254 amb 55 {
255 amb 82 if(only_super)
256     {
257 amb 95 PrintRoute(superresults,OSMNodes,OSMSegments,OSMWays,start,finish,&profile);
258 amb 82 }
259     else
260     {
261     Results *results=CombineRoutes(superresults,OSMNodes,OSMSegments,OSMWays,start,finish,&profile);
262 amb 55
263 amb 95 PrintRoute(results,OSMNodes,OSMSegments,OSMWays,start,finish,&profile);
264 amb 82 }
265 amb 55 }
266 amb 34 }
267 amb 31 }
268    
269 amb 2 return(0);
270     }

Properties

Name Value
cvs:description Router.