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 75 - (hide annotations) (download) (as text)
Fri Jan 23 17:09:41 2009 UTC (16 years, 2 months ago) by amb
File MIME type: text/x-csrc
File size: 4948 byte(s)
Add command line options to planetsplitter and router.
Select transport type (must be allowed on way for parsing).
Select highway types (ignore when parsing or routing).

1 amb 2 /***************************************
2 amb 75 $Header: /home/amb/CVS/routino/src/router.c,v 1.17 2009-01-23 17:09: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 26 #include "nodes.h"
20     #include "ways.h"
21     #include "segments.h"
22 amb 2 #include "functions.h"
23    
24    
25     int main(int argc,char** argv)
26     {
27 amb 33 Nodes *OSMNodes,*SuperNodes;
28 amb 66 Segments *OSMSegments,*SuperSegments;
29 amb 54 Ways *OSMWays,*SuperWays;
30     node_t start,finish;
31     int all=0,noprint=0;
32 amb 74 Transport transport=Transport_Motorcar;
33 amb 75 int highways[Way_Unknown+1];
34     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 75 " [-help]\n"
44     " [-all]\n"
45     " [-no-print]\n"
46     " [-transport=<transport>]\n"
47     " [-not-highway=<highway> ...]\n"
48     "\n"
49     "<transport> can be:\n"
50     "%s"
51     "\n"
52     "<highway> can be:\n"
53     "%s",
54     TransportList(),HighwayList());
55    
56 amb 2 return(1);
57     }
58    
59     start=atoll(argv[1]);
60     finish=atoll(argv[2]);
61    
62 amb 75 for(i=0;i<Way_Unknown;i++)
63     highways[i]=1;
64    
65     highways[Way_Unknown]=0;
66    
67 amb 44 while(--argc>=3)
68     {
69 amb 75 if(!strcmp(argv[argc],"-help"))
70     goto usage;
71     else if(!strcmp(argv[argc],"-all"))
72 amb 44 all=1;
73     else if(!strcmp(argv[argc],"-no-print"))
74     noprint=1;
75 amb 54 else if(!strncmp(argv[argc],"-transport=",11))
76 amb 74 transport=TransportType(&argv[argc][11]);
77 amb 75 else if(!strncmp(argv[argc],"-not-highway=",13))
78     {
79     Highway highway=HighwayType(&argv[argc][13]);
80     highways[highway]=0;
81     }
82 amb 44 else
83     goto usage;
84     }
85    
86 amb 2 /* Load in the data */
87    
88 amb 26 OSMNodes=LoadNodeList("data/nodes.mem");
89 amb 33 SuperNodes=LoadNodeList("data/super-nodes.mem");
90 amb 31
91 amb 66 OSMSegments=LoadSegmentList("data/segments.mem");
92     SuperSegments=LoadSegmentList("data/super-segments.mem");
93    
94 amb 26 OSMWays=LoadWayList("data/ways.mem");
95 amb 54 SuperWays=LoadWayList("data/super-ways.mem");
96 amb 31
97 amb 54 if(all)
98 amb 31 {
99 amb 34 Results *results;
100    
101 amb 31 /* Calculate the route */
102 amb 2
103 amb 75 results=FindRoute(OSMNodes,OSMSegments,OSMWays,start,finish,transport,highways,all);
104 amb 2
105 amb 31 /* Print the route */
106 amb 2
107 amb 48 if(!FindResult(results,finish))
108     fprintf(stderr,"No route found.\n");
109     else if(!noprint)
110 amb 63 PrintRoute(results,OSMNodes,OSMSegments,OSMWays,NULL,start,finish,transport);
111 amb 31 }
112     else
113     {
114 amb 48 Results *begin,*end;
115 amb 2
116 amb 34 /* Calculate the beginning of the route */
117 amb 31
118 amb 34 if(FindNode(SuperNodes,start))
119     {
120     Result *result;
121 amb 31
122 amb 71 begin=NewResultsList(1);
123 amb 34
124     result=InsertResult(begin,start);
125    
126     result->node=start;
127 amb 43 result->shortest.prev=0;
128     result->shortest.next=0;
129 amb 34 result->shortest.distance=0;
130     result->shortest.duration=0;
131 amb 43 result->quickest.prev=0;
132     result->quickest.next=0;
133 amb 34 result->quickest.distance=0;
134     result->quickest.duration=0;
135     }
136     else
137 amb 75 begin=FindRoutes(OSMNodes,OSMSegments,OSMWays,start,SuperNodes,transport,highways);
138 amb 34
139     if(FindResult(begin,finish))
140     {
141     /* Print the route */
142    
143 amb 44 if(!noprint)
144 amb 63 PrintRoute(begin,OSMNodes,OSMSegments,OSMWays,NULL,start,finish,transport);
145 amb 34 }
146     else
147     {
148 amb 55 Results *superresults;
149 amb 48
150 amb 34 /* Calculate the end of the route */
151    
152     if(FindNode(SuperNodes,finish))
153     {
154     Result *result;
155    
156 amb 71 end=NewResultsList(1);
157 amb 34
158     result=InsertResult(end,finish);
159    
160     result->node=finish;
161 amb 43 result->shortest.prev=0;
162     result->shortest.next=0;
163 amb 34 result->shortest.distance=0;
164     result->shortest.duration=0;
165 amb 43 result->quickest.prev=0;
166     result->quickest.next=0;
167 amb 34 result->quickest.distance=0;
168     result->quickest.duration=0;
169     }
170     else
171 amb 75 end=FindReverseRoutes(OSMNodes,OSMSegments,OSMWays,SuperNodes,finish,transport,highways);
172 amb 34
173     /* Calculate the middle of the route */
174    
175 amb 75 superresults=FindRoute3(SuperNodes,SuperSegments,SuperWays,start,finish,begin,end,transport,highways);
176 amb 34
177     /* Print the route */
178    
179 amb 55 if(!FindResult(superresults,finish))
180 amb 48 fprintf(stderr,"No route found.\n");
181     else if(!noprint)
182 amb 55 {
183 amb 75 Results *results=CombineRoutes(superresults,OSMNodes,OSMSegments,OSMWays,start,finish,transport,highways);
184 amb 55
185 amb 63 PrintRoute(results,OSMNodes,OSMSegments,OSMWays,SuperNodes,start,finish,transport);
186 amb 55 }
187 amb 34 }
188 amb 31 }
189    
190 amb 2 return(0);
191     }

Properties

Name Value
cvs:description Router.