]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/trainrouteplanner.cpp
Penalize steps other than the fastest one
[r2c2.git] / source / libr2c2 / trainrouteplanner.cpp
index 163bb281eacd019997e8975802f670a0d904ce6f..dbe6035499c9e61663b2f6337448c35e5518b9d2 100644 (file)
@@ -427,6 +427,7 @@ TrainRoutePlanner::RoutingStep::RoutingStep():
 
 TrainRoutePlanner::RoutingStep::RoutingStep(const RoutingStep *p):
        time(p->time),
+       penalty(p->penalty),
        cost_estimate(p->cost_estimate),
        trains(p->trains),
        prev(p)
@@ -473,11 +474,20 @@ void TrainRoutePlanner::RoutingStep::create_successors(list<RoutingStep> &new_st
                                new_steps.push_back(next);
                }
 
+       new_steps.sort();
+       for(list<RoutingStep>::iterator i=new_steps.begin(); ++i!=new_steps.end(); )
+       {
+               i->penalty += 5*Time::sec;
+               i->update_estimate();
+       }
+
        if(next_entry_ep.paths!=next_track->get_type().get_paths())
        {
                RoutingStep wait(this);
                wait.advance(dt);
                wait.trains[train_index].state = WAITING;
+               wait.penalty += 15*Time::sec;
+               wait.update_estimate();
                if(wait.is_viable())
                        new_steps.push_back(wait);
        }
@@ -573,7 +583,7 @@ void TrainRoutePlanner::RoutingStep::advance(const Time::TimeDelta &dt)
 
 void TrainRoutePlanner::RoutingStep::update_estimate()
 {
-       cost_estimate = Time::zero;
+       cost_estimate = penalty;
        for(vector<TrainRoutingState>::const_iterator i=trains.begin(); i!=trains.end(); ++i)
                if(i->remaining_estimate>=0)
                        cost_estimate += i->wait_time+((i->distance_traveled+i->remaining_estimate)/i->info->speed)*Time::sec;