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 43 -
(hide annotations)
(download)
(as text)
Fri Jan 16 20:04:47 2009 UTC (16 years, 2 months ago) by amb
File MIME type: text/x-csrc
File size: 3324 byte(s)
Fri Jan 16 20:04:47 2009 UTC (16 years, 2 months ago) by amb
File MIME type: text/x-csrc
File size: 3324 byte(s)
Speed optimisation by changing the contents of the Results structure.
1 | amb | 2 | /*************************************** |
2 | amb | 43 | $Header: /home/amb/CVS/routino/src/router.c,v 1.8 2009-01-16 20:04:47 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 | 26 | Ways *OSMWays; |
29 | amb | 31 | Segments *OSMSegments,*SuperSegments; |
30 | amb | 2 | node_t start,finish; |
31 | |||
32 | /* Parse the command line aarguments */ | ||
33 | |||
34 | amb | 31 | if(argc!=3 && argc!=4) |
35 | amb | 2 | { |
36 | fprintf(stderr,"Usage: %s <start-node> <finish-node>\n",argv[0]); | ||
37 | return(1); | ||
38 | } | ||
39 | |||
40 | start=atoll(argv[1]); | ||
41 | finish=atoll(argv[2]); | ||
42 | |||
43 | /* Load in the data */ | ||
44 | |||
45 | amb | 26 | OSMNodes=LoadNodeList("data/nodes.mem"); |
46 | amb | 33 | SuperNodes=LoadNodeList("data/super-nodes.mem"); |
47 | amb | 31 | |
48 | amb | 26 | OSMWays=LoadWayList("data/ways.mem"); |
49 | amb | 31 | |
50 | amb | 26 | OSMSegments=LoadSegmentList("data/segments.mem"); |
51 | amb | 31 | SuperSegments=LoadSegmentList("data/super-segments.mem"); |
52 | amb | 2 | |
53 | amb | 31 | if(argc>3 && !strcmp(argv[3],"-all")) |
54 | { | ||
55 | amb | 34 | Results *results; |
56 | |||
57 | amb | 31 | /* Calculate the route */ |
58 | amb | 2 | |
59 | amb | 31 | results=FindRoute(OSMNodes,OSMSegments,start,finish); |
60 | amb | 2 | |
61 | amb | 31 | /* Print the route */ |
62 | amb | 2 | |
63 | amb | 31 | PrintRoute(results,OSMNodes,OSMSegments,OSMWays,start,finish); |
64 | } | ||
65 | else | ||
66 | { | ||
67 | amb | 34 | Results *begin,*middle,*end; |
68 | amb | 2 | |
69 | amb | 34 | /* Calculate the beginning of the route */ |
70 | amb | 31 | |
71 | amb | 34 | if(FindNode(SuperNodes,start)) |
72 | { | ||
73 | Result *result; | ||
74 | amb | 31 | |
75 | amb | 34 | begin=NewResultsList(); |
76 | |||
77 | result=InsertResult(begin,start); | ||
78 | |||
79 | result->node=start; | ||
80 | amb | 43 | result->shortest.prev=0; |
81 | result->shortest.next=0; | ||
82 | amb | 34 | result->shortest.distance=0; |
83 | result->shortest.duration=0; | ||
84 | amb | 43 | result->quickest.prev=0; |
85 | result->quickest.next=0; | ||
86 | amb | 34 | result->quickest.distance=0; |
87 | result->quickest.duration=0; | ||
88 | } | ||
89 | else | ||
90 | begin=FindRoutes(OSMNodes,OSMSegments,start,SuperNodes); | ||
91 | |||
92 | if(FindResult(begin,finish)) | ||
93 | { | ||
94 | Results *results; | ||
95 | |||
96 | /* Calculate the route */ | ||
97 | |||
98 | results=FindRoute(OSMNodes,OSMSegments,start,finish); | ||
99 | |||
100 | /* Print the route */ | ||
101 | |||
102 | PrintRoute(results,OSMNodes,OSMSegments,OSMWays,start,finish); | ||
103 | } | ||
104 | else | ||
105 | { | ||
106 | /* Calculate the end of the route */ | ||
107 | |||
108 | if(FindNode(SuperNodes,finish)) | ||
109 | { | ||
110 | Result *result; | ||
111 | |||
112 | end=NewResultsList(); | ||
113 | |||
114 | result=InsertResult(end,finish); | ||
115 | |||
116 | result->node=finish; | ||
117 | amb | 43 | result->shortest.prev=0; |
118 | result->shortest.next=0; | ||
119 | amb | 34 | result->shortest.distance=0; |
120 | result->shortest.duration=0; | ||
121 | amb | 43 | result->quickest.prev=0; |
122 | result->quickest.next=0; | ||
123 | amb | 34 | result->quickest.distance=0; |
124 | result->quickest.duration=0; | ||
125 | } | ||
126 | else | ||
127 | end=FindReverseRoutes(OSMNodes,OSMSegments,SuperNodes,finish); | ||
128 | |||
129 | /* Calculate the middle of the route */ | ||
130 | |||
131 | middle=FindRoute3(SuperNodes,SuperSegments,start,finish,begin,end); | ||
132 | |||
133 | /* Print the route */ | ||
134 | |||
135 | PrintRoutes(middle,OSMNodes,OSMSegments,OSMWays,SuperNodes,SuperSegments,start,finish); | ||
136 | } | ||
137 | amb | 31 | } |
138 | |||
139 | amb | 2 | return(0); |
140 | } |
Properties
Name | Value |
---|---|
cvs:description | Router. |