#include "layout.h"
#include "route.h"
#include "train.h"
+#include "trainroutemetric.h"
#include "trainrouteplanner.h"
#include "trainrouter.h"
#include "vehicle.h"
break;
iter = iter.next();
}
+
+ update_estimate();
}
TrainRoutePlanner::TrainRoutingState::TrainRoutingState(const TrainRoutingState &other):
state(other.state),
delay(other.delay),
waypoint(other.waypoint),
+ remaining_estimate(other.remaining_estimate),
blocked_by(other.blocked_by)
{
++occupied_tracks->refcount;
}
--occupied_tracks->n_tracks;
}
+
+ remaining_estimate -= (distance/info->speed)*Time::sec;
+ if(remaining_estimate<Time::zero)
+ remaining_estimate = Time::zero;
}
void TrainRoutePlanner::TrainRoutingState::advance_track(unsigned next_path)
offset = 0;
}
+void TrainRoutePlanner::TrainRoutingState::update_estimate()
+{
+ TrackIter iter = track.reverse(path);
+ float distance = info->router->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)
TrainRoutePlanner::RoutingStep::RoutingStep(const RoutingStep *p):
time(p->time),
+ total_estimate(p->total_estimate),
trains(p->trains),
prev(p)
{ }
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);
}
}
}
+void TrainRoutePlanner::RoutingStep::update_estimate()
+{
+ for(vector<TrainRoutingState>::const_iterator i=trains.begin(); i!=trains.end(); ++i)
+ {
+ if(i->remaining_estimate<Time::zero)
+ {
+ total_estimate = i->remaining_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<Time::zero)
+ return false;
+
for(vector<TrainRoutingState>::const_iterator i=trains.begin(); i!=trains.end(); ++i)
if(i->state==MOVING)
return true;
bool TrainRoutePlanner::RoutingStep::operator<(const RoutingStep &other) const
{
- return time<other.time;
+ return total_estimate<other.total_estimate;
}
} // namespace R2C2