]> git.tdb.fi Git - r2c2.git/commitdiff
Avoid unnecessary wait time with shared destinations
authorMikko Rasa <tdb@tdb.fi>
Tue, 24 Mar 2015 10:28:40 +0000 (12:28 +0200)
committerMikko Rasa <tdb@tdb.fi>
Tue, 24 Mar 2015 17:24:22 +0000 (19:24 +0200)
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.

source/libr2c2/trainrouteplanner.cpp

index 476d102617ff1045658d80391f73cf1f4ccedfee..7aba4a68ed33e7ba0e3e434e655da77bd1dd02b9 100644 (file)
@@ -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; i<trains.size(); ++i)
+       {
+               Time::TimeDelta dt;
                if(trains[i].state==MOVING || (trains[i].state==BLOCKED && prev && prev->trains[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<min_dt || next_train<0)
                {
-                       Time::TimeDelta dt = trains[i].get_time_to_next_track();
-                       if(dt<min_dt || next_train<0)
-                       {
-                               min_dt = dt;
-                               next_train = i;
-                       }
+                       min_dt = dt;
+                       next_train = i;
                }
+       }
 
        return next_train;
 }