예제 #1
0
        /// <summary>
        /// Returns a new router.
        /// </summary>
        /// <param name="interpreter"></param>
        /// <param name="embeddedName"></param>
        /// <param name="contract"></param>
        /// <returns></returns>
        public override Router BuildRouter(IOsmRoutingInterpreter interpreter, string embeddedName, bool contract)
        {
            if (_data == null)
            {
                _data = new Dictionary<string, DynamicGraphRouterDataSource<CHEdgeData>>();
            }
            DynamicGraphRouterDataSource<CHEdgeData> data = null;
            if (!_data.TryGetValue(embeddedName, out data))
            {
                var tagsIndex = new SimpleTagsIndex();

                // do the data processing.
                data =
                    new DynamicGraphRouterDataSource<CHEdgeData>(tagsIndex);
                var targetData = new CHEdgeGraphOsmStreamTarget(
                    data, interpreter, tagsIndex, Vehicle.Car);
                var dataProcessorSource = new XmlOsmStreamSource(
                    Assembly.GetExecutingAssembly().GetManifestResourceStream(string.Format(
                    "OsmSharp.Test.Unittests.{0}", embeddedName)));
                var sorter = new OsmStreamFilterSort();
                sorter.RegisterSource(dataProcessorSource);
                targetData.RegisterSource(sorter);
                targetData.Pull();

                // do the pre-processing part.
                var preProcessor = new CHPreProcessor(data,
                    new SparseOrdering(data), new DykstraWitnessCalculator());
                preProcessor.Start();

                _data[embeddedName] = data;
            }
            return Router.CreateCHFrom(data, new CHRouter(), interpreter);
        }
예제 #2
0
        public void TestRandomBlockTagSerializatonNonBeginPosition()
        {
            SimpleTagsIndex tagsIndex = new SimpleTagsIndex();

            SimpleTagsCollection tagsCollection = new SimpleTagsCollection();
            for (int i = 0; i < 100; i++)
            {
                int tagCollectionSize = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(10) + 1;
                for (int idx = 0; idx < tagCollectionSize; idx++)
                {
                    int tagValue = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(10);
                    tagsCollection.Add(
                        string.Format("key_{0}", tagValue),
                        string.Format("value_{0}", tagValue));
                }
                uint tagsId = tagsIndex.Add(tagsCollection);
            }

            ITagsIndexReadonly tagsIndexReadonly = this.SerializeDeserializeBlock(tagsIndex, 10, 123);
            Assert.AreEqual(tagsIndex.Max, tagsIndexReadonly.Max);
            for (uint idx = 0; idx < tagsIndex.Max; idx++)
            {
                this.CompareTagsCollections(tagsIndex.Get(idx),
                    tagsIndexReadonly.Get(idx));
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="vehicle"></param>
        public CHEdgeGraphFileStreamTarget(Stream stream, Vehicle vehicle)
        {
            _graphStream = stream;

            var tagsIndex = new SimpleTagsIndex();
            var interpreter = new OsmRoutingInterpreter();
            _graph = new DynamicGraphRouterDataSource<CHEdgeData>(tagsIndex);
            _graphTarget = new CHEdgeGraphOsmStreamTarget(
                _graph, interpreter, _graph.TagsIndex, vehicle);
        }
        /// <summary>
        /// Builds a raw data source.
        /// </summary>
        /// <returns></returns>
        public DynamicGraphRouterDataSource<LiveEdge> BuildDykstraDataSource(
            IOsmRoutingInterpreter interpreter, string embeddedName)
        {
            var tagsIndex = new SimpleTagsIndex();

            // do the data processing.
            var data = new DynamicGraphRouterDataSource<LiveEdge>(tagsIndex);
            var targetData = new LiveGraphOsmStreamTarget(
                data, interpreter, data.TagsIndex);
            var dataProcessorSource = new XmlOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream(string.Format(
                "OsmSharp.Test.Unittests.{0}", embeddedName)));
            var sorter = new OsmStreamFilterSort();
            sorter.RegisterSource(dataProcessorSource);
            targetData.RegisterSource(sorter);
            targetData.Pull();

            return data;
        }
        /// <summary>
        /// Creates a router.
        /// </summary>
        /// <param name="interpreter"></param>
        /// <param name="manifestResourceName"></param>
        /// <returns></returns>
        protected override Router CreateRouter(IOsmRoutingInterpreter interpreter, string manifestResourceName)
        {
            SimpleTagsIndex tagsIndex = new SimpleTagsIndex();

            // do the data processing.
            DynamicGraphRouterDataSource<LiveEdge> memoryData =
                new DynamicGraphRouterDataSource<LiveEdge>(tagsIndex);
            LiveGraphOsmStreamTarget target_data = new LiveGraphOsmStreamTarget(
                memoryData, interpreter, memoryData.TagsIndex);
            XmlOsmStreamSource dataProcessorSource = new XmlOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream(manifestResourceName));
            OsmStreamFilterSort sorter = new OsmStreamFilterSort();
            sorter.RegisterSource(dataProcessorSource);
            target_data.RegisterSource(sorter);
            target_data.Pull();

            IBasicRouter<LiveEdge> basicRouter = new DykstraRoutingLive(memoryData.TagsIndex);
            return Router.CreateLiveFrom(memoryData, basicRouter, interpreter);
        }
        public void RoutingRegressionTest1()
        {
            OsmRoutingInterpreter interpreter = new OsmRoutingInterpreter();

            SimpleTagsIndex tags_index = new SimpleTagsIndex();

            // do the data processing.
            DynamicGraphRouterDataSource<LiveEdge> memory_data =
                new DynamicGraphRouterDataSource<LiveEdge>(tags_index);
            LiveGraphOsmStreamTarget target_data = new LiveGraphOsmStreamTarget(
                memory_data, interpreter, memory_data.TagsIndex);
            XmlOsmStreamSource data_processor_source = new XmlOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Test.Unittests.test_routing_regression1.osm"));
            OsmStreamFilterSort sorter = new OsmStreamFilterSort();
            sorter.RegisterSource(data_processor_source);
            target_data.RegisterSource(sorter);
            target_data.Pull();

            IBasicRouter<LiveEdge> basic_router = new DykstraRoutingLive(memory_data.TagsIndex);
            Router router = Router.CreateLiveFrom(memory_data, basic_router, interpreter);

            // resolve the three points in question.
            GeoCoordinate point35 = new GeoCoordinate(51.01257, 4.000753);
            RouterPoint point35resolved = router.Resolve(Vehicle.Car, point35);
            //            GeoCoordinate point40 = new GeoCoordinate(51.01250, 4.000013);
            //            RouterPoint point40resolved = router.Resolve(Vehicle.Car, point40);
            GeoCoordinate point45 = new GeoCoordinate(51.01315, 3.999588);
            RouterPoint point45resolved = router.Resolve(Vehicle.Car, point45);

            // route between 35 and 45.
            Route routebefore = router.Calculate(Vehicle.Car, point35resolved, point45resolved);

            //            GeoCoordinate point129 = new GeoCoordinate(51.01239, 3.999573);
            //            RouterPoint point129resolved = router.Resolve(Vehicle.Car, point129);

            // route between 35 and 45.
            Route routeafter = router.Calculate(Vehicle.Car, point35resolved, point45resolved);
            Assert.AreEqual(routebefore.TotalDistance, routeafter.TotalDistance);
        }
        /// <summary>
        /// Creates a router.
        /// </summary>
        /// <param name="interpreter"></param>
        /// <param name="manifestResourceName"></param>
        /// <returns></returns>
        protected override Router CreateRouter(IOsmRoutingInterpreter interpreter, string manifestResourceName)
        {
            SimpleTagsIndex tagsIndex = new SimpleTagsIndex();

            // do the data processing.
            var data = new DynamicGraphRouterDataSource<CHEdgeData>(tagsIndex);
            var targetData = new CHEdgeGraphOsmStreamTarget(
                data, interpreter, data.TagsIndex, Vehicle.Car);
            var dataProcessorSource = new XmlOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream(manifestResourceName));
            var sorter = new OsmStreamFilterSort();
            sorter.RegisterSource(dataProcessorSource);
            targetData.RegisterSource(sorter);
            targetData.Pull();

            // do the pre-processing part.
            var witnessCalculator = new DykstraWitnessCalculator(data);
            var preProcessor = new CHPreProcessor(data,
                new EdgeDifference(data, witnessCalculator), witnessCalculator);
            preProcessor.Start();

            //IBasicRouter<LiveEdge> basicRouter = new DykstraRoutingLive(memoryData.TagsIndex);
            return Router.CreateCHFrom(data, new CHRouter(data), interpreter);
        }
예제 #8
0
        public void TestRandomPartialTagSerializaton()
        {
            SimpleTagsIndex tagsIndex = new SimpleTagsIndex();

            SimpleTagsCollection tagsCollection = new SimpleTagsCollection();
            for (int i = 0; i < 100; i++)
            {
                int tagCollectionSize = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(10) + 1;
                for (int idx = 0; idx < tagCollectionSize; idx++)
                {
                    int tagValue = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(10);
                    tagsCollection.Add(
                        string.Format("key_{0}", tagValue),
                        string.Format("value_{0}", tagValue));
                }
                uint tagsId = tagsIndex.Add(tagsCollection);
            }

            uint from = 40;
            uint to = 50;

            ITagsIndexReadonly tagsIndexReadonly = this.SerializeDeserialize(tagsIndex, from, to);
            Assert.AreEqual(System.Math.Min(to, tagsIndex.Max), tagsIndexReadonly.Max);
            for (uint idx = 0; idx < tagsIndex.Max; idx++)
            {
                if (idx >= from && idx < to)
                {
                    this.CompareTagsCollections(tagsIndex.Get(idx),
                        tagsIndexReadonly.Get(idx));
                }
                else
                {
                    Assert.IsNull(tagsIndexReadonly.Get(idx));
                }
            }

            from = 0;
            to = 100;

            tagsIndexReadonly = this.SerializeDeserialize(tagsIndex, from, to);
            Assert.AreEqual(System.Math.Min(to, tagsIndex.Max), tagsIndexReadonly.Max);
            for (uint idx = 0; idx < tagsIndex.Max; idx++)
            {
                if (idx >= from && idx < to)
                {
                    this.CompareTagsCollections(tagsIndex.Get(idx),
                        tagsIndexReadonly.Get(idx));
                }
                else
                {
                    Assert.IsNull(tagsIndexReadonly.Get(idx));
                }
            }

            from = 10;
            to = 1000;

            tagsIndexReadonly = this.SerializeDeserialize(tagsIndex, from, to);
            Assert.AreEqual(System.Math.Min(to, tagsIndex.Max), tagsIndexReadonly.Max);
            for (uint idx = 0; idx < tagsIndex.Max; idx++)
            {
                if (idx >= from && idx < to)
                {
                    this.CompareTagsCollections(tagsIndex.Get(idx),
                        tagsIndexReadonly.Get(idx));
                }
                else
                {
                    Assert.IsNull(tagsIndexReadonly.Get(idx));
                }
            }
        }
예제 #9
0
        /// <summary>
        /// Builds an in-memory data source from an xml data stream.
        /// </summary>
        /// <param name="stream"></param>
        /// <returns></returns>
        private DynamicGraphRouterDataSource<CHEdgeData> BuildData(Stream stream)
        {
            var interpreter = new OsmRoutingInterpreter();
            var tagsIndex = new SimpleTagsIndex();

            // do the data processing.
            var data = new DynamicGraphRouterDataSource<CHEdgeData>(tagsIndex);
            var targetData = new CHEdgeGraphOsmStreamTarget(
                data, interpreter, tagsIndex, Vehicle.Car);
            var dataProcessorSource = new XmlOsmStreamSource(stream);
            var sorter = new OsmStreamFilterSort();
            sorter.RegisterSource(dataProcessorSource);
            targetData.RegisterSource(sorter);
            targetData.Pull();

            return data;
        }
예제 #10
0
        /// <summary>
        /// Builds the data source.
        /// </summary>
        /// <returns></returns>
        private DynamicGraphRouterDataSource<CHEdgeData> BuildData(IOsmRoutingInterpreter interpreter)
        {
            DynamicGraphRouterDataSource<CHEdgeData> data = null;
            if (data == null)
            {
                var tagsIndex = new SimpleTagsIndex();

                // do the data processing.
                data = new DynamicGraphRouterDataSource<CHEdgeData>(tagsIndex);
                var targetData = new CHEdgeGraphOsmStreamTarget(
                    data, interpreter, tagsIndex, Vehicle.Car);
                var dataProcessorSource = new XmlOsmStreamSource(
                    Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Test.Unittests.test_network.osm"));
                var sorter = new OsmStreamFilterSort();
                sorter.RegisterSource(dataProcessorSource);
                targetData.RegisterSource(sorter);
                targetData.Pull();
            }
            return data;
        }
예제 #11
0
        public void RoutingSerializationV2CompressedRoutingTest()
        {
            const string embeddedString = "OsmSharp.Test.Unittests.test_network.osm";

            // create the tags index.
            var tagsIndex = new SimpleTagsIndex();

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

            // do the data processing.
            var original =
                new DynamicGraphRouterDataSource<LiveEdge>(tagsIndex);
            var targetData = new LiveGraphOsmStreamTarget(
                original, interpreter, tagsIndex);
            var dataProcessorSource = new XmlOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream(embeddedString));
            targetData.RegisterSource(dataProcessorSource);
            targetData.Pull();

            // create serializer.
            var routingSerializer = new V2RoutingDataSourceLiveEdgeSerializer(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<LiveEdge> deserializedVersion =
                routingSerializer.Deserialize(new MemoryStream(byteArray));
            Assert.AreEqual(original.TagsIndex.Get(0), deserializedVersion.TagsIndex.Get(0));

            // try to do some routing on the deserialized version.
            var basicRouter = new DykstraRoutingLive();
            Router router = Router.CreateLiveFrom(deserializedVersion, basicRouter, interpreter);
            RouterPoint source = router.Resolve(Vehicle.Car,
                new GeoCoordinate(51.0578532, 3.7192229));
            RouterPoint target = router.Resolve(Vehicle.Car,
                new GeoCoordinate(51.0576193, 3.7191801));

            // calculate the route.
            Route route = router.Calculate(Vehicle.Car, source, target);
            Assert.IsNotNull(route);
            Assert.AreEqual(5, route.Entries.Length);

            float latitude, longitude;
            deserializedVersion.GetVertex(20, out latitude, out longitude);
            Assert.AreEqual(latitude, route.Entries[0].Latitude, 0.00001);
            Assert.AreEqual(longitude, route.Entries[0].Longitude, 0.00001);
            Assert.AreEqual(RoutePointEntryType.Start, route.Entries[0].Type);

            deserializedVersion.GetVertex(21, out latitude, out longitude);
            Assert.AreEqual(latitude, route.Entries[1].Latitude, 0.00001);
            Assert.AreEqual(longitude, route.Entries[1].Longitude, 0.00001);
            Assert.AreEqual(RoutePointEntryType.Along, route.Entries[1].Type);

            deserializedVersion.GetVertex(16, out latitude, out longitude);
            Assert.AreEqual(latitude, route.Entries[2].Latitude, 0.00001);
            Assert.AreEqual(longitude, route.Entries[2].Longitude, 0.00001);
            Assert.AreEqual(RoutePointEntryType.Along, route.Entries[2].Type);

            deserializedVersion.GetVertex(22, out latitude, out longitude);
            Assert.AreEqual(latitude, route.Entries[3].Latitude, 0.00001);
            Assert.AreEqual(longitude, route.Entries[3].Longitude, 0.00001);
            Assert.AreEqual(RoutePointEntryType.Along, route.Entries[3].Type);

            deserializedVersion.GetVertex(23, out latitude, out longitude);
            Assert.AreEqual(latitude, route.Entries[4].Latitude, 0.00001);
            Assert.AreEqual(longitude, route.Entries[4].Longitude, 0.00001);
            Assert.AreEqual(RoutePointEntryType.Stop, route.Entries[4].Type);
        }
예제 #12
0
        public void RoutingSerializationV2DataSourceTest()
        {
            const string embeddedString = "OsmSharp.Test.Unittests.test_network.osm";

            // create the tags index.
            var tagsIndex = new SimpleTagsIndex();

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

            // do the data processing.
            var original =
                new DynamicGraphRouterDataSource<LiveEdge>(tagsIndex);
            var targetData = new LiveGraphOsmStreamTarget(
                original, interpreter, tagsIndex);
            var dataProcessorSource = new XmlOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream(embeddedString));
            targetData.RegisterSource(dataProcessorSource);
            targetData.Pull();

            // store some lat/lons.
            var verticesLocations = new List<GeoCoordinate>();
            for (uint vertex = 1; vertex <= 5; vertex++)
            {
                float latitude, longitude;
                if(original.GetVertex(vertex, out latitude, out longitude))
                {
                    verticesLocations.Add(
                        new GeoCoordinate(latitude, longitude));
                }
            }

            // create serializer.
            var routingSerializer = new V2RoutingDataSourceLiveEdgeSerializer(false);

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

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

            for (uint vertex = 1; vertex <= 5; vertex++)
            {
                float latitude, longitude;
                if (deserializedVersion.GetVertex(vertex, out latitude, out longitude))
                {
                    Assert.AreEqual(verticesLocations[(int)vertex - 1].Latitude, latitude, 0.000001);
                    Assert.AreEqual(verticesLocations[(int)vertex - 1].Longitude, longitude, 0.000001);
                }
            }
        }
예제 #13
0
        /// <summary>
        /// Tests the edge matcher in combination with dykstra routing.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="highway"></param>
        /// <param name="vehicle"></param>
        /// <param name="matcher"></param>
        /// <param name="pointName"></param>
        /// <param name="notFound"></param>
        private void TestResolveOnEdgeSingle(string name, string highway, 
            Vehicle vehicle, IEdgeMatcher matcher, 
            string pointName, bool notFound)
        {
            var fromName = new GeoCoordinate(51.0003, 4.0007);
            var toName = new GeoCoordinate(51.0003, 4.0008);

            var fromNoname = new GeoCoordinate(51.0, 4.0007);
            var toNoname = new GeoCoordinate(51.0, 4.0008);

            TagsCollection pointTags = new SimpleTagsCollection();
            pointTags["name"] = pointName;

            TagsCollection tags = new SimpleTagsCollection();
            tags["highway"] = highway;
            //tags["name"] = name;

            var tagsIndex = new SimpleTagsIndex();

            // do the data processing.
            var data = new DynamicGraphRouterDataSource<LiveEdge>(tagsIndex);
            uint vertexNoname1 = data.AddVertex((float)fromNoname.Latitude, (float)fromNoname.Longitude);
            uint vertexNoname2 = data.AddVertex((float)toNoname.Latitude, (float)toNoname.Longitude);
            data.AddArc(vertexNoname1, vertexNoname2, new LiveEdge()
            {
                Forward = true,
                Tags = tagsIndex.Add(tags)
            }, null);
            tags = new SimpleTagsCollection();
            tags["highway"] = highway;
            tags["name"] = name;
            uint vertexName1 = data.AddVertex((float)fromName.Latitude, (float)fromName.Longitude);
            uint vertexName2 = data.AddVertex((float)toName.Latitude, (float)toName.Longitude);
            data.AddArc(vertexName1, vertexName2, new LiveEdge()
            {
                Forward = true,
                Tags = tagsIndex.Add(tags)
            }, null);

            IRoutingInterpreter interpreter = new OsmRoutingInterpreter();

            // creates the data.
            IBasicRouter<LiveEdge> router = new DykstraRoutingLive();

            var nonameLocation = new GeoCoordinate(
                (fromNoname.Latitude + toNoname.Latitude) / 2.0,
                (fromNoname.Longitude + toNoname.Longitude) / 2.0);
            //            var nameLocation = new GeoCoordinate(
            //                (fromName.Latitude + toName.Latitude) / 2.0,
            //                (fromName.Longitude + toName.Longitude) / 2.0);

            const float delta = 0.01f;
            SearchClosestResult result = router.SearchClosest(data, interpreter, vehicle, nonameLocation, delta, matcher, pointTags);
            if (result.Distance < double.MaxValue)
            { // there is a result.
                Assert.IsFalse(notFound, "A result was found but was supposed not to  be found!");

                if (name == pointName)
                { // the name location was supposed to be found!
                    Assert.IsTrue(result.Vertex1 == vertexName1 || result.Vertex1 == vertexName2);
                    Assert.IsTrue(result.Vertex2 == vertexName1 || result.Vertex2 == vertexName2);
                }
                else
                { // the noname location was supposed to be found!
                    Assert.IsTrue(result.Vertex1 == vertexNoname1 || result.Vertex1 == vertexNoname2);
                    Assert.IsTrue(result.Vertex2 == vertexNoname1 || result.Vertex2 == vertexNoname2);
                }
                return;
            }
            Assert.IsTrue(notFound, "A result was not found but was supposed to be found!");
        }
        public void RoutingRegressionTest3()
        {
            OsmRoutingInterpreter interpreter = new OsmRoutingInterpreter();

            SimpleTagsIndex tags_index = new SimpleTagsIndex();

            // do the data processing.
            DynamicGraphRouterDataSource<LiveEdge> memory_data =
                new DynamicGraphRouterDataSource<LiveEdge>(tags_index);
            LiveGraphOsmStreamTarget target_data = new LiveGraphOsmStreamTarget(
                memory_data, interpreter, memory_data.TagsIndex);
            XmlOsmStreamSource data_processor_source = new XmlOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Test.Unittests.test_network.osm"));
            OsmStreamFilterSort sorter = new OsmStreamFilterSort();
            sorter.RegisterSource(data_processor_source);
            target_data.RegisterSource(sorter);
            target_data.Pull();

            IBasicRouter<LiveEdge> basic_router = new DykstraRoutingLive(memory_data.TagsIndex);
            Router router = Router.CreateLiveFrom(memory_data, basic_router, interpreter);

            // build coordinates list of resolved points.
            List<GeoCoordinate> testPoints = new List<GeoCoordinate>();
            testPoints.Add(new GeoCoordinate(51.0581719, 3.7201622));
            testPoints.Add(new GeoCoordinate(51.0580439, 3.7202134));
            testPoints.Add(new GeoCoordinate(51.0580573, 3.7204378));
            testPoints.Add(new GeoCoordinate(51.0581862, 3.7203758));

            // build a matrix of routes between all points.
            Route[][] referenceRoutes = new Route[testPoints.Count][];
            int[] permuationArray = new int[testPoints.Count];
            for (int fromIdx = 0; fromIdx < testPoints.Count; fromIdx++)
            {
                permuationArray[fromIdx] = fromIdx;
                referenceRoutes[fromIdx] = new Route[testPoints.Count];
                for (int toIdx = 0; toIdx < testPoints.Count; toIdx++)
                {
                    // create router from scratch.
                    router = Router.CreateLiveFrom(
                        memory_data, basic_router, interpreter);

                    // resolve points.
                    RouterPoint from = router.Resolve(Vehicle.Car, testPoints[fromIdx]);
                    RouterPoint to = router.Resolve(Vehicle.Car, testPoints[toIdx]);

                    // calculate route.
                    referenceRoutes[fromIdx][toIdx] = router.Calculate(Vehicle.Car, from, to);
                }
            }

            // resolve points in some order and compare the resulting routes.
            // they should be identical in length except for some numerical rounding errors.
            PermutationEnumerable<int> enumerator = new PermutationEnumerable<int>(
                permuationArray);
            foreach (int[] permutation in enumerator)
            {
                // create router from scratch.
                router = Router.CreateLiveFrom(memory_data, basic_router, interpreter);

                // resolve in the order of the permutation.
                RouterPoint[] resolvedPoints = new RouterPoint[permutation.Length];
                for (int idx = 0; idx < permutation.Length; idx++)
                {
                    resolvedPoints[permutation[idx]] = router.Resolve(Vehicle.Car, testPoints[permutation[idx]]);
                }

                for (int fromIdx = 0; fromIdx < testPoints.Count; fromIdx++)
                {
                    for (int toIdx = 0; toIdx < testPoints.Count; toIdx++)
                    {
                        // calculate route.
                        Route route = router.Calculate(Vehicle.Car, resolvedPoints[fromIdx], resolvedPoints[toIdx]);

                        Assert.AreEqual(referenceRoutes[fromIdx][toIdx].TotalDistance, route.TotalDistance, 0.1);
                    }
                }
            }
        }
예제 #15
0
        public void TestSimpleTagSerializatonNonBeginPosition()
        {
            SimpleTagsIndex tagsIndex = new SimpleTagsIndex();

            SimpleTagsCollection tagsCollection = new SimpleTagsCollection();
            tagsCollection.Add("key1", "value1");

            uint tagsId = tagsIndex.Add(tagsCollection);

            ITagsIndexReadonly tagsIndexReadonly = this.SerializeDeserialize(tagsIndex, 1201);
            Assert.AreEqual(tagsIndex.Max, tagsIndexReadonly.Max);
            for (uint idx = 0; idx < tagsIndex.Max; idx++)
            {
                this.CompareTagsCollections(tagsIndex.Get(idx),
                    tagsIndexReadonly.Get(idx));
            }
        }
예제 #16
0
        /// <summary>
        /// Creates a router using live interpreted edges.
        /// </summary>
        /// <param name="reader">The OSM-stream reader.</param>
        /// <param name="interpreter">The routing interpreter.</param>
        /// <returns></returns>
        public static Router CreateLiveFrom(OsmStreamSource reader, IOsmRoutingInterpreter interpreter)
        {
            var tagsIndex = new SimpleTagsIndex(); // creates a tagged index.

            // read from the OSM-stream.
            var memoryData = new DynamicGraphRouterDataSource<LiveEdge>(tagsIndex);
            var targetData = new LiveGraphOsmStreamTarget(memoryData, interpreter, tagsIndex);
            var sorter = new OsmStreamFilterSort();
            sorter.RegisterSource(reader);
            targetData.RegisterSource(sorter);
            targetData.Pull();

            // creates the live edge router.
            var liveEdgeRouter = new TypedRouterLiveEdge(
                memoryData, interpreter, new DykstraRoutingLive(tagsIndex));

            return new Router(liveEdgeRouter); // create the actual router.
        }
예제 #17
0
        public void RoutingRegressionTest2()
        {
            OsmRoutingInterpreter interpreter = new OsmRoutingInterpreter();

            SimpleTagsIndex tags_index = new SimpleTagsIndex();

            // do the data processing.
            DynamicGraphRouterDataSource<LiveEdge> memory_data =
                new DynamicGraphRouterDataSource<LiveEdge>(tags_index);
            LiveGraphOsmStreamTarget target_data = new LiveGraphOsmStreamTarget(
                memory_data, interpreter, tags_index);
            XmlOsmStreamSource data_processor_source = new XmlOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Test.Unittests.test_network.osm"));
            OsmStreamFilterSort sorter = new OsmStreamFilterSort();
            sorter.RegisterSource(data_processor_source);
            target_data.RegisterSource(sorter);
            target_data.Pull();

            IBasicRouter<LiveEdge> basic_router = new DykstraRoutingLive();
            Router router = Router.CreateLiveFrom(memory_data, basic_router, interpreter);

            // build coordinates list of resolved points.
            List<GeoCoordinate> testPoints = new List<GeoCoordinate>();
            testPoints.Add(new GeoCoordinate(51.0582204, 3.7193524));
            testPoints.Add(new GeoCoordinate(51.0582199, 3.7194002));
            //testPoints.Add(new GeoCoordinate(51.0582178, 3.7195025));

            testPoints.Add(new GeoCoordinate(51.0581727, 3.7195833));
            testPoints.Add(new GeoCoordinate(51.0581483, 3.7195553));
            //testPoints.Add(new GeoCoordinate(51.0581219, 3.7195231));
            //testPoints.Add(new GeoCoordinate(51.0580965, 3.7194918));

            testPoints.Add(new GeoCoordinate(51.0581883, 3.7196617));
            testPoints.Add(new GeoCoordinate(51.0581628, 3.7196889));

            // build a matrix of routes between all points.
            Route[][] referenceRoutes = new Route[testPoints.Count][];
            int[] permuationArray = new int[testPoints.Count];
            for (int fromIdx = 0; fromIdx < testPoints.Count; fromIdx++)
            {
                permuationArray[fromIdx] = fromIdx;
                referenceRoutes[fromIdx] = new Route[testPoints.Count];
                for (int toIdx = 0; toIdx < testPoints.Count; toIdx++)
                {
                    // create router from scratch.
                    router = Router.CreateLiveFrom(
                        memory_data, basic_router, interpreter);

                    // resolve points.
                    RouterPoint from = router.Resolve(Vehicle.Car, testPoints[fromIdx]);
                    RouterPoint to = router.Resolve(Vehicle.Car, testPoints[toIdx]);

                    // calculate route.
                    referenceRoutes[fromIdx][toIdx] = router.Calculate(Vehicle.Car, from, to);
                }
            }

            // resolve points in some order and compare the resulting routes.
            // they should be identical in length except for some numerical rounding errors.
            PermutationEnumerable<int> enumerator = new PermutationEnumerable<int>(
                permuationArray);
            foreach (int[] permutation in enumerator)
            {
                //int[] permutation = new int[] { 5, 0, 1, 2, 4, 3, 6, 7, 8 };

                //// incrementally resolve points.
                //// create router from scratch.
                //router = new Router<SimpleWeighedEdge>(memory_data, interpreter, basic_router);

                //// resolve in the order of the permutation.
                //RouterPoint[] resolvedPoints = new RouterPoint[permutation.Length];
                //resolvedPoints[permutation[0]] = router.Resolve(VehicleEnum.Car, testPoints[permutation[0]]);
                //for (int idx = 1; idx < permutation.Length; idx++)
                //{
                //    resolvedPoints[permutation[idx]] = router.Resolve(VehicleEnum.Car, testPoints[permutation[idx]]);

                //    for (int fromIdx = 0; fromIdx <= idx; fromIdx++)
                //    {
                //        for (int toIdx = 0; toIdx <= idx; toIdx++)
                //        {
                //            // calculate route.
                //            OsmSharpRoute route = router.Calculate(VehicleEnum.Car,
                //                resolvedPoints[permutation[fromIdx]], resolvedPoints[permutation[toIdx]]);

                //            Assert.AreEqual(referenceRoutes[permutation[fromIdx]][permutation[toIdx]].TotalDistance,
                //                route.TotalDistance, 0.1);
                //        }
                //    }
                //}

                // create router from scratch.
                router = Router.CreateLiveFrom(memory_data, basic_router, interpreter);

                // resolve in the order of the permutation.
                RouterPoint[] resolvedPoints = new RouterPoint[permutation.Length];
                for (int idx = 0; idx < permutation.Length; idx++)
                {
                    resolvedPoints[permutation[idx]] = router.Resolve(Vehicle.Car, testPoints[permutation[idx]]);
                }

                for (int fromIdx = 0; fromIdx < testPoints.Count; fromIdx++)
                {
                    for (int toIdx = 0; toIdx < testPoints.Count; toIdx++)
                    {
                        // calculate route.
                        Route route = router.Calculate(Vehicle.Car, resolvedPoints[fromIdx], resolvedPoints[toIdx]);

                        Assert.AreEqual(referenceRoutes[fromIdx][toIdx].TotalDistance, route.TotalDistance, 0.1);
                    }
                }
            }
        }
        /// <summary>
        /// Executes the CH contractions while verifying each step.
        /// </summary>
        /// <param name="stream"></param>
        public void DoTestCHEdgeDifferenceVerifiedContraction(Stream stream)
        {
            _interpreter = new OsmRoutingInterpreter();

            var tagsIndex = new SimpleTagsIndex();

            // do the data processing.
            _data = new DynamicGraphRouterDataSource<CHEdgeData>(tagsIndex);
            var targetData = new CHEdgeGraphOsmStreamTarget(
                _data, _interpreter, _data.TagsIndex, Vehicle.Car);
            var dataProcessorSource = new XmlOsmStreamSource(stream);
            var sorter = new OsmStreamFilterSort();
            sorter.RegisterSource(dataProcessorSource);
            targetData.RegisterSource(sorter);
            targetData.Pull();

            // do the pre-processing part.
            var witnessCalculator = new DykstraWitnessCalculator(
                _data);
            var preProcessor = new CHPreProcessor(_data,
                new EdgeDifference(_data, witnessCalculator), witnessCalculator);
            preProcessor.OnBeforeContractionEvent +=
                new CHPreProcessor.VertexDelegate(pre_processor_OnBeforeContractionEvent);
            preProcessor.OnAfterContractionEvent +=
                new CHPreProcessor.VertexDelegate(pre_processor_OnAfterContractionEvent);
            preProcessor.Start();
        }
        /// <summary>
        /// Builds a raw router to compare against.
        /// </summary>
        /// <returns></returns>
        public void BuildDykstraRouter(string embeddedName,
            IOsmRoutingInterpreter interpreter)
        {
            var tagsIndex = new SimpleTagsIndex();

            // do the data processing.
            var data = new DynamicGraphRouterDataSource<LiveEdge>(tagsIndex);
            var targetData = new LiveGraphOsmStreamTarget(
                data, interpreter, tagsIndex, new Vehicle[] { Vehicle.Car });
            var dataProcessorSource = new XmlOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream(embeddedName));
            var sorter = new OsmStreamFilterSort();
            sorter.RegisterSource(dataProcessorSource);
            targetData.RegisterSource(sorter);
            targetData.Pull();

            // initialize the router.
            _referenceRouter = Router.CreateLiveFrom(data, new DykstraRoutingLive(), interpreter);
        }