Beispiel #1
0
        /// <summary>
        /// Calculates all routes between all sources and all targets.
        /// </summary>
        public static Result <Route[][]> TryCalculate(this RouterBase router, Profile profile, RouterPoint[] sources, RouterPoint[] targets)
        {
            var invalidSources = new HashSet <int>();
            var invalidTargets = new HashSet <int>();
            var result         = router.TryCalculate(profile, sources, targets, invalidSources, invalidTargets).Value;

            if (invalidSources.Count > 0)
            {
                return(new Result <Route[][]>("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 <Route[][]>("Some targets could not be routed to. Most likely there are islands in the loaded network.", (s) =>
                {
                    throw new Exceptions.RouteNotFoundException(s);
                }));
            }

            var routes = new Route[result.Length][];

            for (var i = 0; i < result.Length; i++)
            {
                routes[i] = new Route[result[i].Length];
                for (var j = 0; j < result[i].Length; j++)
                {
                    routes[i][j] = result[i][j];
                }
            }
            return(new Result <Route[][]>(routes));
        }
Beispiel #2
0
        /// <summary>
        /// Calculates a route along the given locations.
        /// </summary>
        public static Result <Route> TryCalculate(this RouterBase router, IProfileInstance profile, RouterPoint[] locations)
        {
            if (locations.Length < 2)
            {
                throw new ArgumentOutOfRangeException("Cannot calculate a routing along less than two locations.");
            }
            var route = router.TryCalculate(profile, locations[0], locations[1]);

            if (route.IsError)
            {
                return(route);
            }
            for (var i = 2; i < locations.Length; i++)
            {
                var nextRoute = router.TryCalculate(profile, locations[i - 1], locations[i]);
                if (nextRoute.IsError)
                {
                    return(nextRoute);
                }
                route = new Result <Route>(route.Value.Concatenate(nextRoute.Value));
            }
            return(route);
        }
Beispiel #3
0
        /// <summary>
        /// Calculates a route along the given locations.
        /// </summary>
        public static Result <Route> TryCalculate(this RouterBase router, Profile 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);
        }
Beispiel #4
0
        /// <summary>
        /// Calculates all routes between all sources and all targets.
        /// </summary>
        public static Result <Route[]> TryCalculate(this RouterBase router, IProfileInstance profile, RouterPoint source, RouterPoint[] targets)
        {
            var result = router.TryCalculate(profile, new RouterPoint[] { source }, targets);

            if (result.IsError)
            {
                return(result.ConvertError <Route[]>());
            }

            var routes = new Route[result.Value.Length];

            for (var j = 0; j < result.Value.Length; j++)
            {
                routes[j] = result.Value[0][j];
            }
            return(new Result <Route[]>(routes));
        }
Beispiel #5
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));
        }
Beispiel #6
0
 /// <summary>
 /// Calculates a route between the two locations.
 /// </summary>
 public static Result <Route> TryCalculate(this RouterBase router, IProfileInstance profile, Coordinate source,
                                           Coordinate target)
 {
     return(router.TryCalculate(profile, source.Latitude, source.Longitude, target.Latitude, target.Longitude));
 }
Beispiel #7
0
 /// <summary>
 /// Calculates a route along the given locations.
 /// </summary>
 public static Route Calculate(this RouterBase router, IProfileInstance profile, Coordinate[] locations)
 {
     return(router.TryCalculate(profile, locations).Value);
 }
Beispiel #8
0
 /// <summary>
 /// Calculates a route between the two locations.
 /// </summary>
 public static Route Calculate(this RouterBase router, IProfileInstance profile, Coordinate source, Coordinate target)
 {
     return(router.TryCalculate(profile, source, target).Value);
 }
Beispiel #9
0
 /// <summary>
 /// Calculates all routes between all sources and all targets.
 /// </summary>
 public static Route[][] Calculate(this RouterBase router, IProfileInstance profile, RouterPoint[] sources, RouterPoint[] targets)
 {
     return(router.TryCalculate(profile, sources, targets).Value);
 }
Beispiel #10
0
 /// <summary>
 /// Calculates a route between the two locations.
 /// </summary>
 public static Route Calculate(this RouterBase router, IProfileInstance profile,
                               float sourceLatitude, float sourceLongitude, float targetLatitude, float targetLongitude)
 {
     return(router.TryCalculate(profile, sourceLatitude, sourceLongitude, targetLatitude, targetLongitude).Value);
 }
Beispiel #11
0
 /// <summary>
 /// Calculates all routes between all sources and all targets.
 /// </summary>
 public static Route[][] Calculate(this RouterBase router, Profile profile, RouterPoint[] sources, RouterPoint[] targets,
                                   ISet <int> invalidSources, ISet <int> invalidTargets)
 {
     return(router.TryCalculate(profile, sources, targets, invalidSources, invalidTargets).Value);
 }
Beispiel #12
0
 /// <summary>
 /// Calculates all routes between all sources and all targets.
 /// </summary>
 public static Route[] Calculate(this RouterBase router, Profile profile, RouterPoint source, RouterPoint[] targets)
 {
     return(router.TryCalculate(profile, source, targets).Value);
 }
Beispiel #13
0
 /// <summary>
 /// Calculates a route along the given locations.
 /// </summary>
 public static Route Calculate(this RouterBase router, Profile profile, RouterPoint[] locations)
 {
     return(router.TryCalculate(profile, locations).Value);
 }