Routino SVN Repository Browser

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

ViewVC logotype

Annotation of /trunk/src/router.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 44 - (hide annotations) (download) (as text)
Sat Jan 17 11:25:38 2009 UTC (16 years, 2 months ago) by amb
File MIME type: text/x-csrc
File size: 3604 byte(s)
Added an option to not print the result.

1 amb 2 /***************************************
2 amb 44 $Header: /home/amb/CVS/routino/src/router.c,v 1.9 2009-01-17 11:25:38 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 44 node_t start,finish;
31     int all=0,noprint=0;
32 amb 2
33 amb 44 /* Parse the command line arguments */
34 amb 2
35 amb 44 if(argc<3)
36 amb 2 {
37 amb 44 usage:
38     fprintf(stderr,"Usage: %s <start-node> <finish-node> [-all] [-no-print]\n",argv[0]);
39 amb 2 return(1);
40     }
41    
42     start=atoll(argv[1]);
43     finish=atoll(argv[2]);
44    
45 amb 44 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 amb 2 /* Load in the data */
56    
57 amb 26 OSMNodes=LoadNodeList("data/nodes.mem");
58 amb 33 SuperNodes=LoadNodeList("data/super-nodes.mem");
59 amb 31
60 amb 26 OSMWays=LoadWayList("data/ways.mem");
61 amb 31
62 amb 26 OSMSegments=LoadSegmentList("data/segments.mem");
63 amb 31 SuperSegments=LoadSegmentList("data/super-segments.mem");
64 amb 2
65 amb 31 if(argc>3 && !strcmp(argv[3],"-all"))
66     {
67 amb 34 Results *results;
68    
69 amb 31 /* Calculate the route */
70 amb 2
71 amb 31 results=FindRoute(OSMNodes,OSMSegments,start,finish);
72 amb 2
73 amb 31 /* Print the route */
74 amb 2
75 amb 44 if(!noprint)
76     PrintRoute(results,OSMNodes,OSMSegments,OSMWays,start,finish);
77 amb 31 }
78     else
79     {
80 amb 34 Results *begin,*middle,*end;
81 amb 2
82 amb 34 /* Calculate the beginning of the route */
83 amb 31
84 amb 34 if(FindNode(SuperNodes,start))
85     {
86     Result *result;
87 amb 31
88 amb 34 begin=NewResultsList();
89    
90     result=InsertResult(begin,start);
91    
92     result->node=start;
93 amb 43 result->shortest.prev=0;
94     result->shortest.next=0;
95 amb 34 result->shortest.distance=0;
96     result->shortest.duration=0;
97 amb 43 result->quickest.prev=0;
98     result->quickest.next=0;
99 amb 34 result->quickest.distance=0;
100     result->quickest.duration=0;
101     }
102     else
103     begin=FindRoutes(OSMNodes,OSMSegments,start,SuperNodes);
104    
105     if(FindResult(begin,finish))
106     {
107     Results *results;
108    
109     /* Calculate the route */
110    
111     results=FindRoute(OSMNodes,OSMSegments,start,finish);
112    
113     /* Print the route */
114    
115 amb 44 if(!noprint)
116     PrintRoute(results,OSMNodes,OSMSegments,OSMWays,start,finish);
117 amb 34 }
118     else
119     {
120     /* Calculate the end of the route */
121    
122     if(FindNode(SuperNodes,finish))
123     {
124     Result *result;
125    
126     end=NewResultsList();
127    
128     result=InsertResult(end,finish);
129    
130     result->node=finish;
131 amb 43 result->shortest.prev=0;
132     result->shortest.next=0;
133 amb 34 result->shortest.distance=0;
134     result->shortest.duration=0;
135 amb 43 result->quickest.prev=0;
136     result->quickest.next=0;
137 amb 34 result->quickest.distance=0;
138     result->quickest.duration=0;
139     }
140     else
141     end=FindReverseRoutes(OSMNodes,OSMSegments,SuperNodes,finish);
142    
143     /* Calculate the middle of the route */
144    
145     middle=FindRoute3(SuperNodes,SuperSegments,start,finish,begin,end);
146    
147     /* Print the route */
148    
149 amb 44 if(!noprint)
150     PrintRoutes(middle,OSMNodes,OSMSegments,OSMWays,SuperNodes,SuperSegments,start,finish);
151 amb 34 }
152 amb 31 }
153    
154 amb 2 return(0);
155     }

Properties

Name Value
cvs:description Router.