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