コード例 #1
0
        private (bool success, ResolvedStop to, IncludedAssociation association) AssociationComesFrom(Station origin, Time arrivalTime, ResolvedServiceWithAssociations service)
        {
            foreach (var association in service.Associations.Where(a => !a.IsCancelled))
            {
                if (association.IsJoin)
                {
                    var foundInAssociated = JoinComesFrom(association);
                    if (foundInAssociated.success)
                    {
                        return(foundInAssociated);
                    }
                }

                if (association.IsSplit)
                {
                    var foundInAssociated = SplitComesFrom(association);
                    if (foundInAssociated.success)
                    {
                        return(foundInAssociated);
                    }
                }
            }
            return(false, null, IncludedAssociation.NoAssociation);

            (bool success, ResolvedStop to, IncludedAssociation association) JoinComesFrom(ResolvedAssociation association)
            {
                if (association.IsAssociated(Service.TimetableUid))
                {
                    return(false, null, null);   // We're already on the join so cannot come from main
                }
                var main     = association.Details.Main;
                var joinStop = Service.GetStop(main.AtLocation, main.Sequence);

                if (joinStop.IsAfter(arrivalTime, true))
                {
                    return(false, null, null);   // We're past the join stop
                }
                var lastStop    = association.AssociatedService.Destination;
                var joinArrives = lastStop.StopArrival;

                var(success, to) = lastStop.ComesFrom(origin, joinArrives.Time);
                return(success,
                       to,
                       success ? new IncludedAssociation(association.AssociatedService.TimetableUid)  : IncludedAssociation.NoAssociation);
            }

            (bool success, ResolvedStop to, IncludedAssociation association) SplitComesFrom(ResolvedAssociation association)
            {
                if (association.IsMain(Service.TimetableUid))
                {
                    return(false, null, null);   // We're on the main, fail as split not possible
                }
                var main         = association.Details.Main;
                var splitStop    = association.AssociatedService.GetStop(main.AtLocation, main.Sequence);
                var splitArrival = splitStop.StopArrival;

                var(success, to) = splitStop.ComesFrom(origin, splitArrival.Time);
                return(success,
                       to,
                       success ? new IncludedAssociation(association.AssociatedService.TimetableUid)  : IncludedAssociation.NoAssociation);
            }
        }
コード例 #2
0
        private (bool success, ResolvedStop to, IncludedAssociation association) AssociationGoesTo(Station destination, Time departureTime, ResolvedServiceWithAssociations service)
        {
            foreach (var association in service.Associations.Where(a => !a.IsCancelled))
            {
                if (association.IsJoin)
                {
                    var foundInAssociated = JoinGoesTo(association);
                    if (foundInAssociated.success)
                    {
                        return(foundInAssociated);
                    }
                }

                if (association.IsSplit)
                {
                    var foundInAssociated = SplitGoesTo(association);
                    if (foundInAssociated.success)
                    {
                        return(foundInAssociated);
                    }
                }
            }
            return(false, null, IncludedAssociation.NoAssociation);


            (bool success, ResolvedStop to, IncludedAssociation association) JoinGoesTo(ResolvedAssociation association)
            {
                if (association.IsMain(Service.TimetableUid))
                {
                    return(false, null, null);   // We're on the main, fail as join not possible
                }
                var main          = association.Details.Main;
                var joinStop      = association.AssociatedService.GetStop(main.AtLocation, main.Sequence);
                var joinDeparture = joinStop.StopDeparture;

                var(success, to) = joinStop.GoesTo(destination, joinDeparture.Time);
                return(success,
                       to,
                       success ? new IncludedAssociation(association.AssociatedService.TimetableUid)  : IncludedAssociation.NoAssociation);
            }

            (bool success, ResolvedStop to, IncludedAssociation association) SplitGoesTo(ResolvedAssociation association)
            {
                if (!association.IsMain(Service.TimetableUid))
                {
                    return(false, null, null);   // We're already on the split so cannot go to the main
                }
                var main      = association.Details.Main;
                var splitStop = Service.GetStop(main.AtLocation, main.Sequence);

                if (splitStop.IsBefore(departureTime, true))
                {
                    return(false, null, null);   // We're past the split stop
                }
                var firstStop      = association.AssociatedService.Origin;
                var splitDeparture = firstStop.StopDeparture;

                var(success, to) = firstStop.GoesTo(destination, splitDeparture.Time);
                return(success,
                       to,
                       success ? new IncludedAssociation(association.AssociatedService.TimetableUid)  : IncludedAssociation.NoAssociation);
            }
        }