X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Ftrainrouteplanner.cpp;h=9ba860be29cd765a1ade273779a040e2ccbdcfff;hb=d578d036656c0e89fe9dca5aefd1f81d2777a69e;hp=22ac5400ea4fb050437ccdff14de77dbafc483e9;hpb=b42a312323d36775ab550630b3ee818c3b948bf6;p=r2c2.git diff --git a/source/libr2c2/trainrouteplanner.cpp b/source/libr2c2/trainrouteplanner.cpp index 22ac540..9ba860b 100644 --- a/source/libr2c2/trainrouteplanner.cpp +++ b/source/libr2c2/trainrouteplanner.cpp @@ -2,6 +2,7 @@ #include "layout.h" #include "route.h" #include "train.h" +#include "trainroutemetric.h" #include "trainrouteplanner.h" #include "trainrouter.h" #include "vehicle.h" @@ -164,6 +165,8 @@ TrainRoutePlanner::TrainRoutingState::TrainRoutingState(TrainRoutingInfo &inf): break; iter = iter.next(); } + + update_estimate(); } TrainRoutePlanner::TrainRoutingState::TrainRoutingState(const TrainRoutingState &other): @@ -176,6 +179,7 @@ TrainRoutePlanner::TrainRoutingState::TrainRoutingState(const TrainRoutingState state(other.state), delay(other.delay), waypoint(other.waypoint), + remaining_estimate(other.remaining_estimate), blocked_by(other.blocked_by) { ++occupied_tracks->refcount; @@ -241,6 +245,10 @@ void TrainRoutePlanner::TrainRoutingState::advance(float distance) } --occupied_tracks->n_tracks; } + + remaining_estimate -= (distance/info->speed)*Time::sec; + if(remaining_estimaterouter->get_metric(waypoint).get_distance_from(*iter.track(), iter.entry()); + distance += track->get_type().get_path_length(path)-offset; + remaining_estimate = (distance/info->speed)*Time::sec+delay; +} + TrainRoutePlanner::RoutingStep::RoutingStep(): prev(0) @@ -260,6 +276,7 @@ TrainRoutePlanner::RoutingStep::RoutingStep(): TrainRoutePlanner::RoutingStep::RoutingStep(const RoutingStep *p): time(p->time), + total_estimate(p->total_estimate), trains(p->trains), prev(p) { } @@ -299,6 +316,8 @@ void TrainRoutePlanner::RoutingStep::create_successors(list &new_st if(next_entry_ep.has_path(i)) { train.path = i; + train.update_estimate(); + next.update_estimate(); if(next.is_viable()) new_steps.push_back(next); } @@ -411,8 +430,27 @@ void TrainRoutePlanner::RoutingStep::advance(const Time::TimeDelta &dt) } } +void TrainRoutePlanner::RoutingStep::update_estimate() +{ + for(vector::const_iterator i=trains.begin(); i!=trains.end(); ++i) + { + if(i->remaining_estimateremaining_estimate; + return; + } + + Time::TimeDelta t = time+i->remaining_estimate; + if(i==trains.begin() || t>total_estimate) + total_estimate = t; + } +} + bool TrainRoutePlanner::RoutingStep::is_viable() const { + if(total_estimate::const_iterator i=trains.begin(); i!=trains.end(); ++i) if(i->state==MOVING) return true; @@ -430,7 +468,7 @@ bool TrainRoutePlanner::RoutingStep::is_goal() const bool TrainRoutePlanner::RoutingStep::operator<(const RoutingStep &other) const { - return time