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 77 -
(hide annotations)
(download)
(as text)
Fri Jan 23 17:21:05 2009 UTC (16 years, 2 months ago) by amb
File MIME type: text/x-csrc
File size: 4987 byte(s)
Fri Jan 23 17:21:05 2009 UTC (16 years, 2 months ago) by amb
File MIME type: text/x-csrc
File size: 4987 byte(s)
Proper check that it was unroutable.
1 | amb | 2 | /*************************************** |
2 | amb | 77 | $Header: /home/amb/CVS/routino/src/router.c,v 1.18 2009-01-23 17:21:05 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 | 77 | if(!results) |
108 | { | ||
109 | amb | 48 | fprintf(stderr,"No route found.\n"); |
110 | amb | 77 | return(1); |
111 | } | ||
112 | amb | 48 | else if(!noprint) |
113 | amb | 63 | PrintRoute(results,OSMNodes,OSMSegments,OSMWays,NULL,start,finish,transport); |
114 | amb | 31 | } |
115 | else | ||
116 | { | ||
117 | amb | 48 | Results *begin,*end; |
118 | amb | 2 | |
119 | amb | 34 | /* Calculate the beginning of the route */ |
120 | amb | 31 | |
121 | amb | 34 | if(FindNode(SuperNodes,start)) |
122 | { | ||
123 | Result *result; | ||
124 | amb | 31 | |
125 | amb | 71 | begin=NewResultsList(1); |
126 | amb | 34 | |
127 | result=InsertResult(begin,start); | ||
128 | |||
129 | result->node=start; | ||
130 | amb | 43 | result->shortest.prev=0; |
131 | result->shortest.next=0; | ||
132 | amb | 34 | result->shortest.distance=0; |
133 | result->shortest.duration=0; | ||
134 | amb | 43 | result->quickest.prev=0; |
135 | result->quickest.next=0; | ||
136 | amb | 34 | result->quickest.distance=0; |
137 | result->quickest.duration=0; | ||
138 | } | ||
139 | else | ||
140 | amb | 75 | begin=FindRoutes(OSMNodes,OSMSegments,OSMWays,start,SuperNodes,transport,highways); |
141 | amb | 34 | |
142 | if(FindResult(begin,finish)) | ||
143 | { | ||
144 | /* Print the route */ | ||
145 | |||
146 | amb | 44 | if(!noprint) |
147 | amb | 63 | PrintRoute(begin,OSMNodes,OSMSegments,OSMWays,NULL,start,finish,transport); |
148 | amb | 34 | } |
149 | else | ||
150 | { | ||
151 | amb | 55 | Results *superresults; |
152 | amb | 48 | |
153 | amb | 34 | /* Calculate the end of the route */ |
154 | |||
155 | if(FindNode(SuperNodes,finish)) | ||
156 | { | ||
157 | Result *result; | ||
158 | |||
159 | amb | 71 | end=NewResultsList(1); |
160 | amb | 34 | |
161 | result=InsertResult(end,finish); | ||
162 | |||
163 | result->node=finish; | ||
164 | amb | 43 | result->shortest.prev=0; |
165 | result->shortest.next=0; | ||
166 | amb | 34 | result->shortest.distance=0; |
167 | result->shortest.duration=0; | ||
168 | amb | 43 | result->quickest.prev=0; |
169 | result->quickest.next=0; | ||
170 | amb | 34 | result->quickest.distance=0; |
171 | result->quickest.duration=0; | ||
172 | } | ||
173 | else | ||
174 | amb | 75 | end=FindReverseRoutes(OSMNodes,OSMSegments,OSMWays,SuperNodes,finish,transport,highways); |
175 | amb | 34 | |
176 | /* Calculate the middle of the route */ | ||
177 | |||
178 | amb | 75 | superresults=FindRoute3(SuperNodes,SuperSegments,SuperWays,start,finish,begin,end,transport,highways); |
179 | amb | 34 | |
180 | /* Print the route */ | ||
181 | |||
182 | amb | 77 | if(!superresults) |
183 | { | ||
184 | amb | 48 | fprintf(stderr,"No route found.\n"); |
185 | amb | 77 | return(1); |
186 | } | ||
187 | amb | 48 | else if(!noprint) |
188 | amb | 55 | { |
189 | amb | 75 | Results *results=CombineRoutes(superresults,OSMNodes,OSMSegments,OSMWays,start,finish,transport,highways); |
190 | amb | 55 | |
191 | amb | 63 | PrintRoute(results,OSMNodes,OSMSegments,OSMWays,SuperNodes,start,finish,transport); |
192 | amb | 55 | } |
193 | amb | 34 | } |
194 | amb | 31 | } |
195 | |||
196 | amb | 2 | return(0); |
197 | } |
Properties
Name | Value |
---|---|
cvs:description | Router. |