Ejemplo n.º 1
0
        /// <summary>
        /// Calculates all weights between all sources and all targets.
        /// </summary>
        public static Result <T[][]> TryCalculateWeight <T>(this RouterBase router, IProfileInstance profile, WeightHandler <T> weightHandler, Coordinate[] sources, Coordinate[] targets)
            where T : struct
        {
            var resolvedSources = new RouterPoint[sources.Length];

            for (var i = 0; i < sources.Length; i++)
            {
                var result = router.TryResolve(profile, sources[i]);
                if (result.IsError)
                {
                    return(new Result <T[][]>(string.Format("Source at index {0} could not be resolved: {1}",
                                                            i, result.ErrorMessage), (s) =>
                    {
                        throw new Exceptions.ResolveFailedException(s);
                    }));
                }
                resolvedSources[i] = result.Value;
            }
            var resolvedTargets = new RouterPoint[targets.Length];

            for (var i = 0; i < targets.Length; i++)
            {
                var result = router.TryResolve(profile, targets[i]);
                if (result.IsError)
                {
                    return(new Result <T[][]>(string.Format("Target at index {0} could not be resolved: {1}",
                                                            i, result.ErrorMessage), (s) =>
                    {
                        throw new Exceptions.ResolveFailedException(s);
                    }));
                }
                resolvedTargets[i] = result.Value;
            }

            var invalidSources = new HashSet <int>();
            var invalidTargets = new HashSet <int>();
            var weights        = router.TryCalculateWeight(profile, weightHandler, resolvedSources, resolvedTargets, invalidSources, invalidTargets);

            if (invalidSources.Count > 0)
            {
                return(new Result <T[][]>("Some sources could not be routed from. Most likely there are islands in the loaded network.", (s) =>
                {
                    throw new Exceptions.RouteNotFoundException(s);
                }));
            }
            if (invalidTargets.Count > 0)
            {
                return(new Result <T[][]>("Some targets could not be routed to. Most likely there are islands in the loaded network.", (s) =>
                {
                    throw new Exceptions.RouteNotFoundException(s);
                }));
            }
            return(weights);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Calculates the weight between the two locations.
        /// </summary>
        public static Result <T> TryCalculateWeight <T>(this RouterBase router, IProfileInstance profile, WeightHandler <T> weightHandler,
                                                        float sourceLatitude, float sourceLongitude, float targetLatitude, float targetLongitude) where T : struct
        {
            var profiles    = new IProfileInstance[] { profile };
            var sourcePoint = router.TryResolve(profiles, sourceLatitude, sourceLongitude);
            var targetPoint = router.TryResolve(profiles, targetLatitude, targetLongitude);

            if (sourcePoint.IsError)
            {
                return(sourcePoint.ConvertError <T>());
            }
            if (targetPoint.IsError)
            {
                return(targetPoint.ConvertError <T>());
            }
            return(router.TryCalculateWeight(profile, weightHandler, sourcePoint.Value, targetPoint.Value));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Calculates a route between the two locations.
        /// </summary>
        public static Result <Route> TryCalculate(this RouterBase router, IProfileInstance profile,
                                                  float sourceLatitude, float sourceLongitude, float targetLatitude, float targetLongitude)
        {
            var profiles    = new IProfileInstance[] { profile };
            var sourcePoint = router.TryResolve(profiles, sourceLatitude, sourceLongitude);
            var targetPoint = router.TryResolve(profiles, targetLatitude, targetLongitude);

            if (sourcePoint.IsError)
            {
                return(sourcePoint.ConvertError <Route>());
            }
            if (targetPoint.IsError)
            {
                return(targetPoint.ConvertError <Route>());
            }
            return(router.TryCalculate(profile, sourcePoint.Value, targetPoint.Value));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Searches for the closest point on the routing network that's routable for the given profiles.
        /// </summary>
        public static RouterPoint[] Resolve(this RouterBase router, IProfileInstance profile, Coordinate[] coordinates,
                                            float searchDistanceInMeter = Constants.SearchDistanceInMeter)
        {
            var results      = router.TryResolve(profile, coordinates, searchDistanceInMeter);
            var routerPoints = new RouterPoint[results.Length];

            for (var i = 0; i < results.Length; i++)
            {
                routerPoints[i] = results[i].Value;
            }
            return(routerPoints);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Searches for the closest points on the routing network that's routable for the given profile(s).
        /// </summary>
        public static Result <RouterPoint>[] TryResolve(this RouterBase router, IProfileInstance[] profiles, Coordinate[] coordinates,
                                                        float searchDistanceInMeter = Constants.SearchDistanceInMeter)
        {
            if (coordinates == null)
            {
                throw new ArgumentNullException("coordinate");
            }

            var result = new Result <RouterPoint> [coordinates.Length];

            for (var i = 0; i < coordinates.Length; i++)
            {
                result[i] = router.TryResolve(profiles, coordinates[i], searchDistanceInMeter);
            }
            return(result);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Calculates a route along the given locations.
        /// </summary>
        public static Result <Route> TryCalculate(this RouterBase router, IProfileInstance profile, Coordinate[] locations)
        {
            if (locations.Length < 2)
            {
                throw new ArgumentOutOfRangeException("Cannot calculate a routing along less than two locations.");
            }
            var resolved = router.TryResolve(profile, locations);
            var route    = router.TryCalculate(profile, resolved[0].Value, resolved[1].Value);

            if (route.IsError)
            {
                return(route);
            }
            for (var i = 2; i < resolved.Length; i++)
            {
                var nextRoute = router.TryCalculate(profile, resolved[i - 1].Value, resolved[i].Value);
                if (nextRoute.IsError)
                {
                    return(nextRoute);
                }
                route = new Result <Route>(route.Value.Concatenate(nextRoute.Value));
            }
            return(route);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Searches for the closest point on the routing network that's routable for the given profiles.
 /// </summary>
 public static RouterPoint Resolve(this RouterBase router, IProfileInstance[] profiles, Coordinate coordinate,
                                   Func <RoutingEdge, bool> isBetter,
                                   float searchDistanceInMeter = Constants.SearchDistanceInMeter)
 {
     return(router.TryResolve(profiles, coordinate, isBetter, searchDistanceInMeter).Value);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Searches for the closest point on the routing network that's routable for the given profiles.
 /// </summary>
 public static RouterPoint Resolve(this RouterBase router, IProfileInstance profile, Coordinate coordinate,
                                   float searchDistanceInMeter = Constants.SearchDistanceInMeter)
 {
     return(router.TryResolve(profile, coordinate, searchDistanceInMeter).Value);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Searches for the closest point on the routing network that's routable for the given profiles.
 /// </summary>
 public static Result <RouterPoint> TryResolve(this RouterBase router, IProfileInstance[] profiles, Coordinate coordinate,
                                               float searchDistanceInMeter = Constants.SearchDistanceInMeter)
 {
     return(router.TryResolve(profiles, coordinate.Latitude, coordinate.Longitude,
                              searchDistanceInMeter));
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Searches for the closest point on the routing network that's routable for the given profiles.
 /// </summary>
 public static Result <RouterPoint> TryResolve(this RouterBase router, IProfileInstance profile, Coordinate coordinate,
                                               float searchDistanceInMeter = Constants.SearchDistanceInMeter)
 {
     return(router.TryResolve(new IProfileInstance[] { profile }, coordinate, searchDistanceInMeter));
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Searches for the closest point on the routing network that's routable for the given profiles.
 /// </summary>
 public static RouterPoint Resolve(this RouterBase router, IProfileInstance[] profiles, float latitude, float longitude,
                                   float searchDistanceInMeter = Constants.SearchDistanceInMeter)
 {
     return(router.TryResolve(profiles, latitude, longitude, searchDistanceInMeter).Value);
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Searches for the closest point on the routing network that's routable for the given profiles.
 /// </summary>
 public static Result <RouterPoint> TryResolve(this RouterBase router, Profile[] profiles, Coordinate coordinate,
                                               Func <RoutingEdge, bool> isBetter, float searchDistanceInMeter = Constants.SearchDistanceInMeter)
 {
     return(router.TryResolve(profiles, coordinate.Latitude, coordinate.Longitude, isBetter,
                              searchDistanceInMeter));
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Searches for the closest point on the routing network that's routable for the given profiles.
 /// </summary>
 public static RouterPoint Resolve(this RouterBase router, Profile[] profiles, float latitude, float longitude,
                                   Func <RoutingEdge, bool> isBetter, float searchDistanceInMeter = Constants.SearchDistanceInMeter)
 {
     return(router.TryResolve(profiles, latitude, longitude, isBetter, searchDistanceInMeter).Value);
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Searches for the closest point on the routing network that's routable for the given profiles.
 /// </summary>
 public static Result <RouterPoint> TryResolve(this RouterBase router, Profile[] profiles, float latitude, float longitude,
                                               float searchDistanceInMeter = Constants.SearchDistanceInMeter)
 {
     return(router.TryResolve(profiles, latitude, longitude, null,
                              searchDistanceInMeter));
 }