X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Ftrainrouteplanner.cpp;h=d9eedd2d4daccd0d33224548325c594859c7777a;hb=cac4176a9685e8b39147d1e18d969b3bee052b03;hp=e42e61838d4fdc0c7dfa74fe2aa7b451211c8421;hpb=54cb832334a83fc266b59e2c9b60ee936db7118f;p=r2c2.git diff --git a/source/libr2c2/trainrouteplanner.cpp b/source/libr2c2/trainrouteplanner.cpp index e42e618..d9eedd2 100644 --- a/source/libr2c2/trainrouteplanner.cpp +++ b/source/libr2c2/trainrouteplanner.cpp @@ -16,6 +16,7 @@ namespace R2C2 { TrainRoutePlanner::TrainRoutePlanner(Layout &layout): goal(0), + path_switch_bias(15*Time::sec), timeout(10*Time::sec), result(PENDING), thread(0) @@ -147,7 +148,12 @@ void TrainRoutePlanner::add_steps(const RoutingStep &step) { list new_steps; step.create_successors(new_steps); + if(new_steps.empty()) + return; + new_steps.sort(); + if(!queue.empty() && new_steps.front().cost_estimatetime), - penalty(p->penalty), cost_estimate(p->cost_estimate), + preferred(false), trains(p->trains), prev(p) { } @@ -570,13 +577,6 @@ void TrainRoutePlanner::RoutingStep::create_successors(list &new_st create_successor(next, train_index, i, new_steps); } - new_steps.sort(); - for(list::iterator i=new_steps.begin(); ++i!=new_steps.end(); ) - { - i->penalty += 5*Time::sec; - i->update_estimate(); - } - if(entry_ep.paths!=train.track->get_type().get_paths() && !train.critical) { /* Create a waiting state before the track if there's at least one path @@ -719,7 +719,7 @@ void TrainRoutePlanner::RoutingStep::advance(const Time::TimeDelta &dt) void TrainRoutePlanner::RoutingStep::update_estimate() { - cost_estimate = penalty; + cost_estimate = Time::zero; for(vector::const_iterator i=trains.begin(); i!=trains.end(); ++i) if(i->remaining_estimate>=0) cost_estimate += i->wait_time+i->estimated_wait+((i->distance_traveled+i->remaining_estimate)/i->info->speed)*Time::sec; @@ -748,6 +748,8 @@ bool TrainRoutePlanner::RoutingStep::is_goal() const bool TrainRoutePlanner::RoutingStep::operator<(const RoutingStep &other) const { + if(preferred!=other.preferred) + return preferred>other.preferred; return cost_estimate