Ejemplo n.º 1
0
        public TrainPathData(Timetable tt, ITrain train) : base(tt)
        {
            var path    = train.GetPath().ToArray();
            var arrDeps = train.GetArrDepsUnsorted();

            Entries = Init(path, (s, r) =>
            {
                arrDeps.TryGetValue(s, out var ardp);
                return(new TrainPathEntry(s, ardp, r));
            });
            PathEntries = Entries.OfType <TrainPathEntry>().ToArray();
        }
Ejemplo n.º 2
0
        private IEnumerable <Station> GetSortedStations(ITrain train)
        {
            var path    = train.GetPath();
            var arrdeps = train.GetArrDepsUnsorted();

            foreach (var sta in path)
            {
                if (arrdeps[sta].HasMinOneTimeSet)
                {
                    yield return(sta);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Get the direction the train passes through this station.
        /// </summary>
        /// <remarks>This direction may differ from train to train (at the same station) and from station to station (with the same train).</remarks>
        /// <returns>If null, the train does not pass through this station.</returns>
        public TrainDirection?GetTrainDirectionAtStation(ITrain train, Station sta)
        {
            var stasAfter  = GetStationsInDir(TrainDirection.ti, sta);
            var stasBefore = GetStationsInDir(TrainDirection.ta, sta);

            var path = train.GetPath();

            if (!path.Contains(sta))
            {
                return(null);
            }

            var ardeps     = train.GetArrDepsUnsorted();
            var isStopping = ardeps[sta].HasMinOneTimeSet;

            Station?nextStopStation = path.Where(s => stasAfter.Contains(s)).FirstOrDefault(s => ardeps[s].HasMinOneTimeSet);
            Station?lastStopStation = null;

            if (nextStopStation == null || !isStopping)
            {
                lastStopStation = path.Where(s => stasBefore.Contains(s)).FirstOrDefault(s => ardeps[s].HasMinOneTimeSet);
            }

            // We have a stop at this station, use time difference between first/last and current.
            if (isStopping)
            {
                if (nextStopStation == null)
                {
                    if (lastStopStation == null)
                    {
                        return(null);
                    }
                    var lastStopTime = ardeps[lastStopStation].LastSetTime;
                    return(lastStopTime < ardeps[sta].FirstSetTime ? TrainDirection.ti : TrainDirection.ta);
                }

                var nextStopTime = ardeps[nextStopStation].FirstSetTime;
                return(nextStopTime > ardeps[sta].LastSetTime ? TrainDirection.ti : TrainDirection.ta);
            }

            if (lastStopStation == null || nextStopStation == null)
            {
                return(null); // We are (proven!) not running over this station.
            }
            // Passthrough, use difference between first and last
            return(ardeps[nextStopStation].FirstSetTime > ardeps[lastStopStation].LastSetTime ? TrainDirection.ti : TrainDirection.ta);
        }
Ejemplo n.º 4
0
        public IStation[] GetStations(ITrain train)
        {
            List <IStation> points    = new List <IStation>();
            var             fstations = train.GetPath().Where(s => filterable.LoadStationRules(tt).All(r => !r.Matches(s))); // Filter

            points.AddRange(fstations);

            var p = attrs?.Points ?? new List <BfplPoint>();

            for (int i = 0; i < points.Count; i++)
            {
                var sta0 = points[i];
                if (sta0 == points.Last())
                {
                    break; // Hier ist die Strecke zuende
                }
                var sta1 = points[i + 1];

                int route = Timetable.LINEAR_ROUTE_ID;
                if (tt.Type == TimetableType.Network)
                {
                    var routes = sta0.Routes.Where(r => sta1.Routes.Contains(r)).ToArray();
                    if (routes.Length > 1 || routes.Length == 0)
                    {
                        throw new Exception(T._("Zwei benachbarte Stationen sollten nicht mehr als eine/keine Route gemeinsam haben! Zusammengefallene Routen sind vorhanden und werden nicht unterstützt."));
                    }
                    route = routes[0];
                }

                var maxPos = Math.Max(sta0.Positions.GetPosition(route).Value, sta1.Positions.GetPosition(route).Value);
                var minPos = Math.Min(sta0.Positions.GetPosition(route).Value, sta1.Positions.GetPosition(route).Value);

                var p1            = tt.Type == TimetableType.Network ? p.Where(po => po.Routes.Contains(route)) : p;
                var pointsBetween = p1.Where(po => po.Positions.GetPosition(route) > minPos && po.Positions.GetPosition(route) < maxPos).ToArray();
                points.InsertRange(points.IndexOf(sta0) + 1, pointsBetween);
                i += pointsBetween.Length;
            }
            return(points.ToArray());
        }
Ejemplo n.º 5
0
 /// <inheritdoc />
 public List <Station> GetPath() => baseTrain.GetPath();
Ejemplo n.º 6
0
        private string BuildPath(ITrain t)
        {
            var path = t.GetPath();

            return(path.FirstOrDefault()?.SName + " - " + path.LastOrDefault()?.SName);
        }