Example #1
0
        /// <summary>
        /// Tests calculating a weight matrix.
        /// </summary>
        public static Action GetTestWeightMatrixAlgorithm(Router router, Profiles.Profile profile, int count)
        {
            var random    = new System.Random(145171654);
            var vertices  = new HashSet <uint>();
            var locations = new List <Coordinate>();

            while (locations.Count < count)
            {
                var v = (uint)random.Next((int)router.Db.Network.VertexCount);
                if (!vertices.Contains(v))
                {
                    vertices.Add(v);
                    locations.Add(router.Db.Network.GetVertex(v));
                }
            }

            var locationsArray = locations.ToArray();
            var massResolver   = new MassResolvingAlgorithm(router, new Profiles.IProfileInstance[] { profile }, locationsArray);

            massResolver.Run();

            return(() =>
            {
                var matrix = new Itinero.Algorithms.Matrices.WeightMatrixAlgorithm(router, profile, massResolver);
                matrix.Run();
                Assert.IsTrue(matrix.HasSucceeded);
            });
        }
Example #2
0
        /// <summary>
        /// Tests calculating a weight matrix.
        /// </summary>
        public static Action GetTestDirectedWeightMatrix(Router router, Profiles.Profile profile, int count)
        {
            var random    = new System.Random(145171654);
            var vertices  = new HashSet <uint>();
            var locations = new List <Coordinate>();

            while (locations.Count < count)
            {
                var v = (uint)random.Next((int)router.Db.Network.VertexCount);
                if (!vertices.Contains(v))
                {
                    vertices.Add(v);
                    locations.Add(router.Db.Network.GetVertex(v));
                }
            }

            var locationsArray = locations.ToArray();
            var massResolver   = new MassResolvingAlgorithm(router, new Profiles.IProfileInstance[] { profile }, locationsArray);

            massResolver.Run();

            var edges = new List <DirectedEdgeId>();

            foreach (var resolved in massResolver.RouterPoints)
            {
                edges.Add(new DirectedEdgeId(resolved.EdgeId, true));
                edges.Add(new DirectedEdgeId(resolved.EdgeId, false));
            }

            return(() =>
            {
                var result = router.TryCalculateWeight(profile, edges.ToArray(), edges.ToArray(), null);
            });
        }
Example #3
0
        /// <summary>
        /// Tests calculating a weight matrix.
        /// </summary>
        public static Action GetTestWeightMatrix(Router router, Profiles.Profile profile, int count)
        {
            var random    = new System.Random(145171654);
            var vertices  = new HashSet <uint>();
            var locations = new List <Coordinate>();

            while (locations.Count < count)
            {
                var v = (uint)random.Next((int)router.Db.Network.VertexCount);
                if (!vertices.Contains(v))
                {
                    vertices.Add(v);
                    locations.Add(router.Db.Network.GetVertex(v));
                }
            }

            var locationsArray = locations.ToArray();
            var massResolver   = new MassResolvingAlgorithm(router, new Profiles.IProfileInstance[] { profile }, locationsArray);

            massResolver.Run();

            return(() =>
            {
                var invalids = new HashSet <int>();
                var weights = router.CalculateWeight(profile, massResolver.RouterPoints.ToArray(), invalids);
            });
        }
Example #4
0
        public void Test1TwoPointsWithMatching()
        {
            // build test case.
            var router    = new RouterMock(new AttributeCollection(new Itinero.Attributes.Attribute("highway", "residential")));
            var locations = new Coordinate[] {
                new Coordinate(0, 0),
                new Coordinate(1, 1)
            };
            var resolver = new MassResolvingAlgorithm(router, new Itinero.Profiles.Profile[] { Itinero.Osm.Vehicles.Vehicle.Car.Fastest() }, locations,
                                                      (edge, i) =>
            {
                return(true);
            });

            // run.
            resolver.Run();

            // check result.
            Assert.IsNotNull(resolver);
            Assert.IsTrue(resolver.HasRun);
            Assert.IsTrue(resolver.HasSucceeded);
            Assert.AreEqual(0, resolver.Errors.Count);
            Assert.AreEqual(2, resolver.RouterPoints.Count);
            Assert.AreEqual(0, resolver.ResolvedIndexOf(0));
            Assert.AreEqual(1, resolver.ResolvedIndexOf(1));

            // build test case.
            router    = new RouterMock(new AttributeCollection(new Itinero.Attributes.Attribute("highway", "primary")));
            locations = new Coordinate[] {
                new Coordinate(0, 0),
                new Coordinate(1, 1)
            };
            resolver = new MassResolvingAlgorithm(router, new Itinero.Profiles.Profile[] { Itinero.Osm.Vehicles.Vehicle.Car.Fastest() }, locations,
                                                  (edge, i) =>
            {
                return(false);
            });

            // run.
            resolver.Run();

            Assert.IsNotNull(resolver);
            Assert.IsTrue(resolver.HasRun);
            Assert.IsTrue(resolver.HasSucceeded);
            Assert.AreEqual(2, resolver.Errors.Count);
            Assert.AreEqual(LocationErrorCode.NotResolved, resolver.Errors[0].Code);
            Assert.AreEqual(LocationErrorCode.NotResolved, resolver.Errors[1].Code);
        }
Example #5
0
        public void Test2TwoPoints()
        {
            // build test case.
            var router    = new RouterMock();
            var locations = new Coordinate[] {
                new Coordinate(0, 0),
                new Coordinate(180, 1)
            };
            var resolver = new MassResolvingAlgorithm(router, new Itinero.Profiles.Profile[] { Itinero.Osm.Vehicles.Vehicle.Car.Fastest() }, locations);

            // run.
            resolver.Run();

            Assert.IsNotNull(resolver);
            Assert.IsTrue(resolver.HasRun);
            Assert.IsTrue(resolver.HasSucceeded);
            Assert.AreEqual(1, resolver.Errors.Count);
            Assert.IsTrue(resolver.Errors.ContainsKey(1));
            Assert.AreEqual(1, resolver.RouterPoints.Count);
            Assert.AreEqual(0, resolver.ResolvedIndexOf(0));
            Assert.AreEqual(0, resolver.LocationIndexOf(0));

            // build test case.
            locations = new Coordinate[] {
                new Coordinate(180, 0),
                new Coordinate(1, 1)
            };
            resolver = new MassResolvingAlgorithm(router, new Itinero.Profiles.Profile[] { Itinero.Osm.Vehicles.Vehicle.Car.Fastest() }, locations);

            // run.
            resolver.Run();

            Assert.IsNotNull(resolver);
            Assert.IsTrue(resolver.HasRun);
            Assert.IsTrue(resolver.HasSucceeded);
            Assert.AreEqual(1, resolver.Errors.Count);
            Assert.IsTrue(resolver.Errors.ContainsKey(0));
            Assert.AreEqual(0, resolver.ResolvedIndexOf(1));
            Assert.AreEqual(1, resolver.LocationIndexOf(0));
        }