コード例 #1
0
ファイル: ResolverCache.cs プロジェクト: schrod/routing
        //private int _added = 0;

        /// <summary>
        /// Adds to this cache, the closest point on the routing network that's routable for the given profiles.
        /// </summary>
        /// <param name="profileInstances">The profile instances.</param>
        /// <param name="latitude">The latitude.</param>
        /// <param name="longitude">The longitude.</param>
        /// <param name="isBetter">The is better function.</param>
        /// <param name="maxSearchDistance">The maximum search distance.</param>
        /// <param name="settings">The settings, if any.</param>
        /// <param name="routerPointResult">The result to keep.</param>
        /// <returns>The resulting router point in cache.</returns>
        public void Add(IProfileInstance[] profileInstances, float latitude, float longitude, Func <RoutingEdge, bool> isBetter, float maxSearchDistance,
                        ResolveSettings settings, Result <RouterPoint> routerPointResult)
        {
            var key = new Key(profileInstances, isBetter, maxSearchDistance, settings);

            if (!_data.TryGetValue(key, out var lruCache))
            {
                _data.TryAdd(key, new LRUCache <Coordinate, Result <RouterPoint> >(_size));
                _data.TryGetValue(key, out lruCache);
                if (lruCache == null)
                { // can this happen, it shouldn't, how does concurrent dictionary work exactly?
                    return;
                }
            }

            var location = new Coordinate(latitude, longitude);

            if (lruCache.TryGet(location, out var cachedResult))
            { // already in cache.
                return;
            }

            //_added++;
            //Console.WriteLine($"Added: {_added}");

            lruCache.Add(location, cachedResult);
        }
コード例 #2
0
ファイル: ResolverCache.cs プロジェクト: schrod/routing
 public Key(IProfileInstance[] profileInstances, Func <RoutingEdge, bool> isBetter,
            float maxSearchDistance, ResolveSettings settings)
 {
     this.ProfileInstanceNames = new string[profileInstances.Length];
     for (var i = 0; i < this.ProfileInstanceNames.Length; i++)
     {
         this.ProfileInstanceNames[i] = profileInstances[i].Profile.FullName;
     }
     this.IsBetterFunc      = isBetter;
     this.MaxSearchDistance = maxSearchDistance;
     this.ResolveSettings   = settings?.Clone();
 }
コード例 #3
0
ファイル: RouterMock.cs プロジェクト: schrod/routing
 public override Result <RouterPoint> TryResolve(IProfileInstance[] profiles,
                                                 float latitude, float longitude, System.Func <RoutingEdge, bool> isBetter,
                                                 float maxSearchDistance, ResolveSettings settings, CancellationToken token)
 {
     if (latitude < -90 || latitude > 90 ||
         longitude < -180 || longitude > 180)
     {
         return(new Result <RouterPoint>("Outside of loaded network."));
     }
     if (isBetter != null &&
         !isBetter(null))
     {
         return(new Result <RouterPoint>("Not better."));
     }
     _resolvedId++;
     return(new Result <RouterPoint>(new RouterPoint(latitude, longitude, 0, 0)));
 }
コード例 #4
0
ファイル: ResolverCache.cs プロジェクト: schrod/routing
        //private int _hits = 0;

        /// <summary>
        /// Tries to get from this cache, the closest point on the routing network that's routable for the given profiles.
        /// </summary>
        /// <param name="profileInstances">The profile instances.</param>
        /// <param name="latitude">The latitude.</param>
        /// <param name="longitude">The longitude.</param>
        /// <param name="isBetter">The is better function.</param>
        /// <param name="maxSearchDistance">The maximum search distance.</param>
        /// <param name="settings">The settings, if any.</param>
        /// <returns>The resulting router point in cache.</returns>
        public Result <RouterPoint> TryGet(IProfileInstance[] profileInstances, float latitude, float longitude, Func <RoutingEdge, bool> isBetter,
                                           float maxSearchDistance, ResolveSettings settings)
        {
            var key = new Key(profileInstances, isBetter, maxSearchDistance, settings);

            if (!_data.TryGetValue(key, out var lruCache))
            {
                return(null);
            }

            if (!lruCache.TryGet(new Coordinate(latitude, longitude), out var cachedResult))
            {
                return(null);
            }

            //_hits++;
            //Console.WriteLine($"Cache hit: {_hits}");

            return(cachedResult);
        }
コード例 #5
0
ファイル: RouterBase.cs プロジェクト: amseet/Orion
 /// <summary>
 /// Searches for the closest point on the routing network that's routable for the given profiles.
 /// </summary>
 /// <returns></returns>
 public abstract Result <RouterPoint> TryResolve(IProfileInstance[] profiles, float latitude, float longitude,
                                                 Func <RoutingEdge, bool> isBetter, float searchDistanceInMeter,
                                                 ResolveSettings settings, CancellationToken cancellationToken);
コード例 #6
0
ファイル: RouterBase.cs プロジェクト: amseet/Orion
 /// <summary>
 /// Searches for the closest point on the routing network that's routable for the given profiles.
 /// </summary>
 /// <returns></returns>
 public Result <RouterPoint> TryResolve(IProfileInstance[] profiles, float latitude, float longitude,
                                        Func <RoutingEdge, bool> isBetter, float searchDistanceInMeter = Constants.SearchDistanceInMeter,
                                        ResolveSettings settings = null)
 {
     return(this.TryResolve(profiles, latitude, longitude, isBetter, searchDistanceInMeter, settings, CancellationToken.None));
 }