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