Routino SVN Repository Browser

Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino

ViewVC logotype

Contents of /trunk/src/router.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 34 - (show annotations) (download) (as text)
Sun Jan 11 20:09:37 2009 UTC (16 years, 2 months ago) by amb
File MIME type: text/x-csrc
File size: 3444 byte(s)
Routes correctly using super-nodes (not Lands End to John O'Groats though).

1 /***************************************
2 $Header: /home/amb/CVS/routino/src/router.c,v 1.7 2009-01-11 20:09:37 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
32 /* Parse the command line aarguments */
33
34 if(argc!=3 && argc!=4)
35 {
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 OSMNodes=LoadNodeList("data/nodes.mem");
46 SuperNodes=LoadNodeList("data/super-nodes.mem");
47
48 OSMWays=LoadWayList("data/ways.mem");
49
50 OSMSegments=LoadSegmentList("data/segments.mem");
51 SuperSegments=LoadSegmentList("data/super-segments.mem");
52
53 if(argc>3 && !strcmp(argv[3],"-all"))
54 {
55 Results *results;
56
57 /* Calculate the route */
58
59 results=FindRoute(OSMNodes,OSMSegments,start,finish);
60
61 /* Print the route */
62
63 PrintRoute(results,OSMNodes,OSMSegments,OSMWays,start,finish);
64 }
65 else
66 {
67 Results *begin,*middle,*end;
68
69 /* Calculate the beginning of the route */
70
71 if(FindNode(SuperNodes,start))
72 {
73 Result *result;
74
75 begin=NewResultsList();
76
77 result=InsertResult(begin,start);
78
79 result->node=start;
80 result->Node=FindNode(OSMNodes,start);
81 result->shortest.Prev=NULL;
82 result->shortest.Next=NULL;
83 result->shortest.distance=0;
84 result->shortest.duration=0;
85 result->quickest.Prev=NULL;
86 result->quickest.Next=NULL;
87 result->quickest.distance=0;
88 result->quickest.duration=0;
89 }
90 else
91 begin=FindRoutes(OSMNodes,OSMSegments,start,SuperNodes);
92
93 if(FindResult(begin,finish))
94 {
95 Results *results;
96
97 /* Calculate the route */
98
99 results=FindRoute(OSMNodes,OSMSegments,start,finish);
100
101 /* Print the route */
102
103 PrintRoute(results,OSMNodes,OSMSegments,OSMWays,start,finish);
104 }
105 else
106 {
107 /* Calculate the end of the route */
108
109 if(FindNode(SuperNodes,finish))
110 {
111 Result *result;
112
113 end=NewResultsList();
114
115 result=InsertResult(end,finish);
116
117 result->node=finish;
118 result->Node=FindNode(OSMNodes,finish);
119 result->shortest.Prev=NULL;
120 result->shortest.Next=NULL;
121 result->shortest.distance=0;
122 result->shortest.duration=0;
123 result->quickest.Prev=NULL;
124 result->quickest.Next=NULL;
125 result->quickest.distance=0;
126 result->quickest.duration=0;
127 }
128 else
129 end=FindReverseRoutes(OSMNodes,OSMSegments,SuperNodes,finish);
130
131 /* Calculate the middle of the route */
132
133 middle=FindRoute3(SuperNodes,SuperSegments,start,finish,begin,end);
134
135 /* Print the route */
136
137 PrintRoutes(middle,OSMNodes,OSMSegments,OSMWays,SuperNodes,SuperSegments,start,finish);
138 }
139 }
140
141 return(0);
142 }

Properties

Name Value
cvs:description Router.