Ejemplo n.º 1
0
        /// <summary>
        /// Searches for the closest point on the routing network that's routable for the given profiles.
        /// </summary>
        /// <returns></returns>
        public sealed override Result <RouterPoint> TryResolve(IProfileInstance[] profileInstances, float latitude, float longitude,
                                                               Func <RoutingEdge, bool> isBetter, float maxSearchDistance = Constants.SearchDistanceInMeter)
        {
            try
            {
                if (!_db.SupportsAll(profileInstances))
                {
                    return(new Result <RouterPoint>("Not all routing profiles are supported.", (message) =>
                    {
                        return new Exceptions.ResolveFailedException(message);
                    }));
                }

                IResolver resolver = null;

                // get is acceptable.
                var isAcceptable = this.GetIsAcceptable(profileInstances);

                if (this.CreateCustomResolver == null)
                { // just use the default resolver algorithm.
                    Func <GeometricEdge, bool> isBetterGeometric = null;
                    if (isBetter != null)
                    { // take into account isBetter function.
                        isBetterGeometric = (edge) =>
                        {
                            return(isBetter(_db.Network.GetEdge(edge.Id)));
                        };
                    }

                    // create resolver.
                    resolver = new ResolveAlgorithm(_db.Network.GeometricGraph, latitude, longitude,
                                                    _db.Network.MaxEdgeDistance / 2,
                                                    maxSearchDistance, isAcceptable, isBetterGeometric);
                }
                else
                { // create the custom resolver algorithm.
                    resolver = this.CreateCustomResolver(latitude, longitude, isAcceptable, isBetter);
                }
                resolver.Run();
                if (!resolver.HasSucceeded)
                { // something went wrong.
                    return(new Result <RouterPoint>(resolver.ErrorMessage, (message) =>
                    {
                        return new Exceptions.ResolveFailedException(message);
                    }));
                }
                return(new Result <RouterPoint>(resolver.Result));
            }
            catch (Exception ex)
            {
                return(new Result <RouterPoint>(ex.Message, (m) => ex));
            }
        }
Ejemplo n.º 2
0
        public void TestTwoEdgesWithIsBetter()
        {
            var vertex0 = new Coordinate(51.26779566943717f, 4.801347255706787f);
            var vertex1 = new Coordinate(51.26689735000000f, 4.801347255706787f);
            var vertex2 = new Coordinate(51.26689735000000f, 4.801347255706787f);

            var graph = new GeometricGraph(1);

            graph.AddVertex(0, vertex0.Latitude, vertex0.Longitude);
            graph.AddVertex(1, vertex1.Latitude, vertex1.Longitude);
            graph.AddVertex(2, vertex2.Latitude, vertex2.Longitude);
            graph.AddEdge(0, 1, new uint[] { 0 }, null);
            var expectedEdgeId = graph.AddEdge(0, 2, new uint[] { 1 }, null);

            // resolve on vertex0.
            var location = vertex0;
            var resolver = new ResolveAlgorithm(graph, location.Latitude, location.Longitude, Constants.DefaultMaxEdgeDistance, 50f,
                                                (edge) => { return(true); }, (edge) => { return(edge.Data[0] == 1); });

            resolver.Run();

            var result = resolver.Result;

            Assert.IsNotNull(result);
            Assert.AreEqual(expectedEdgeId, result.EdgeId);

            // resolve on vertex1.
            location = vertex1;
            resolver = new ResolveAlgorithm(graph, location.Latitude, location.Longitude, Constants.DefaultMaxEdgeDistance, 50f,
                                            (edge) => { return(true); }, (edge) => { return(edge.Data[0] == 1); });
            resolver.Run();

            result = resolver.Result;
            Assert.IsNotNull(result);
            Assert.AreEqual(expectedEdgeId, result.EdgeId);

            // resolve right in between.
            location = new Coordinate((vertex0.Latitude + vertex1.Latitude) / 2,
                                      (vertex0.Longitude + vertex1.Longitude) / 2);
            resolver = new ResolveAlgorithm(graph, location.Latitude, location.Longitude, Constants.DefaultMaxEdgeDistance, 50f,
                                            (edge) => { return(true); }, (edge) => { return(edge.Data[0] == 1); });
            resolver.Run();

            result = resolver.Result;
            Assert.IsNotNull(result);
            Assert.AreEqual(expectedEdgeId, result.EdgeId);
        }
Ejemplo n.º 3
0
        public void TestOneEdge()
        {
            var vertex0 = new Coordinate(51.26779566943717f, 4.801347255706787f);
            var vertex1 = new Coordinate(51.26689735000000f, 4.801347255706787f);

            var graph = new GeometricGraph(1);

            graph.AddVertex(0, (float)vertex0.Latitude, (float)vertex0.Longitude);
            graph.AddVertex(1, (float)vertex1.Latitude, (float)vertex1.Longitude);
            graph.AddEdge(0, 1, new uint[] { 0 }, null);

            // resolve on vertex0.
            var location = vertex0;
            var resolver = new ResolveAlgorithm(graph, (float)location.Latitude, (float)location.Longitude,
                                                Constants.DefaultMaxEdgeDistance, 50f,
                                                (edge) => { return(true); });

            resolver.Run();

            var result = resolver.Result;

            Assert.IsNotNull(result);

            // resolve on vertex1.
            location = vertex1;
            resolver = new ResolveAlgorithm(graph, (float)location.Latitude, (float)location.Longitude, Constants.DefaultMaxEdgeDistance, 50f,
                                            (edge) => { return(true); });
            resolver.Run();

            result = resolver.Result;
            Assert.IsNotNull(result);

            // resolve right in between.
            location = new Coordinate((vertex0.Latitude + vertex1.Latitude) / 2,
                                      (vertex0.Longitude + vertex1.Longitude) / 2);
            resolver = new ResolveAlgorithm(graph, (float)location.Latitude, (float)location.Longitude, Constants.DefaultMaxEdgeDistance, 50f,
                                            (edge) => { return(true); });
            resolver.Run();

            result = resolver.Result;
            Assert.IsNotNull(result);
        }
Ejemplo n.º 4
0
        public void TestOneEdgeWithShape()
        {
            var vertex0 = new Coordinate(51.26779566943717f, 4.801347255706787f);
            var shape0  = new Coordinate(51.26763791763357f, 4.801728129386902f);
            var shape1  = new Coordinate(51.267070677950585f, 4.801749587059021f);
            var vertex1 = new Coordinate(51.26689735000000f, 4.801347255706787f);

            var graph = new GeometricGraph(1);

            graph.AddVertex(0, vertex0.Latitude, vertex0.Longitude);
            graph.AddVertex(1, vertex1.Latitude, vertex1.Longitude);
            graph.AddEdge(0, 1, new uint[] { 0 }, shape0, shape1);

            // resolve on vertex0.
            var location = vertex0;
            var resolver = new ResolveAlgorithm(graph, location.Latitude, location.Longitude, Constants.DefaultMaxEdgeDistance, 50f,
                                                (edge) => { return(true); });

            resolver.Run();

            var result = resolver.Result;

            Assert.IsNotNull(result);

            // resolve on vertex1.
            location = vertex1;
            resolver = new ResolveAlgorithm(graph, location.Latitude, location.Longitude, Constants.DefaultMaxEdgeDistance, 50f,
                                            (edge) => { return(true); });
            resolver.Run();

            result = resolver.Result;
            Assert.IsNotNull(result);

            // resolve on shape0.
            location = shape0;
            resolver = new ResolveAlgorithm(graph, location.Latitude, location.Longitude, Constants.DefaultMaxEdgeDistance, 50f,
                                            (edge) => { return(true); });
            resolver.Run();

            result = resolver.Result;
            Assert.IsNotNull(result);

            // resolve on shape1.
            location = shape1;
            resolver = new ResolveAlgorithm(graph, location.Latitude, location.Longitude, Constants.DefaultMaxEdgeDistance, 50f,
                                            (edge) => { return(true); });
            resolver.Run();

            result = resolver.Result;
            Assert.IsNotNull(result);

            // resolve on shape0 a bit to the top-right.
            location = new Coordinate(51.26771847181371f, 4.801915884017944f);
            resolver = new ResolveAlgorithm(graph, location.Latitude, location.Longitude, Constants.DefaultMaxEdgeDistance, 50f,
                                            (edge) => { return(true); });
            resolver.Run();

            result = resolver.Result;
            Assert.IsNotNull(result);

            // resolve on shape1 a bit to the bottom-right.
            location = new Coordinate(51.266986766160414f, 4.8019373416900635f);
            resolver = new ResolveAlgorithm(graph, location.Latitude, location.Longitude, Constants.DefaultMaxEdgeDistance, 50f,
                                            (edge) => { return(true); });
            resolver.Run();

            result = resolver.Result;
            Assert.IsNotNull(result);
        }