if(info.router && info.router->get_destination())
routed_trains.push_back(info);
}
+}
+
+void TrainRoutePlanner::plan()
+{
+ steps.clear();
+ queue.clear();
queue.push_back(RoutingStep());
RoutingStep &start = queue.back();
for(vector<TrainRoutingInfo>::iterator i=routed_trains.begin(); i!=routed_trains.end(); ++i)
start.trains.push_back(TrainRoutingState(*i));
start.update_estimate();
-}
-void TrainRoutePlanner::plan()
-{
const RoutingStep *goal = 0;
while(!queue.empty())
{
{
for(vector<TrainRoutingInfo>::iterator i=routed_trains.begin(); i!=routed_trains.end(); ++i)
{
- Route *route = new Route(i->train->get_layout());
- route->set_name("Router");
- route->set_temporary(true);
- i->routes.push_front(route);
-
+ i->routes.clear();
+ i->sequence.clear();
for(unsigned j=0; j<3; ++j)
i->track_history[j] = 0;
}
if(j->track.track()==history[0])
continue;
- Route *route = j->info->routes.front();
- bool start_new_route = route->has_track(*j->track);
- if(!start_new_route)
+ Route *route = 0;
+ bool start_new_route = true;
+ if(!j->info->routes.empty())
{
- unsigned nls = j->track->get_n_link_slots();
- for(unsigned k=0; (!start_new_route && k<nls); ++k)
+ route = j->info->routes.front();
+ start_new_route = route->has_track(*j->track);
+ if(!start_new_route)
{
- Track *link = j->track->get_link(k);
- start_new_route = (link && link!=history[0] && route->has_track(*link));
+ unsigned nls = j->track->get_n_link_slots();
+ for(unsigned k=0; (!start_new_route && k<nls); ++k)
+ {
+ Track *link = j->track->get_link(k);
+ start_new_route = (link && link!=history[0] && route->has_track(*link));
+ }
}
}
route->set_name("Router");
route->set_temporary(true);
for(unsigned k=2; k>0; --k)
- route->add_track(*history[k]);
+ if(history[k])
+ route->add_track(*history[k]);
j->info->routes.push_front(route);
}