Beispiel #1
0
        /// <summary>
        /// Calculates all routes between all sources and all targets.
        /// </summary>
        /// <returns></returns>
        public static Result <Route[][]> TryCalculate(this RouterBase router, IProfileInstance profile, RouterPoint[] sources, RouterPoint[] targets)
        {
            var weightHandler = router.GetDefaultWeightHandler(profile);
            var paths         = router.TryCalculateRaw(profile, weightHandler, sources, targets);

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

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

            for (var s = 0; s < paths.Value.Length; s++)
            {
                routes[s] = new Route[paths.Value[s].Length];
                for (var t = 0; t < paths.Value[s].Length; t++)
                {
                    var localPath = paths.Value[s][t];
                    if (localPath != null)
                    {
                        var route = router.BuildRoute(profile, weightHandler, sources[s],
                                                      targets[t], localPath);
                        if (route.IsError)
                        {
                            return(route.ConvertError <Route[][]>());
                        }
                        routes[s][t] = route.Value;
                    }
                }
            }
            return(new Result <Route[][]>(routes));
        }
Beispiel #2
0
        /// <summary>
        /// Calculates a route the given locations;
        /// </summary>
        public static Result <Route> TryCalculate(this RouterBase router, IProfileInstance profile, RouterPoint source, RouterPoint target)
        {
            var weightHandler = router.GetDefaultWeightHandler(profile);
            var path          = router.TryCalculateRaw(profile, weightHandler, source, target);

            if (path.IsError)
            {
                return(path.ConvertError <Route>());
            }
            return(router.BuildRoute(profile, weightHandler, source, target, path.Value));
        }