Esempio n. 1
0
        public void TestCHEdgeDifferenceNonContracted()
        {
            var interpreter    = new OsmSharp.Routing.Osm.Interpreter.OsmRoutingInterpreter();
            var edgeDifference = this.BuildEdgeDifference(interpreter);

            Assert.AreEqual(5, edgeDifference.Calculate(1)); // witness paths from 2<->4.
            Assert.AreEqual(16, edgeDifference.Calculate(2));
            Assert.AreEqual(2, edgeDifference.Calculate(3));
            Assert.AreEqual(2, edgeDifference.Calculate(4));
            Assert.AreEqual(2, edgeDifference.Calculate(5));
            Assert.AreEqual(2, edgeDifference.Calculate(6));
            Assert.AreEqual(9, edgeDifference.Calculate(7));
            Assert.AreEqual(9, edgeDifference.Calculate(8));
            Assert.AreEqual(2, edgeDifference.Calculate(9));
            Assert.AreEqual(9, edgeDifference.Calculate(10));
            Assert.AreEqual(9, edgeDifference.Calculate(11));
            Assert.AreEqual(2, edgeDifference.Calculate(12));
            Assert.AreEqual(2, edgeDifference.Calculate(13));
            Assert.AreEqual(2, edgeDifference.Calculate(14));
            Assert.AreEqual(2, edgeDifference.Calculate(15));
            Assert.AreEqual(9, edgeDifference.Calculate(16));
            Assert.AreEqual(2, edgeDifference.Calculate(17));
            Assert.AreEqual(2, edgeDifference.Calculate(18));
            Assert.AreEqual(2, edgeDifference.Calculate(19));
            Assert.AreEqual(-1, edgeDifference.Calculate(20));
            Assert.AreEqual(2, edgeDifference.Calculate(21));
            Assert.AreEqual(2, edgeDifference.Calculate(22));
            Assert.AreEqual(-1, edgeDifference.Calculate(23));
        }
        /// <summary>
        /// Tests one route.
        /// </summary>
        /// <param name="embeddedName"></param>
        /// <param name="contract"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        protected void TestCompareOne(string embeddedName, GeoCoordinate from, GeoCoordinate to)
        {
            // build the routing settings.
            var interpreter = new OsmSharp.Routing.Osm.Interpreter.OsmRoutingInterpreter();

            // get the osm data source.
            var data = this.BuildDykstraDataSource(interpreter, embeddedName);

            // build the reference router.;
            var referenceRouter = this.BuildDykstraRouter(
                this.BuildDykstraDataSource(interpreter, embeddedName), interpreter,
                new Dykstra());

            // build the router to be tested.
            var router = this.BuildRouter(interpreter, embeddedName);

            var referenceResolvedFrom = referenceRouter.Resolve(Vehicle.Car, from);
            var referenceResolvedTo   = referenceRouter.Resolve(Vehicle.Car, to);
            var resolvedFrom          = router.Resolve(Vehicle.Car, from);
            var resolvedTo            = router.Resolve(Vehicle.Car, to);

            var referenceRoute = referenceRouter.Calculate(Vehicle.Car, referenceResolvedFrom, referenceResolvedTo);
            var route          = router.Calculate(Vehicle.Car, resolvedFrom, resolvedTo);

            this.CompareRoutes(referenceRoute, route);
        }
        public void TestCHDepthFirstEnumerator()
        {
            const string embeddedString = "OsmSharp.Test.Unittests.test_network_real1.osm";

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

            // do the data processing.
            var original = CHEdgeGraphOsmStreamTarget.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));
            }
        }
        public void RoutingRegressionTest1()
        {
            var interpreter = new OsmRoutingInterpreter();
            var tagsIndex = new TagsTableCollectionIndex();

            // do the data processing.
            var memoryData = new DynamicGraphRouterDataSource<LiveEdge>(tagsIndex);
            var targetData = new LiveGraphOsmStreamTarget(memoryData, interpreter, tagsIndex);
            var dataProcessorSource = new XmlOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Test.Unittests.test_routing_regression1.osm"));
            var sorter = new OsmStreamFilterSort();
            sorter.RegisterSource(dataProcessorSource);
            targetData.RegisterSource(sorter);
            targetData.Pull();

            var basicRouter = new Dykstra();
            var router = Router.CreateLiveFrom(memoryData, basicRouter, interpreter);

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

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

            // route between 35 and 45.
            var routeafter = router.Calculate(Vehicle.Car, point35resolved, point45resolved);
            Assert.AreEqual(routebefore.TotalDistance, routeafter.TotalDistance);
        }
        public void InstructionGenerationAFewTurns()
        {
            // create new interpreter.
            var interpreter = new OsmRoutingInterpreter();

            // create the language generator.
            var languageGenerator = new LanguageTestGenerator();

            // calculate the route.
            OsmSharpRoute route = this.Calculate(
                new GeoCoordinate(51.089900970459, 3.44386267662048),
                new GeoCoordinate(51.0862655639648, 3.44465517997742));

            // generate the instructions.
            var instructionGenerator = new InstructionGenerator();
            List<Instruction> instructions =
                instructionGenerator.Generate(route, interpreter, languageGenerator);

            // test the results in the language generator.
            Assert.AreEqual(6, instructions.Count);
            Assert.AreEqual("GeneratePoi:1", instructions[0].Text);
            Assert.AreEqual("GenerateDirectTurn:0_Right_0", instructions[1].Text);
            Assert.AreEqual("GenerateDirectTurn:0_Left_0", instructions[2].Text);
            Assert.AreEqual("GenerateDirectTurn:0_Left_0", instructions[3].Text);
            Assert.AreEqual("GenerateDirectTurn:0_Right_0", instructions[4].Text);
            Assert.AreEqual("GeneratePoi:1", instructions[5].Text);
        }
        public void RoutingSerializationV2CHRoutingComparisonTest()
        {
            const string embeddedString = "OsmSharp.Test.Unittests.test_network_real1.osm";

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

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

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

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

            IBasicRouterDataSource<CHEdgeData> deserializedVersion =
                routingSerializer.Deserialize(new MemoryStream(byteArray), out metaData);
            Assert.AreEqual(original.TagsIndex.Get(0), deserializedVersion.TagsIndex.Get(0));

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

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

            //this.TestCompareAll(original, referenceRouter, router);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="vehicle"></param>
        public CHEdgeGraphFileStreamTarget(Stream stream, Vehicle vehicle)
        {
            _graphStream = stream;

            var tagsIndex = new TagsTableCollectionIndex();
            var interpreter = new OsmRoutingInterpreter();
            _graph = new DynamicGraphRouterDataSource<CHEdgeData>(tagsIndex);
            _graphTarget = new CHEdgeGraphOsmStreamTarget(
                _graph, interpreter, tagsIndex, vehicle);
        }
Esempio n. 8
0
        /// <summary>
        /// Tests routing from a serialized routing file.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="stream"></param>
        /// <param name="testCount"></param>
        public static void TestSerializedRouting(string name, Stream stream, int testCount)
        {
            var vehicle = Vehicle.Car;

            var tagsIndex = new TagsTableCollectionIndex(); // creates a tagged index.

            // read from the OSM-stream.
            var reader = new OsmSharp.Osm.PBF.Streams.PBFOsmStreamSource(stream);
            var interpreter = new OsmRoutingInterpreter();
            var data = new DynamicGraphRouterDataSource<LiveEdge>(tagsIndex);
            data.DropVertexIndex();
            var targetData = new LiveGraphOsmStreamTarget(data, interpreter, tagsIndex);
            targetData.RegisterSource(reader);
            targetData.Pull();
            data.RebuildVertexIndex();

            // creates the live edge router.
            var router = new Dykstra();

            var performanceInfo = new PerformanceInfoConsumer("LiveRouting");
            performanceInfo.Start();
            performanceInfo.Report("Routing {0} routes...", testCount);

            var successCount = 0;
            var totalCount = testCount;
            var latestProgress = -1.0f;
            while (testCount > 0)
            {
                var from = (uint)OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(data.VertexCount - 1) + 1;
                var to = (uint)OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(data.VertexCount - 1) + 1;

                var route = router.Calculate(data, interpreter, vehicle, from, to);

                if (route != null)
                {
                    successCount++;
                }
                testCount--;

                // report progress.
                var progress = (float)System.Math.Round(((double)(totalCount - testCount) / (double)totalCount) * 100);
                if (progress != latestProgress)
                {
                    OsmSharp.Logging.Log.TraceEvent("LiveRouting", TraceEventType.Information,
                        "Routing... {0}%", progress);
                    latestProgress = progress;
                }
            }
            performanceInfo.Stop();

            OsmSharp.Logging.Log.TraceEvent("LiveRouting", OsmSharp.Logging.TraceEventType.Information,
                string.Format("{0}/{1} routes successfull!", successCount, totalCount));
        }
Esempio n. 9
0
        private Engine()
        {
            if (string.IsNullOrWhiteSpace(PbfDataFilePath))
            {
                throw new NullReferenceException("PbfDataFilePath must be set.");
            }

            if (!File.Exists(PbfDataFilePath))
            {
                throw new NullReferenceException("PbfDataFilePath '" + PbfDataFilePath + "' does not exist.");
            }

            // keeps a memory-efficient version of the osm-tags.
            var tagsIndex = new OsmTagsIndex();

            // creates a routing interpreter. (used to translate osm-tags into a routable network)
            var interpreter = new OsmRoutingInterpreter();

            // create a routing datasource, keeps all processed osm routing data.
            var osmData = new MemoryRouterDataSource<SimpleWeighedEdge>(tagsIndex);

            // load data into this routing datasource.
            Stream osmPbfData = new FileInfo(PbfDataFilePath).OpenRead(); // for example moscow!
            using (osmPbfData)
            {
                var targetData = new
                   SimpleWeighedDataGraphProcessingTarget(
                                osmData, interpreter, osmData.TagsIndex, VehicleEnum.Car);

                // replace this with PBFdataProcessSource when having downloaded a PBF file.
                var dataProcessorSource = new
                  PBFDataProcessorSource(osmPbfData);

                // pre-process the data.
                var stopwatch = new Stopwatch();
                stopwatch.Start();

                var sorter = new DataProcessorFilterSort();
                sorter.RegisterSource(dataProcessorSource);
                targetData.RegisterSource(sorter);
                targetData.Pull();

                stopwatch.Stop();
            }

            // create the router object: there all routing functions are available.
            router = new Router<SimpleWeighedEdge>(
                osmData, interpreter, new DykstraRoutingLive(osmData.TagsIndex));
        }
Esempio n. 10
0
        /// <summary>
        /// Calculates the TSP.
        /// </summary>
        /// <param name="dataStream"></param>
        /// <param name="csvStream"></param>
        /// <param name="pbf"></param>
        /// <param name="vehicleEnum"></param>
        /// <returns></returns>
        private Route CalculateTSP(Stream dataStream, Stream csvStream, bool pbf, Vehicle vehicleEnum)
        {
            // create the router.
            OsmRoutingInterpreter interpreter = new OsmRoutingInterpreter();
            Router router = Router.CreateLiveFrom(
                new XmlOsmStreamSource(dataStream), interpreter);

            // read the source files.
            const int latitudeIdx = 2;
            const int longitudeIdx = 3;
            string[][] pointStrings = DelimitedFileHandler.ReadDelimitedFileFromStream(
                csvStream,
                DelimiterType.DotCommaSeperated);
            var points = new List<RouterPoint>();
            int cnt = 10;
            foreach (string[] line in pointStrings)
            {
                if (points.Count >= cnt)
                {
                    break;
                }
                var latitudeString = (string)line[latitudeIdx];
                var longitudeString = (string)line[longitudeIdx];

                //string route_ud = (string)line[1];

                double longitude = 0;
                double latitude = 0;
                if (double.TryParse(longitudeString, System.Globalization.NumberStyles.Any,
                    System.Globalization.CultureInfo.InvariantCulture, out longitude) &&
                   double.TryParse(latitudeString, System.Globalization.NumberStyles.Any,
                    System.Globalization.CultureInfo.InvariantCulture, out latitude))
                {
                    var point = new GeoCoordinate(latitude, longitude);

                    RouterPoint resolved = router.Resolve(Vehicle.Car, point);
                    if (resolved != null && router.CheckConnectivity(Vehicle.Car, resolved, 100))
                    {
                        points.Add(resolved);
                    }
                }
            }

            var tspSolver = new RouterTSPWrapper<RouterTSP>(
                new RouterTSPAEXGenetic(), router, interpreter);
            return tspSolver.CalculateTSP(vehicleEnum, points.ToArray());
        }
        /// <summary>
        /// Tests preprocessing data from a PBF file.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="pbfFile"></param>
        public static void TestSerialization(string name, string pbfFile)
        {
            var testFile = new FileInfo(string.Format(@".\TestFiles\{0}", pbfFile));
            var stream = testFile.OpenRead();
            var source = new OsmSharp.Osm.Streams.Filters.OsmStreamFilterProgress();
            source.RegisterSource(new PBFOsmStreamSource(stream));

            var testOutputFile = new FileInfo(@"test.pedestrian.routing");
            testOutputFile.Delete();
            Stream writeStream = testOutputFile.OpenWrite();

            var tagsIndex = new TagsTableCollectionIndex();
            var interpreter = new OsmRoutingInterpreter();
            var graph = new DynamicGraphRouterDataSource<CHEdgeData>(tagsIndex);

            var performanceInfo = new PerformanceInfoConsumer("CHSerializerFlatFile.Serialize");
            performanceInfo.Start();
            performanceInfo.Report("Pulling from {0}...", testFile.Name);

            var data = CHEdgeGraphOsmStreamTarget.Preprocess(
                source, new OsmRoutingInterpreter(), Vehicle.Car);

            var metaData = new TagsCollection();
            metaData.Add("some_key", "some_value");
            var routingSerializer = new CHEdgeFlatfileSerializer();
            routingSerializer.Serialize(writeStream, data, metaData);

            stream.Dispose();
            writeStream.Dispose();

            OsmSharp.Logging.Log.TraceEvent("CHSerializerFlatFile", OsmSharp.Logging.TraceEventType.Information,
                string.Format("Serialized file: {0}KB", testOutputFile.Length / 1024));

            performanceInfo.Stop();

            performanceInfo = new PerformanceInfoConsumer("CHSerializerFlatFile.Deserialize");
            performanceInfo.Start();
            performanceInfo.Report("Deserializing again...");

            // open file again and read.
            writeStream = testOutputFile.OpenRead();
            var deserializedGraph = routingSerializer.Deserialize(writeStream);

            performanceInfo.Stop();
        }
        /// <summary>
        /// Compares all routes against the reference router.
        /// </summary>
        protected void TestCompareAll(string embeddedName)
        {
            // build the routing settings.
            var interpreter = new OsmSharp.Routing.Osm.Interpreter.OsmRoutingInterpreter();

            // get the osm data source.
            var data = this.BuildDykstraDataSource(interpreter, embeddedName);

            // build the reference router.;
            var referenceRouter = this.BuildDykstraRouter(
                this.BuildDykstraDataSource(interpreter, embeddedName), interpreter,
                new Dykstra());

            // build the router to be tested.
            var router = this.BuildRouter(interpreter, embeddedName);

            this.TestCompareAll(data, referenceRouter, router);
        }
Esempio n. 13
0
        /// <summary>
        /// Compares all routes against the reference router.
        /// </summary>
        protected void TestCompareAll(string embeddedName, bool contract)
        {
            // build the routing settings.
            IOsmRoutingInterpreter interpreter = new OsmSharp.Routing.Osm.Interpreter.OsmRoutingInterpreter();

            // get the osm data source.
            IBasicRouterDataSource <LiveEdge> data = this.BuildDykstraDataSource(interpreter, embeddedName);

            // build the reference router.;
            Router referenceRouter = this.BuildDykstraRouter(
                this.BuildDykstraDataSource(interpreter, embeddedName), interpreter,
                new DykstraRoutingLive());

            // build the router to be tested.
            Router router = this.BuildRouter(interpreter, embeddedName, contract);

            this.TestCompareAll(data, referenceRouter, router);
        }
Esempio n. 14
0
        public void SQLServerRoutingRegressionTests1()
        {
            // the connectionstring.
            string connectionString =
                @"Server=windows8-test\sqlexpress;User Id=OsmSharp;Password=OsmSharp;Database=OsmData;";

            // drop whatever data is there.
            SqlConnection sqlConnection = new SqlConnection(connectionString);
            sqlConnection.Open();
            SQLServer.SimpleSchema.SchemaTools.SQLServerSimpleSchemaTools.Remove(sqlConnection);
            sqlConnection.Close();

            // create the source from the osm file.
            var xmlSource = new XmlDataProcessorSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream(
                    "OsmSharp.Osm.Data.SQLServer.Unittests.Data.ukraine1.osm"));

            // create the SQLServer processor target.
            var testTarget = new SQLServerSimpleSchemaDataProcessorTarget(connectionString, true);
            testTarget.RegisterSource(xmlSource); // register the source.
            testTarget.Pull(); // pull the data from source to target.

            var source = new SQLServerSimpleSchemaSource(
                connectionString);
            var tagsIndex = new OsmTagsIndex();
            var interpreter = new OsmRoutingInterpreter();
            var routingData = new OsmSourceRouterDataSource(
                interpreter, tagsIndex, source, VehicleEnum.Car);

            IRouter<RouterPoint> router = new Router<PreProcessedEdge>(routingData, interpreter,
                new DykstraRoutingPreProcessed(routingData.TagsIndex));

            OsmSharpRoute route;

            RouterPoint point1 = router.Resolve(VehicleEnum.Car,
                new GeoCoordinate(50.3150034243338, 34.8784106812928));
            RouterPoint point2 = router.Resolve(VehicleEnum.Car,
                new GeoCoordinate(50.3092549484347, 34.8894929841615));
            route = router.Calculate(VehicleEnum.Car, point1, point2);

            Assert.IsNotNull(route);
        }
        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);
        }
Esempio n. 16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Engine"/> class.
        /// </summary>
        protected Engine()
        {
            // keeps a memory-efficient version of the osm-tags.
            var tagsIndex = new OsmTagsIndex();

            // creates a routing interpreter. (used to translate osm-tags into a routable network)
            interpreter = new OsmRoutingInterpreter();

            // create a routing datasource, keeps all processed osm routing data.
            var osmData = new MemoryRouterDataSource<SimpleWeighedEdge>(tagsIndex);

            // load data into this routing datasource.
            var fileSource = HostingEnvironment.MapPath("~/App_Data/Manchester.osm.pbf");
            Stream osmXmlData = new FileInfo(fileSource).OpenRead(); // for example moscow!
            using (osmXmlData)
            {
                var targetData = new SimpleWeighedDataGraphProcessingTarget(
                                osmData,
                                interpreter,
                                osmData.TagsIndex,
                                VehicleEnum.Car);

                // replace this with PBFdataProcessSource when having downloaded a PBF file.
                var dataProcessorSource = new
                  OsmSharp.Osm.Data.PBF.Raw.Processor.PBFDataProcessorSource(osmXmlData);

                // pre-process the data.
                var sorter = new DataProcessorFilterSort();
                sorter.RegisterSource(dataProcessorSource);
                targetData.RegisterSource(sorter);
                targetData.Pull();
            }

            // create the router object: there all routing functions are available.
            router = new Router<SimpleWeighedEdge>(
                osmData,
                interpreter,
                new DykstraRoutingLive(osmData.TagsIndex));
        }
        public void InstructionGenerationNoTurns()
        {
            // create new interpreter.
            var interpreter = new OsmRoutingInterpreter();

            // create the language generator.
            var languageGenerator = new LanguageTestGenerator();

            // calculate the route.
            OsmSharpRoute route = this.Calculate(
                new GeoCoordinate(51.09002, 3.44380),
                new GeoCoordinate(51.089900970459, 3.44386267662048));

            // generate the instructions.
            var instructionGenerator = new InstructionGenerator();
            List<Instruction> instructions =
                instructionGenerator.Generate(route, interpreter, languageGenerator);

            // test the results in the language generator.
            Assert.AreEqual(2, instructions.Count);
            Assert.AreEqual("GeneratePoi:1", instructions[0].Text);
            Assert.AreEqual("GeneratePoi:1", instructions[1].Text);
        }
Esempio n. 18
0
        static void Main(string[] args)
        {
            OsmSharp.Logging.Log.Enable();
            OsmSharp.Logging.Log.RegisterListener(new OsmSharp.WinForms.UI.Logging.ConsoleTraceListener());
            // read the source file.
            var lines = OsmSharp.IO.DelimitedFiles.DelimitedFileHandler.ReadDelimitedFile(null,
                new FileInfo("bicylestations.csv").OpenRead(), OsmSharp.IO.DelimitedFiles.DelimiterType.DotCommaSeperated, true);

            // create router.
            var interpreter = new OsmRoutingInterpreter();
            var router = Router.CreateLiveFrom(new PBFOsmStreamSource(new FileInfo("antwerp.osm.pbf").OpenRead()), interpreter);

            // resolve all points.
            var resolvedPoints = new List<RouterPoint>();
            foreach(var line in lines)
            {
                var latitude = double.Parse(line[0], System.Globalization.CultureInfo.InvariantCulture);
                var longitude = double.Parse(line[1], System.Globalization.CultureInfo.InvariantCulture);
                var refId = double.Parse(line[2], System.Globalization.CultureInfo.InvariantCulture);

                var resolved = router.Resolve(Vehicle.Bicycle, new Math.Geo.GeoCoordinate(latitude, longitude));
                if(resolved != null && router.CheckConnectivity(Vehicle.Bicycle, resolved, 100))
                { // point exists and is connected.
                    resolvedPoints.Add(resolved);
                }
                else
                { // report that the point could not be resolved.
                    Console.WriteLine("Point with ref {0} could not be resolved!", refId);
                }
            }

            // calculate TSP.
            var tspSolver = new RouterTSPWrapper<RouterTSP>(
                new RouterTSPAEXGenetic(1000, 200), router, interpreter);
            var route = tspSolver.CalculateTSP(Vehicle.Bicycle, resolvedPoints.ToArray());
            route.SaveAsGpx(new FileInfo("output.gpx").OpenWrite());
        }
        /// <summary>
        /// Calculates a route to test on.
        /// </summary>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <returns></returns>
        private OsmSharpRoute Calculate(GeoCoordinate from, GeoCoordinate to)
        {
            if (_router == null)
            {
                var interpreter = new OsmRoutingInterpreter();
                var tagsIndex = new OsmTagsIndex();

                // do the data processing.
                var memoryData =
                    new DynamicGraphRouterDataSource<SimpleWeighedEdge>(tagsIndex);
                var targetData = new SimpleWeighedDataGraphProcessingTarget(
                    memoryData, interpreter, memoryData.TagsIndex, VehicleEnum.Car);
                var dataProcessorSource = new XmlDataProcessorSource(
                    Assembly.GetExecutingAssembly().GetManifestResourceStream(
                        "OsmSharp.UnitTests.test_instructions.osm"));
                var sorter = new DataProcessorFilterSort();
                sorter.RegisterSource(dataProcessorSource);
                targetData.RegisterSource(sorter);
                targetData.Pull();

                _router = new Router<SimpleWeighedEdge>(
                    memoryData, interpreter, new DykstraRoutingLive(memoryData.TagsIndex));
            }

            RouterPoint fromPoint = _router.Resolve(VehicleEnum.Car, from);
            RouterPoint toPoint = _router.Resolve(VehicleEnum.Car, to);
            return _router.Calculate(VehicleEnum.Car, fromPoint, toPoint);
        }
Esempio n. 20
0
        public void TestCHEdgeDifferenceContractions()
        {
            IOsmRoutingInterpreter interpreter = new OsmSharp.Routing.Osm.Interpreter.OsmRoutingInterpreter();
            CHPreProcessor processor = this.BuildCHPreProcessor(interpreter);
            //processor.InitializeQueue();
            INodeWeightCalculator edgeDifference = processor.NodeWeightCalculator;

            Assert.AreEqual(1, edgeDifference.Calculate(1)); // witness paths from 2<->4.
            Assert.AreEqual(6, edgeDifference.Calculate(2));
            Assert.AreEqual(0, edgeDifference.Calculate(3));
            Assert.AreEqual(0, edgeDifference.Calculate(4));
            Assert.AreEqual(0, edgeDifference.Calculate(5));
            Assert.AreEqual(0, edgeDifference.Calculate(6));
            Assert.AreEqual(3, edgeDifference.Calculate(7));
            Assert.AreEqual(3, edgeDifference.Calculate(8));
            Assert.AreEqual(0, edgeDifference.Calculate(9));
            Assert.AreEqual(3, edgeDifference.Calculate(10));
            Assert.AreEqual(3, edgeDifference.Calculate(11));
            Assert.AreEqual(0, edgeDifference.Calculate(12));
            Assert.AreEqual(0, edgeDifference.Calculate(13));
            Assert.AreEqual(0, edgeDifference.Calculate(14));
            Assert.AreEqual(0, edgeDifference.Calculate(15));
            Assert.AreEqual(3, edgeDifference.Calculate(16));
            Assert.AreEqual(0, edgeDifference.Calculate(17));
            Assert.AreEqual(0, edgeDifference.Calculate(18));
            Assert.AreEqual(0, edgeDifference.Calculate(19));
            Assert.AreEqual(-1, edgeDifference.Calculate(20));
            Assert.AreEqual(0, edgeDifference.Calculate(21));
            Assert.AreEqual(0, edgeDifference.Calculate(22));
            Assert.AreEqual(-1, edgeDifference.Calculate(23));

            // contract 20.
            processor.Contract(20);

            Assert.AreEqual(1, edgeDifference.Calculate(1)); // witness paths from 2<->4.
            Assert.AreEqual(6, edgeDifference.Calculate(2));
            Assert.AreEqual(0, edgeDifference.Calculate(3));
            Assert.AreEqual(0, edgeDifference.Calculate(4));
            Assert.AreEqual(0, edgeDifference.Calculate(5));
            Assert.AreEqual(0, edgeDifference.Calculate(6));
            Assert.AreEqual(3, edgeDifference.Calculate(7));
            Assert.AreEqual(3, edgeDifference.Calculate(8));
            Assert.AreEqual(0, edgeDifference.Calculate(9));
            Assert.AreEqual(3, edgeDifference.Calculate(10));
            Assert.AreEqual(3, edgeDifference.Calculate(11));
            Assert.AreEqual(0, edgeDifference.Calculate(12));
            Assert.AreEqual(0, edgeDifference.Calculate(13));
            Assert.AreEqual(0, edgeDifference.Calculate(14));
            Assert.AreEqual(0, edgeDifference.Calculate(15));
            Assert.AreEqual(3, edgeDifference.Calculate(16));
            Assert.AreEqual(0, edgeDifference.Calculate(17));
            Assert.AreEqual(0, edgeDifference.Calculate(18));
            Assert.AreEqual(0, edgeDifference.Calculate(19));
            Assert.AreEqual(-1, edgeDifference.Calculate(21));
            Assert.AreEqual(0, edgeDifference.Calculate(22));
            Assert.AreEqual(-1, edgeDifference.Calculate(23));

            // contract 21.
            processor.Contract(21);

            Assert.AreEqual(1, edgeDifference.Calculate(1)); // witness paths from 2<->4.
            Assert.AreEqual(6, edgeDifference.Calculate(2));
            Assert.AreEqual(0, edgeDifference.Calculate(3));
            Assert.AreEqual(0, edgeDifference.Calculate(4));
            Assert.AreEqual(0, edgeDifference.Calculate(5));
            Assert.AreEqual(0, edgeDifference.Calculate(6));
            Assert.AreEqual(3, edgeDifference.Calculate(7));
            Assert.AreEqual(3, edgeDifference.Calculate(8));
            Assert.AreEqual(0, edgeDifference.Calculate(9));
            Assert.AreEqual(3, edgeDifference.Calculate(10));
            Assert.AreEqual(3, edgeDifference.Calculate(11));
            Assert.AreEqual(0, edgeDifference.Calculate(12));
            Assert.AreEqual(0, edgeDifference.Calculate(13));
            Assert.AreEqual(0, edgeDifference.Calculate(14));
            Assert.AreEqual(0, edgeDifference.Calculate(15));
            Assert.AreEqual(0, edgeDifference.Calculate(16));
            Assert.AreEqual(0, edgeDifference.Calculate(17));
            Assert.AreEqual(0, edgeDifference.Calculate(18));
            Assert.AreEqual(0, edgeDifference.Calculate(19));
            Assert.AreEqual(0, edgeDifference.Calculate(22));
            Assert.AreEqual(-1, edgeDifference.Calculate(23));

            // contract 23.
            processor.Contract(23);

            Assert.AreEqual(1, edgeDifference.Calculate(1)); // witness paths from 2<->4.
            Assert.AreEqual(6, edgeDifference.Calculate(2));
            Assert.AreEqual(0, edgeDifference.Calculate(3));
            Assert.AreEqual(0, edgeDifference.Calculate(4));
            Assert.AreEqual(0, edgeDifference.Calculate(5));
            Assert.AreEqual(0, edgeDifference.Calculate(6));
            Assert.AreEqual(3, edgeDifference.Calculate(7));
            Assert.AreEqual(3, edgeDifference.Calculate(8));
            Assert.AreEqual(0, edgeDifference.Calculate(9));
            Assert.AreEqual(3, edgeDifference.Calculate(10));
            Assert.AreEqual(3, edgeDifference.Calculate(11));
            Assert.AreEqual(0, edgeDifference.Calculate(12));
            Assert.AreEqual(0, edgeDifference.Calculate(13));
            Assert.AreEqual(0, edgeDifference.Calculate(14));
            Assert.AreEqual(0, edgeDifference.Calculate(15));
            Assert.AreEqual(0, edgeDifference.Calculate(16));
            Assert.AreEqual(0, edgeDifference.Calculate(17));
            Assert.AreEqual(0, edgeDifference.Calculate(18));
            Assert.AreEqual(0, edgeDifference.Calculate(19));
            Assert.AreEqual(-1, edgeDifference.Calculate(22));

            // contract 22.
            processor.Contract(22);

            Assert.AreEqual(1, edgeDifference.Calculate(1)); // witness paths from 2<->4.
            Assert.AreEqual(6, edgeDifference.Calculate(2));
            Assert.AreEqual(0, edgeDifference.Calculate(3));
            Assert.AreEqual(0, edgeDifference.Calculate(4));
            Assert.AreEqual(0, edgeDifference.Calculate(5));
            Assert.AreEqual(0, edgeDifference.Calculate(6));
            Assert.AreEqual(3, edgeDifference.Calculate(7));
            Assert.AreEqual(3, edgeDifference.Calculate(8));
            Assert.AreEqual(0, edgeDifference.Calculate(9));
            Assert.AreEqual(3, edgeDifference.Calculate(10));
            Assert.AreEqual(3, edgeDifference.Calculate(11));
            Assert.AreEqual(0, edgeDifference.Calculate(12));
            Assert.AreEqual(0, edgeDifference.Calculate(13));
            Assert.AreEqual(0, edgeDifference.Calculate(14));
            Assert.AreEqual(0, edgeDifference.Calculate(15));
            Assert.AreEqual(-1, edgeDifference.Calculate(16));
            Assert.AreEqual(0, edgeDifference.Calculate(17));
            Assert.AreEqual(0, edgeDifference.Calculate(18));
            Assert.AreEqual(0, edgeDifference.Calculate(19));

            // contract 16.
            processor.Contract(16);

            Assert.AreEqual(1, edgeDifference.Calculate(1)); // witness paths from 2<->4.
            Assert.AreEqual(6, edgeDifference.Calculate(2));
            Assert.AreEqual(0, edgeDifference.Calculate(3));
            Assert.AreEqual(0, edgeDifference.Calculate(4));
            Assert.AreEqual(0, edgeDifference.Calculate(5));
            Assert.AreEqual(0, edgeDifference.Calculate(6));
            Assert.AreEqual(3, edgeDifference.Calculate(7));
            Assert.AreEqual(3, edgeDifference.Calculate(8));
            Assert.AreEqual(0, edgeDifference.Calculate(9));
            Assert.AreEqual(3, edgeDifference.Calculate(10));
            Assert.AreEqual(3, edgeDifference.Calculate(11));
            Assert.AreEqual(0, edgeDifference.Calculate(12));
            Assert.AreEqual(0, edgeDifference.Calculate(13));
            Assert.AreEqual(0, edgeDifference.Calculate(14));
            Assert.AreEqual(0, edgeDifference.Calculate(15));
            Assert.AreEqual(-1, edgeDifference.Calculate(17));
            Assert.AreEqual(0, edgeDifference.Calculate(18));
            Assert.AreEqual(0, edgeDifference.Calculate(19));

            // contract 17.
            processor.Contract(17);

            Assert.AreEqual(1, edgeDifference.Calculate(1)); // witness paths from 2<->4.
            Assert.AreEqual(6, edgeDifference.Calculate(2));
            Assert.AreEqual(0, edgeDifference.Calculate(3));
            Assert.AreEqual(0, edgeDifference.Calculate(4));
            Assert.AreEqual(0, edgeDifference.Calculate(5));
            Assert.AreEqual(0, edgeDifference.Calculate(6));
            Assert.AreEqual(0, edgeDifference.Calculate(7));
            Assert.AreEqual(3, edgeDifference.Calculate(8));
            Assert.AreEqual(0, edgeDifference.Calculate(9));
            Assert.AreEqual(3, edgeDifference.Calculate(10));
            Assert.AreEqual(3, edgeDifference.Calculate(11));
            Assert.AreEqual(0, edgeDifference.Calculate(12));
            Assert.AreEqual(0, edgeDifference.Calculate(13));
            Assert.AreEqual(0, edgeDifference.Calculate(14));
            Assert.AreEqual(0, edgeDifference.Calculate(15));
            Assert.AreEqual(0, edgeDifference.Calculate(18));
            Assert.AreEqual(0, edgeDifference.Calculate(19));

            processor.Contract(3);

            Assert.AreEqual(1, edgeDifference.Calculate(1)); // witness paths from 2<->4.
            Assert.AreEqual(6, edgeDifference.Calculate(2));
            Assert.AreEqual(-2, edgeDifference.Calculate(4));
            Assert.AreEqual(0, edgeDifference.Calculate(5));
            Assert.AreEqual(0, edgeDifference.Calculate(6));
            Assert.AreEqual(0, edgeDifference.Calculate(7));
            Assert.AreEqual(3, edgeDifference.Calculate(8));
            Assert.AreEqual(0, edgeDifference.Calculate(9));
            Assert.AreEqual(3, edgeDifference.Calculate(10));
            Assert.AreEqual(3, edgeDifference.Calculate(11));
            Assert.AreEqual(0, edgeDifference.Calculate(12));
            Assert.AreEqual(0, edgeDifference.Calculate(13));
            Assert.AreEqual(0, edgeDifference.Calculate(14));
            Assert.AreEqual(0, edgeDifference.Calculate(15));
            Assert.AreEqual(0, edgeDifference.Calculate(18));
            Assert.AreEqual(0, edgeDifference.Calculate(19));

            processor.Contract(4);

            Assert.AreEqual(0, edgeDifference.Calculate(1)); // witness paths from 2<->4.
            Assert.AreEqual(3, edgeDifference.Calculate(2));
            Assert.AreEqual(0, edgeDifference.Calculate(5));
            Assert.AreEqual(0, edgeDifference.Calculate(6));
            Assert.AreEqual(0, edgeDifference.Calculate(7));
            Assert.AreEqual(3, edgeDifference.Calculate(8));
            Assert.AreEqual(0, edgeDifference.Calculate(9));
            Assert.AreEqual(3, edgeDifference.Calculate(10));
            Assert.AreEqual(3, edgeDifference.Calculate(11));
            Assert.AreEqual(0, edgeDifference.Calculate(12));
            Assert.AreEqual(0, edgeDifference.Calculate(13));
            Assert.AreEqual(0, edgeDifference.Calculate(14));
            Assert.AreEqual(0, edgeDifference.Calculate(15));
            Assert.AreEqual(0, edgeDifference.Calculate(18));
            Assert.AreEqual(0, edgeDifference.Calculate(19));

            processor.Contract(1);

            Assert.AreEqual(1, edgeDifference.Calculate(2)); // witness paths from 11<->5.
            Assert.AreEqual(-2, edgeDifference.Calculate(5)); // witness paths from 11<->6.
            Assert.AreEqual(0, edgeDifference.Calculate(6));
            Assert.AreEqual(0, edgeDifference.Calculate(7));
            Assert.AreEqual(3, edgeDifference.Calculate(8));
            Assert.AreEqual(0, edgeDifference.Calculate(9));
            Assert.AreEqual(3, edgeDifference.Calculate(10));
            Assert.AreEqual(3, edgeDifference.Calculate(11));
            Assert.AreEqual(0, edgeDifference.Calculate(12));
            Assert.AreEqual(0, edgeDifference.Calculate(13));
            Assert.AreEqual(0, edgeDifference.Calculate(14));
            Assert.AreEqual(0, edgeDifference.Calculate(15));
            Assert.AreEqual(0, edgeDifference.Calculate(18));
            Assert.AreEqual(0, edgeDifference.Calculate(19));

            processor.Contract(5);

            Assert.AreEqual(1, edgeDifference.Calculate(2)); // witness paths from 11<->5.
            Assert.AreEqual(-2, edgeDifference.Calculate(6));
            Assert.AreEqual(0, edgeDifference.Calculate(7));
            Assert.AreEqual(3, edgeDifference.Calculate(8));
            Assert.AreEqual(0, edgeDifference.Calculate(9));
            Assert.AreEqual(3, edgeDifference.Calculate(10));
            Assert.AreEqual(3, edgeDifference.Calculate(11));
            Assert.AreEqual(0, edgeDifference.Calculate(12));
            Assert.AreEqual(0, edgeDifference.Calculate(13));
            Assert.AreEqual(0, edgeDifference.Calculate(14));
            Assert.AreEqual(0, edgeDifference.Calculate(15));
            Assert.AreEqual(0, edgeDifference.Calculate(18));
            Assert.AreEqual(0, edgeDifference.Calculate(19));

            processor.Contract(6);

            Assert.AreEqual(0, edgeDifference.Calculate(2)); // witness paths from 11<->5.
            Assert.AreEqual(-1, edgeDifference.Calculate(7));
            Assert.AreEqual(3, edgeDifference.Calculate(8));
            Assert.AreEqual(0, edgeDifference.Calculate(9));
            Assert.AreEqual(3, edgeDifference.Calculate(10));
            Assert.AreEqual(3, edgeDifference.Calculate(11));
            Assert.AreEqual(0, edgeDifference.Calculate(12));
            Assert.AreEqual(0, edgeDifference.Calculate(13));
            Assert.AreEqual(0, edgeDifference.Calculate(14));
            Assert.AreEqual(0, edgeDifference.Calculate(15));
            Assert.AreEqual(0, edgeDifference.Calculate(18));
            Assert.AreEqual(0, edgeDifference.Calculate(19));

            processor.Contract(7);

            Assert.AreEqual(0, edgeDifference.Calculate(2)); // witness paths from 11<->5.
            Assert.AreEqual(3, edgeDifference.Calculate(8));
            Assert.AreEqual(0, edgeDifference.Calculate(9));
            Assert.AreEqual(3, edgeDifference.Calculate(10));
            Assert.AreEqual(0, edgeDifference.Calculate(11));
            Assert.AreEqual(0, edgeDifference.Calculate(12));
            Assert.AreEqual(0, edgeDifference.Calculate(13));
            Assert.AreEqual(0, edgeDifference.Calculate(14));
            Assert.AreEqual(0, edgeDifference.Calculate(15));
            Assert.AreEqual(0, edgeDifference.Calculate(18));
            Assert.AreEqual(0, edgeDifference.Calculate(19));

            processor.Contract(2);

            Assert.AreEqual(3, edgeDifference.Calculate(8));
            Assert.AreEqual(0, edgeDifference.Calculate(9));
            Assert.AreEqual(3, edgeDifference.Calculate(10));
            Assert.AreEqual(-2, edgeDifference.Calculate(11)); // witness paths from 18<->10.
            Assert.AreEqual(0, edgeDifference.Calculate(12));
            Assert.AreEqual(0, edgeDifference.Calculate(13));
            Assert.AreEqual(0, edgeDifference.Calculate(14));
            Assert.AreEqual(0, edgeDifference.Calculate(15));
            Assert.AreEqual(0, edgeDifference.Calculate(18));
            Assert.AreEqual(0, edgeDifference.Calculate(19));

            processor.Contract(11);

            Assert.AreEqual(3, edgeDifference.Calculate(8));
            Assert.AreEqual(0, edgeDifference.Calculate(9));
            Assert.AreEqual(1, edgeDifference.Calculate(10));
            Assert.AreEqual(0, edgeDifference.Calculate(12));
            Assert.AreEqual(0, edgeDifference.Calculate(13));
            Assert.AreEqual(0, edgeDifference.Calculate(14));
            Assert.AreEqual(0, edgeDifference.Calculate(15));
            Assert.AreEqual(-2, edgeDifference.Calculate(18)); // witness paths from 10<->8.
            Assert.AreEqual(0, edgeDifference.Calculate(19));

            processor.Contract(18);

            Assert.AreEqual(0, edgeDifference.Calculate(8));
            Assert.AreEqual(0, edgeDifference.Calculate(9));
            Assert.AreEqual(0, edgeDifference.Calculate(10));
            Assert.AreEqual(0, edgeDifference.Calculate(12));
            Assert.AreEqual(0, edgeDifference.Calculate(13));
            Assert.AreEqual(0, edgeDifference.Calculate(14));
            Assert.AreEqual(0, edgeDifference.Calculate(15));
            Assert.AreEqual(0, edgeDifference.Calculate(19));

            processor.Contract(8);

            Assert.AreEqual(0, edgeDifference.Calculate(9));
            Assert.AreEqual(0, edgeDifference.Calculate(10));
            Assert.AreEqual(0, edgeDifference.Calculate(12));
            Assert.AreEqual(0, edgeDifference.Calculate(13));
            Assert.AreEqual(0, edgeDifference.Calculate(14));
            Assert.AreEqual(0, edgeDifference.Calculate(15));
            Assert.AreEqual(0, edgeDifference.Calculate(19));

            processor.Contract(9);

            Assert.AreEqual(-2, edgeDifference.Calculate(10)); // witness paths from 19<->12.
            Assert.AreEqual(0, edgeDifference.Calculate(12));
            Assert.AreEqual(0, edgeDifference.Calculate(13));
            Assert.AreEqual(0, edgeDifference.Calculate(14));
            Assert.AreEqual(0, edgeDifference.Calculate(15));
            Assert.AreEqual(-2, edgeDifference.Calculate(19)); // witness paths from 15<->10.

            processor.Contract(10);

            Assert.AreEqual(-2, edgeDifference.Calculate(12));
            Assert.AreEqual(0, edgeDifference.Calculate(13));
            Assert.AreEqual(0, edgeDifference.Calculate(14));
            Assert.AreEqual(0, edgeDifference.Calculate(15));
            Assert.AreEqual(-2, edgeDifference.Calculate(19)); // witness paths from 15<->10.

            processor.Contract(12);

            Assert.AreEqual(-1, edgeDifference.Calculate(13));
            Assert.AreEqual(0, edgeDifference.Calculate(14));
            Assert.AreEqual(0, edgeDifference.Calculate(15));
            Assert.AreEqual(-1, edgeDifference.Calculate(19)); // witness paths from 15<->10.

            processor.Contract(13);

            Assert.AreEqual(-1, edgeDifference.Calculate(14));
            Assert.AreEqual(0, edgeDifference.Calculate(15));
            Assert.AreEqual(-1, edgeDifference.Calculate(19)); // witness paths from 15<->10.

            processor.Contract(14);

            Assert.AreEqual(-1, edgeDifference.Calculate(15));
            Assert.AreEqual(-1, edgeDifference.Calculate(19)); // witness paths from 15<->10.

            processor.Contract(15);

            Assert.AreEqual(0, edgeDifference.Calculate(19));

            processor.Contract(19);
        }
Esempio n. 21
0
        public void TestCHEdgeDifferenceContractions()
        {
            var interpreter    = new OsmSharp.Routing.Osm.Interpreter.OsmRoutingInterpreter();
            var processor      = this.BuildCHPreProcessor(interpreter);
            var edgeDifference = processor.NodeWeightCalculator;

            Assert.AreEqual(5, edgeDifference.Calculate(1)); // witness paths from 2<->4.
            Assert.AreEqual(16, edgeDifference.Calculate(2));
            Assert.AreEqual(2, edgeDifference.Calculate(3));
            Assert.AreEqual(2, edgeDifference.Calculate(4));
            Assert.AreEqual(2, edgeDifference.Calculate(5));
            Assert.AreEqual(2, edgeDifference.Calculate(6));
            Assert.AreEqual(9, edgeDifference.Calculate(7));
            Assert.AreEqual(9, edgeDifference.Calculate(8));
            Assert.AreEqual(2, edgeDifference.Calculate(9));
            Assert.AreEqual(9, edgeDifference.Calculate(10));
            Assert.AreEqual(9, edgeDifference.Calculate(11));
            Assert.AreEqual(2, edgeDifference.Calculate(12));
            Assert.AreEqual(2, edgeDifference.Calculate(13));
            Assert.AreEqual(2, edgeDifference.Calculate(14));
            Assert.AreEqual(2, edgeDifference.Calculate(15));
            Assert.AreEqual(9, edgeDifference.Calculate(16));
            Assert.AreEqual(2, edgeDifference.Calculate(17));
            Assert.AreEqual(2, edgeDifference.Calculate(18));
            Assert.AreEqual(2, edgeDifference.Calculate(19));
            Assert.AreEqual(-1, edgeDifference.Calculate(20));
            Assert.AreEqual(2, edgeDifference.Calculate(21));
            Assert.AreEqual(2, edgeDifference.Calculate(22));
            Assert.AreEqual(-1, edgeDifference.Calculate(23));

            // contract 20.
            processor.Contract(20);

            Assert.AreEqual(5, edgeDifference.Calculate(1)); // witness paths from 2<->4.
            Assert.AreEqual(16, edgeDifference.Calculate(2));
            Assert.AreEqual(2, edgeDifference.Calculate(3));
            Assert.AreEqual(2, edgeDifference.Calculate(4));
            Assert.AreEqual(2, edgeDifference.Calculate(5));
            Assert.AreEqual(2, edgeDifference.Calculate(6));
            Assert.AreEqual(9, edgeDifference.Calculate(7));
            Assert.AreEqual(9, edgeDifference.Calculate(8));
            Assert.AreEqual(2, edgeDifference.Calculate(9));
            Assert.AreEqual(9, edgeDifference.Calculate(10));
            Assert.AreEqual(9, edgeDifference.Calculate(11));
            Assert.AreEqual(2, edgeDifference.Calculate(12));
            Assert.AreEqual(2, edgeDifference.Calculate(13));
            Assert.AreEqual(2, edgeDifference.Calculate(14));
            Assert.AreEqual(2, edgeDifference.Calculate(15));
            Assert.AreEqual(9, edgeDifference.Calculate(16));
            Assert.AreEqual(2, edgeDifference.Calculate(17));
            Assert.AreEqual(2, edgeDifference.Calculate(18));
            Assert.AreEqual(2, edgeDifference.Calculate(19));
            Assert.AreEqual(-1, edgeDifference.Calculate(21));
            Assert.AreEqual(2, edgeDifference.Calculate(22));
            Assert.AreEqual(-1, edgeDifference.Calculate(23));

            // contract 21.
            processor.Contract(21);

            Assert.AreEqual(5, edgeDifference.Calculate(1)); // witness paths from 2<->4.
            Assert.AreEqual(16, edgeDifference.Calculate(2));
            Assert.AreEqual(2, edgeDifference.Calculate(3));
            Assert.AreEqual(2, edgeDifference.Calculate(4));
            Assert.AreEqual(2, edgeDifference.Calculate(5));
            Assert.AreEqual(2, edgeDifference.Calculate(6));
            Assert.AreEqual(9, edgeDifference.Calculate(7));
            Assert.AreEqual(9, edgeDifference.Calculate(8));
            Assert.AreEqual(2, edgeDifference.Calculate(9));
            Assert.AreEqual(9, edgeDifference.Calculate(10));
            Assert.AreEqual(9, edgeDifference.Calculate(11));
            Assert.AreEqual(2, edgeDifference.Calculate(12));
            Assert.AreEqual(2, edgeDifference.Calculate(13));
            Assert.AreEqual(2, edgeDifference.Calculate(14));
            Assert.AreEqual(2, edgeDifference.Calculate(15));
            Assert.AreEqual(2, edgeDifference.Calculate(16));
            Assert.AreEqual(2, edgeDifference.Calculate(17));
            Assert.AreEqual(2, edgeDifference.Calculate(18));
            Assert.AreEqual(2, edgeDifference.Calculate(19));
            Assert.AreEqual(2, edgeDifference.Calculate(22));
            Assert.AreEqual(-1, edgeDifference.Calculate(23));

            // contract 23.
            processor.Contract(23);

            Assert.AreEqual(5, edgeDifference.Calculate(1)); // witness paths from 2<->4.
            Assert.AreEqual(16, edgeDifference.Calculate(2));
            Assert.AreEqual(2, edgeDifference.Calculate(3));
            Assert.AreEqual(2, edgeDifference.Calculate(4));
            Assert.AreEqual(2, edgeDifference.Calculate(5));
            Assert.AreEqual(2, edgeDifference.Calculate(6));
            Assert.AreEqual(9, edgeDifference.Calculate(7));
            Assert.AreEqual(9, edgeDifference.Calculate(8));
            Assert.AreEqual(2, edgeDifference.Calculate(9));
            Assert.AreEqual(9, edgeDifference.Calculate(10));
            Assert.AreEqual(9, edgeDifference.Calculate(11));
            Assert.AreEqual(2, edgeDifference.Calculate(12));
            Assert.AreEqual(2, edgeDifference.Calculate(13));
            Assert.AreEqual(2, edgeDifference.Calculate(14));
            Assert.AreEqual(2, edgeDifference.Calculate(15));
            Assert.AreEqual(2, edgeDifference.Calculate(16));
            Assert.AreEqual(2, edgeDifference.Calculate(17));
            Assert.AreEqual(2, edgeDifference.Calculate(18));
            Assert.AreEqual(2, edgeDifference.Calculate(19));
            Assert.AreEqual(-1, edgeDifference.Calculate(22));

            // contract 22.
            processor.Contract(22);

            Assert.AreEqual(5, edgeDifference.Calculate(1)); // witness paths from 2<->4.
            Assert.AreEqual(16, edgeDifference.Calculate(2));
            Assert.AreEqual(2, edgeDifference.Calculate(3));
            Assert.AreEqual(2, edgeDifference.Calculate(4));
            Assert.AreEqual(2, edgeDifference.Calculate(5));
            Assert.AreEqual(2, edgeDifference.Calculate(6));
            Assert.AreEqual(9, edgeDifference.Calculate(7));
            Assert.AreEqual(9, edgeDifference.Calculate(8));
            Assert.AreEqual(2, edgeDifference.Calculate(9));
            Assert.AreEqual(9, edgeDifference.Calculate(10));
            Assert.AreEqual(9, edgeDifference.Calculate(11));
            Assert.AreEqual(2, edgeDifference.Calculate(12));
            Assert.AreEqual(2, edgeDifference.Calculate(13));
            Assert.AreEqual(2, edgeDifference.Calculate(14));
            Assert.AreEqual(2, edgeDifference.Calculate(15));
            Assert.AreEqual(-1, edgeDifference.Calculate(16));
            Assert.AreEqual(2, edgeDifference.Calculate(17));
            Assert.AreEqual(2, edgeDifference.Calculate(18));
            Assert.AreEqual(2, edgeDifference.Calculate(19));

            // contract 16.
            processor.Contract(16);

            Assert.AreEqual(5, edgeDifference.Calculate(1)); // witness paths from 2<->4.
            Assert.AreEqual(16, edgeDifference.Calculate(2));
            Assert.AreEqual(2, edgeDifference.Calculate(3));
            Assert.AreEqual(2, edgeDifference.Calculate(4));
            Assert.AreEqual(2, edgeDifference.Calculate(5));
            Assert.AreEqual(2, edgeDifference.Calculate(6));
            Assert.AreEqual(9, edgeDifference.Calculate(7));
            Assert.AreEqual(9, edgeDifference.Calculate(8));
            Assert.AreEqual(2, edgeDifference.Calculate(9));
            Assert.AreEqual(9, edgeDifference.Calculate(10));
            Assert.AreEqual(9, edgeDifference.Calculate(11));
            Assert.AreEqual(2, edgeDifference.Calculate(12));
            Assert.AreEqual(2, edgeDifference.Calculate(13));
            Assert.AreEqual(2, edgeDifference.Calculate(14));
            Assert.AreEqual(2, edgeDifference.Calculate(15));
            Assert.AreEqual(-1, edgeDifference.Calculate(17));
            Assert.AreEqual(2, edgeDifference.Calculate(18));
            Assert.AreEqual(2, edgeDifference.Calculate(19));

            // contract 17.
            processor.Contract(17);

            Assert.AreEqual(5, edgeDifference.Calculate(1)); // witness paths from 2<->4.
            Assert.AreEqual(16, edgeDifference.Calculate(2));
            Assert.AreEqual(2, edgeDifference.Calculate(3));
            Assert.AreEqual(2, edgeDifference.Calculate(4));
            Assert.AreEqual(2, edgeDifference.Calculate(5));
            Assert.AreEqual(2, edgeDifference.Calculate(6));
            Assert.AreEqual(2, edgeDifference.Calculate(7));
            Assert.AreEqual(9, edgeDifference.Calculate(8));
            Assert.AreEqual(2, edgeDifference.Calculate(9));
            Assert.AreEqual(9, edgeDifference.Calculate(10));
            Assert.AreEqual(9, edgeDifference.Calculate(11));
            Assert.AreEqual(2, edgeDifference.Calculate(12));
            Assert.AreEqual(2, edgeDifference.Calculate(13));
            Assert.AreEqual(2, edgeDifference.Calculate(14));
            Assert.AreEqual(2, edgeDifference.Calculate(15));
            Assert.AreEqual(2, edgeDifference.Calculate(18));
            Assert.AreEqual(2, edgeDifference.Calculate(19));

            processor.Contract(3);

            Assert.AreEqual(5, edgeDifference.Calculate(1)); // witness paths from 2<->4.
            Assert.AreEqual(16, edgeDifference.Calculate(2));
            Assert.AreEqual(-2, edgeDifference.Calculate(4));
            Assert.AreEqual(2, edgeDifference.Calculate(5));
            Assert.AreEqual(2, edgeDifference.Calculate(6));
            Assert.AreEqual(2, edgeDifference.Calculate(7));
            Assert.AreEqual(9, edgeDifference.Calculate(8));
            Assert.AreEqual(2, edgeDifference.Calculate(9));
            Assert.AreEqual(9, edgeDifference.Calculate(10));
            Assert.AreEqual(9, edgeDifference.Calculate(11));
            Assert.AreEqual(2, edgeDifference.Calculate(12));
            Assert.AreEqual(2, edgeDifference.Calculate(13));
            Assert.AreEqual(2, edgeDifference.Calculate(14));
            Assert.AreEqual(2, edgeDifference.Calculate(15));
            Assert.AreEqual(2, edgeDifference.Calculate(18));
            Assert.AreEqual(2, edgeDifference.Calculate(19));

            processor.Contract(4);

            Assert.AreEqual(2, edgeDifference.Calculate(1)); // witness paths from 2<->4.
            Assert.AreEqual(9, edgeDifference.Calculate(2));
            Assert.AreEqual(2, edgeDifference.Calculate(5));
            Assert.AreEqual(2, edgeDifference.Calculate(6));
            Assert.AreEqual(2, edgeDifference.Calculate(7));
            Assert.AreEqual(9, edgeDifference.Calculate(8));
            Assert.AreEqual(2, edgeDifference.Calculate(9));
            Assert.AreEqual(9, edgeDifference.Calculate(10));
            Assert.AreEqual(9, edgeDifference.Calculate(11));
            Assert.AreEqual(2, edgeDifference.Calculate(12));
            Assert.AreEqual(2, edgeDifference.Calculate(13));
            Assert.AreEqual(2, edgeDifference.Calculate(14));
            Assert.AreEqual(2, edgeDifference.Calculate(15));
            Assert.AreEqual(2, edgeDifference.Calculate(18));
            Assert.AreEqual(2, edgeDifference.Calculate(19));

            processor.Contract(1);

            Assert.AreEqual(5, edgeDifference.Calculate(2));
            Assert.AreEqual(-2, edgeDifference.Calculate(5));
            Assert.AreEqual(2, edgeDifference.Calculate(6));
            Assert.AreEqual(2, edgeDifference.Calculate(7));
            Assert.AreEqual(9, edgeDifference.Calculate(8));
            Assert.AreEqual(2, edgeDifference.Calculate(9));
            Assert.AreEqual(9, edgeDifference.Calculate(10));
            Assert.AreEqual(9, edgeDifference.Calculate(11));
            Assert.AreEqual(2, edgeDifference.Calculate(12));
            Assert.AreEqual(2, edgeDifference.Calculate(13));
            Assert.AreEqual(2, edgeDifference.Calculate(14));
            Assert.AreEqual(2, edgeDifference.Calculate(15));
            Assert.AreEqual(2, edgeDifference.Calculate(18));
            Assert.AreEqual(2, edgeDifference.Calculate(19));

            processor.Contract(5);

            Assert.AreEqual(1, edgeDifference.Calculate(2));
            Assert.AreEqual(-2, edgeDifference.Calculate(6));
            Assert.AreEqual(2, edgeDifference.Calculate(7));
            Assert.AreEqual(9, edgeDifference.Calculate(8));
            Assert.AreEqual(2, edgeDifference.Calculate(9));
            Assert.AreEqual(9, edgeDifference.Calculate(10));
            Assert.AreEqual(9, edgeDifference.Calculate(11));
            Assert.AreEqual(2, edgeDifference.Calculate(12));
            Assert.AreEqual(2, edgeDifference.Calculate(13));
            Assert.AreEqual(2, edgeDifference.Calculate(14));
            Assert.AreEqual(2, edgeDifference.Calculate(15));
            Assert.AreEqual(2, edgeDifference.Calculate(18));
            Assert.AreEqual(2, edgeDifference.Calculate(19));

            processor.Contract(6);

            Assert.AreEqual(2, edgeDifference.Calculate(2));
            Assert.AreEqual(-1, edgeDifference.Calculate(7));
            Assert.AreEqual(9, edgeDifference.Calculate(8));
            Assert.AreEqual(2, edgeDifference.Calculate(9));
            Assert.AreEqual(9, edgeDifference.Calculate(10));
            Assert.AreEqual(9, edgeDifference.Calculate(11));
            Assert.AreEqual(2, edgeDifference.Calculate(12));
            Assert.AreEqual(2, edgeDifference.Calculate(13));
            Assert.AreEqual(2, edgeDifference.Calculate(14));
            Assert.AreEqual(2, edgeDifference.Calculate(15));
            Assert.AreEqual(2, edgeDifference.Calculate(18));
            Assert.AreEqual(2, edgeDifference.Calculate(19));

            processor.Contract(7);

            Assert.AreEqual(2, edgeDifference.Calculate(2));
            Assert.AreEqual(9, edgeDifference.Calculate(8));
            Assert.AreEqual(2, edgeDifference.Calculate(9));
            Assert.AreEqual(9, edgeDifference.Calculate(10));
            Assert.AreEqual(2, edgeDifference.Calculate(11));
            Assert.AreEqual(2, edgeDifference.Calculate(12));
            Assert.AreEqual(2, edgeDifference.Calculate(13));
            Assert.AreEqual(2, edgeDifference.Calculate(14));
            Assert.AreEqual(2, edgeDifference.Calculate(15));
            Assert.AreEqual(2, edgeDifference.Calculate(18));
            Assert.AreEqual(2, edgeDifference.Calculate(19));

            processor.Contract(2);

            Assert.AreEqual(9, edgeDifference.Calculate(8));
            Assert.AreEqual(2, edgeDifference.Calculate(9));
            Assert.AreEqual(9, edgeDifference.Calculate(10));
            Assert.AreEqual(-2, edgeDifference.Calculate(11));
            Assert.AreEqual(2, edgeDifference.Calculate(12));
            Assert.AreEqual(2, edgeDifference.Calculate(13));
            Assert.AreEqual(2, edgeDifference.Calculate(14));
            Assert.AreEqual(2, edgeDifference.Calculate(15));
            Assert.AreEqual(2, edgeDifference.Calculate(18));
            Assert.AreEqual(2, edgeDifference.Calculate(19));

            processor.Contract(11);

            Assert.AreEqual(9, edgeDifference.Calculate(8));
            Assert.AreEqual(2, edgeDifference.Calculate(9));
            Assert.AreEqual(1, edgeDifference.Calculate(10));
            Assert.AreEqual(2, edgeDifference.Calculate(12));
            Assert.AreEqual(2, edgeDifference.Calculate(13));
            Assert.AreEqual(2, edgeDifference.Calculate(14));
            Assert.AreEqual(2, edgeDifference.Calculate(15));
            Assert.AreEqual(-2, edgeDifference.Calculate(18));
            Assert.AreEqual(2, edgeDifference.Calculate(19));

            processor.Contract(18);

            Assert.AreEqual(2, edgeDifference.Calculate(8));
            Assert.AreEqual(2, edgeDifference.Calculate(9));
            Assert.AreEqual(2, edgeDifference.Calculate(10));
            Assert.AreEqual(2, edgeDifference.Calculate(12));
            Assert.AreEqual(2, edgeDifference.Calculate(13));
            Assert.AreEqual(2, edgeDifference.Calculate(14));
            Assert.AreEqual(2, edgeDifference.Calculate(15));
            Assert.AreEqual(2, edgeDifference.Calculate(19));

            processor.Contract(8);

            Assert.AreEqual(2, edgeDifference.Calculate(9));
            Assert.AreEqual(2, edgeDifference.Calculate(10));
            Assert.AreEqual(2, edgeDifference.Calculate(12));
            Assert.AreEqual(2, edgeDifference.Calculate(13));
            Assert.AreEqual(2, edgeDifference.Calculate(14));
            Assert.AreEqual(2, edgeDifference.Calculate(15));
            Assert.AreEqual(2, edgeDifference.Calculate(19));

            processor.Contract(9);

            Assert.AreEqual(-2, edgeDifference.Calculate(10));
            Assert.AreEqual(2, edgeDifference.Calculate(12));
            Assert.AreEqual(2, edgeDifference.Calculate(13));
            Assert.AreEqual(2, edgeDifference.Calculate(14));
            Assert.AreEqual(2, edgeDifference.Calculate(15));
            Assert.AreEqual(-2, edgeDifference.Calculate(19));

            processor.Contract(10);

            Assert.AreEqual(-2, edgeDifference.Calculate(12));
            Assert.AreEqual(2, edgeDifference.Calculate(13));
            Assert.AreEqual(2, edgeDifference.Calculate(14));
            Assert.AreEqual(2, edgeDifference.Calculate(15));
            Assert.AreEqual(-2, edgeDifference.Calculate(19));

            processor.Contract(12);

            Assert.AreEqual(-1, edgeDifference.Calculate(13));
            Assert.AreEqual(2, edgeDifference.Calculate(14));
            Assert.AreEqual(2, edgeDifference.Calculate(15));
            Assert.AreEqual(-1, edgeDifference.Calculate(19));

            processor.Contract(13);

            Assert.AreEqual(-1, edgeDifference.Calculate(14));
            Assert.AreEqual(2, edgeDifference.Calculate(15));
            Assert.AreEqual(-1, edgeDifference.Calculate(19));

            processor.Contract(14);

            Assert.AreEqual(-1, edgeDifference.Calculate(15));
            Assert.AreEqual(-1, edgeDifference.Calculate(19)); // witness paths from 15<->10.

            processor.Contract(15);

            Assert.AreEqual(0, edgeDifference.Calculate(19));

            processor.Contract(19);
        }
        public void InstructionGenerationSimpleTurnSameStreet()
        {
            // create new interpreter.
            var interpreter = new OsmRoutingInterpreter();

            // create the language generator.
            var languageGenerator = new LanguageTestGenerator();

            // calculate the route.
            OsmSharpRoute route = this.Calculate(
                new GeoCoordinate(51.09030, 3.44391),
                new GeoCoordinate(51.09002, 3.44380));

            // generate the instructions.
            var instructionGenerator = new InstructionGenerator();
            List<Instruction> instructions =
                instructionGenerator.Generate(route, interpreter, languageGenerator);

            // test the results in the language generator.
            Assert.AreEqual(3, instructions.Count);
            Assert.AreEqual("GeneratePoi:1", instructions[0].Text);
            Assert.AreEqual("GenerateDirectTurn:0_Left_0", instructions[1].Text);
            Assert.AreEqual("GeneratePoi:1", instructions[2].Text);
        }
Esempio n. 23
0
        public void RoutingSerializationRoutingTest()
        {
            const string embeddedString = "OsmSharp.Test.Unittests.test_network.osm";

            // create the tags index (and make sure it's serializable).
            var tagsIndex = new TagsIndex(new MemoryMappedStream(new MemoryStream()));

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

            // do the data processing.
            var original =
                new RouterDataSource<Edge>(new Graph<Edge>(), tagsIndex);
            var targetData = new GraphOsmStreamTarget(
                original, interpreter, tagsIndex, null, false);
            var dataProcessorSource = new XmlOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream(embeddedString));
            targetData.RegisterSource(dataProcessorSource);
            targetData.Pull();

            // create serializer.
            var routingSerializer = new RoutingDataSourceSerializer();

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

            var deserializedVersion = routingSerializer.Deserialize(new MemoryStream(byteArray), out metaData);
            Assert.AreEqual(original.TagsIndex.Get(0), deserializedVersion.TagsIndex.Get(0));

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

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

            float latitude, longitude;
            //deserializedVersion.GetVertex(20, out latitude, out longitude);
            Assert.AreEqual(51.0578537, route.Segments[0].Latitude, 0.00001);
            Assert.AreEqual(3.71922255, route.Segments[0].Longitude, 0.00001);
            Assert.AreEqual(RouteSegmentType.Start, route.Segments[0].Type);

            //deserializedVersion.GetVertex(21, out latitude, out longitude);
            Assert.AreEqual(51.0578537, route.Segments[1].Latitude, 0.00001);
            Assert.AreEqual(3.71956515, route.Segments[1].Longitude, 0.00001);
            Assert.AreEqual(RouteSegmentType.Along, route.Segments[1].Type);

            //deserializedVersion.GetVertex(16, out latitude, out longitude);
            Assert.AreEqual(51.05773, route.Segments[2].Latitude, 0.00001);
            Assert.AreEqual(3.719745, route.Segments[2].Longitude, 0.00001);
            Assert.AreEqual(RouteSegmentType.Along, route.Segments[2].Type);

            //deserializedVersion.GetVertex(22, out latitude, out longitude);
            Assert.AreEqual(51.05762, route.Segments[3].Latitude, 0.00001);
            Assert.AreEqual(3.71965766, route.Segments[3].Longitude, 0.00001);
            Assert.AreEqual(RouteSegmentType.Along, route.Segments[3].Type);

            deserializedVersion.GetVertex(23, out latitude, out longitude);
            Assert.AreEqual(51.05762, route.Segments[4].Latitude, 0.00001);
            Assert.AreEqual(3.71917963, route.Segments[4].Longitude, 0.00001);
            Assert.AreEqual(RouteSegmentType.Stop, route.Segments[4].Type);
        }
        /// <summary>
        /// Issue with generation instructions but where streetnames seem to be stripped.
        /// Some streetnames are missing from the instructions.
        /// </summary>
        protected void DoInstructionRegressionTest1()
        {
            OsmRoutingInterpreter interpreter = new OsmRoutingInterpreter();

            Router router = this.CreateRouter(interpreter, "OsmSharp.Test.Unittests.test_routing_regression1.osm");

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

            // calculate two smaller routes.
            Route route3545 = router.Calculate(Vehicle.Car, point35resolved, point45resolved);
            Route route4540 = router.Calculate(Vehicle.Car, point45resolved, point40resolved);
            Route route3540concatenated = Route.Concatenate(route3545, route4540);

            Route route3540 = router.Calculate(Vehicle.Car, point35resolved, point40resolved);

            // check if both routes are equal.
            Assert.AreEqual(route3540.Entries.Length, route3540concatenated.Entries.Length);
            for (int idx = 0; idx < route3540.Entries.Length; idx++)
            {
                Assert.AreEqual(route3540.Entries[idx].Distance, route3540concatenated.Entries[idx].Distance);
                Assert.AreEqual(route3540.Entries[idx].Latitude, route3540concatenated.Entries[idx].Latitude);
                Assert.AreEqual(route3540.Entries[idx].Longitude, route3540concatenated.Entries[idx].Longitude);
                Assert.AreEqual(route3540.Entries[idx].Time, route3540concatenated.Entries[idx].Time);
                Assert.AreEqual(route3540.Entries[idx].Type, route3540concatenated.Entries[idx].Type);
                Assert.AreEqual(route3540.Entries[idx].WayFromName, route3540concatenated.Entries[idx].WayFromName);

                // something that is allowed to be different in this case!
                // route3540.Entries[idx].Points != null

            //    // check sidestreets.
            //    if (route3540.Entries[idx].SideStreets != null &&
            //        route3540.Entries[idx].SideStreets.Length > 0)
            //    { // check if the sidestreets represent the same information.
            //        for (int metricIdx = 0; metricIdx < route3540concatenated.Entries[idx].SideStreets.Length; metricIdx++)
            //        {
            //            Assert.AreEqual(route3540.Entries[idx].SideStreets[metricIdx].WayName,
            //                route3540concatenated.Entries[idx].SideStreets[metricIdx].WayName);
            //            Assert.AreEqual(route3540.Entries[idx].SideStreets[metricIdx].Latitude,
            //                route3540concatenated.Entries[idx].SideStreets[metricIdx].Latitude);
            //            Assert.AreEqual(route3540.Entries[idx].SideStreets[metricIdx].Longitude,
            //                route3540concatenated.Entries[idx].SideStreets[metricIdx].Longitude);
            //        }
            //    }
            //    else
            //    {
            //        Assert.IsTrue(route3540concatenated.Entries[idx].SideStreets == null ||
            //            route3540concatenated.Entries[idx].SideStreets.Length == 0);
            //    }

            //    if (route3540.Entries[idx].Tags != null &&
            //        route3540.Entries[idx].Tags.Length > 0)
            //    { // check if the Tags represent the same information.
            //        for (int metricIdx = 0; metricIdx < route3540concatenated.Entries[idx].Tags.Length; metricIdx++)
            //        {
            //            Assert.AreEqual(route3540.Entries[idx].Tags[metricIdx].Key,
            //                route3540concatenated.Entries[idx].Tags[metricIdx].Key);
            //            Assert.AreEqual(route3540.Entries[idx].Tags[metricIdx].Value,
            //                route3540concatenated.Entries[idx].Tags[metricIdx].Value);
            //        }
            //    }
            //    else
            //    {
            //        Assert.IsTrue(route3540concatenated.Entries[idx].Tags == null ||
            //            route3540concatenated.Entries[idx].Tags.Length == 0);
            //    }

            //    Assert.AreEqual(route3540.Entries[idx].Distance, route3540concatenated.Entries[idx].Distance);
            }
            if (route3540.Tags != null &&
                route3540.Tags.Length > 0)
            {
                for (int tagIdx = 0; tagIdx < route3540.Tags.Length; tagIdx++)
                {
                    if (route3540.Tags[tagIdx].Key != "debug_route")
                    {
                        Assert.AreEqual(route3540.Tags[tagIdx].Key, route3540concatenated.Tags[tagIdx].Key);
                        Assert.AreEqual(route3540.Tags[tagIdx].Value, route3540concatenated.Tags[tagIdx].Value);
                    }
                }
            }
            else
            {
                Assert.IsTrue(route3540concatenated.Tags == null ||
                    route3540concatenated.Tags.Length == 0);
            }
            if (route3540.Metrics != null)
            {
                for (int metricIdx = 0; metricIdx < route3540concatenated.Entries.Length; metricIdx++)
                {
                    Assert.AreEqual(route3540.Metrics[metricIdx].Key, route3540concatenated.Metrics[metricIdx].Key);
                    Assert.AreEqual(route3540.Metrics[metricIdx].Value, route3540concatenated.Metrics[metricIdx].Value);
                }
            }
            else
            {
                Assert.IsNull(route3540concatenated.Metrics);
            }

            // remove the point in between, the only difference between the regular and the concatenated route.
            route3540concatenated.Entries[7].Points = null;

            // create the language generator.
            var languageGenerator = new LanguageTestGenerator();

            // generate the instructions.
            List<Instruction> instructions =
                InstructionGenerator.Generate(route3540, interpreter, languageGenerator);
            List<Instruction> instructionsConcatenated =
                InstructionGenerator.Generate(route3540concatenated, interpreter, languageGenerator);

            Assert.AreEqual(instructions.Count, instructionsConcatenated.Count);
            for (int idx = 0; idx < instructions.Count; idx++)
            {
                Assert.AreEqual(instructions[idx].Location.Center,
                    instructionsConcatenated[idx].Location.Center);
                Assert.AreEqual(instructions[idx].Text,
                    instructionsConcatenated[idx].Text);
            }
        }
        /// <summary>
        /// Issue with generation of instruction between different algorithms.
        /// </summary>
        protected void DoInstructionRegressionTest2()
        {
            OsmRoutingInterpreter interpreter = new OsmRoutingInterpreter();

            Router router = this.CreateRouter(interpreter,
                "OsmSharp.Test.Unittests.test_routing_regression1.osm");
            Router referenceRouter = this.CreateReferenceRouter(interpreter,
                "OsmSharp.Test.Unittests.test_routing_regression1.osm");

            // resolve the three points in question.
            GeoCoordinate point1 = new GeoCoordinate(51.01257, 4.000753);
            RouterPoint point1resolved = router.Resolve(Vehicle.Car, point1);
            GeoCoordinate point2 = new GeoCoordinate(51.01250, 4.000013);
            RouterPoint point2resolved = router.Resolve(Vehicle.Car, point2);

            // calculate two smaller routes.
            Route route12 = router.Calculate(Vehicle.Car,
                point1resolved, point2resolved);

            // resolve the three points in question.
            GeoCoordinate pointReference1 = new GeoCoordinate(51.01257, 4.000753);
            RouterPoint pointReference1resolved = referenceRouter.Resolve(Vehicle.Car, point1);
            GeoCoordinate pointReference2 = new GeoCoordinate(51.01250, 4.000013);
            RouterPoint pointReference2resolved = referenceRouter.Resolve(Vehicle.Car, point2);

            // calculate two smaller routes.
            Route routeReference12 = referenceRouter.Calculate(Vehicle.Car,
                pointReference1resolved, pointReference2resolved);

            // compares the two routes.
            this.CompareRoutes(routeReference12, route12);

            // create the language generator.
            var languageGenerator = new LanguageTestGenerator();

            // generate the instructions.
            List<Instruction> instructions =
                InstructionGenerator.Generate(route12, interpreter, languageGenerator);
            List<Instruction> instructionsReference =
                InstructionGenerator.Generate(routeReference12, interpreter, languageGenerator);

            Assert.AreEqual(instructions.Count, instructionsReference.Count);
            for (int idx = 0; idx < instructions.Count; idx++)
            {
                Assert.AreEqual(instructions[idx].Location.Center,
                    instructionsReference[idx].Location.Center);
                Assert.AreEqual(instructions[idx].Text,
                    instructionsReference[idx].Text);
            }
        }
Esempio n. 26
0
        public void RoutingSerializationRoutingComparisonTest()
        {
            const string embeddedString = "OsmSharp.Test.Unittests.test_network_real1.osm";

            // create the tags index (and make sure it's serializable).
            var tagsIndex = new TagsIndex(new MemoryMappedStream(new MemoryStream()));

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

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

            // create serializer.
            var routingSerializer = new RoutingDataSourceSerializer();

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

            var deserializedVersion =
                routingSerializer.Deserialize(new MemoryStream(byteArray), out metaData);
            Assert.AreEqual(original.TagsIndex.Get(0), deserializedVersion.TagsIndex.Get(0));

            //// try to do some routing on the deserialized version.
            //var basicRouter =
            //    new Dykstra();
            //var router = Router.CreateFrom(
            //    deserializedVersion, basicRouter, interpreter);
            //var referenceRouter = Router.CreateFrom(
            //    original, 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++)
            //    {
            //        var referenceRoute = referenceRouter.Calculate(Vehicle.Car,
            //            resolvedReference[fromIdx], resolvedReference[toIdx]);
            //        var 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 TestCHDataSourceTopologicalSortTest()
        {
            const string embeddedString = "OsmSharp.Test.Unittests.test_network_real1.osm";

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

            // do the data processing.
            var original = CHEdgeGraphOsmStreamTarget.Preprocess(new XmlOsmStreamSource(
                                                                   Assembly.GetExecutingAssembly()
                                                                           .GetManifestResourceStream(embeddedString)),
                                                               interpreter,
                                                               Vehicle.Car);
            var sortedGraph = CHEdgeDataDataSourceSerializer.SortGraph(original);
            original = CHEdgeGraphOsmStreamTarget.Preprocess(new XmlOsmStreamSource(
                                                                   Assembly.GetExecutingAssembly()
                                                                           .GetManifestResourceStream(embeddedString)),
                                                               interpreter,
                                                               Vehicle.Car);
            var basicRouterOriginal = new CHRouter();
            Router referenceRouter = Router.CreateCHFrom(
                original, basicRouterOriginal, interpreter);

            // try to do some routing on the deserialized version.
            var basicRouter = new CHRouter();
            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);
            //    }
            //}
        }
        /// <summary>
        /// Does the actual testing.
        /// </summary>
        /// <param name="embeddedString"></param>
        private void DoRoutingSerializationV2CHRoutingV2ComparisonTest(string embeddedString)
        {
            // creates a new interpreter.
            var interpreter = new OsmRoutingInterpreter();

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

            // create serializer.
            var routingSerializer = new OsmSharp.Routing.CH.Serialization.Sorted.v2.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 = CHEdgeGraphOsmStreamTarget.Preprocess(new XmlOsmStreamSource(
                                                                   Assembly.GetExecutingAssembly()
                                                                           .GetManifestResourceStream(embeddedString)),
                                                               interpreter,
                                                               Vehicle.Car);
            var basicRouterOriginal = new CHRouter();
            Router referenceRouter = Router.CreateCHFrom(
                original, basicRouterOriginal, interpreter);

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

            this.TestCompareAll(original, referenceRouter, router);
        }
Esempio n. 29
0
        public void RoutingRegressionTest2()
        {
            var interpreter = new OsmRoutingInterpreter();
            var tagsIndex = new TagsIndex();

            // do the data processing.
            var memoryData = new RouterDataSource<Edge>(new Graph<Edge>(), tagsIndex);
            var targetData = new GraphOsmStreamTarget(memoryData, interpreter, tagsIndex);
            var dataProcessorSource = new XmlOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Routing.Test.data.test_network.osm"));
            var sorter = new OsmStreamFilterSort();
            sorter.RegisterSource(dataProcessorSource);
            targetData.RegisterSource(sorter);
            targetData.Pull();

            var basicRouter = new Dykstra();
            var router = Router.CreateFrom(memoryData, basicRouter, interpreter);

            // build coordinates list of resolved points.
            var 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.0581727, 3.7195833));
            testPoints.Add(new GeoCoordinate(51.0581483, 3.7195553));

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

            // build a matrix of routes between all points.
            var referenceRoutes = new Route[testPoints.Count][];
            var 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.CreateFrom(
                        memoryData, basicRouter, interpreter);

                    // resolve points.
                    var from = router.Resolve(Vehicle.Car, testPoints[fromIdx]);
                    var 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.
            var enumerator = new PermutationEnumerable<int>(permuationArray);
            foreach (int[] permutation in enumerator)
            {
                // create router from scratch.
                router = Router.CreateFrom(memoryData, basicRouter, interpreter);

                // resolve in the order of the permutation.
                var 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.
                        var route = router.Calculate(Vehicle.Car, resolvedPoints[fromIdx], resolvedPoints[toIdx]);

                        // TODO: changed the resolve accuracy to .5m. Make sure this is more accurate in the future.
                        Assert.AreEqual(referenceRoutes[fromIdx][toIdx].TotalDistance, route.TotalDistance, 1);
                    }
                }
            }
        }
Esempio n. 30
0
        public void RoutingRegressionTest4()
        {
            var interpreter = new OsmRoutingInterpreter();
            var tagsIndex = new TagsTableCollectionIndex();

            // do the data processing.
            var memoryData = new DynamicGraphRouterDataSource<LiveEdge>(tagsIndex);
            var targetData = new LiveGraphOsmStreamTarget(memoryData, interpreter, tagsIndex);
            var dataProcessorSource = new XmlOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Test.Unittests.test_routing_regression1.osm"));
            var sorter = new OsmStreamFilterSort();
            sorter.RegisterSource(dataProcessorSource);
            targetData.RegisterSource(sorter);
            targetData.Pull();

            var basicRouter = new Dykstra();
            var router = Router.CreateLiveFrom(memoryData, basicRouter, interpreter);

            // resolve the three points in question.
            var point35 = new GeoCoordinate(51.01257, 4.000753);
            var point35ResolvedCar = router.Resolve(Vehicle.Car, point35);
            var point35ResolvedBicycle = router.Resolve(Vehicle.Bicycle, point35);
        }
Esempio n. 31
0
        public void RoutingRegressionTest3()
        {
            var interpreter = new OsmRoutingInterpreter();
            var tagsIndex = new TagsTableCollectionIndex();

            // do the data processing.
            var memoryData = new DynamicGraphRouterDataSource<LiveEdge>(tagsIndex);
            var targetData = new LiveGraphOsmStreamTarget(memoryData, interpreter, tagsIndex);
            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();

            var basicRouter = new Dykstra();
            var router = Router.CreateLiveFrom(memoryData, basicRouter, interpreter);

            // build coordinates list of resolved points.
            var 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.
            var referenceRoutes = new Route[testPoints.Count][];
            var 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(
                        memoryData, basicRouter, interpreter);

                    // resolve points.
                    var from = router.Resolve(Vehicle.Car, testPoints[fromIdx]);
                    var 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.
            var enumerator = new PermutationEnumerable<int>(
                permuationArray);
            foreach (int[] permutation in enumerator)
            {
                // create router from scratch.
                router = Router.CreateLiveFrom(memoryData, basicRouter, interpreter);

                // resolve in the order of the permutation.
                var 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.
                        var route = router.Calculate(Vehicle.Car, resolvedPoints[fromIdx], resolvedPoints[toIdx]);

                        Assert.AreEqual(referenceRoutes[fromIdx][toIdx].TotalDistance, route.TotalDistance, 0.1);
                    }
                }
            }
        }
Esempio n. 32
0
        public void TestCHEdgeDifferenceNonContracted()
        {
            IOsmRoutingInterpreter interpreter = new OsmSharp.Routing.Osm.Interpreter.OsmRoutingInterpreter();
            EdgeDifference edgeDifference = this.BuildEdgeDifference(interpreter);

            Assert.AreEqual(1, edgeDifference.Calculate(1)); // witness paths from 2<->4.
            Assert.AreEqual(6, edgeDifference.Calculate(2));
            Assert.AreEqual(0, edgeDifference.Calculate(3));
            Assert.AreEqual(0, edgeDifference.Calculate(4));
            Assert.AreEqual(0, edgeDifference.Calculate(5));
            Assert.AreEqual(0, edgeDifference.Calculate(6));
            Assert.AreEqual(3, edgeDifference.Calculate(7));
            Assert.AreEqual(3, edgeDifference.Calculate(8));
            Assert.AreEqual(0, edgeDifference.Calculate(9));
            Assert.AreEqual(3, edgeDifference.Calculate(10));
            Assert.AreEqual(3, edgeDifference.Calculate(11));
            Assert.AreEqual(0, edgeDifference.Calculate(12));
            Assert.AreEqual(0, edgeDifference.Calculate(13));
            Assert.AreEqual(0, edgeDifference.Calculate(14));
            Assert.AreEqual(0, edgeDifference.Calculate(15));
            Assert.AreEqual(3, edgeDifference.Calculate(16));
            Assert.AreEqual(0, edgeDifference.Calculate(17));
            Assert.AreEqual(0, edgeDifference.Calculate(18));
            Assert.AreEqual(0, edgeDifference.Calculate(19));
            Assert.AreEqual(-1, edgeDifference.Calculate(20));
            Assert.AreEqual(0, edgeDifference.Calculate(21));
            Assert.AreEqual(0, edgeDifference.Calculate(22));
            Assert.AreEqual(-1, edgeDifference.Calculate(23));
        }
Esempio n. 33
0
        public void TestGraphSerialize3()
        {
            const string embeddedString = "OsmSharp.Routing.Test.data.test_network_real1.osm";

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

            // do the data processing.
            var graph = GraphOsmStreamTarget.Preprocess(new XmlOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream(embeddedString)),
                new TagsIndex(new MemoryMappedStream(new MemoryStream())), interpreter);

            // serialize.
            using (var stream = new MemoryStream())
            {
                graph.Serialize(stream, Edge.SizeUints, Edge.MapFromDelegate, Edge.MapToDelegate);

                // deserialize.
                stream.Seek(0, SeekOrigin.Begin);
                var graphDeserialized = RouterDataSource<Edge>.Deserialize(stream, Edge.SizeUints, Edge.MapFromDelegate, Edge.MapToDelegate, false);

                // compare.
                Assert.AreEqual(graph.VertexCount, graphDeserialized.VertexCount);
                for (uint vertex = 1; vertex <= graph.VertexCount; vertex++)
                {
                    float latitude1, longitude1, latitude2, longitude2;
                    if (graph.GetVertex(vertex, out latitude1, out longitude1) &&
                        graphDeserialized.GetVertex(vertex, out latitude2, out longitude2))
                    {
                        Assert.AreEqual(latitude1, latitude2, 0.000001);
                        Assert.AreEqual(longitude1, longitude2, 0.000001);
                    }
                    var edges =  graph.GetEdges(vertex).ToKeyValuePairs();
                    var edgesDeserialized = graphDeserialized.GetEdges(vertex).ToKeyValuePairs();
                    Assert.AreEqual(edges.Length, edgesDeserialized.Length);
                    for (int idx = 0; idx < edges.Length; idx++)
                    {
                        Assert.AreEqual(edges[idx].Value.Distance, edgesDeserialized[idx].Value.Distance);
                        Assert.AreEqual(edges[idx].Value.Tags, edgesDeserialized[idx].Value.Tags);
                        Assert.AreEqual(edges[idx].Value.Forward, edgesDeserialized[idx].Value.Forward);
                    }
                }
            }
        }
        public void TestOsmRoutingInterpreterCanBeTraversedBy()
        {
            var interpreter = new OsmRoutingInterpreter();

            TagsCollectionBase tags = new TagsCollection();
            tags["highway"] = "footway";
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Pedestrian));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bicycle));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Moped));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.MotorCycle));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Car));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.SmallTruck));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.BigTruck));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bus));

            tags["highway"] = "cycleway";
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Pedestrian));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bicycle));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Moped));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.MotorCycle));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Car));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.SmallTruck));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.BigTruck));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bus));

            tags["highway"] = "bridleway";
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Pedestrian));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bicycle));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Moped));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.MotorCycle));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Car));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.SmallTruck));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.BigTruck));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bus));

            tags["highway"] = "path";
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Pedestrian));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bicycle));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Moped));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.MotorCycle));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Car));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.SmallTruck));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.BigTruck));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bus));

            tags["highway"] = "pedestrian";
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Pedestrian));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bicycle));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Moped));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.MotorCycle));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Car));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.SmallTruck));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.BigTruck));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bus));

            tags["highway"] = "road";
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Pedestrian));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bicycle));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Moped));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.MotorCycle));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Car));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.SmallTruck));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.BigTruck));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bus));

            tags["highway"] = "living_street";
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Pedestrian));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bicycle));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Moped));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.MotorCycle));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Car));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.SmallTruck));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.BigTruck));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bus));

            tags["highway"] = "residential";
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Pedestrian));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bicycle));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Moped));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.MotorCycle));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Car));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.SmallTruck));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.BigTruck));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bus));

            tags["highway"] = "unclassified";
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Pedestrian));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bicycle));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Moped));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.MotorCycle));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Car));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.SmallTruck));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.BigTruck));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bus));

            tags["highway"] = "tertiary";
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Pedestrian));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bicycle));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Moped));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.MotorCycle));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Car));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.SmallTruck));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.BigTruck));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bus));

            tags["highway"] = "secondary";
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Pedestrian));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bicycle));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Moped));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.MotorCycle));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Car));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.SmallTruck));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.BigTruck));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bus));

            tags["highway"] = "primary";
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Pedestrian));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bicycle));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Moped));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.MotorCycle));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Car));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.SmallTruck));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.BigTruck));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bus));

            tags["highway"] = "trunk";
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Pedestrian));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bicycle));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Moped));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.MotorCycle));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Car));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.SmallTruck));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.BigTruck));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bus));

            tags["highway"] = "motorway";
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Pedestrian));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bicycle));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Moped));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.MotorCycle));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Car));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.SmallTruck));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.BigTruck));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bus));
        }
Esempio n. 35
0
        /// <summary>
        /// Calculates the TSP.
        /// </summary>
        /// <param name="dataStream"></param>
        /// <param name="csvStream"></param>
        /// <param name="pbf"></param>
        /// <param name="vehicleEnum"></param>
        /// <returns></returns>
        private OsmSharpRoute CalculateTSP(Stream dataStream, Stream csvStream, bool pbf, VehicleEnum vehicleEnum)
        {
            // create the router.
            var interpreter = new OsmRoutingInterpreter();
            var tagsIndex = new OsmTagsIndex();

            // do the data processing.
            var osmData =
                new DynamicGraphRouterDataSource<PreProcessedEdge>(tagsIndex);
            var targetData = new PreProcessedDataGraphProcessingTarget(
                osmData, interpreter, osmData.TagsIndex, vehicleEnum);
            var dataProcessorSource = new XmlDataProcessorSource(dataStream);
            var sorter = new DataProcessorFilterSort();
            sorter.RegisterSource(dataProcessorSource);
            targetData.RegisterSource(sorter);
            targetData.Pull();

            IRouter<RouterPoint> router = new Router<PreProcessedEdge>(osmData, interpreter,
                new DykstraRoutingPreProcessed(osmData.TagsIndex));

            // read the source files.
            const int latitudeIdx = 2;
            const int longitudeIdx = 3;
            string[][] pointStrings = OsmSharp.Tools.DelimitedFiles.DelimitedFileHandler.ReadDelimitedFileFromStream(
                csvStream,
                DelimiterType.DotCommaSeperated);
            var points = new List<RouterPoint>();
            int cnt = 10;
            foreach (string[] line in pointStrings)
            {
                if (points.Count >= cnt)
                {
                    break;
                }
                var latitudeString = (string)line[latitudeIdx];
                var longitudeString = (string)line[longitudeIdx];

                //string route_ud = (string)line[1];

                double longitude = 0;
                double latitude = 0;
                if (double.TryParse(longitudeString, System.Globalization.NumberStyles.Any,
                    System.Globalization.CultureInfo.InvariantCulture, out longitude) &&
                   double.TryParse(latitudeString, System.Globalization.NumberStyles.Any,
                    System.Globalization.CultureInfo.InvariantCulture, out latitude))
                {
                    var point = new GeoCoordinate(latitude, longitude);

                    RouterPoint resolved = router.Resolve(VehicleEnum.Car, point);
                    if (resolved != null && router.CheckConnectivity(VehicleEnum.Car, resolved, 100))
                    {
                        points.Add(resolved);
                    }
                }
            }

            var tspSolver = new RouterTSPWrapper<RouterPoint, RouterTSP>(
                new RouterTSPAEXGenetic(), router, interpreter);
            return tspSolver.CalculateTSP(vehicleEnum, points.ToArray());
        }