Esempio n. 1
0
        public void TestCHDepthFirstEnumerator()
        {
            const string embeddedString = "OsmSharp.UnitTests.test_network_real1.osm";

            // creates a new interpreter.
            var interpreter = new OsmRoutingInterpreter();

            // do the data processing.
            var original = CHEdgeGraphOsmStreamWriter.Preprocess(new XmlOsmStreamSource(
                                                                     Assembly.GetExecutingAssembly()
                                                                     .GetManifestResourceStream(embeddedString)),
                                                                 interpreter,
                                                                 Vehicle.Car);

            // add the downward edges.
            original.AddDownwardEdges();

            // enumerate using depth-first search.
            CHDepthFirstEnumerator enumerator =
                new CHDepthFirstEnumerator(original);
            HashSet <uint> vertices = new HashSet <uint>(
                enumerator.Select(x => x.VertexId));

            for (uint vertexId = 1; vertexId < original.VertexCount + 1; vertexId++)
            {
                Assert.IsTrue(vertices.Contains(vertexId));
            }
        }
Esempio n. 2
0
        public void TestCHDataSourceTopologicalSortTest()
        {
            const string embeddedString = "OsmSharp.UnitTests.test_network_real1.osm";

            // creates a new interpreter.
            var interpreter = new OsmRoutingInterpreter();

            // do the data processing.
            var original = CHEdgeGraphOsmStreamWriter.Preprocess(new XmlOsmStreamSource(
                                                                     Assembly.GetExecutingAssembly()
                                                                     .GetManifestResourceStream(embeddedString)),
                                                                 interpreter,
                                                                 Vehicle.Car);
            var sortedGraph = CHEdgeDataDataSourceSerializer.SortGraph(original);

            original = CHEdgeGraphOsmStreamWriter.Preprocess(new XmlOsmStreamSource(
                                                                 Assembly.GetExecutingAssembly()
                                                                 .GetManifestResourceStream(embeddedString)),
                                                             interpreter,
                                                             Vehicle.Car);
            var    basicRouterOriginal = new CHRouter(original);
            Router referenceRouter     = Router.CreateCHFrom(
                original, basicRouterOriginal, interpreter);

            // try to do some routing on the deserialized version.
            var basicRouter =
                new CHRouter(sortedGraph);
            Router router = Router.CreateCHFrom(
                new DynamicGraphRouterDataSource <CHEdgeData>(sortedGraph, original.TagsIndex), basicRouter, interpreter);

            // loop over all nodes and resolve their locations.
            var resolvedReference = new RouterPoint[original.VertexCount];
            var resolved          = new RouterPoint[original.VertexCount];

            for (uint idx = 1; idx < original.VertexCount + 1; idx++)
            { // resolve each vertex.
                float latitude, longitude;
                if (original.GetVertex(idx, out latitude, out longitude))
                {
                    resolvedReference[idx - 1] = referenceRouter.Resolve(Vehicle.Car, new GeoCoordinate(latitude, longitude));
                    resolved[idx - 1]          = router.Resolve(Vehicle.Car, new GeoCoordinate(latitude, longitude));
                }

                Assert.IsNotNull(resolvedReference[idx - 1]);
                Assert.IsNotNull(resolved[idx - 1]);

                //Assert.AreEqual(resolvedReference[idx - 1].Location.Latitude,
                //    resolved[idx - 1].Location.Latitude, 0.0001);
                //Assert.AreEqual(resolvedReference[idx - 1].Location.Longitude,
                //    resolved[idx - 1].Location.Longitude, 0.0001);
            }

            //// check all the routes having the same weight(s).
            //for (int fromIdx = 0; fromIdx < resolved.Length; fromIdx++)
            //{
            //    for (int toIdx = 0; toIdx < resolved.Length; toIdx++)
            //    {
            //        OsmSharpRoute referenceRoute = referenceRouter.Calculate(Vehicle.Car,
            //            resolvedReference[fromIdx], resolvedReference[toIdx]);
            //        OsmSharpRoute route = router.Calculate(Vehicle.Car,
            //            resolved[fromIdx], resolved[toIdx]);

            //        Assert.IsNotNull(referenceRoute);
            //        Assert.IsNotNull(route);
            //        //Assert.AreEqual(referenceRoute.TotalDistance, route.TotalDistance, 0.1);
            //        // TODO: meta data is missing in some CH routing; see issue
            //        //Assert.AreEqual(reference_route.TotalTime, route.TotalTime, 0.0001);
            //    }
            //}
        }
        public void RoutingSerializationV2CHRoutingComparisonTest()
        {
            const string embeddedString = "OsmSharp.UnitTests.test_network_real1.osm";

            // creates a new interpreter.
            var interpreter = new OsmRoutingInterpreter();

            // do the data processing.
            var original = CHEdgeGraphOsmStreamWriter.Preprocess(new XmlOsmStreamSource(
                                                                     Assembly.GetExecutingAssembly()
                                                                     .GetManifestResourceStream(embeddedString)),
                                                                 interpreter,
                                                                 Vehicle.Car);

            // create serializer.
            var routingSerializer = new OsmSharp.Routing.CH.Serialization.Sorted.CHEdgeDataDataSourceSerializer(true);

            // serialize/deserialize.
            byte[] byteArray;
            using (var stream = new MemoryStream())
            {
                try
                {
                    routingSerializer.Serialize(stream, original);
                    byteArray = stream.ToArray();
                }
                catch (Exception)
                {
                    if (Debugger.IsAttached)
                    {
                        Debugger.Break();
                    }
                    throw;
                }
            }

            IBasicRouterDataSource <CHEdgeData> deserializedVersion =
                routingSerializer.Deserialize(new MemoryStream(byteArray));

            Assert.AreEqual(original.TagsIndex.Get(0), deserializedVersion.TagsIndex.Get(0));

            // create reference router.
            original = CHEdgeGraphOsmStreamWriter.Preprocess(new XmlOsmStreamSource(
                                                                 Assembly.GetExecutingAssembly()
                                                                 .GetManifestResourceStream(embeddedString)),
                                                             interpreter,
                                                             Vehicle.Car);
            var    basicRouterOriginal = new CHRouter(original);
            Router referenceRouter     = Router.CreateCHFrom(
                original, basicRouterOriginal, interpreter);

            // try to do some routing on the deserialized version.
            var basicRouter =
                new CHRouter(deserializedVersion);
            Router router = Router.CreateCHFrom(
                deserializedVersion, basicRouter, interpreter);

            // loop over all nodes and resolve their locations.
            var resolvedReference = new RouterPoint[original.VertexCount];
            var resolved          = new RouterPoint[original.VertexCount];

            for (uint idx = 1; idx < original.VertexCount + 1; idx++)
            { // resolve each vertex.
                float latitude, longitude;
                if (original.GetVertex(idx, out latitude, out longitude))
                {
                    resolvedReference[idx - 1] = referenceRouter.Resolve(Vehicle.Car, new GeoCoordinate(latitude, longitude));
                    resolved[idx - 1]          = router.Resolve(Vehicle.Car, new GeoCoordinate(latitude, longitude));
                }

                Assert.IsNotNull(resolvedReference[idx - 1]);
                Assert.IsNotNull(resolved[idx - 1]);

                //Assert.AreEqual(resolvedReference[idx - 1].Location.Latitude,
                //    resolved[idx - 1].Location.Latitude, 0.0001);
                //Assert.AreEqual(resolvedReference[idx - 1].Location.Longitude,
                //    resolved[idx - 1].Location.Longitude, 0.0001);
            }

            //// check all the routes having the same weight(s).
            //for (int fromIdx = 0; fromIdx < resolved.Length; fromIdx++)
            //{
            //    for (int toIdx = 0; toIdx < resolved.Length; toIdx++)
            //    {
            //        OsmSharpRoute referenceRoute = referenceRouter.Calculate(Vehicle.Car,
            //            resolvedReference[fromIdx], resolvedReference[toIdx]);
            //        OsmSharpRoute route = router.Calculate(Vehicle.Car,
            //            resolved[fromIdx], resolved[toIdx]);

            //        if (route != null)
            //        {
            //            Assert.IsNotNull(referenceRoute);
            //        }
            //        else
            //        {
            //            Assert.IsNull(referenceRoute);
            //        }
            //        //Assert.AreEqual(referenceRoute.TotalDistance, route.TotalDistance, 0.1);
            //        // TODO: meta data is missing in some CH routing; see issue
            //        //Assert.AreEqual(reference_route.TotalTime, route.TotalTime, 0.0001);
            //    }
            //}
        }