]> git.tdb.fi Git - r2c2.git/commitdiff
Penalize steps other than the fastest one
authorMikko Rasa <tdb@tdb.fi>
Thu, 5 Feb 2015 08:48:48 +0000 (10:48 +0200)
committerMikko Rasa <tdb@tdb.fi>
Thu, 5 Feb 2015 08:48:48 +0000 (10:48 +0200)
This encourages the planner to follow a single chain of steps and avoids
exploding the state tree too much.  In the future this may be replaced by
different speed limits on diverging paths of turnouts (reducing the
ambiguity of fastest path) and an actual heuristic for potential wait time
(giving wait states an implicit penalty).

source/libr2c2/trainrouteplanner.cpp
source/libr2c2/trainrouteplanner.h

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;
index fa97920e4d02730469ab1d5a190377891cf63126..85a748c204099bd4e5cff2947ce5962a687528a1 100644 (file)
@@ -98,6 +98,7 @@ private:
        struct RoutingStep
        {
                Msp::Time::TimeDelta time;
+               Msp::Time::TimeDelta penalty;
                Msp::Time::TimeDelta cost_estimate;
                std::vector<TrainRoutingState> trains;
                const RoutingStep *prev;