From: Mikko Rasa Date: Tue, 24 Mar 2015 10:28:40 +0000 (+0200) Subject: Avoid unnecessary wait time with shared destinations X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=9ee88e5028953444d363047b8aab179b833a3e4a;p=r2c2.git Avoid unnecessary wait time with shared destinations If a train gets blocked by another train which has already arrived but has a trip duration, a step must be processed when the blocking train departs again. Otherwise the next step might be a long time off (in case all other trains have long departure delays) and would get an overly inflated cost. --- diff --git a/source/libr2c2/trainrouteplanner.cpp b/source/libr2c2/trainrouteplanner.cpp index 476d102..7aba4a6 100644 --- a/source/libr2c2/trainrouteplanner.cpp +++ b/source/libr2c2/trainrouteplanner.cpp @@ -367,13 +367,16 @@ TrainRoutePlanner::TrainRoutingState::~TrainRoutingState() Time::TimeDelta TrainRoutePlanner::TrainRoutingState::get_time_to_next_track() const { - return ((occupied_tracks->path_length-offset)/info->speed)*Time::sec+delay; + return ((occupied_tracks->path_length-offset)/info->speed)*Time::sec+delay+estimated_wait; } Time::TimeDelta TrainRoutePlanner::TrainRoutingState::get_time_to_pass(Track &trk) const { if(is_occupying(trk)) { + if(state==ARRIVED && info->has_duration) + return duration; + float passed_length = 0; for(const OccupiedTrack *occ=occupied_tracks; (occ && occ->track!=&trk); occ=occ->next) passed_length += occ->path_length; @@ -734,15 +737,21 @@ int TrainRoutePlanner::RoutingStep::find_next_train() const Time::TimeDelta min_dt; int next_train = -1; for(unsigned i=0; itrains[i].state==MOVING)) + dt = trains[i].get_time_to_next_track(); + else if(trains[i].state==BLOCKED && trains[trains[i].blocked_by].state==ARRIVED) + dt = trains[i].estimated_wait; + else + continue; + + if(dt