]> git.tdb.fi Git - r2c2.git/blob - source/libr2c2/trainrouteplanner.cpp
Consider train length when calculating wait time estimate
[r2c2.git] / source / libr2c2 / trainrouteplanner.cpp
1 #include <msp/core/maputils.h>
2 #include <msp/time/utils.h>
3 #include "catalogue.h"
4 #include "layout.h"
5 #include "route.h"
6 #include "train.h"
7 #include "trainroutemetric.h"
8 #include "trainrouteplanner.h"
9 #include "trainrouter.h"
10 #include "vehicle.h"
11
12 using namespace std;
13 using namespace Msp;
14
15 namespace R2C2 {
16
17 TrainRoutePlanner::TrainRoutePlanner(Layout &layout):
18         goal(0),
19         timeout(10*Time::sec),
20         result(PENDING),
21         thread(0)
22 {
23         const map<unsigned, Train *> &trains = layout.get_trains();
24         for(map<unsigned, Train *>::const_iterator i=trains.begin(); i!=trains.end(); ++i)
25         {
26                 TrainRoutingInfo info(*i->second);
27                 if(!info.waypoints.empty())
28                         routed_trains.push_back(info);
29         }
30 }
31
32 TrainRoutePlanner::~TrainRoutePlanner()
33 {
34         if(thread)
35         {
36                 thread->join();
37                 delete thread;
38         }
39 }
40
41 void TrainRoutePlanner::set_timeout(const Time::TimeDelta &t)
42 {
43         timeout = t;
44 }
45
46 TrainRoutePlanner::Result TrainRoutePlanner::plan()
47 {
48         prepare_plan();
49         create_plan();
50         if(result==PENDING)
51                 finalize_plan();
52
53         return result;
54 }
55
56 void TrainRoutePlanner::plan_async()
57 {
58         if(thread)
59                 throw logic_error("already planning");
60
61         prepare_plan();
62         thread = new PlanningThread(*this);
63 }
64
65 TrainRoutePlanner::Result TrainRoutePlanner::check()
66 {
67         if(result==PENDING && goal)
68         {
69                 if(thread)
70                 {
71                         thread->join();
72                         delete thread;
73                         thread = 0;
74                 }
75                 finalize_plan();
76         }
77
78         return result;
79 }
80
81 const list<Route *> &TrainRoutePlanner::get_routes_for(const Train &train) const
82 {
83         return get_train_info(train).routes;
84 }
85
86 const list<TrainRouter::SequencePoint> &TrainRoutePlanner::get_sequence_for(const Train &train) const
87 {
88         return get_train_info(train).sequence;
89 }
90
91 const TrainRoutePlanner::TrainRoutingInfo &TrainRoutePlanner::get_train_info(const Train &train) const
92 {
93         for(vector<TrainRoutingInfo>::const_iterator i=routed_trains.begin(); i!=routed_trains.end(); ++i)
94                 if(i->train==&train)
95                         return *i;
96
97         throw key_error(train.get_name());
98 }
99
100 const TrainRoutePlanner::RoutingStep &TrainRoutePlanner::get_step()
101 {
102         steps.splice(steps.end(), queue, queue.begin());
103         return steps.back();
104 }
105
106 void TrainRoutePlanner::prepare_plan()
107 {
108         steps.clear();
109         queue.clear();
110         goal = 0;
111         result = PENDING;
112
113         queue.push_back(RoutingStep());
114         RoutingStep &start = queue.back();
115         for(vector<TrainRoutingInfo>::iterator i=routed_trains.begin(); i!=routed_trains.end(); ++i)
116                 start.trains.push_back(TrainRoutingState(*i));
117         start.update_estimate();
118 }
119
120 void TrainRoutePlanner::create_plan()
121 {
122         Time::TimeStamp timeout_stamp = Time::now()+timeout;
123         unsigned count = 0;
124         while(!queue.empty())
125         {
126                 const RoutingStep &step = get_step();
127                 if(step.is_goal())
128                 {
129                         goal = &step;
130                         return;
131                 }
132
133                 add_steps(step);
134
135                 if(++count>=1000)
136                 {
137                         if(Time::now()>timeout_stamp)
138                                 break;
139                         count = 0;
140                 }
141         }
142
143         result = FAILED;
144 }
145
146 void TrainRoutePlanner::add_steps(const RoutingStep &step)
147 {
148         list<RoutingStep> new_steps;
149         step.create_successors(new_steps);
150         new_steps.sort();
151         queue.merge(new_steps);
152 }
153
154 void TrainRoutePlanner::finalize_plan()
155 {
156         for(vector<TrainRoutingInfo>::iterator i=routed_trains.begin(); i!=routed_trains.end(); ++i)
157         {
158                 i->routes.clear();
159                 i->sequence.clear();
160                 for(unsigned j=0; j<2; ++j)
161                         i->track_history[j] = 0;
162         }
163
164         map<Track *, TrainRouter::SequencePoint *> sequenced_tracks;
165         unsigned sequence = steps.size();
166         for(const RoutingStep *i=goal; i; i=i->prev)
167                 for(vector<TrainRoutingState>::const_iterator j=i->trains.begin(); j!=i->trains.end(); ++j)
168                 {
169                         Track **history = j->info->track_history;
170                         // Don't process the same track again.
171                         if(j->track.track()==history[0])
172                                 continue;
173
174                         Route *route = 0;
175                         bool start_new_route = true;
176                         if(!j->info->routes.empty())
177                         {
178                                 /* If we already have a route and this track or any linked track is
179                                 in it, start a new one to avoid loops. */
180                                 route = j->info->routes.front();
181                                 start_new_route = route->has_track(*j->track);
182                                 if(!start_new_route)
183                                 {
184                                         unsigned nls = j->track->get_n_link_slots();
185                                         for(unsigned k=0; (!start_new_route && k<nls); ++k)
186                                         {
187                                                 Track *link = j->track->get_link(k);
188                                                 start_new_route = (link && link!=history[0] && route->has_track(*link));
189                                         }
190                                 }
191                         }
192
193                         if(start_new_route)
194                         {
195                                 route = new Route(j->info->train->get_layout());
196                                 route->set_name("Router");
197                                 route->set_temporary(true);
198                                 /* Have the routes overlap by two tracks to ensure that turnout
199                                 paths can be deduced. */
200                                 for(unsigned k=0; (k<2 && history[k]); ++k)
201                                         route->add_track(*history[k]);
202                                 j->info->routes.push_front(route);
203                         }
204
205                         route->add_track(*j->track.track());
206                         history[1] = history[0];
207                         history[0] = j->track.track();
208
209                         bool waitable = j->track.endpoint().paths!=j->track->get_type().get_paths();
210                         map<Track *, TrainRouter::SequencePoint *>::iterator k = sequenced_tracks.find(j->track.track());
211                         if(k!=sequenced_tracks.end())
212                         {
213                                 // Add a sequence point if another train uses this track afterwards.
214                                 if(!k->second->preceding_train)
215                                 {
216                                         k->second->preceding_train = j->info->train;
217                                         k->second->sequence_in = sequence;
218                                 }
219                                 j->info->sequence.push_front(TrainRouter::SequencePoint(j->track->get_block(), sequence));
220                                 if(waitable)
221                                         k->second = &j->info->sequence.front();
222                                 --sequence;
223                         }
224                         else if(waitable)
225                         {
226                                 /* Create a sequence point if it's possible to wait and let another
227                                 train past. */
228                                 j->info->sequence.push_front(TrainRouter::SequencePoint(j->track->get_block(), sequence));
229                                 sequenced_tracks[j->track.track()] = &j->info->sequence.front();
230                                 --sequence;
231                         }
232                 }
233
234         result = COMPLETE;
235 }
236
237
238 TrainRoutePlanner::TrainRoutingInfo::TrainRoutingInfo(Train &t):
239         train(&t),
240         length(0),
241         speed(train->get_maximum_speed()),
242         first_noncritical(train->get_last_critical_block().next().block()),
243         router(train->get_ai_of_type<TrainRouter>()),
244         has_duration(false)
245 {
246         if(unsigned n_wps = router->get_n_waypoints())
247         {
248                 waypoints.reserve(n_wps),
249                 metrics.reserve(n_wps);
250                 for(unsigned i=0; i<n_wps; ++i)
251                 {
252                         waypoints.push_back(router->get_waypoint(i));
253                         metrics.push_back(&router->get_metric(i));
254                 }
255                 has_duration = router->get_trip_duration();
256         }
257
258         unsigned n_vehs = train->get_n_vehicles();
259         for(unsigned i=0; i<n_vehs; ++i)
260                 length += train->get_vehicle(i).get_type().get_length();
261
262         // If no maximum speed is specified, use a sensible default
263         if(!speed)
264                 speed = 20*train->get_layout().get_catalogue().get_scale();
265 }
266
267
268 TrainRoutePlanner::OccupiedTrack::OccupiedTrack(Track &t, unsigned p, OccupiedTrack *n):
269         track(&t),
270         path_length(track->get_type().get_path_length(p)),
271         next(n),
272         n_tracks(next ? next->n_tracks+1 : 1),
273         refcount(1)
274 {
275         if(next)
276                 ++next->refcount;
277 }
278
279 TrainRoutePlanner::OccupiedTrack::OccupiedTrack(const OccupiedTrack &other):
280         track(other.track),
281         path_length(other.path_length),
282         next(other.next),
283         n_tracks(other.n_tracks),
284         refcount(1)
285 {
286         if(next)
287                 ++next->refcount;
288 }
289
290 TrainRoutePlanner::OccupiedTrack::~OccupiedTrack()
291 {
292         if(next && !--next->refcount)
293                 delete next;
294 }
295
296
297 TrainRoutePlanner::TrainRoutingState::TrainRoutingState(TrainRoutingInfo &inf):
298         info(&inf),
299         critical(true),
300         occupied_tracks(0),
301         state(MOVING),
302         delay(info->router->get_departure_delay()),
303         duration(info->router->get_trip_duration()),
304         waypoint(0),
305         blocked_by(-1)
306 {
307         const Vehicle *veh = &info->train->get_vehicle(0);
308         // TODO margins
309         TrackOffsetIter track_and_offs = veh->get_placement().get_position(VehiclePlacement::FRONT_BUFFER);
310         track = track_and_offs.track_iter();
311         offset = track_and_offs.offset();
312         path = track->get_active_path();
313
314         while(Vehicle *next = veh->get_link(1))
315                 veh = next;
316         track_and_offs = veh->get_placement().get_position(VehiclePlacement::BACK_BUFFER);
317         back_offset = track_and_offs.offset();
318
319         TrackIter iter = track_and_offs.track_iter();
320         while(1)
321         {
322                 occupied_tracks = new OccupiedTrack(*iter, iter->get_active_path(), occupied_tracks);
323                 if(iter.track()==track.track())
324                         break;
325                 iter = iter.next();
326         }
327
328         update_estimate();
329 }
330
331 TrainRoutePlanner::TrainRoutingState::TrainRoutingState(const TrainRoutingState &other):
332         info(other.info),
333         track(other.track),
334         path(other.path),
335         critical(other.critical),
336         occupied_tracks(other.occupied_tracks),
337         offset(other.offset),
338         back_offset(other.back_offset),
339         state(other.state),
340         delay(other.delay),
341         duration(other.duration),
342         waypoint(other.waypoint),
343         distance_traveled(other.distance_traveled),
344         remaining_estimate(other.remaining_estimate),
345         wait_time(other.wait_time),
346         estimated_wait(other.estimated_wait),
347         blocked_by(other.blocked_by)
348 {
349         ++occupied_tracks->refcount;
350 }
351
352 TrainRoutePlanner::TrainRoutingState::~TrainRoutingState()
353 {
354         if(occupied_tracks && !--occupied_tracks->refcount)
355                 delete occupied_tracks;
356 }
357
358 Time::TimeDelta TrainRoutePlanner::TrainRoutingState::get_time_to_next_track() const
359 {
360         return ((track->get_type().get_path_length(path)-offset)/info->speed)*Time::sec+delay;
361 }
362
363 Time::TimeDelta TrainRoutePlanner::TrainRoutingState::get_time_to_pass(Track &trk) const
364 {
365         if(is_occupying(trk))
366         {
367                 float passed_length = 0;
368                 for(const OccupiedTrack *occ=occupied_tracks; (occ && occ->track!=&trk); occ=occ->next)
369                         passed_length += occ->path_length;
370                 return (max(info->length-passed_length, 0.0f)/info->speed)*Time::sec+delay;
371         }
372
373         for(unsigned wp=waypoint; wp<info->waypoints.size(); ++wp)
374         {
375                 float distance = info->metrics[wp]->get_distance_from(trk);
376                 if(distance>=0 && distance<remaining_estimate)
377                         return ((remaining_estimate-distance+info->length)/info->speed)*Time::sec+delay;
378         }
379
380         return Time::day;
381 }
382
383 bool TrainRoutePlanner::TrainRoutingState::is_occupying(Track &trk) const
384 {
385         if(state==ARRIVED && !duration && info->has_duration)
386                 return false;
387
388         OccupiedTrack *occ = occupied_tracks;
389         for(unsigned n=occ->n_tracks; n>0; --n, occ=occ->next)
390                 if(occ->track==&trk)
391                         return true;
392         return false;
393 }
394
395 bool TrainRoutePlanner::TrainRoutingState::check_arrival()
396 {
397         TrackIter next_track = track.next(path);
398
399         // Check if we're about the exit the current waypoint's tracks.
400         const TrainRouter::Waypoint &wp = info->waypoints[waypoint];
401         if(wp.chain->has_track(*track) && !wp.chain->has_track(*next_track))
402                 if(wp.direction==TrackChain::UNSPECIFIED || track==wp.chain->iter_for(*track, wp.direction))
403                 {
404                         if(waypoint+1<info->waypoints.size())
405                                 ++waypoint;
406                         else
407                         {
408                                 state = ARRIVED;
409                                 return true;
410                         }
411                 }
412
413         // If we're entering the first non-critical block, clear the critical flag.
414         if(info->first_noncritical->has_track(*next_track))
415                 critical = false;
416
417         return false;
418 }
419
420 void TrainRoutePlanner::TrainRoutingState::advance(float distance)
421 {
422         offset += distance;
423         back_offset += distance;
424
425         // See if the tail end of the train has passed any sensors.
426         unsigned count_to_free = 0;
427         unsigned last_sensor_addr = 0;
428         float distance_after_sensor = 0;
429         OccupiedTrack *occ = occupied_tracks;
430         for(unsigned n=occupied_tracks->n_tracks; n>0; --n)
431         {
432                 if(unsigned saddr = occ->track->get_sensor_address())
433                 {
434                         if(saddr!=last_sensor_addr)
435                         {
436                                 count_to_free = 0;
437                                 distance_after_sensor = 0;
438                         }
439                         last_sensor_addr = saddr;
440                 }
441
442                 ++count_to_free;
443                 distance_after_sensor += occ->path_length;
444
445                 occ = occ->next;
446         }
447
448         // Free the last passed sensor and any tracks behind it.
449         if(count_to_free && back_offset>distance_after_sensor)
450         {
451                 back_offset -= distance_after_sensor;
452                 if(occupied_tracks->refcount>1)
453                 {
454                         --occupied_tracks->refcount;
455                         occupied_tracks = new OccupiedTrack(*occupied_tracks);
456                 }
457                 occupied_tracks->n_tracks -= count_to_free;
458         }
459
460         distance_traveled += distance;
461         remaining_estimate -= distance;
462 }
463
464 void TrainRoutePlanner::TrainRoutingState::advance(const Time::TimeDelta &dt)
465 {
466         if(delay>=dt)
467         {
468                 delay -= dt;
469                 return;
470         }
471
472         float secs = dt/Time::sec;
473         // There may be negative delay remaining after previous step.
474         if(delay)
475         {
476                 secs -= delay/Time::sec;
477                 delay = Time::zero;
478         }
479
480         if(duration)
481                 duration = max(duration-secs*Time::sec, Time::zero);
482
483         if(estimated_wait)
484                 estimated_wait = max(estimated_wait-secs*Time::sec, Time::zero);
485
486         if(state==MOVING)
487                 advance(info->speed*secs);
488         else if(state!=ARRIVED)
489                 wait_time += secs*Time::sec;
490 }
491
492 void TrainRoutePlanner::TrainRoutingState::advance_track(unsigned next_path)
493 {
494         float distance = occupied_tracks->path_length-offset;
495         track = track.next(path);
496         path = next_path;
497         occupied_tracks = new OccupiedTrack(*track, path, occupied_tracks);
498         advance(distance);
499         offset = 0;
500 }
501
502 void TrainRoutePlanner::TrainRoutingState::update_estimate()
503 {
504         TrackIter iter = track.reverse(path);
505         remaining_estimate = info->metrics[waypoint]->get_distance_from(*iter.track(), iter.entry());
506         if(remaining_estimate>=0)
507                 remaining_estimate += track->get_type().get_path_length(path)-offset;
508 }
509
510 bool TrainRoutePlanner::TrainRoutingState::is_viable() const
511 {
512         if(remaining_estimate<0)
513                 return false;
514         if(critical && state==BLOCKED)
515                 return false;
516         return true;
517 }
518
519
520 TrainRoutePlanner::RoutingStep::RoutingStep():
521         prev(0)
522 { }
523
524 TrainRoutePlanner::RoutingStep::RoutingStep(const RoutingStep *p):
525         time(p->time),
526         penalty(p->penalty),
527         cost_estimate(p->cost_estimate),
528         trains(p->trains),
529         prev(p)
530 { }
531
532 void TrainRoutePlanner::RoutingStep::create_successors(list<RoutingStep> &new_steps) const
533 {
534         RoutingStep next(this);
535         if(next.update_states() && next.check_deadlocks())
536                 return;
537
538         int train_index = find_next_train();
539         if(train_index<0)
540                 return;
541
542         TrainRoutingState &train = next.trains[train_index];
543
544         Time::TimeDelta dt = train.get_time_to_next_track();
545         next.advance(dt);
546
547         /* Check arrival after the train has advanced to the end of its current track
548         so travel time and occupied tracks will be correct. */
549         if(train.check_arrival())
550         {
551                 new_steps.push_back(next);
552                 return;
553         }
554
555         train.advance_track(0);
556
557         const TrackType::Endpoint &entry_ep = train.track.endpoint();
558         if(train.critical)
559         {
560                 /* Only create a successor step matching the currently set path for a
561                 critical track. */
562                 unsigned critical_path = train.track->get_type().coerce_path(train.track.entry(), train.track->get_active_path());
563                 create_successor(next, train_index, critical_path, new_steps);
564         }
565         else
566         {
567                 // Create successor steps for all possible paths through the new track.
568                 for(unsigned i=0; entry_ep.paths>>i; ++i)
569                         if(entry_ep.has_path(i))
570                                 create_successor(next, train_index, i, new_steps);
571         }
572
573         new_steps.sort();
574         for(list<RoutingStep>::iterator i=new_steps.begin(); ++i!=new_steps.end(); )
575         {
576                 i->penalty += 5*Time::sec;
577                 i->update_estimate();
578         }
579
580         if(entry_ep.paths!=train.track->get_type().get_paths() && !train.critical)
581         {
582                 /* Create a waiting state before the track if there's at least one path
583                 that doesn't pass through the entry endpoint. */
584                 RoutingStep wait(this);
585                 wait.advance(dt);
586                 wait.trains[train_index].state = WAITING;
587
588                 Time::TimeDelta estimated_wait = Time::day;
589                 for(unsigned i=0; i<wait.trains.size(); ++i)
590                         if(i!=static_cast<unsigned>(train_index) && wait.trains[i].state!=ARRIVED)
591                         {
592                                 Time::TimeDelta ttp = wait.trains[i].get_time_to_pass(*train.track);
593                                 estimated_wait = min(estimated_wait, ttp);
594                         }
595                 wait.trains[train_index].estimated_wait = estimated_wait;
596
597                 wait.update_estimate();
598                 if(wait.is_viable())
599                         new_steps.push_back(wait);
600         }
601 }
602
603 void TrainRoutePlanner::RoutingStep::create_successor(RoutingStep &next, unsigned train_index, unsigned path, list<RoutingStep> &new_steps)
604 {
605         TrainRoutingState &train = next.trains[train_index];
606
607         train.path = path;
608         train.update_estimate();
609         next.update_estimate();
610         if(next.is_viable())
611                 new_steps.push_back(next);
612 }
613
614 bool TrainRoutePlanner::RoutingStep::update_states()
615 {
616         bool changes = false;
617         for(vector<TrainRoutingState>::iterator i=trains.begin(); i!=trains.end(); ++i)
618         {
619                 if(i->state==ARRIVED)
620                         continue;
621
622                 TrainState old_state = i->state;
623
624                 TrackIter next_track = i->track.next(i->path);
625                 if(next_track)
626                 {
627                         i->blocked_by = get_occupant(*next_track);
628                         if(i->blocked_by>=0)
629                         {
630                                 /* If the train is still traversing its last critical track, the
631                                 flag needs to be cleared here to pass viability test. */
632                                 if(i->info->first_noncritical->has_track(*next_track))
633                                         i->critical = false;
634
635                                 if(i->state!=BLOCKED)
636                                         i->estimated_wait = trains[i->blocked_by].get_time_to_pass(*next_track);
637
638                                 /* Trains in the WAITING state will also transition to BLOCKED and
639                                 then to MOVING when the other train has passed. */
640                                 i->state = BLOCKED;
641                         }
642                         else if(i->state==BLOCKED)
643                         {
644                                 i->estimated_wait = Time::zero;
645                                 i->state = MOVING;
646                         }
647                 }
648                 else
649                         i->state = BLOCKED;
650
651                 if(i->state!=old_state)
652                         changes = true;
653         }
654
655         return changes;
656 }
657
658 bool TrainRoutePlanner::RoutingStep::check_deadlocks() const
659 {
660         for(vector<TrainRoutingState>::const_iterator i=trains.begin(); i!=trains.end(); ++i)
661         {
662                 if(i->state!=BLOCKED)
663                         continue;
664
665                 // A train blocked by end of track is always considered a deadlock.
666                 if(i->blocked_by<0)
667                         return true;
668
669                 /* Use the tortoise and hare algorithm to check if trains are blocked
670                 cyclically (A blocks B, which blocks ..., which blocks A). */
671                 int slow = i->blocked_by;
672                 int fast = trains[slow].blocked_by;
673                 while(fast>=0 && trains[fast].blocked_by>=0)
674                 {
675                         if(fast==slow)
676                                 return true;
677
678                         slow = trains[slow].blocked_by;
679                         fast = trains[trains[fast].blocked_by].blocked_by;
680                 }
681         }
682
683         return false;
684 }
685
686 int TrainRoutePlanner::RoutingStep::get_occupant(Track &track) const
687 {
688         for(unsigned i=0; i<trains.size(); ++i)
689                 if(trains[i].is_occupying(track))
690                         return i;
691
692         return -1;
693 }
694
695 int TrainRoutePlanner::RoutingStep::find_next_train() const
696 {
697         Time::TimeDelta min_dt;
698         int next_train = -1;
699         for(unsigned i=0; i<trains.size(); ++i)
700                 if(trains[i].state==MOVING)
701                 {
702                         Time::TimeDelta dt = trains[i].get_time_to_next_track();
703                         if(dt<min_dt || next_train<0)
704                         {
705                                 min_dt = dt;
706                                 next_train = i;
707                         }
708                 }
709
710         return next_train;
711 }
712
713 void TrainRoutePlanner::RoutingStep::advance(const Time::TimeDelta &dt)
714 {
715         time += dt;
716         for(vector<TrainRoutingState>::iterator i=trains.begin(); i!=trains.end(); ++i)
717                 i->advance(dt);
718 }
719
720 void TrainRoutePlanner::RoutingStep::update_estimate()
721 {
722         cost_estimate = penalty;
723         for(vector<TrainRoutingState>::const_iterator i=trains.begin(); i!=trains.end(); ++i)
724                 if(i->remaining_estimate>=0)
725                         cost_estimate += i->wait_time+i->estimated_wait+((i->distance_traveled+i->remaining_estimate)/i->info->speed)*Time::sec;
726 }
727
728 bool TrainRoutePlanner::RoutingStep::is_viable() const
729 {
730         for(vector<TrainRoutingState>::const_iterator i=trains.begin(); i!=trains.end(); ++i)
731                 if(!i->is_viable())
732                         return false;
733
734         for(vector<TrainRoutingState>::const_iterator i=trains.begin(); i!=trains.end(); ++i)
735                 if(i->state==MOVING)
736                         return true;
737
738         return false;
739 }
740
741 bool TrainRoutePlanner::RoutingStep::is_goal() const
742 {
743         for(vector<TrainRoutingState>::const_iterator i=trains.begin(); i!=trains.end(); ++i)
744                 if(i->state!=ARRIVED)
745                         return false;
746         return true;
747 }
748
749 bool TrainRoutePlanner::RoutingStep::operator<(const RoutingStep &other) const
750 {
751         return cost_estimate<other.cost_estimate;
752 }
753
754
755 TrainRoutePlanner::PlanningThread::PlanningThread(TrainRoutePlanner &p):
756         planner(p)
757 {
758         launch();
759 }
760
761 void TrainRoutePlanner::PlanningThread::main()
762 {
763         planner.create_plan();
764 }
765
766 } // namespace R2C2