/// <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); }
/// <summary> /// Calculates all weights between all locations. /// </summary> public static Result <T[][]> TryCalculateWeight <T>(this RouterBase router, IProfileInstance profile, WeightHandler <T> weightHandler, RouterPoint[] locations) where T : struct { var invalids = new HashSet <int>(); var result = router.TryCalculateWeight(profile, weightHandler, locations, locations, invalids, invalids); if (invalids.Count > 0) { return(new Result <T[][]>("At least one location could not be routed from/to. Most likely there are islands in the loaded network.", (s) => { throw new Exceptions.RouteNotFoundException(s); })); } return(result); }
/// <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)); }
/// <summary> /// Calculates all weights between all given locations. /// </summary> public static Result <T[][]> TryCalculateWeight <T>(this RouterBase router, WeightHandler <T> weightHandler, IProfileInstance profile, Coordinate[] locations) where T : struct { return(router.TryCalculateWeight(profile, weightHandler, locations, locations)); }
/// <summary> /// Calculates the weight between the two locations. /// </summary> public static Result <T> TryCalculateWeight <T>(this RouterBase router, IProfileInstance profile, WeightHandler <T> weightHandler, Coordinate source, Coordinate target) where T : struct { return(router.TryCalculateWeight(profile, weightHandler, source.Latitude, source.Longitude, target.Latitude, target.Longitude)); }
/// <summary> /// Calculates the weight between the two locations. /// </summary> public static Result <float> TryCalculateWeight(this RouterBase router, IProfileInstance profile, Coordinate source, Coordinate target) { return(router.TryCalculateWeight(profile, profile.DefaultWeightHandler(router), source, target)); }
/// <summary> /// Calculates all weights between all locations. /// </summary> public static float[][] CalculateWeight(this RouterBase router, IProfileInstance profile, RouterPoint[] locations, ISet <int> invalids) { return(router.TryCalculateWeight(profile, profile.DefaultWeightHandler(router), locations, invalids).Value); }
/// <summary> /// Calculates all weights between all locations. /// </summary> public static T[][] CalculateWeight <T>(this RouterBase router, IProfileInstance profile, WeightHandler <T> weightHandler, RouterPoint[] locations, ISet <int> invalids) where T : struct { return(router.TryCalculateWeight(profile, weightHandler, locations, invalids).Value); }
/// <summary> /// Calculates all weights between all locations. /// </summary> public static Result <T[][]> TryCalculateWeight <T>(this RouterBase router, Profile profile, WeightHandler <T> weightHandler, RouterPoint[] locations, ISet <int> invalids) where T : struct { return(router.TryCalculateWeight(profile, weightHandler, locations, locations, invalids, invalids)); }