Exemplo n.º 1
0
        public SmallTrie <(string, int)> BuildTrie(IStopsReader allStops)
        {
            var trie = new SmallTrie <(string, int)>();

            allStops.Reset();
            while (allStops.MoveNext())
            {
                var names = ExtractNames(allStops);
                if (names == null)
                {
                    continue;
                }

                foreach (var(name, dist) in names)
                {
                    if (name == null)
                    {
                        continue;
                    }

                    trie.Add(name.ToCharArray().ToList(), (allStops.GlobalId, dist));
                }
            }

            return(trie);
        }
Exemplo n.º 2
0
        private static void DetectFirstMileWalks <T>(
            this Profile <T> p,
            IStopsReader stops, Stop stop, uint osmIndex, bool isLastMile, string name) where T : IJourneyMetric <T>
        {
            var failIfNoneFound = stop.Id.DatabaseId == osmIndex;


            if (stop.Id.DatabaseId != osmIndex)
            {
                // The location is already on the Public Transport network
                // We don't need to walk
                // and thus don't need to check that a start walk exists
                return;
            }

            if (p.WalksGenerator.Range() == 0)
            {
                // We can't walk with the current settings
                return;
            }

            var inRange = stops.StopsAround(stop, p.WalksGenerator.Range()).ToList();

            if (inRange == null ||
                !inRange.Any() ||
                inRange.Count == 1 && inRange[0].Id.Equals(stop.Id))
            {
                if (!failIfNoneFound)
                {
                    return;
                }

                throw new ArgumentException(
                          $"Could not find a station that is in range from the {name}-location {stop.GlobalId} within {p.WalksGenerator.Range()}m. This range is calculated 'as the  crows fly', try increasing the range of your walksGenerator");
            }

            var foundRoutes = isLastMile
                ? p.WalksGenerator.TimesBetween(inRange, stop)
                : p.WalksGenerator.TimesBetween(stop, inRange);


            if (!failIfNoneFound)
            {
                return;
            }

            if (foundRoutes == null)
            {
                throw CreateException(p, stop, isLastMile, name, inRange);
            }

            if (!foundRoutes.Any())
            {
                throw CreateException(p, stop, isLastMile, name, inRange);
            }

            foreach (var(_, distance) in foundRoutes)
            {
                if (distance != uint.MaxValue)
                {
                    return;
                }
            }

            throw CreateException(p, stop, isLastMile, name, inRange);
        }
Exemplo n.º 3
0
 public NameIndex Build(IStopsReader reader)
 {
     return(new NameIndex(BuildTrie(reader), reader));
 }