X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Flibr2c2%2Ftrainrouteplanner.cpp;h=22ac5400ea4fb050437ccdff14de77dbafc483e9;hb=b42a312323d36775ab550630b3ee818c3b948bf6;hp=3f8739347d455405f1f2a6fef03c6b2c02c5e3a9;hpb=3d5779e12351547dded382f2d05d3f3f037dbcfd;p=r2c2.git diff --git a/source/libr2c2/trainrouteplanner.cpp b/source/libr2c2/trainrouteplanner.cpp index 3f87393..22ac540 100644 --- a/source/libr2c2/trainrouteplanner.cpp +++ b/source/libr2c2/trainrouteplanner.cpp @@ -21,36 +21,44 @@ TrainRoutePlanner::TrainRoutePlanner(Layout &layout) routed_trains.push_back(info); } - steps.push_back(RoutingStep()); - RoutingStep &start = steps.back(); + queue.push_back(RoutingStep()); + RoutingStep &start = queue.back(); for(vector::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::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 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)