routed_trains.push_back(info);
}
- steps.push_back(RoutingStep());
- RoutingStep &start = steps.back();
+ 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;
- for(list<RoutingStep>::iterator i=steps.begin(); i!=steps.end(); ++i)
+ while(!queue.empty())
{
- if(i->is_goal())
+ const RoutingStep &step = get_step();
+ if(step.is_goal())
{
- goal = &*i;
+ goal = &step;
break;
}
- add_steps(*i);
+ add_steps(step);
}
if(goal)
create_routes(*goal);
}
+const TrainRoutePlanner::RoutingStep &TrainRoutePlanner::get_step()
+{
+ steps.splice(steps.end(), queue, queue.begin());
+ return steps.back();
+}
+
void TrainRoutePlanner::add_steps(const RoutingStep &step)
{
list<RoutingStep> new_steps;
step.create_successors(new_steps);
new_steps.sort();
- steps.merge(new_steps);
+ queue.merge(new_steps);
}
void TrainRoutePlanner::create_routes(const RoutingStep &goal)
std::vector<TrainRoutingInfo> routed_trains;
std::list<RoutingStep> steps;
+ std::list<RoutingStep> queue;
public:
TrainRoutePlanner(Layout &);
void plan();
private:
+ const RoutingStep &get_step();
void add_steps(const RoutingStep &);
void create_routes(const RoutingStep &);
};