Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Contents of /trunk/src/relationsx.c
Parent Directory
|
Revision Log
Revision 551 -
(show annotations)
(download)
(as text)
Sun Dec 19 19:03:02 2010 UTC (14 years, 3 months ago) by amb
File MIME type: text/x-csrc
File size: 21051 byte(s)
Sun Dec 19 19:03:02 2010 UTC (14 years, 3 months ago) by amb
File MIME type: text/x-csrc
File size: 21051 byte(s)
Process the turn relations (apart from updating the indexes to the geographically sorted nodes).
1 | /*************************************** |
2 | $Header: /home/amb/CVS/routino/src/relationsx.c,v 1.16 2010-12-19 19:01:46 amb Exp $ |
3 | |
4 | Extended Relation data type functions. |
5 | |
6 | Part of the Routino routing software. |
7 | ******************/ /****************** |
8 | This file Copyright 2010 Andrew M. Bishop |
9 | |
10 | This program is free software: you can redistribute it and/or modify |
11 | it under the terms of the GNU Affero General Public License as published by |
12 | the Free Software Foundation, either version 3 of the License, or |
13 | (at your option) any later version. |
14 | |
15 | This program is distributed in the hope that it will be useful, |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 | GNU Affero General Public License for more details. |
19 | |
20 | You should have received a copy of the GNU Affero General Public License |
21 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
22 | ***************************************/ |
23 | |
24 | |
25 | #include <assert.h> |
26 | #include <stdlib.h> |
27 | #include <stdio.h> |
28 | #include <string.h> |
29 | #include <sys/stat.h> |
30 | |
31 | #include "types.h" |
32 | #include "relations.h" |
33 | |
34 | #include "nodesx.h" |
35 | #include "segmentsx.h" |
36 | #include "waysx.h" |
37 | #include "relationsx.h" |
38 | |
39 | #include "files.h" |
40 | #include "logging.h" |
41 | #include "sorting.h" |
42 | |
43 | |
44 | /* Functions */ |
45 | |
46 | static int sort_by_via(TurnRestrictRelX *a,TurnRestrictRelX *b); |
47 | static int deduplicate_by_id(TurnRestrictRelX *relationx,index_t index); |
48 | |
49 | |
50 | /* Variables */ |
51 | |
52 | /*+ The command line '--tmpdir' option or its default value. +*/ |
53 | extern char *option_tmpdirname; |
54 | |
55 | static RelationsX* sortrelationsx; |
56 | |
57 | |
58 | /*++++++++++++++++++++++++++++++++++++++ |
59 | Allocate a new relation list (create a new file or open an existing one). |
60 | |
61 | RelationsX *NewRelationList Returns the relation list. |
62 | |
63 | int append Set to 1 if the file is to be opened for appending (now or later). |
64 | ++++++++++++++++++++++++++++++++++++++*/ |
65 | |
66 | RelationsX *NewRelationList(int append) |
67 | { |
68 | RelationsX *relationsx; |
69 | |
70 | relationsx=(RelationsX*)calloc(1,sizeof(RelationsX)); |
71 | |
72 | assert(relationsx); /* Check calloc() worked */ |
73 | |
74 | /* Route relations */ |
75 | |
76 | relationsx->rfilename=(char*)malloc(strlen(option_tmpdirname)+32); |
77 | |
78 | if(append) |
79 | sprintf(relationsx->rfilename,"%s/relationsx.route.input.tmp",option_tmpdirname); |
80 | else |
81 | sprintf(relationsx->rfilename,"%s/relationsx.route.%p.tmp",option_tmpdirname,relationsx); |
82 | |
83 | if(append) |
84 | { |
85 | off_t size,position=0; |
86 | |
87 | relationsx->rfd=OpenFileAppend(relationsx->rfilename); |
88 | |
89 | size=SizeFile(relationsx->rfilename); |
90 | |
91 | while(position<size) |
92 | { |
93 | FILESORT_VARINT relationsize; |
94 | |
95 | SeekFile(relationsx->rfd,position); |
96 | ReadFile(relationsx->rfd,&relationsize,FILESORT_VARSIZE); |
97 | |
98 | relationsx->rxnumber++; |
99 | position+=relationsize+FILESORT_VARSIZE; |
100 | } |
101 | |
102 | SeekFile(relationsx->rfd,size); |
103 | } |
104 | else |
105 | relationsx->rfd=OpenFileNew(relationsx->rfilename); |
106 | |
107 | /* Turn Restriction relations */ |
108 | |
109 | relationsx->trfilename=(char*)malloc(strlen(option_tmpdirname)+32); |
110 | |
111 | if(append) |
112 | sprintf(relationsx->trfilename,"%s/relationsx.turn.input.tmp",option_tmpdirname); |
113 | else |
114 | sprintf(relationsx->trfilename,"%s/relationsx.turn.%p.tmp",option_tmpdirname,relationsx); |
115 | |
116 | if(append) |
117 | { |
118 | off_t size; |
119 | |
120 | relationsx->trfd=OpenFileAppend(relationsx->trfilename); |
121 | |
122 | size=SizeFile(relationsx->trfilename); |
123 | |
124 | relationsx->trxnumber=size/sizeof(TurnRestrictRelX); |
125 | } |
126 | else |
127 | relationsx->trfd=OpenFileNew(relationsx->trfilename); |
128 | |
129 | return(relationsx); |
130 | } |
131 | |
132 | |
133 | /*++++++++++++++++++++++++++++++++++++++ |
134 | Free a relation list. |
135 | |
136 | RelationsX *relationsx The list to be freed. |
137 | |
138 | int keep Set to 1 if the file is to be kept. |
139 | ++++++++++++++++++++++++++++++++++++++*/ |
140 | |
141 | void FreeRelationList(RelationsX *relationsx,int keep) |
142 | { |
143 | /* Route relations */ |
144 | |
145 | if(!keep) |
146 | DeleteFile(relationsx->rfilename); |
147 | |
148 | free(relationsx->rfilename); |
149 | |
150 | /* Turn Restriction relations */ |
151 | |
152 | if(!keep) |
153 | DeleteFile(relationsx->trfilename); |
154 | |
155 | free(relationsx->trfilename); |
156 | |
157 | free(relationsx); |
158 | } |
159 | |
160 | |
161 | /*++++++++++++++++++++++++++++++++++++++ |
162 | Append a single relation to an unsorted route relation list. |
163 | |
164 | RelationsX* relationsx The set of relations to process. |
165 | |
166 | relation_t id The ID of the relation. |
167 | |
168 | transports_t routes The types of routes that this relation is for. |
169 | |
170 | way_t *ways The array of ways that are members of the relation. |
171 | |
172 | int nways The number of ways that are members of the relation. |
173 | |
174 | relation_t *relations The array of relations that are members of the relation. |
175 | |
176 | int nrelations The number of relations that are members of the relation. |
177 | ++++++++++++++++++++++++++++++++++++++*/ |
178 | |
179 | void AppendRouteRelation(RelationsX* relationsx,relation_t id, |
180 | transports_t routes, |
181 | way_t *ways,int nways, |
182 | relation_t *relations,int nrelations) |
183 | { |
184 | RouteRelX relationx; |
185 | FILESORT_VARINT size; |
186 | way_t zeroway=0; |
187 | relation_t zerorelation=0; |
188 | |
189 | relationx.id=id; |
190 | relationx.routes=routes; |
191 | |
192 | size=sizeof(RouteRelX)+(nways+1)*sizeof(way_t)+(nrelations+1)*sizeof(relation_t); |
193 | |
194 | WriteFile(relationsx->rfd,&size,FILESORT_VARSIZE); |
195 | WriteFile(relationsx->rfd,&relationx,sizeof(RouteRelX)); |
196 | |
197 | WriteFile(relationsx->rfd,ways ,nways*sizeof(way_t)); |
198 | WriteFile(relationsx->rfd,&zeroway, sizeof(way_t)); |
199 | |
200 | WriteFile(relationsx->rfd,relations ,nrelations*sizeof(relation_t)); |
201 | WriteFile(relationsx->rfd,&zerorelation, sizeof(relation_t)); |
202 | |
203 | relationsx->rxnumber++; |
204 | |
205 | assert(!(relationsx->rxnumber==0)); /* Zero marks the high-water mark for relations. */ |
206 | } |
207 | |
208 | |
209 | /*++++++++++++++++++++++++++++++++++++++ |
210 | Append a single relation to an unsorted turn restriction relation list. |
211 | |
212 | RelationsX* relationsx The set of relations to process. |
213 | |
214 | relation_t id The ID of the relation. |
215 | |
216 | way_t from The way that the turn restriction starts from. |
217 | |
218 | way_t to The way that the restriction finished on. |
219 | |
220 | node_t via The node that the turn restriction passes through. |
221 | |
222 | TurnRestriction restriction The type of restriction. |
223 | |
224 | transports_t except The set of transports allowed to bypass the restriction. |
225 | ++++++++++++++++++++++++++++++++++++++*/ |
226 | |
227 | void AppendTurnRestrictRelation(RelationsX* relationsx,relation_t id, |
228 | way_t from,way_t to,node_t via, |
229 | TurnRestriction restriction,transports_t except) |
230 | { |
231 | TurnRestrictRelX relationx; |
232 | |
233 | relationx.id=id; |
234 | relationx.from=from; |
235 | relationx.to=to; |
236 | relationx.via=via; |
237 | relationx.restrict=restriction; |
238 | relationx.except=except; |
239 | |
240 | WriteFile(relationsx->trfd,&relationx,sizeof(TurnRestrictRelX)); |
241 | |
242 | relationsx->trxnumber++; |
243 | |
244 | assert(!(relationsx->trxnumber==0)); /* Zero marks the high-water mark for relations. */ |
245 | } |
246 | |
247 | |
248 | /*++++++++++++++++++++++++++++++++++++++ |
249 | Sort the list of relations. |
250 | |
251 | RelationsX* relationsx The set of relations to process. |
252 | ++++++++++++++++++++++++++++++++++++++*/ |
253 | |
254 | void SortRelationList(RelationsX* relationsx) |
255 | { |
256 | /* Don't need to sort route relations */ |
257 | |
258 | |
259 | /* Sort the turn restriction relations by via node. */ |
260 | |
261 | if(relationsx->trxnumber) |
262 | { |
263 | int trfd; |
264 | |
265 | /* Print the start message */ |
266 | |
267 | printf_first("Sorting Turn Restriction Relations"); |
268 | |
269 | /* Open the new file */ |
270 | |
271 | DeleteFile(relationsx->trfilename); |
272 | |
273 | trfd=OpenFileNew(relationsx->trfilename); |
274 | |
275 | /* Sort the relations */ |
276 | |
277 | sortrelationsx=relationsx; |
278 | |
279 | filesort_fixed(relationsx->trfd,trfd,sizeof(TurnRestrictRelX),(int (*)(const void*,const void*))sort_by_via,(int (*)(void*,index_t))deduplicate_by_id); |
280 | |
281 | /* Close the files and re-open read-only */ |
282 | |
283 | CloseFile(relationsx->trfd); |
284 | CloseFile(trfd); |
285 | |
286 | relationsx->trfd=ReOpenFile(relationsx->trfilename); |
287 | |
288 | /* Print the final message */ |
289 | |
290 | printf_last("Sorted Relations: Relations=%d Duplicates=%d",relationsx->trxnumber,relationsx->trxnumber-relationsx->trnumber); |
291 | } |
292 | } |
293 | |
294 | |
295 | /*++++++++++++++++++++++++++++++++++++++ |
296 | Sort the turn restriction relations into via node order. |
297 | |
298 | int sort_by_via Returns the comparison of the via fields. |
299 | |
300 | TurnRestrictRelX *a The first extended relation. |
301 | |
302 | TurnRestrictRelX *b The second extended relation. |
303 | ++++++++++++++++++++++++++++++++++++++*/ |
304 | |
305 | static int sort_by_via(TurnRestrictRelX *a,TurnRestrictRelX *b) |
306 | { |
307 | node_t a_id=a->via; |
308 | node_t b_id=b->via; |
309 | |
310 | if(a_id<b_id) |
311 | return(-1); |
312 | else if(a_id>b_id) |
313 | return(1); |
314 | else |
315 | { |
316 | relation_t a_id=a->id; |
317 | relation_t b_id=b->id; |
318 | |
319 | if(a_id<b_id) |
320 | return(-1); |
321 | else if(a_id>b_id) |
322 | return(1); |
323 | else |
324 | return(0); |
325 | } |
326 | } |
327 | |
328 | |
329 | /*++++++++++++++++++++++++++++++++++++++ |
330 | Deduplicate the extended relations using the id after sorting. |
331 | |
332 | int deduplicate_by_id Return 1 if the value is to be kept, otherwise zero. |
333 | |
334 | TurnRestrictRelX *relationx The extended relation. |
335 | |
336 | index_t index The index of this relation in the total. |
337 | ++++++++++++++++++++++++++++++++++++++*/ |
338 | |
339 | static int deduplicate_by_id(TurnRestrictRelX *relationx,index_t index) |
340 | { |
341 | static relation_t previd; |
342 | |
343 | if(index==0 || relationx->id!=previd) |
344 | { |
345 | previd=relationx->id; |
346 | |
347 | sortrelationsx->trnumber++; |
348 | |
349 | return(1); |
350 | } |
351 | |
352 | return(0); |
353 | } |
354 | |
355 | |
356 | /*++++++++++++++++++++++++++++++++++++++ |
357 | Process the route relations and apply the information to the ways. |
358 | |
359 | RelationsX *relationsx The set of relations to process. |
360 | |
361 | WaysX *waysx The set of ways to update. |
362 | ++++++++++++++++++++++++++++++++++++++*/ |
363 | |
364 | void ProcessRouteRelations(RelationsX *relationsx,WaysX *waysx) |
365 | { |
366 | RouteRelX *unmatched=NULL,*lastunmatched=NULL; |
367 | int nunmatched=0,lastnunmatched=0,iteration=0; |
368 | |
369 | if(waysx->number==0) |
370 | return; |
371 | |
372 | /* Map into memory */ |
373 | |
374 | #if !SLIM |
375 | waysx->xdata=MapFileWriteable(waysx->filename); |
376 | #endif |
377 | |
378 | /* Re-open the ways file read/write */ |
379 | |
380 | #if SLIM |
381 | CloseFile(waysx->fd); |
382 | waysx->fd=ReOpenFileWriteable(waysx->filename); |
383 | #endif |
384 | |
385 | /* Close the file and re-open it (finished appending) */ |
386 | |
387 | CloseFile(relationsx->rfd); |
388 | relationsx->rfd=ReOpenFile(relationsx->rfilename); |
389 | |
390 | /* Read through the file. */ |
391 | |
392 | do |
393 | { |
394 | int ways=0,relations=0; |
395 | int i; |
396 | |
397 | SeekFile(relationsx->rfd,0); |
398 | |
399 | /* Print the start message */ |
400 | |
401 | printf_first("Processing Route Relations: Iteration=%d Relations=0 Modified Ways=0",iteration); |
402 | |
403 | for(i=0;i<relationsx->rxnumber;i++) |
404 | { |
405 | FILESORT_VARINT size; |
406 | RouteRelX relationx; |
407 | way_t wayid; |
408 | relation_t relationid; |
409 | transports_t routes=Transports_None; |
410 | |
411 | /* Read each route relation */ |
412 | |
413 | ReadFile(relationsx->rfd,&size,FILESORT_VARSIZE); |
414 | ReadFile(relationsx->rfd,&relationx,sizeof(RouteRelX)); |
415 | |
416 | /* Decide what type of route it is */ |
417 | |
418 | if(iteration==0) |
419 | { |
420 | relations++; |
421 | routes=relationx.routes; |
422 | } |
423 | else |
424 | { |
425 | int j; |
426 | |
427 | for(j=0;j<lastnunmatched;j++) |
428 | if(lastunmatched[j].id==relationx.id) |
429 | { |
430 | relations++; |
431 | |
432 | if((lastunmatched[j].routes|relationx.routes)==relationx.routes) |
433 | routes=0; /* Nothing new to add */ |
434 | else |
435 | routes=lastunmatched[j].routes; |
436 | break; |
437 | } |
438 | } |
439 | |
440 | /* Loop through the ways */ |
441 | |
442 | do |
443 | { |
444 | ReadFile(relationsx->rfd,&wayid,sizeof(way_t)); |
445 | |
446 | /* Update the ways that are listed for the relation */ |
447 | |
448 | if(wayid && routes) |
449 | { |
450 | index_t way=IndexWayX(waysx,wayid); |
451 | |
452 | if(way!=NO_WAY) |
453 | { |
454 | WayX *wayx=LookupWayX(waysx,way,1); |
455 | |
456 | if(routes&Transports_Foot) |
457 | wayx->way.props|=Properties_FootRoute; |
458 | |
459 | if(routes&Transports_Bicycle) |
460 | wayx->way.props|=Properties_BicycleRoute; |
461 | |
462 | #if SLIM |
463 | PutBackWayX(waysx,way,1); |
464 | #endif |
465 | |
466 | ways++; |
467 | } |
468 | } |
469 | } |
470 | while(wayid); |
471 | |
472 | /* Loop through the relations */ |
473 | |
474 | do |
475 | { |
476 | ReadFile(relationsx->rfd,&relationid,sizeof(relation_t)); |
477 | |
478 | /* Add the relations that are listed for this relation to the list for next time */ |
479 | |
480 | if(relationid && routes && relationid!=relationx.id) |
481 | { |
482 | if(nunmatched%256==0) |
483 | unmatched=(RouteRelX*)realloc((void*)unmatched,(nunmatched+256)*sizeof(RouteRelX)); |
484 | |
485 | unmatched[nunmatched].id=relationid; |
486 | unmatched[nunmatched].routes=routes; |
487 | |
488 | nunmatched++; |
489 | } |
490 | } |
491 | while(relationid); |
492 | |
493 | if(!((i+1)%10000)) |
494 | printf_middle("Processing Route Relations: Iteration=%d Relations=%d Modified Ways=%d",iteration,relations,ways); |
495 | } |
496 | |
497 | if(lastunmatched) |
498 | free(lastunmatched); |
499 | |
500 | lastunmatched=unmatched; |
501 | lastnunmatched=nunmatched; |
502 | |
503 | unmatched=NULL; |
504 | nunmatched=0; |
505 | |
506 | /* Print the final message */ |
507 | |
508 | printf_last("Processed Route Relations: Iteration=%d Relations=%d Modified Ways=%d",iteration,relations,ways); |
509 | } |
510 | while(lastnunmatched && ++iteration<5); |
511 | |
512 | if(lastunmatched) |
513 | free(lastunmatched); |
514 | |
515 | CloseFile(relationsx->rfd); |
516 | |
517 | /* Unmap from memory */ |
518 | |
519 | #if !SLIM |
520 | waysx->xdata=UnmapFile(waysx->filename); |
521 | #endif |
522 | |
523 | /* Re-open the ways file read only */ |
524 | |
525 | #if SLIM |
526 | CloseFile(waysx->fd); |
527 | waysx->fd=ReOpenFile(waysx->filename); |
528 | #endif |
529 | } |
530 | |
531 | |
532 | /*++++++++++++++++++++++++++++++++++++++ |
533 | Process the turn relations (first part) to update them with the node information. |
534 | |
535 | RelationsX *relationsx The set of relations to process. |
536 | |
537 | NodesX *nodesx The set of nodes to process. |
538 | |
539 | SegmentsX *segmentsx The set of segments to process. |
540 | |
541 | WaysX *waysx The set of ways to process. |
542 | ++++++++++++++++++++++++++++++++++++++*/ |
543 | |
544 | void ProcessTurnRelations1(RelationsX *relationsx,NodesX *nodesx,SegmentsX *segmentsx,WaysX *waysx) |
545 | { |
546 | TurnRestrictRelX relationx; |
547 | int trfd; |
548 | |
549 | if(nodesx->number==0 || segmentsx->number==0) |
550 | return; |
551 | |
552 | /* Print the start message */ |
553 | |
554 | printf_first("Processing Turn Restriction Relations (1): Turn Relations=0"); |
555 | |
556 | /* Map into memory */ |
557 | |
558 | #if !SLIM |
559 | nodesx->xdata =MapFile(nodesx->filename); |
560 | segmentsx->xdata=MapFile(segmentsx->filename); |
561 | #endif |
562 | |
563 | /* Close the file and re-open it (finished appending) */ |
564 | |
565 | CloseFile(relationsx->trfd); |
566 | relationsx->trfd=ReOpenFile(relationsx->trfilename); |
567 | |
568 | /* Open the new file */ |
569 | |
570 | DeleteFile(relationsx->trfilename); |
571 | |
572 | trfd=OpenFileNew(relationsx->trfilename); |
573 | |
574 | /* Process all of the relations */ |
575 | |
576 | relationsx->trxnumber=0; |
577 | |
578 | while(!ReadFile(relationsx->trfd,&relationx,sizeof(TurnRestrictRelX))) |
579 | { |
580 | if(relationx.restrict==TurnRestrict_no_right_turn || |
581 | relationx.restrict==TurnRestrict_no_left_turn || |
582 | relationx.restrict==TurnRestrict_no_u_turn || |
583 | relationx.restrict==TurnRestrict_no_straight_on) |
584 | { |
585 | index_t seg; |
586 | node_t node_from=NO_NODE,node_to=NO_NODE; |
587 | |
588 | /* Find the segments that join the node 'via' */ |
589 | |
590 | seg=IndexFirstSegmentX1(segmentsx,relationx.via); |
591 | |
592 | do |
593 | { |
594 | SegmentX *segx=LookupSegmentX(segmentsx,seg,1); |
595 | |
596 | if(segx->way==relationx.from) |
597 | { |
598 | if(node_from!=NO_NODE) /* Only one segment can be on the 'from' way */ |
599 | goto endloop; |
600 | |
601 | node_from=segx->node2; |
602 | } |
603 | |
604 | if(segx->way==relationx.to) |
605 | { |
606 | if(node_to!=NO_NODE) /* Only one segment can be on the 'to' way */ |
607 | goto endloop; |
608 | |
609 | node_to=segx->node2; |
610 | } |
611 | |
612 | seg=IndexNextSegmentX1(segmentsx,seg,relationx.via); |
613 | } |
614 | while(seg!=NO_SEGMENT); |
615 | |
616 | if(node_to==NO_NODE || node_from==NO_NODE) /* Not enough segments for the selected ways */ |
617 | goto endloop; |
618 | |
619 | /* Write the results */ |
620 | |
621 | relationx.from=IndexNodeX(nodesx,node_from); |
622 | relationx.to =IndexNodeX(nodesx,node_to); |
623 | relationx.via =IndexNodeX(nodesx,relationx.via); |
624 | |
625 | WriteFile(trfd,&relationx,sizeof(TurnRestrictRelX)); |
626 | |
627 | relationsx->trxnumber++; |
628 | |
629 | if(!(relationsx->trxnumber%10000)) |
630 | printf_middle("Processing Turn Restriction Relations (1): Turn Relations=%d",relationsx->trxnumber); |
631 | } |
632 | else |
633 | { |
634 | index_t seg; |
635 | node_t node_from=NO_NODE,node_to[8]; |
636 | int nnodes_to=0,i; |
637 | |
638 | /* Find the segments that join the node 'via' */ |
639 | |
640 | seg=IndexFirstSegmentX1(segmentsx,relationx.via); |
641 | |
642 | do |
643 | { |
644 | SegmentX *segx=LookupSegmentX(segmentsx,seg,1); |
645 | |
646 | if(segx->way==relationx.from) |
647 | { |
648 | if(node_from!=NO_NODE) /* Only one segment can be on the 'from' way */ |
649 | goto endloop; |
650 | |
651 | node_from=segx->node2; |
652 | } |
653 | |
654 | if(segx->way!=relationx.to) |
655 | { |
656 | if(nnodes_to==8) /* Too many segments (arbitrary choice) */ |
657 | goto endloop; |
658 | |
659 | node_to[nnodes_to++]=segx->node2; |
660 | } |
661 | |
662 | seg=IndexNextSegmentX1(segmentsx,seg,relationx.via); |
663 | } |
664 | while(seg!=NO_SEGMENT); |
665 | |
666 | if(nnodes_to==0 || node_from==NO_NODE) /* Not enough segments for the selected ways */ |
667 | goto endloop; |
668 | |
669 | /* Write the results */ |
670 | |
671 | relationx.via=IndexNodeX(nodesx,relationx.via); |
672 | |
673 | for(i=0;i<nnodes_to;i++) |
674 | { |
675 | if(node_to[i]==node_from) |
676 | continue; |
677 | |
678 | relationx.from=IndexNodeX(nodesx,node_from); |
679 | relationx.to =IndexNodeX(nodesx,node_to[i]); |
680 | |
681 | WriteFile(trfd,&relationx,sizeof(TurnRestrictRelX)); |
682 | |
683 | relationsx->trxnumber++; |
684 | |
685 | if(!(relationsx->trxnumber%10000)) |
686 | printf_middle("Processing Turn Restriction Relations (1): Turn Relations=%d",relationsx->trxnumber); |
687 | } |
688 | } |
689 | |
690 | endloop: ; |
691 | } |
692 | |
693 | /* Close the files and re-open read-only */ |
694 | |
695 | CloseFile(relationsx->trfd); |
696 | CloseFile(trfd); |
697 | |
698 | relationsx->trfd=ReOpenFile(relationsx->trfilename); |
699 | |
700 | /* Unmap from memory */ |
701 | |
702 | #if !SLIM |
703 | nodesx->xdata =UnmapFile(nodesx->filename); |
704 | segmentsx->xdata=UnmapFile(segmentsx->filename); |
705 | #endif |
706 | |
707 | /* Print the final message */ |
708 | |
709 | printf_last("Processing Turn Restriction Relations (1): Turn Relations=%d",relationsx->trxnumber); |
710 | } |
711 | |
712 | |
713 | /*++++++++++++++++++++++++++++++++++++++ |
714 | Process the turn relations (second part) to update them with the re-ordered node information. |
715 | |
716 | RelationsX *relationsx The set of relations to process. |
717 | |
718 | NodesX *nodesx The set of nodes to process. |
719 | ++++++++++++++++++++++++++++++++++++++*/ |
720 | |
721 | void ProcessTurnRelations2(RelationsX *relationsx,NodesX *nodesx) |
722 | { |
723 | return; |
724 | |
725 | TurnRestrictRelX relationx; |
726 | int trfd; |
727 | |
728 | if(nodesx->number==0) |
729 | return; |
730 | |
731 | /* Print the start message */ |
732 | |
733 | printf_first("Processing Turn Restriction Relations (2): Turn Relations=0"); |
734 | |
735 | /* Map into memory */ |
736 | |
737 | #if !SLIM |
738 | nodesx->xdata=MapFile(nodesx->filename); |
739 | #endif |
740 | |
741 | /* Open the new file */ |
742 | |
743 | DeleteFile(relationsx->trfilename); |
744 | |
745 | trfd=OpenFileNew(relationsx->trfilename); |
746 | |
747 | /* Process all of the relations */ |
748 | |
749 | while(!ReadFile(relationsx->trfd,&relationx,sizeof(TurnRestrictRelX))) |
750 | { |
751 | NodeX *nodex; |
752 | |
753 | nodex=LookupNodeX(nodesx,relationx.from,1); |
754 | relationx.from=nodex->id; |
755 | |
756 | nodex=LookupNodeX(nodesx,relationx.via,1); |
757 | relationx.via=nodex->id; |
758 | |
759 | nodex=LookupNodeX(nodesx,relationx.to,1); |
760 | relationx.to=nodex->id; |
761 | |
762 | WriteFile(trfd,&relationx,sizeof(TurnRestrictRelX)); |
763 | |
764 | if(!(relationsx->trxnumber%10000)) |
765 | printf_middle("Processing Turn Restriction Relations (2): Turn Relations=%d",relationsx->trxnumber); |
766 | } |
767 | |
768 | /* Close the files and re-open read-only */ |
769 | |
770 | CloseFile(relationsx->trfd); |
771 | CloseFile(trfd); |
772 | |
773 | relationsx->trfd=ReOpenFile(relationsx->trfilename); |
774 | |
775 | /* Unmap from memory */ |
776 | |
777 | #if !SLIM |
778 | nodesx->xdata=UnmapFile(nodesx->filename); |
779 | #endif |
780 | |
781 | /* Print the final message */ |
782 | |
783 | printf_last("Processing Turn Restriction Relations (2): Turn Relations=%d",relationsx->trxnumber); |
784 | } |
785 | |
786 | |
787 | /*++++++++++++++++++++++++++++++++++++++ |
788 | Save the relation list to a file. |
789 | |
790 | RelationsX* relationsx The set of relations to save. |
791 | |
792 | const char *filename The name of the file to save. |
793 | ++++++++++++++++++++++++++++++++++++++*/ |
794 | |
795 | void SaveRelationList(RelationsX* relationsx,const char *filename) |
796 | { |
797 | index_t i; |
798 | int fd; |
799 | RelationsFile relationsfile={0}; |
800 | |
801 | /* Print the start message */ |
802 | |
803 | printf_first("Writing Relations: Turn Relations=0"); |
804 | |
805 | /* Write out the relations data */ |
806 | |
807 | fd=OpenFileNew(filename); |
808 | |
809 | SeekFile(fd,sizeof(RelationsFile)); |
810 | |
811 | for(i=0;i<relationsx->trnumber;i++) |
812 | { |
813 | TurnRestrictRelX relationx; |
814 | TurnRelation relation; |
815 | |
816 | ReadFile(relationsx->trfd,&relationx,sizeof(TurnRestrictRelX)); |
817 | |
818 | relation.from=relationx.from; |
819 | relation.via=relationx.via; |
820 | relation.to=relationx.to; |
821 | relation.except=relationx.except; |
822 | |
823 | WriteFile(fd,&relation,sizeof(TurnRelation)); |
824 | |
825 | if(!((i+1)%10000)) |
826 | printf_middle("Writing Relations: Turn Relations=%d",i+1); |
827 | } |
828 | |
829 | /* Write out the header structure */ |
830 | |
831 | relationsfile.trnumber=relationsx->trnumber; |
832 | |
833 | SeekFile(fd,0); |
834 | WriteFile(fd,&relationsfile,sizeof(RelationsFile)); |
835 | |
836 | CloseFile(fd); |
837 | |
838 | /* Close the file */ |
839 | |
840 | CloseFile(relationsx->trfd); |
841 | |
842 | /* Print the final message */ |
843 | |
844 | printf_last("Wrote Relations: Turn Relations=%d",relationsx->trnumber); |
845 | } |