/// <summary> /// Creates a new weight-matrix algorithm. /// </summary> public WeightMatrixAlgorithm(RouterBase router, IProfileInstance profile, WeightHandler <T> weightHandler, IMassResolvingAlgorithm massResolver) { _router = router; _profile = profile; _weightHandler = weightHandler; _massResolver = massResolver; }
/// <summary> /// Calculates heatmap for the given profile. /// </summary> public static HeatmapResult CalculateHeatmap(this RouterBase router, Profile profile, RouterPoint origin, int limitInSeconds, int zoom, CancellationToken cancellationToken) { if (!router.SupportsAll(profile)) { throw new ArgumentException(string.Format("Profile {0} not supported.", profile.FullName)); } if (profile.Metric != ProfileMetric.TimeInSeconds) { throw new ArgumentException(string.Format("Profile {0} not supported, only profiles with metric TimeInSeconds are supported.", profile.FullName)); } // get the weight handler. var weightHandler = router.GetDefaultWeightHandler(profile); var getFactor = router.GetDefaultGetFactor(profile); // calculate isochrones. var isochrone = new TileBasedHeatmapBuilder(router.Db.Network.GeometricGraph, new Algorithms.Default.Dykstra(router.Db.Network.GeometricGraph.Graph, weightHandler, null, origin.ToEdgePaths <float>(router.Db, weightHandler, true), limitInSeconds, false), zoom); isochrone.Run(cancellationToken); var result = isochrone.Result; result.MaxMetric = profile.Metric.ToInvariantString(); return(result); }
/// <summary> /// Tries to calculate a tree starting at the given location. /// </summary> public static Result <Tree> TryCalculateTree(this RouterBase router, Profile profile, RouterPoint origin, float max) { if (!router.SupportsAll(profile)) { return(new Result <Tree>(string.Format("Profile {0} not supported.", profile.Name))); } if (profile.Metric != ProfileMetric.TimeInSeconds) { return(new Result <Tree>(string.Format("Profile {0} not supported, only profiles with metric TimeInSeconds are supported.", profile.Name))); } // get the weight handler. var weightHandler = router.GetDefaultWeightHandler(profile); var getFactor = router.GetDefaultGetFactor(profile); // calculate isochrones. var treeBuilder = new TreeBuilder( new DykstraEdgeVisitor(router.Db.Network.GeometricGraph, getFactor, origin.ToEdgePaths <float>(router.Db, weightHandler, true), max)); treeBuilder.Run(); return(new Result <Tree>(treeBuilder.Tree)); }
/// <summary> /// Creates a new weight-matrix algorithm. /// </summary> public DirectedWeightMatrixAlgorithm(RouterBase router, IProfileInstance profile, WeightHandler <T> weightHandler, IMassResolvingAlgorithm massResolver, T?max = null) { _router = router; _profile = profile; _weightHandler = weightHandler; _massResolver = massResolver; ContractedDb contractedDb; if (!router.Db.TryGetContracted(profile.Profile, out contractedDb)) { throw new NotSupportedException( "Contraction-based many-to-many calculates are not supported in the given router db for the given profile."); } if (!contractedDb.HasEdgeBasedGraph) { throw new NotSupportedException( "Contraction-based edge-based many-to-many calculates are not supported in the given router db for the given profile."); } _graph = contractedDb.EdgeBasedGraph; weightHandler.CheckCanUse(contractedDb); if (max.HasValue) { _max = max.Value; } else { _max = weightHandler.Infinite; } _buckets = new Dictionary <uint, Dictionary <int, LinkedEdgePath <T> > >(); }
/// <summary>Register service method with a service binder with or without implementation. Useful when customizing the service binding logic. /// Note: this method is part of an experimental API that can change or be removed without any prior notice.</summary> /// <param name="serviceBinder">Service methods will be bound by calling <c>AddMethod</c> on this object.</param> /// <param name="serviceImpl">An object implementing the server-side handling logic.</param> public static void BindService(grpc::ServiceBinderBase serviceBinder, RouterBase serviceImpl) { serviceBinder.AddMethod(__Method_Start, serviceImpl == null ? null : new grpc::UnaryServerMethod <global::Loko.Metro.Api.StartRequest, global::Loko.Metro.Api.Response>(serviceImpl.Start)); serviceBinder.AddMethod(__Method_Link, serviceImpl == null ? null : new grpc::UnaryServerMethod <global::Loko.Metro.Api.LinkRequest, global::Loko.Metro.Api.Response>(serviceImpl.Link)); serviceBinder.AddMethod(__Method_Block, serviceImpl == null ? null : new grpc::UnaryServerMethod <global::Loko.Metro.Api.BlockRequest, global::Loko.Metro.Api.Response>(serviceImpl.Block)); serviceBinder.AddMethod(__Method_Transmit, serviceImpl == null ? null : new grpc::UnaryServerMethod <global::Loko.Metro.Api.TransmitRequest, global::Loko.Metro.Api.Response>(serviceImpl.Transmit)); serviceBinder.AddMethod(__Method_Listen, serviceImpl == null ? null : new grpc::ServerStreamingServerMethod <global::Loko.Metro.Api.ListenRequest, global::Loko.Metro.Api.Signal>(serviceImpl.Listen)); }
/// <summary> /// Creates a new mass-resolving algorithm. /// </summary> public MassResolvingAlgorithm(RouterBase router, IProfileInstance[] profiles, Coordinate[] locations, Func <RoutingEdge, int, bool> matchEdge = null, float maxSearchDistance = Constants.SearchDistanceInMeter) { _router = router; _profiles = profiles; _locations = locations; _matchEdge = matchEdge; _maxSearchDistance = maxSearchDistance; }
/// <summary>Creates service definition that can be registered with a server</summary> /// <param name="serviceImpl">An object implementing the server-side handling logic.</param> public static grpc::ServerServiceDefinition BindService(RouterBase serviceImpl) { return(grpc::ServerServiceDefinition.CreateBuilder() .AddMethod(__Method_Start, serviceImpl.Start) .AddMethod(__Method_Link, serviceImpl.Link) .AddMethod(__Method_Block, serviceImpl.Block) .AddMethod(__Method_Transmit, serviceImpl.Transmit) .AddMethod(__Method_Listen, serviceImpl.Listen).Build()); }
/// <summary> /// Creates a new mass-resolving algorithm with pre-resolved locations. /// </summary> public MassResolvingAlgorithm(RouterBase router, IProfileInstance[] profiles, IEnumerable <RouterPoint> routerPoints) { _router = router; _profiles = profiles; _resolvedPoints = new List <RouterPoint>(routerPoints); _locations = _resolvedPoints.Select(x => x.Location()).ToArray(); _matchEdge = null; }
/// <summary> /// Calculates TSP. /// </summary> public static Result <Route> TryCalculateTSP(this RouterBase router, Profile profile, Coordinate[] locations, int first = 0, int?last = null) { var tspRouter = new TSPRouter(new WeightMatrixAlgorithm(router, profile, locations), first, last); tspRouter.Run(); if (!tspRouter.HasSucceeded) { return(new Result <Route>(tspRouter.ErrorMessage)); } return(new Result <Route>(tspRouter.WeightMatrix.BuildRoute(tspRouter.Tour))); }
/// <summary> /// Calculates a directed sequence of the given sequence of locations. /// </summary> public static Result <Route> TryCalculateDirected(this RouterBase router, Profile profile, Coordinate[] locations, float turnPenaltyInSeconds, Tour sequence) { var directedRouter = new SequenceDirectedRouter(new DirectedWeightMatrixAlgorithm(router, profile, locations), turnPenaltyInSeconds, sequence); directedRouter.Run(); if (!directedRouter.HasSucceeded) { return(new Result <Route>(directedRouter.ErrorMessage)); } return(new Result <Route>(directedRouter.WeightMatrix.BuildRoute(directedRouter.Tour))); }
/// <summary> /// Creates a new weight-matrix algorithm. /// </summary> public WeightMatrixAlgorithm(RouterBase router, Profile profile, WeightHandler <T> weightHandler, Coordinate[] locations, Func <RoutingEdge, int, bool> matchEdge) { _router = router; _profile = profile; _locations = locations; _matchEdge = matchEdge; _weightHandler = weightHandler; this.SearchDistanceInMeter = Constants.SearchDistanceInMeter; }
/// <summary> /// Calculates heatmap for the given profile. /// </summary> public static HeatmapResult CalculateHeatmap(this RouterBase router, Profile profile, Coordinate origin, int limitInSeconds, int zoom, CancellationToken cancellationToken) { if (!router.SupportsAll(profile)) { throw new ArgumentException(string.Format("Profile {0} not supported.", profile.FullName)); } var routerOrigin = router.Resolve(profile, origin); return(router.CalculateHeatmap(profile, routerOrigin, limitInSeconds, zoom, cancellationToken)); }
/// <summary> /// Creates a new presolved mass resolve algorithm /// </summary> public PresolvedMassResolvingAlgorithm(RouterBase router, IProfileInstance[] profiles, List <RouterPoint> routerPoints) { _router = router; _profiles = profiles; _routerPoints = routerPoints; _locations = new Coordinate[_routerPoints.Count]; for (var l = 0; l < _locations.Length; l++) { _locations[l] = _routerPoints[l].Location(); } }
private static void PrintAllRoutes(string start, string destination, RouterBase router) { Console.WriteLine("--------------------------------"); Console.WriteLine($"{start} to {destination}"); var routes = router.GetAllRoutes(start, destination); if (routes.Any()) { Console.WriteLine("The route exists from {0} to {1}.", start, destination); foreach (var route in routes) { Console.WriteLine($"{route.ResultingPath} costs {route.CumulativeWeight}"); } } else { Console.WriteLine("The route does not exist from {0} to {1}.", start, destination); } }
/// <summary> /// Calculates isochrones for the given profile based on the given limits. /// </summary> public static List <LocalGeo.Polygon> CalculateIsochrones(this RouterBase router, Profile profile, RouterPoint origin, List <float> limits, int zoom = 16) { if (profile.Metric != ProfileMetric.TimeInSeconds) { throw new ArgumentException(string.Format("Profile {0} not supported, only profiles with metric TimeInSeconds are supported.", profile.FullName)); } // get the weight handler. var weightHandler = router.GetDefaultWeightHandler(profile); var getFactor = router.GetDefaultGetFactor(profile); // calculate isochrones. var isochrone = new TileBasedIsochroneBuilder(router.Db.Network.GeometricGraph, new Algorithms.Default.Dykstra(router.Db.Network.GeometricGraph.Graph, weightHandler, null, origin.ToEdgePaths <float>(router.Db, weightHandler, true), limits.Max() * 1.1f, false), limits, zoom); isochrone.Run(); return(isochrone.Polygons); }
/// <summary> /// Tries to calculate a tree starting at the given location. /// </summary> public static Result <Tree> TryCalculateTree(this RouterBase router, Profile profile, RouterPoint origin, float max) { if (!router.SupportsAll(profile)) { return(new Result <Tree>(string.Format("Profile {0} not supported.", profile.FullName))); } if (profile.Metric != ProfileMetric.TimeInSeconds) { return(new Result <Tree>(string.Format("Profile {0} not supported, only profiles with metric TimeInSeconds are supported.", profile.FullName))); } // get the weight handler. var weightHandler = router.GetDefaultWeightHandler(profile); var getFactor = router.GetDefaultGetFactor(profile); // calculate isochrones. TreeBuilder treeBuilder = null; if (!router.Db.HasComplexRestrictions(profile)) { treeBuilder = new TreeBuilder(router.Db.Network.GeometricGraph, new Algorithms.Default.Dykstra(router.Db.Network.GeometricGraph.Graph, weightHandler, null, origin.ToEdgePaths <float>(router.Db, weightHandler, true), max, router.Closures, false)); } else { treeBuilder = new TreeBuilder(router.Db.Network.GeometricGraph, new Algorithms.Default.EdgeBased.Dykstra(router.Db.Network.GeometricGraph.Graph, weightHandler, router.Db.GetGetRestrictions(profile, true), origin.ToEdgePaths <float>(router.Db, weightHandler, true), max, router.Closures, false)); } treeBuilder.Run(); return(new Result <Tree>(treeBuilder.Tree)); }
/// <summary> /// Calculates heatmap for the given profile. /// </summary> public static HeatmapResult CalculateHeatmap(this RouterBase router, Profile profile, RouterPoint origin, int limitInSeconds, int zoom = 16) { if (profile.Metric != ProfileMetric.TimeInSeconds) { throw new ArgumentException(string.Format("Profile {0} not supported, only profiles with metric TimeInSeconds are supported.", profile.Name)); } // get the weight handler. var weightHandler = router.GetDefaultWeightHandler(profile); var getFactor = router.GetDefaultGetFactor(profile); // calculate isochrones. var isochrone = new TileBasedHeatmapBuilder( new DykstraEdgeVisitor(router.Db.Network.GeometricGraph, getFactor, origin.ToEdgePaths <float>(router.Db, weightHandler, true), limitInSeconds), zoom); isochrone.Run(); var result = isochrone.Result; result.MaxMetric = profile.Name; return(result); }
/// <summary> /// Tries to calculate a tree starting at the given location. /// </summary> public static Tree CalculateTree(this RouterBase router, Profile profile, Coordinate origin, float max) { return(router.TryCalculateTree(profile, router.Resolve(profile, origin, 500), max).Value); }
/// <summary> /// Returns the default weight handler. /// </summary> public static DefaultWeightHandler DefaultWeightHandler(this IProfileInstance profile, RouterBase router) { return(router.GetDefaultWeightHandler(profile)); }
/// <summary> /// Creates a new weight-matrix algorithm. /// </summary> public WeightMatrixAlgorithm(RouterBase router, Profile profile, WeightHandler <T> weightHandler, Coordinate[] locations) : this(router, profile, weightHandler, locations, null) { }
/// <summary> /// Tries to calculate a tree starting at the given location. /// </summary> public static Tree CalculateTree(this RouterBase router, Profile profile, RouterPoint origin, float max) { return(router.TryCalculateTree(profile, origin, max).Value); }
/// <summary> /// Creates a new weight-matrix algorithm. /// </summary> public DirectedAugmentedWeightMatrixAlgorithm(RouterBase router, IProfileInstance profile, IMassResolvingAlgorithm massResolver, Weight max) : base(router, profile, profile.AugmentedWeightHandler(router), massResolver, max) { }
/// <summary> /// Creates a new weight-matrix algorithm. /// </summary> public DirectedAugmentedWeightMatrixAlgorithm(RouterBase router, IProfileInstance profile, Coordinate[] locations, Weight max) : base(router, profile, profile.AugmentedWeightHandler(router), locations, max) { }
/// <summary> /// Calculates a directed sequence of the given sequence of locations. /// </summary> public static Route CalculateDirected(this RouterBase router, Profile profile, Coordinate[] locations, float turnPenaltyInSeconds, Tour sequence) { return(router.TryCalculateDirected(profile, locations, turnPenaltyInSeconds, sequence).Value); }
/// <summary> /// Calculates isochrones for the given profile based on the given limits. /// </summary> public static List <LocalGeo.Polygon> CalculateIsochrones(this RouterBase router, Profile profile, RouterPoint origin, List <float> limits, int zoom = 16) { return(router.CalculateIsochrones(profile, origin, limits, zoom, CancellationToken.None)); }
/// <summary> /// Calculates heatmap for the given profile. /// </summary> public static HeatmapResult CalculateHeatmap(this RouterBase router, Profile profile, RouterPoint origin, int limitInSeconds, int zoom = 16) { return(router.CalculateHeatmap(profile, origin, limitInSeconds, zoom, CancellationToken.None)); }
/// <summary> /// Returns the augmented weight handler. /// </summary> public static WeightHandler AugmentedWeightHandler(this IProfileInstance profile, RouterBase router) { return(router.GetAugmentedWeightHandler(profile)); }
/// <summary> /// Calculates TSP. /// </summary> public static Route CalculateTSP(this RouterBase router, Profile profile, Coordinate[] locations, int first = 0, int?last = null) { return(router.TryCalculateTSP(profile, locations, first, last).Value); }
/// <summary> /// Creates a new weight-matrix algorithm. /// </summary> public DirectedWeightMatrixAlgorithm(RouterBase router, IProfileInstance profile, WeightHandler <T> weightHandler, Coordinate[] locations, T?max = null) : this(router, profile, weightHandler, new MassResolvingAlgorithm( router, new IProfileInstance[] { profile }, locations), max) { }
/// <summary> /// Calculates isochrones for the given profile based on the given limits. /// </summary> public static List <LocalGeo.Polygon> CalculateIsochrones(this RouterBase router, Profile profile, Coordinate origin, List <float> limits, int zoom = 16) { var routerOrigin = router.Resolve(profile, origin); return(router.CalculateIsochrones(profile, routerOrigin, limits, zoom)); }