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 54 - (hide annotations) (download) (as text)
Sun Jan 18 16:04:09 2009 UTC (16 years, 2 months ago) by amb
File MIME type: text/x-csrc
File size: 4028 byte(s)
Added Super-Ways and allow user to select method of transport.

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

Properties

Name Value
cvs:description Router.