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 66 -
(show annotations)
(download)
(as text)
Thu Jan 22 19:15:30 2009 UTC (16 years, 1 month ago) by amb
File MIME type: text/x-csrc
File size: 4189 byte(s)
Thu Jan 22 19:15:30 2009 UTC (16 years, 1 month ago) by amb
File MIME type: text/x-csrc
File size: 4189 byte(s)
Nodes, Segments, Ways - Nodes, Segments, Ways.
1 | /*************************************** |
2 | $Header: /home/amb/CVS/routino/src/router.c,v 1.14 2009-01-22 19:15:30 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 | AllowType transport=Allow_Motorcar; |
33 | |
34 | /* Parse the command line arguments */ |
35 | |
36 | if(argc<3) |
37 | { |
38 | usage: |
39 | fprintf(stderr,"Usage: router <start-node> <finish-node>\n" |
40 | " [-all] [-no-print]\n" |
41 | " [-transport=(foot|bicycle|...)]\n"); |
42 | return(1); |
43 | } |
44 | |
45 | start=atoll(argv[1]); |
46 | finish=atoll(argv[2]); |
47 | |
48 | while(--argc>=3) |
49 | { |
50 | if(!strcmp(argv[argc],"-all")) |
51 | all=1; |
52 | else if(!strcmp(argv[argc],"-no-print")) |
53 | noprint=1; |
54 | else if(!strncmp(argv[argc],"-transport=",11)) |
55 | transport=AllowedType(&argv[argc][11]); |
56 | else |
57 | goto usage; |
58 | } |
59 | |
60 | /* Load in the data */ |
61 | |
62 | OSMNodes=LoadNodeList("data/nodes.mem"); |
63 | SuperNodes=LoadNodeList("data/super-nodes.mem"); |
64 | |
65 | OSMSegments=LoadSegmentList("data/segments.mem"); |
66 | SuperSegments=LoadSegmentList("data/super-segments.mem"); |
67 | |
68 | OSMWays=LoadWayList("data/ways.mem"); |
69 | SuperWays=LoadWayList("data/super-ways.mem"); |
70 | |
71 | if(all) |
72 | { |
73 | Results *results; |
74 | |
75 | /* Calculate the route */ |
76 | |
77 | results=FindRoute(OSMNodes,OSMSegments,OSMWays,start,finish,transport); |
78 | |
79 | /* Print the route */ |
80 | |
81 | if(!FindResult(results,finish)) |
82 | fprintf(stderr,"No route found.\n"); |
83 | else if(!noprint) |
84 | PrintRoute(results,OSMNodes,OSMSegments,OSMWays,NULL,start,finish,transport); |
85 | } |
86 | else |
87 | { |
88 | Results *begin,*end; |
89 | |
90 | /* Calculate the beginning of the route */ |
91 | |
92 | if(FindNode(SuperNodes,start)) |
93 | { |
94 | Result *result; |
95 | |
96 | begin=NewResultsList(); |
97 | |
98 | result=InsertResult(begin,start); |
99 | |
100 | result->node=start; |
101 | result->shortest.prev=0; |
102 | result->shortest.next=0; |
103 | result->shortest.distance=0; |
104 | result->shortest.duration=0; |
105 | result->quickest.prev=0; |
106 | result->quickest.next=0; |
107 | result->quickest.distance=0; |
108 | result->quickest.duration=0; |
109 | } |
110 | else |
111 | begin=FindRoutes(OSMNodes,OSMSegments,OSMWays,start,SuperNodes,transport); |
112 | |
113 | if(FindResult(begin,finish)) |
114 | { |
115 | /* Print the route */ |
116 | |
117 | if(!noprint) |
118 | PrintRoute(begin,OSMNodes,OSMSegments,OSMWays,NULL,start,finish,transport); |
119 | } |
120 | else |
121 | { |
122 | Results *superresults; |
123 | |
124 | /* Calculate the end of the route */ |
125 | |
126 | if(FindNode(SuperNodes,finish)) |
127 | { |
128 | Result *result; |
129 | |
130 | end=NewResultsList(); |
131 | |
132 | result=InsertResult(end,finish); |
133 | |
134 | result->node=finish; |
135 | result->shortest.prev=0; |
136 | result->shortest.next=0; |
137 | result->shortest.distance=0; |
138 | result->shortest.duration=0; |
139 | result->quickest.prev=0; |
140 | result->quickest.next=0; |
141 | result->quickest.distance=0; |
142 | result->quickest.duration=0; |
143 | } |
144 | else |
145 | end=FindReverseRoutes(OSMNodes,OSMSegments,OSMWays,SuperNodes,finish,transport); |
146 | |
147 | /* Calculate the middle of the route */ |
148 | |
149 | superresults=FindRoute3(SuperNodes,SuperSegments,SuperWays,start,finish,begin,end,transport); |
150 | |
151 | /* Print the route */ |
152 | |
153 | if(!FindResult(superresults,finish)) |
154 | fprintf(stderr,"No route found.\n"); |
155 | else if(!noprint) |
156 | { |
157 | Results *results=CombineRoutes(superresults,OSMNodes,OSMSegments,OSMWays,start,finish,transport); |
158 | |
159 | PrintRoute(results,OSMNodes,OSMSegments,OSMWays,SuperNodes,start,finish,transport); |
160 | } |
161 | } |
162 | } |
163 | |
164 | return(0); |
165 | } |
Properties
Name | Value |
---|---|
cvs:description | Router. |