Пример #1
0
        /// <summary>
        /// Tests interpreting all data from a given pbf source.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="scene"></param>
        /// <param name="interpreter"></param>
        /// <param name="pbfSource"></param>
        public static Stream TestInterpret(string name, MapCSSInterpreter interpreter, Scene2D scene, string pbfSource)
        {
            StyleOsmStreamSceneTarget target = new StyleOsmStreamSceneTarget(
                interpreter, scene, new WebMercator());
            FileInfo                testFile = new FileInfo(string.Format(@".\TestFiles\{0}", pbfSource));
            Stream                  stream   = testFile.OpenRead();
            OsmStreamSource         source   = new PBFOsmStreamSource(stream);
            OsmStreamFilterProgress progress = new OsmStreamFilterProgress();

            progress.RegisterSource(source);
            target.RegisterSource(progress);

            PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer(string.Format("{0}.Add", name));

            performanceInfo.Start();
            performanceInfo.Report("Interpreting style with objects from {0}...", pbfSource.ToString());

            target.Pull();

            performanceInfo.Stop();

            Console.Write("", scene.BackColor);
            stream.Dispose();

            return(testFile.OpenRead());
        }
Пример #2
0
        /// <summary>
        /// Tests preprocessing data from a PBF file.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="pbfFile"></param>
        public static void TestPreprocessing(string name, string pbfFile)
        {
            FileInfo testFile = new FileInfo(string.Format(@".\TestFiles\{0}", pbfFile));
            Stream   stream   = testFile.OpenRead();
            var      progress = new OsmStreamFilterProgress();

            progress.RegisterSource(new PBFOsmStreamSource(stream));

            var performanceInfo = new PerformanceInfoConsumer("PreProcessor", 20000);

            performanceInfo.Start();
            performanceInfo.Report("Pulling from {0}...", testFile.Name);

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

            // read from the OSM-stream.
            var memoryData = new RouterDataSource <Edge>(new Graph <Edge>(), tagsIndex);
            var targetData = new GraphOsmStreamTarget(memoryData, new OsmRoutingInterpreter(), tagsIndex);

            targetData.RegisterSource(progress);
            targetData.Pull();

            stream.Dispose();

            performanceInfo.Stop();
            // make sure the router is still here after GC to note the memory difference.
            OsmSharp.Logging.Log.TraceEvent("PreProcessor", Logging.TraceEventType.Information, memoryData.ToString());
            memoryData = null;

            GC.Collect();
        }
Пример #3
0
        /// <summary>
        /// Tests writing to an array.
        /// </summary>
        public static void TestWrite(ArrayProfile profile)
        {
            using (var mapStream = new FileInfo(Global.FileName).Open(
                       FileMode.Create, FileAccess.ReadWrite))
            {
                using (var map = new MemoryMapStream(mapStream))
                {
                    var array = new Array <int>(map, Global.ArrayTestLength,
                                                profile);

                    var perf = new PerformanceInfoConsumer(
                        string.Format("Write Array: {0}", profile.ToString()),
                        1000);
                    perf.Start();
                    for (var i = 0; i < array.Length; i++)
                    {
                        array[i] = i * 2;

                        if (Global.Verbose && i % (array.Length / 100) == 0)
                        {
                            perf.Report("Writing... {0}%", i, array.Length - 1);
                        }
                    }
                    perf.Stop();
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Tests writing to an array.
        /// </summary>
        public static void TestWrite(ArrayProfile profile)
        {
            using (var mapStream = new FileInfo(Global.FileName).Open(
                FileMode.Create, FileAccess.ReadWrite))
            {
                using (var map = new MemoryMapStream(mapStream))
                {
                    var array = new Array<int>(map, Global.ArrayTestLength,
                        profile);

                    var perf = new PerformanceInfoConsumer(
                        string.Format("Write Array: {0}", profile.ToString()), 
                            1000);
                    perf.Start();
                    for (var i = 0; i < array.Length; i++)
                    {
                        array[i] = i * 2;

                        if (Global.Verbose && i % (array.Length / 100) == 0)
                        {
                            perf.Report("Writing... {0}%", i, array.Length - 1);
                        }
                    }
                    perf.Stop();
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Tests preprocessing data from a PBF file.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="pbfFile"></param>
        public static void TestPreprocessing(string name, string pbfFile)
        {
            FileInfo testFile = new FileInfo(string.Format(@".\TestFiles\{0}", pbfFile));
            Stream stream = testFile.OpenRead();
            var progress = new OsmStreamFilterProgress();
            progress.RegisterSource(new PBFOsmStreamSource(stream));

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

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

            // read from the OSM-stream.
            // var memoryGraph = new MemoryMappedGraph<LiveEdge>(1000000, @"c:\temp\");
            var memoryData = new DynamicGraphRouterDataSource<LiveEdge>(tagsIndex);
            var targetData = new LiveGraphOsmStreamTarget(memoryData, new OsmRoutingInterpreter(), tagsIndex);
            targetData.RegisterSource(progress);
            targetData.Pull();

            stream.Dispose();

            performanceInfo.Stop();
            // make sure the router is still here after GC to note the memory difference.
            OsmSharp.Logging.Log.TraceEvent("LivePreProcessor", Logging.TraceEventType.Information, memoryData.ToString());
            memoryData = null;

            GC.Collect();
        }
        /// <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)
        {
            FileInfo testFile = new FileInfo(string.Format(@".\TestFiles\{0}", pbfFile));
            Stream stream = testFile.OpenRead();
            PBFOsmStreamSource source = new PBFOsmStreamSource(stream);

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

            CHEdgeGraphFileStreamTarget target = new CHEdgeGraphFileStreamTarget(writeStream,
                Vehicle.Car);
            target.RegisterSource(source);

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

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

            var routingSerializer = new CHEdgeDataDataSourceSerializer(true);
            routingSerializer.Serialize(writeStream, data);

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

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

            performanceInfo.Stop();
        }
Пример #7
0
        /// <summary>
        /// Tests adding random keys.
        /// </summary>
        public static void TestRandom()
        {
            using (var mapStream = new FileInfo(Global.FileName).Open(
                       FileMode.Create, FileAccess.ReadWrite))
            {
                using (var map = new MemoryMapStream(mapStream))
                {
                    var random     = new Random();
                    var dictionary = new Dictionary <int, long>(map);

                    var count = 65536 * 2;
                    var perf  = new PerformanceInfoConsumer(
                        string.Format("Write Dictionary Random"), 1000);
                    perf.Start();
                    for (var i = 0; i < count; i++)
                    {
                        var r = random.Next();
                        dictionary[r] = (long)r * 2;

                        if (Global.Verbose && i % (count / 100) == 0)
                        {
                            perf.Report("Writing... {0}%", i, count - 1);
                        }
                    }
                    perf.Stop();
                }
            }
        }
Пример #8
0
        /// <summary>
        /// Tests read from an array.
        /// </summary>
        public static void TestReadRandom(ArrayProfile profile)
        {
            using (var mapStream = new FileInfo(Global.FileName).Open(
                       FileMode.Open, FileAccess.ReadWrite))
            {
                using (var map = new MemoryMapStream(mapStream))
                {
                    var array = new Array <int>(map.CreateInt32(mapStream.Length / 4), profile);

                    var size = 1000000;
                    var perf = new PerformanceInfoConsumer(
                        string.Format("Read Random Array: {0} {1}", size, profile.ToString()),
                        1000);
                    perf.Start();
                    var rand = new Random();
                    for (var i = 0; i < size; i++)
                    {
                        var ran = (long)rand.Next((int)array.Length);
                        var val = array[ran];
                        if (val != ran * 2)
                        { // oeps, something went wrong here!
                            throw new System.Exception();
                        }

                        if (Global.Verbose && i % (size / 100) == 0)
                        {
                            perf.Report("Reading... {0}%", i, size);
                        }
                    }
                    perf.Stop();
                }
            }
        }
        public static Stream TestSerialization(string name, string pbfFile, DynamicGraphRouterDataSource <CHEdgeData> data)
        {
            var testOutputFile = new FileInfo(@"test.routing");

            testOutputFile.Delete();
            var writeStream = testOutputFile.OpenWrite();

            var performanceInfo = new PerformanceInfoConsumer("CHSerializer");

            performanceInfo.Start();
            performanceInfo.Report("Writing to {0}...", testOutputFile.Name);

            TagsCollectionBase metaData = new TagsCollection();

            metaData.Add("some_key", "some_value");
            var routingSerializer = new CHEdgeDataDataSourceSerializer();

            routingSerializer.Serialize(writeStream, data, metaData);

            writeStream.Dispose();

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

            performanceInfo.Stop();

            return(testOutputFile.OpenRead());
        }
Пример #10
0
        /// <summary>
        /// Tests adding random keys.
        /// </summary>
        public static void TestRandom()
        {
            using (var mapStream = new FileInfo(Global.FileName).Open(
                FileMode.Create, FileAccess.ReadWrite))
            {
                using (var map = new MemoryMapStream(mapStream))
                {
                    var random = new Random();
                    var dictionary = new Dictionary<int, long>(map);

                    var count = 65536 * 2;
                    var perf = new PerformanceInfoConsumer(
                        string.Format("Write Dictionary Random"), 1000);
                    perf.Start();
                    for (var i = 0; i < count; i++)
                    {
                        var r = random.Next();
                        dictionary[r] = (long)r * 2;

                        if (Global.Verbose && i % (count / 100) == 0)
                        {
                            perf.Report("Writing... {0}%", i, count - 1);
                        }
                    }
                    perf.Stop();
                }
            }
        }
        /// <summary>
        /// Tests preprocessing data from a PBF file.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="pbfFile"></param>
        public static RouterDataSource <CHEdgeData> TestSerialization(string name, string pbfFile)
        {
            var testFilePath = Path.Combine(
                Path.GetDirectoryName(Assembly.GetEntryAssembly().Location),
                "TestFiles", pbfFile);
            //var testFilePath = @"/Users/xivk/work/OSM/bin/africa-latest.osm.pbf";
            var testFile = new FileInfo(testFilePath);
            var stream   = testFile.OpenRead();
            var source   = new OsmSharp.Osm.Streams.Filters.OsmStreamFilterProgress();

            source.RegisterSource(new PBFOsmStreamSource(stream));

            var testOutputFile = new FileInfo(@"test.routing");

            testOutputFile.Delete();
            Stream writeStream = testOutputFile.Open(FileMode.CreateNew, FileAccess.ReadWrite);

            var performanceInfo = new PerformanceInfoConsumer("CHSerializerFlatFile.Serialize");

            performanceInfo.Start();
            performanceInfo.Report("Pulling from {0}...", testFile.Name);

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

            (data.Graph as DirectedGraph <CHEdgeData>).Compress(true);

            //var graphCopy = new DirectedGraph<CHEdgeData>();
            //graphCopy.CopyFrom(data);
            //data = new RouterDataSource<CHEdgeData>(graphCopy, data.TagsIndex);

            var metaData = new TagsCollection();

            metaData.Add("some_key", "some_value");
            var routingSerializer = new CHEdgeSerializer();

            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, false);

            performanceInfo.Stop();
            return(data);
        }
Пример #12
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));
        }
Пример #13
0
        /// <summary>
        /// Tests serializing a stream.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="stream"></param>
        /// <param name="scene"></param>
        /// <param name="compress"></param>
        public static void TestSerialize(string name, Stream stream, Scene2D scene, bool compress)
        {
            PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer(string.Format("{0}.Serialize", name));
            performanceInfo.Start();
            performanceInfo.Report("Serializing stream...");

            scene.Serialize(stream, compress);

            performanceInfo.Stop();

            Console.Write("", scene.BackColor);
        }
Пример #14
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 TestRouting(string name, Stream stream, int testCount)
        {
            var vehicle = Vehicle.Car;

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

            // read from the OSM-stream.
            var source = new OsmSharp.Osm.Streams.Filters.OsmStreamFilterProgress();

            source.RegisterSource(new OsmSharp.Osm.PBF.Streams.PBFOsmStreamSource(stream));
            var data = CHEdgeGraphOsmStreamTarget.Preprocess(source,
                                                             new OsmRoutingInterpreter(), vehicle);

            var router = new CHRouter();

            var performanceInfo = new PerformanceInfoConsumer("CHRouting");

            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, 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("CHRouting", TraceEventType.Information,
                                                    "Routing... {0}%", progress);
                    latestProgress = progress;
                }
            }
            performanceInfo.Stop();

            OsmSharp.Logging.Log.TraceEvent("CHRouting", OsmSharp.Logging.TraceEventType.Information,
                                            string.Format("{0}/{1} routes successfull!", successCount, totalCount));
        }
Пример #15
0
        /// <summary>
        /// Tests adding simple tags to the given index.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="index"></param>
        /// <param name="collectionCount"></param>
        public static void TestAdd(string name, ITagsCollectionIndex index,
                                   int collectionCount)
        {
            PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer(string.Format("{0}.Add", name));

            performanceInfo.Start();
            performanceInfo.Report("Adding {0} tag collections...", collectionCount);

            ITagCollectionIndexTests.FillIndex(index, collectionCount);

            performanceInfo.Stop();

            Console.Write("", index.Max);
        }
Пример #16
0
        /// <summary>
        /// Tests adding simple tags to the given index.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="index"></param>
        /// <param name="source"></param>
        public static void TestAdd(string name, ITagsCollectionIndex index,
                                   OsmStreamSource source)
        {
            PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer(string.Format("{0}.Add", name));

            performanceInfo.Start();
            performanceInfo.Report("Adding tags from {0}...", source.ToString());

            ITagCollectionIndexTests.FillIndex(index, source);

            performanceInfo.Stop();

            Console.Write("", index.Max);
        }
Пример #17
0
        /// <summary>
        /// Tests serializing a stream.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="stream"></param>
        /// <param name="scene"></param>
        /// <param name="compress"></param>
        public static void TestSerialize(string name, Stream stream, Scene2D scene, bool compress)
        {
            PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer(string.Format("{0}.Serialize", name));
            performanceInfo.Start();
            performanceInfo.Report("Serializing stream...");

            TagsCollectionBase metaTags = new TagsCollection();
            metaTags.Add("generated_by", "performance_test");
            scene.Serialize(stream, compress, metaTags);

            performanceInfo.Stop();

            Console.Write("", scene.BackColor);
        }
Пример #18
0
        /// <summary>
        /// Tests rendering the given serialized scene.
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="box"></param>
        /// <param name="testCount"></param>
        /// <param name="createTarget"></param>
        /// <param name="createRenderer"></param>
        /// <param name="range"></param>
        /// <param name="minZoom"></param>
        public static void TestRenderScene(CreateTarget createTarget, CreateRenderer createRenderer,
                                           Stream stream, GeoCoordinateBox box, int testCount, int range, int minZoom)
        {
            WebMercator projection = new WebMercator();

            // build a map.
            Map map = new Map();
            TagsCollectionBase metaTags;

            map.AddLayer(new LayerScene(
                             Scene2D.Deserialize(stream, true, out metaTags)));

            // build the target and renderer.
            TTarget target = createTarget.Invoke(TargetWidth, TargetHeight);
            MapRenderer <TTarget> mapRenderer = new MapRenderer <TTarget>(
                createRenderer.Invoke());

            // render the map.
            PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer("Scene2DLayeredRendering");

            performanceInfo.Start();
            //performanceInfo.Report("Rendering {0} random images...", testCount);

            while (testCount > 0)
            {
                // randomize view.
                int zoom = minZoom;
                if (range > 1)
                { // only randomize when range is > 1
                    zoom = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(range) + minZoom;
                }
                GeoCoordinate center = box.GenerateRandomIn();
                View2D        view   = mapRenderer.Create(TargetWidth, TargetHeight, map,
                                                          (float)projection.ToZoomFactor(zoom), center, false, true);

                OsmSharp.Logging.Log.TraceEvent("Scene2DLayeredRendering", OsmSharp.Logging.TraceEventType.Information,
                                                string.Format("Rendering at z{0} l{1}.",
                                                              zoom, center));
                map.ViewChanged((float)projection.ToZoomFactor(zoom), center, view, view);

                mapRenderer.Render(target, map, view, (float)projection.ToZoomFactor(zoom));

                testCount--;
            }

            performanceInfo.Stop();
            stream.Seek(0, SeekOrigin.Begin);
        }
Пример #19
0
        /// <summary>
        /// Tests routing between two points and the associated instructions.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="stream"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        public static void TestSerializeRoutingInstrictions(string name, Stream stream,
                                                            GeoCoordinate from, GeoCoordinate to)
        {
            PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer("CHSerializedRouting");

            performanceInfo.Start();
            performanceInfo.Report("Routing & generating instructions...");

            TagsCollectionBase metaData = null;
            var routingSerializer       = new CHEdgeDataDataSourceSerializer();
            var graphDeserialized       = routingSerializer.Deserialize(
                stream, out metaData, true);

            var interpreter = new OsmRoutingInterpreter();
            var router      = Router.CreateCHFrom(
                graphDeserialized, new CHRouter(),
                interpreter);

            RouterPoint fromPoint = router.Resolve(Vehicle.Car, from);
            RouterPoint toPoint   = router.Resolve(Vehicle.Car, to);

            List <Instruction> instructions = new List <Instruction>();

            if (fromPoint != null && toPoint != null)
            {
                Route route = router.Calculate(Vehicle.Car, fromPoint, toPoint);
                if (route != null)
                {
                    instructions = InstructionGenerator.Generate(route, interpreter);
                }
            }

            performanceInfo.Stop();

            if (instructions.Count == 0)
            {
                OsmSharp.Logging.Log.TraceEvent("CHSerializedRouting", OsmSharp.Logging.TraceEventType.Information,
                                                "Routing unsuccesfull!");
            }
            else
            {
                foreach (Instruction instruction in instructions)
                {
                    OsmSharp.Logging.Log.TraceEvent("CHSerializedRouting", OsmSharp.Logging.TraceEventType.Information,
                                                    instruction.Text);
                }
            }
        }
Пример #20
0
        /// <summary>
        /// Tests routing from a serialized routing file.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="stream"></param>
        /// <param name="box"></param>
        /// <param name="testCount"></param>
        public static void TestSerializedRouting(string name, Stream stream,
                                                 GeoCoordinateBox box, int testCount)
        {
            var router = Router.CreateLiveFrom(new OsmSharp.Osm.PBF.Streams.PBFOsmStreamSource(stream),
                                               new OsmRoutingInterpreter());

            var performanceInfo = new PerformanceInfoConsumer("LiveRouting");

            performanceInfo.Start();
            performanceInfo.Report("Routing {0} routes...", testCount);

            int   successCount   = 0;
            int   totalCount     = testCount;
            float latestProgress = -1;

            while (testCount > 0)
            {
                var from = box.GenerateRandomIn();
                var to   = box.GenerateRandomIn();

                var fromPoint = router.Resolve(Vehicle.Car, from);
                var toPoint   = router.Resolve(Vehicle.Car, to);

                if (fromPoint != null && toPoint != null)
                {
                    var route = router.Calculate(Vehicle.Car, fromPoint, toPoint);
                    if (route != null)
                    {
                        successCount++;
                    }
                }

                testCount--;

                // report progress.
                float progress = (float)System.Math.Round(((double)(totalCount - testCount) / (double)totalCount) * 100);
                if (progress != latestProgress)
                {
                    OsmSharp.Logging.Log.TraceEvent("LiveEdgePreprocessor", 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));
        }
        /// <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 PBFOsmStreamSource(stream);

            var testOutputFile = new FileInfo(@"test.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();
        }
Пример #22
0
        /// <summary>
        /// Tests serializing a stream.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="stream"></param>
        /// <param name="scene"></param>
        /// <param name="compress"></param>
        public static void TestSerialize(string name, Stream stream, Scene2D scene, bool compress)
        {
            PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer(string.Format("{0}.Serialize", name));

            performanceInfo.Start();
            performanceInfo.Report("Serializing stream...");

            TagsCollectionBase metaTags = new TagsCollection();

            metaTags.Add("generated_by", "performance_test");
            scene.Serialize(stream, compress, metaTags);

            performanceInfo.Stop();

            Console.Write("", scene.BackColor);
        }
Пример #23
0
        /// <summary>
        /// Tests preprocessing data from a PBF file.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="pbfFile"></param>
        public static void TestPreprocessing(string name, string pbfFile)
        {
            FileInfo testFile = new FileInfo(string.Format(@".\TestFiles\{0}", pbfFile));
            Stream stream = testFile.OpenRead();
            PBFOsmStreamSource source = new PBFOsmStreamSource(stream);

            PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer("CHPreProcessor.Pre");
            performanceInfo.Start();
            performanceInfo.Report("Pulling from {0}...", testFile.Name);

            Router.CreateCHFrom(source, new OsmRoutingInterpreter(), Vehicle.Car);

            stream.Dispose();

            performanceInfo.Stop();
        }
Пример #24
0
        /// <summary>
        /// Tests random access to an already filled index.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="index"></param>
        /// <param name="testCount"></param>
        public static void TestRandomAccess(string name, ITagsCollectionIndexReadonly index,
                                            int testCount)
        {
            PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer(string.Format("{0}.Access", name));

            performanceInfo.Start();
            performanceInfo.Report("Random accessing tags index {0} times...", testCount);

            for (int idx = 0; idx < testCount; idx++)
            {
                uint collectionIndex          = (uint)OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(index.Max);
                TagsCollectionBase collection = index.Get(collectionIndex);
            }

            performanceInfo.Stop();
        }
Пример #25
0
        /// <summary>
        /// Tests preprocessing data from a PBF file.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="pbfFile"></param>
        public static void TestPreprocessing(string name, string pbfFile)
        {
            FileInfo           testFile = new FileInfo(string.Format(@".\TestFiles\{0}", pbfFile));
            Stream             stream   = testFile.OpenRead();
            PBFOsmStreamSource source   = new PBFOsmStreamSource(stream);

            PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer("CHPreProcessor.Pre");

            performanceInfo.Start();
            performanceInfo.Report("Pulling from {0}...", testFile.Name);

            Router.CreateCHFrom(source, new OsmRoutingInterpreter(), Vehicle.Car);

            stream.Dispose();

            performanceInfo.Stop();
        }
Пример #26
0
        /// <summary>
        /// Executes reading tests.
        /// </summary>
        public static void Test()
        {
            FileInfo testFile = new FileInfo(@".\TestFiles\kempen.osm.pbf");
            Stream stream = testFile.OpenRead();
            PBFOsmStreamSource source = new PBFOsmStreamSource(stream);
            OsmStreamTargetEmpty emptyTarget = new OsmStreamTargetEmpty();
            emptyTarget.RegisterSource(source);

            PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer("PBFOsmStreamSource.Pull");
            performanceInfo.Start();
            performanceInfo.Report("Pulling from {0}...", testFile.Name);

            emptyTarget.Pull();
            stream.Dispose();

            performanceInfo.Stop();
        }
Пример #27
0
        /// <summary>
        /// Tests routing within a bounding box.
        /// </summary>
        /// <param name="router"></param>
        /// <param name="box"></param>
        /// <param name="testCount"></param>
        public static void TestRouting(Router router, GeoCoordinateBox box, int testCount)
        {
            var performanceInfo = new PerformanceInfoConsumer("CHSerializedRouting");

            performanceInfo.Start();
            performanceInfo.Report("Routing {0} routes: Resolving...", testCount);
            int successCount   = 0;
            int totalCount     = testCount;
            var resolvedPoints = new List <RouterPoint>();

            while (testCount > 0)
            {
                var from = box.GenerateRandomIn();
                var to   = box.GenerateRandomIn();

                var fromPoint = router.Resolve(Vehicle.Car, from);
                var toPoint   = router.Resolve(Vehicle.Car, to);

                resolvedPoints.Add(fromPoint);
                resolvedPoints.Add(toPoint);

                testCount--;
            }
            performanceInfo.Stop();

            performanceInfo = new PerformanceInfoConsumer("CHSerializedRouting");
            performanceInfo.Start();
            performanceInfo.Report("Routing {0} routes: Routing...", testCount);
            for (int idx = 0; idx < resolvedPoints.Count; idx = idx + 2)
            {
                var fromPoint = resolvedPoints[idx];
                var toPoint   = resolvedPoints[idx + 1];
                if (fromPoint != null && toPoint != null)
                {
                    var route = router.Calculate(Vehicle.Car, fromPoint, toPoint, float.MaxValue, true);
                    if (route != null)
                    {
                        successCount++;
                    }
                }
            }
            performanceInfo.Stop();

            OsmSharp.Logging.Log.TraceEvent("CHSerializedRouting", OsmSharp.Logging.TraceEventType.Information,
                                            string.Format("{0}/{1} routes successfull!", successCount, totalCount));
        }
        /// <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 PBFOsmStreamSource(stream);
            var progress = new OsmStreamFilterProgress();

            progress.RegisterSource(source);

            var testOutputFile = new FileInfo(@"test.routing");

            testOutputFile.Delete();
            Stream writeStream = testOutputFile.OpenWrite();

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

            var performanceInfo = new PerformanceInfoConsumer("LiveSerializerFlatFile.Serialize", 5000);

            performanceInfo.Start();
            performanceInfo.Report("Pulling from {0}...", testFile.Name);

            // read from the OSM-stream.
            var memoryData = new DynamicGraphRouterDataSource <LiveEdge>(tagsIndex, 100000000);
            var targetData = new LiveGraphOsmStreamTarget(memoryData, new OsmRoutingInterpreter(), tagsIndex);

            targetData.RegisterSource(progress);
            targetData.Pull();

            var metaData = new TagsCollection();

            metaData.Add("some_key", "some_value");
            var routingSerializer = new LiveEdgeFlatfileSerializer();

            routingSerializer.Serialize(writeStream, memoryData, 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();
        }
Пример #29
0
        /// <summary>
        /// Tests routing from a serialized routing file.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="stream"></param>
        /// <param name="box"></param>
        /// <param name="testCount"></param>
        public static void TestSerializedRouting(string name, Stream stream,
                                                 GeoCoordinateBox box, int testCount)
        {
            PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer("CHSerializedRouting");

            performanceInfo.Start();
            performanceInfo.Report("Routing {0} routes...", testCount);

            TagsCollectionBase metaData = null;
            var routingSerializer       = new CHEdgeDataDataSourceSerializer();
            var graphDeserialized       = routingSerializer.Deserialize(
                stream, out metaData, true);

            var router = Router.CreateCHFrom(
                graphDeserialized, new CHRouter(),
                new OsmRoutingInterpreter());

            int successCount = 0;
            int totalCount   = testCount;

            while (testCount > 0)
            {
                GeoCoordinate from = box.GenerateRandomIn();
                GeoCoordinate to   = box.GenerateRandomIn();

                RouterPoint fromPoint = router.Resolve(Vehicle.Car, from);
                RouterPoint toPoint   = router.Resolve(Vehicle.Car, to);

                if (fromPoint != null && toPoint != null)
                {
                    Route route = router.Calculate(Vehicle.Car, fromPoint, toPoint, float.MaxValue, true);
                    if (route != null)
                    {
                        successCount++;
                    }
                }

                testCount--;
            }

            performanceInfo.Stop();

            OsmSharp.Logging.Log.TraceEvent("CHSerializedRouting", OsmSharp.Logging.TraceEventType.Information,
                                            string.Format("{0}/{1} routes successfull!", successCount, totalCount));
        }
Пример #30
0
        public static void TestResolved(RouterDataSource <CHEdgeData> data, int testCount, GeoCoordinateBox box)
        {
            var router = Router.CreateCHFrom(data, new CHRouter(), new OsmRoutingInterpreter());

            var performanceInfo = new PerformanceInfoConsumer("CHRouting");

            performanceInfo.Start();
            performanceInfo.Report("Routing {0} routes...", testCount);

            var successCount   = 0;
            var totalCount     = testCount;
            var latestProgress = -1.0f;

            while (testCount > 0)
            {
                var from = box.GenerateRandomIn();
                var to   = box.GenerateRandomIn();

                var fromPoint = router.Resolve(Vehicle.Car, from);
                var toPoint   = router.Resolve(Vehicle.Car, to);

                if (fromPoint != null && toPoint != null)
                {
                    var route = router.Calculate(Vehicle.Car, fromPoint, toPoint);
                    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("CHRouting", TraceEventType.Information,
                                                    "Routing... {0}%", progress);
                    latestProgress = progress;
                }
            }
            performanceInfo.Stop();

            OsmSharp.Logging.Log.TraceEvent("CHRouting", OsmSharp.Logging.TraceEventType.Information,
                                            string.Format("{0}/{1} routes successfull!", successCount, totalCount));
        }
Пример #31
0
        /// <summary>
        /// Tests preprocessing data from a PBF file.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="pbfFile"></param>
        public static Stream TestSerialization(string name, string pbfFile)
        {
            FileInfo           testFile = new FileInfo(string.Format(@".\TestFiles\{0}", pbfFile));
            Stream             stream   = testFile.OpenRead();
            PBFOsmStreamSource source   = new PBFOsmStreamSource(stream);

            FileInfo testOutputFile = new FileInfo(@"test.routing");

            testOutputFile.Delete();
            Stream writeStream = testOutputFile.OpenWrite();

            var tagsIndex   = new TagsTableCollectionIndex();
            var interpreter = new OsmRoutingInterpreter();
            var graph       = new DynamicGraphRouterDataSource <CHEdgeData>(tagsIndex);
            CHEdgeGraphFileStreamTarget target = new CHEdgeGraphFileStreamTarget(writeStream, graph, interpreter, tagsIndex,
                                                                                 Vehicle.Car);

            target.RegisterSource(source);

            PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer("CHSerializer");

            performanceInfo.Start();
            performanceInfo.Report("Pulling from {0}...", testFile.Name);

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

            TagsCollectionBase metaData = new TagsCollection();

            metaData.Add("some_key", "some_value");
            var routingSerializer = new CHEdgeDataDataSourceSerializer();

            routingSerializer.Serialize(writeStream, data, metaData);

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

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

            performanceInfo.Stop();

            return(testOutputFile.OpenRead());
        }
        /// <summary>
        /// Executes reading tests.
        /// </summary>
        public static void Test()
        {
            var testFile = new FileInfo(@".\TestFiles\kempen-big.osm.pbf");
            var stream = testFile.OpenRead();
            var source = new PBFOsmStreamSource(stream);
            var progress = new OsmStreamFilterProgress();
            progress.RegisterSource(source);
            var completeSource = new OsmSharp.Osm.Streams.Complete.OsmSimpleCompleteStreamSource(progress);

            PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer("OsmSimpleCompleteStreamSourceTests.Pull");
            performanceInfo.Start();
            performanceInfo.Report("Pulling from {0}...", testFile.Name);

            var completeObjects = new List<ICompleteOsmGeo>(completeSource);

            stream.Dispose();

            performanceInfo.Stop();
        }
Пример #33
0
        /// <summary>
        /// Executes reading tests.
        /// </summary>
        public static void Test()
        {
            FileInfo             testFile    = new FileInfo(@".\TestFiles\kempen-big.osm.pbf");
            Stream               stream      = testFile.OpenRead();
            PBFOsmStreamSource   source      = new PBFOsmStreamSource(stream);
            OsmStreamTargetEmpty emptyTarget = new OsmStreamTargetEmpty();

            emptyTarget.RegisterSource(source);

            PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer("PBFOsmStreamSource.Pull");

            performanceInfo.Start();
            performanceInfo.Report("Pulling from {0}...", testFile.Name);

            emptyTarget.Pull();
            stream.Dispose();

            performanceInfo.Stop();
        }
        /// <summary>
        /// Tests preprocessing data from a PBF file.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="pbfFile"></param>
        public static DynamicGraphRouterDataSource<CHEdgeData> 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 performanceInfo = new PerformanceInfoConsumer("CHSerializerFlatFile.Serialize");
            performanceInfo.Start();
            performanceInfo.Report("Pulling from {0}...", testFile.Name);

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

            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();
            return data;
        }
Пример #35
0
        public static void Test(IRoutingAlgorithmData <Edge> data, Vehicle vehicle, int testCount)
        {
            // creates the edge router.
            var router      = new Dykstra();
            var interpreter = new OsmRoutingInterpreter();

            var performanceInfo = new PerformanceInfoConsumer("Routing");

            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("Routing", TraceEventType.Information,
                                                    "Routing... {0}%", progress);
                    latestProgress = progress;
                }
            }
            performanceInfo.Stop();

            OsmSharp.Logging.Log.TraceEvent("Routing", OsmSharp.Logging.TraceEventType.Information,
                                            string.Format("{0}/{1} routes successfull!", successCount, totalCount));
        }
Пример #36
0
        /// <summary>
        /// Executes reading tests.
        /// </summary>
        public static void Test()
        {
            var testFile = new FileInfo(@".\TestFiles\kempen-big.osm.pbf");
            var stream   = testFile.OpenRead();
            var source   = new PBFOsmStreamSource(stream);
            var progress = new OsmStreamFilterProgress();

            progress.RegisterSource(source);
            var completeSource = new OsmSharp.Osm.Streams.Complete.OsmSimpleCompleteStreamSource(progress);

            PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer("OsmSimpleCompleteStreamSourceTests.Pull");

            performanceInfo.Start();
            performanceInfo.Report("Pulling from {0}...", testFile.Name);

            var completeObjects = new List <ICompleteOsmGeo>(completeSource);

            stream.Dispose();

            performanceInfo.Stop();
        }
Пример #37
0
        /// <summary>
        /// Tests adding random string.
        /// </summary>
        public static void TestRandomStringInMemory()
        {
            var dictionary = new Dictionary <string, long>();

            var count = 65536 * 16;
            var perf  = new PerformanceInfoConsumer(
                string.Format("Write Dictionary Random Strings in memory"), 10000);

            perf.Start();
            for (var i = 0; i < count; i++)
            {
                var r = RandomString(5);
                dictionary[r] = (long)(r.GetHashCode());

                if (Global.Verbose && i % (count / 100) == 0)
                {
                    perf.Report("Writing... {0}%", i, count - 1);
                }
            }

            perf.Stop();
        }
Пример #38
0
        /// <summary>
        /// Tests preprocessing data from a PBF file.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="pbfFile"></param>
        public static void TestPreprocessing(string name, string pbfFile)
        {
            FileInfo                testFile = new FileInfo(string.Format(@".\TestFiles\{0}", pbfFile));
            Stream                  stream   = testFile.OpenRead();
            PBFOsmStreamSource      source   = new PBFOsmStreamSource(stream);
            OsmStreamFilterProgress progress = new OsmStreamFilterProgress(source);

            PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer("LivePreProcessor");

            performanceInfo.Start();
            performanceInfo.Report("Pulling from {0}...", testFile.Name);

            var router = Router.CreateLiveFrom(progress, new OsmRoutingInterpreter());

            stream.Dispose();

            performanceInfo.Stop();
            // make sure the route is still here after GC to note the memory difference.
            OsmSharp.Logging.Log.TraceEvent("LivePreProcessor", Logging.TraceEventType.Information, router.ToString());
            router = null;

            GC.Collect();
        }
Пример #39
0
        /// <summary>
        /// Tests routing from a serialized routing file.
        /// </summary>
        /// <param name="data"></param>
        /// <param name="box"></param>
        /// <param name="testCount"></param>
        public static void TestSerializedResolved(RouterDataSource <CHEdgeData> data,
                                                  GeoCoordinateBox box, int testCount = 100)
        {
            var successCount = 0;
            var totalCount   = testCount;

            var router = Router.CreateCHFrom(data, new CHRouter(), new OsmRoutingInterpreter());

            var performanceInfo = new PerformanceInfoConsumer("CHRouting");

            performanceInfo.Start();
            performanceInfo.Report("Routing {0} routes...", testCount);

            while (testCount > 0)
            {
                var point1 = router.Resolve(Vehicle.Car, box.GenerateRandomIn());
                var point2 = router.Resolve(Vehicle.Car, box.GenerateRandomIn());

                Route route = null;
                if (point1 != null && point2 != null)
                {
                    route = router.Calculate(Vehicle.Car, point1, point2);
                }

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

            performanceInfo.Stop();

            OsmSharp.Logging.Log.TraceEvent("CHRouting", OsmSharp.Logging.TraceEventType.Information,
                                            string.Format("{0}/{1} routes successfull!", successCount, totalCount));
        }
        /// <summary>
        /// Tests preprocessing data from a PBF file.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="pbfFile"></param>
        public static Stream 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.routing");
            testOutputFile.Delete();
            var writeStream = testOutputFile.OpenWrite();

            var tagsIndex = new TagsTableCollectionIndex();
            var interpreter = new OsmRoutingInterpreter();
            var graph = new DynamicGraphRouterDataSource<CHEdgeData>(tagsIndex);
            //CHEdgeGraphFileStreamTarget target = new CHEdgeGraphFileStreamTarget(writeStream, graph, interpreter, tagsIndex,
            //    Vehicle.Car);
            //target.RegisterSource(source);

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

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

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

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

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

            performanceInfo.Stop();

            return testOutputFile.OpenRead();
        }
Пример #41
0
        /// <summary>
        /// Tests adding simple tags to the given index.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="index"></param>
        /// <param name="source"></param>
        public static void TestAdd(string name, ITagsCollectionIndex index,
            OsmStreamSource source)
        {
            PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer(string.Format("{0}.Add", name));
            performanceInfo.Start();
            performanceInfo.Report("Adding tags from {0}...", source.ToString());

            ITagCollectionIndexTests.FillIndex(index, source);

            performanceInfo.Stop();

            Console.Write("", index.Max);
        }
        /// <summary>
        /// Tests preprocessing data from a PBF file.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="pbfFile"></param>
        public static RouterDataSource<CHEdgeData> TestSerialization(string name, string pbfFile)
        {
            var testFilePath = Path.Combine (
                Path.GetDirectoryName(Assembly.GetEntryAssembly().Location),
                "TestFiles", pbfFile);
            //var testFilePath = @"/Users/xivk/work/OSM/bin/africa-latest.osm.pbf";
            var testFile = new FileInfo(testFilePath);
            var stream = testFile.OpenRead();
            var source = new OsmSharp.Osm.Streams.Filters.OsmStreamFilterProgress();
            source.RegisterSource(new PBFOsmStreamSource(stream));

            var testOutputFile = new FileInfo(@"test.routing");
            testOutputFile.Delete();
            Stream writeStream = testOutputFile.Open(FileMode.CreateNew, FileAccess.ReadWrite);

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

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

            (data.Graph as DirectedGraph<CHEdgeData>).Compress(true);

            //var graphCopy = new DirectedGraph<CHEdgeData>();
            //graphCopy.CopyFrom(data);
            //data = new RouterDataSource<CHEdgeData>(graphCopy, data.TagsIndex);

            var metaData = new TagsCollection();
            metaData.Add("some_key", "some_value");
            var routingSerializer = new CHEdgeSerializer();
            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, false);

            performanceInfo.Stop();
            return data;
        }
Пример #43
0
        /// <summary>
        /// Tests routing from a serialized routing file.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="stream"></param>
        /// <param name="box"></param>
        /// <param name="testCount"></param>
        public static void TestSerializedRouting(string name, Stream stream,
            GeoCoordinateBox box, int testCount)
        {
            PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer("CHSerializedRouting");
            performanceInfo.Start();
            performanceInfo.Report("Routing {0} routes...", testCount);

            TagsCollectionBase metaData = null;
            var routingSerializer = new CHEdgeDataDataSourceSerializer(true);
            var graphDeserialized = routingSerializer.Deserialize(
                stream, out metaData, true);

            var router = Router.CreateCHFrom(
                graphDeserialized, new CHRouter(),
                new OsmRoutingInterpreter());

            int successCount = 0;
            int totalCount = testCount;
            while (testCount > 0)
            {
                GeoCoordinate from = box.GenerateRandomIn();
                GeoCoordinate to = box.GenerateRandomIn();

                RouterPoint fromPoint = router.Resolve(Vehicle.Car, from);
                RouterPoint toPoint = router.Resolve(Vehicle.Car, to);

                if (fromPoint != null && toPoint != null)
                {
                    Route route = router.Calculate(Vehicle.Car, fromPoint, toPoint);
                    if (route != null)
                    {
                        successCount++;
                    }
                }

                testCount--;
            }

            performanceInfo.Stop();

            OsmSharp.Logging.Log.TraceEvent("CHSerializedRouting", OsmSharp.Logging.TraceEventType.Information,
                string.Format("{0}/{1} routes successfull!", successCount, totalCount));
        }
        public static Stream TestSerialization(string name, string pbfFile, RouterDataSource<CHEdgeData> data)
        {
            var testOutputFile = new FileInfo(@"test.routing");
            testOutputFile.Delete();
            var writeStream = testOutputFile.OpenWrite();

            var performanceInfo = new PerformanceInfoConsumer("CHSerializer");
            performanceInfo.Start();
            performanceInfo.Report("Writing to {0}...", testOutputFile.Name);

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

            writeStream.Dispose();

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

            performanceInfo.Stop();

            return testOutputFile.OpenRead();
        }
Пример #45
0
        /// <summary>
        /// Tests routing from a serialized routing file.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="stream"></param>
        /// <param name="box"></param>
        /// <param name="testCount"></param>
        public static void TestRouting(string name, Stream stream,
            GeoCoordinateBox box, int testCount)
        {
            var vehicle = Vehicle.Car;

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

            // read from the OSM-stream.
            var data = CHEdgeGraphOsmStreamTarget.Preprocess(
                new OsmSharp.Osm.PBF.Streams.PBFOsmStreamSource(stream),
                new OsmRoutingInterpreter(), vehicle);

            var router = Router.CreateCHFrom(data, new CHRouter(), new OsmRoutingInterpreter());

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

            int successCount = 0;
            int totalCount = testCount;
            float latestProgress = -1;
            while (testCount > 0)
            {
                var from = box.GenerateRandomIn();
                var to = box.GenerateRandomIn();

                var fromPoint = router.Resolve(vehicle, from);
                var toPoint = router.Resolve(vehicle, to);

                if (fromPoint != null && toPoint != null)
                {
                    Route route = null;
                    try
                    {
                        route = router.Calculate(vehicle, fromPoint, toPoint);
                    }
                    catch
                    {

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

                testCount--;

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

            OsmSharp.Logging.Log.TraceEvent("CHRouting", OsmSharp.Logging.TraceEventType.Information,
                string.Format("{0}/{1} routes successfull!", successCount, totalCount));
        }
        /// <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 performanceInfo = new PerformanceInfoConsumer("SerializerFlatFile.Serialize", 2000);

            performanceInfo.Start();
            performanceInfo.Report("Pulling from {0}...", testFile.Name);

            var stream   = testFile.OpenRead();
            var source   = new PBFOsmStreamSource(stream);
            var progress = new OsmStreamFilterProgress();

            progress.RegisterSource(source);

            var testOutputFile = new FileInfo(@"test.routing");

            testOutputFile.Delete();
            var writeStream = testOutputFile.Open(FileMode.OpenOrCreate, FileAccess.ReadWrite);

            var tagsIndex         = new TagsIndex();
            var interpreter       = new OsmRoutingInterpreter();
            var graph             = new RouterDataSource <Edge>(new Graph <Edge>(), tagsIndex);
            var routingSerializer = new RoutingDataSourceSerializer();

            var memoryMappedGraph = new Graph <Edge>(1024);
            var coordinates       = new HugeCoordinateIndex(1024);
            var memoryData        = new RouterDataSource <Edge>(memoryMappedGraph, tagsIndex);
            var targetData        = new GraphOsmStreamTarget(memoryData, new OsmRoutingInterpreter(), tagsIndex, coordinates);

            targetData.RegisterSource(progress);
            targetData.Pull();

            performanceInfo.Stop();

            memoryData.Compress();

            performanceInfo = new PerformanceInfoConsumer("SerializerFlatFile.Serialize", 100000);
            performanceInfo.Start();
            performanceInfo.Report("Writing file for {0}...", testFile.Name);

            var metaData = new TagsCollection();

            metaData.Add("some_key", "some_value");
            routingSerializer.Serialize(writeStream, memoryData, metaData);
            stream.Dispose();
            writeStream.Dispose();

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

            ////performanceInfo = new PerformanceInfoConsumer("SerializerFlatFile.Serialize", 100000);
            ////performanceInfo.Start();
            ////performanceInfo.Report("Reading file for {0}...", testFile.Name);

            //var testInputFile = new FileInfo(@"test.routing");
            //var readStream = testInputFile.OpenRead();

            //RoutingTest.TestSerialized(readStream);

            ////var deserializedGraph = routingSerializer.Deserialize(readStream, false);

            ////readStream.Dispose();

            ////OsmSharp.Logging.Log.TraceEvent("SerializerFlatFile", OsmSharp.Logging.TraceEventType.Information,
            ////    string.Format("Read: {0}KB", testInputFile.Length / 1024));

            ////OsmSharp.Logging.Log.TraceEvent("SerializerFlatFile", Logging.TraceEventType.Information, deserializedGraph.ToInvariantString());

            ////performanceInfo.Stop();
        }
Пример #47
0
        /// <summary>
        /// Tests routing from a serialized routing file.
        /// </summary>
        /// <param name="data"></param>
        /// <param name="testCount"></param>
        public static void Test(RouterDataSource<CHEdgeData> data, int testCount)
        {
            var router = new CHRouter();

            var performanceInfo = new PerformanceInfoConsumer("CHRouting");
            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, 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("CHRouting", TraceEventType.Information,
                        "Routing... {0}%", progress);
                    latestProgress = progress;
                }
            }
            performanceInfo.Stop();

            OsmSharp.Logging.Log.TraceEvent("CHRouting", OsmSharp.Logging.TraceEventType.Information,
                string.Format("{0}/{1} routes successfull!", successCount, totalCount));
        }
Пример #48
0
        /// <summary>
        /// Tests routing from a serialized routing file.
        /// </summary>
        /// <param name="data"></param>
        /// <param name="box"></param>
        /// <param name="testCount"></param>
        public static void TestSerializedResolved(RouterDataSource<CHEdgeData> data, 
			GeoCoordinateBox box, int testCount = 100)
        {
            var successCount = 0;
            var totalCount = testCount;

            var router = Router.CreateCHFrom(data, new CHRouter(), new OsmRoutingInterpreter());

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

            while (testCount > 0)
            {
                var point1 = router.Resolve(Vehicle.Car, box.GenerateRandomIn());
                var point2 = router.Resolve(Vehicle.Car, box.GenerateRandomIn());

                Route route = null;
                if (point1 != null && point2 != null)
                {
                    route = router.Calculate(Vehicle.Car, point1, point2);
                }

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

            performanceInfo.Stop();

            OsmSharp.Logging.Log.TraceEvent("CHRouting", OsmSharp.Logging.TraceEventType.Information,
                string.Format("{0}/{1} routes successfull!", successCount, totalCount));
        }
Пример #49
0
        public static void TestResolved(RouterDataSource<CHEdgeData> data, int testCount, GeoCoordinateBox box)
        {
            var router = Router.CreateCHFrom(data, new CHRouter(), new OsmRoutingInterpreter());

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

            var successCount = 0;
            var totalCount = testCount;
            var latestProgress = -1.0f;
            while (testCount > 0)
            {
                var from = box.GenerateRandomIn();
                var to = box.GenerateRandomIn();

                var fromPoint = router.Resolve(Vehicle.Car, from);
                var toPoint = router.Resolve(Vehicle.Car, to);

                if (fromPoint != null && toPoint != null)
                {
                    var route = router.Calculate(Vehicle.Car, fromPoint, toPoint);
                    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("CHRouting", TraceEventType.Information,
                        "Routing... {0}%", progress);
                    latestProgress = progress;
                }
            }
            performanceInfo.Stop();

            OsmSharp.Logging.Log.TraceEvent("CHRouting", OsmSharp.Logging.TraceEventType.Information,
                string.Format("{0}/{1} routes successfull!", successCount, totalCount));
        }
Пример #50
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 TestRouting(string name, Stream stream, int testCount)
        {
            var vehicle = Vehicle.Car;

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

            // read from the OSM-stream.
            var source = new OsmSharp.Osm.Streams.Filters.OsmStreamFilterProgress();
            source.RegisterSource(new OsmSharp.Osm.PBF.Streams.PBFOsmStreamSource(stream));
            var data = CHEdgeGraphOsmStreamTarget.Preprocess(source,
                new OsmRoutingInterpreter(), vehicle);

            var router = new CHRouter();

            var performanceInfo = new PerformanceInfoConsumer("CHRouting");
            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, 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("CHRouting", TraceEventType.Information,
                        "Routing... {0}%", progress);
                    latestProgress = progress;
                }
            }
            performanceInfo.Stop();

            OsmSharp.Logging.Log.TraceEvent("CHRouting", OsmSharp.Logging.TraceEventType.Information,
                string.Format("{0}/{1} routes successfull!", successCount, totalCount));
        }
Пример #51
0
        /// <summary>
        /// Tests interpreting all data from a given pbf source.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="scene"></param>
        /// <param name="interpreter"></param>
        /// <param name="pbfSource"></param>
        public static Stream TestInterpret(string name, MapCSSInterpreter interpreter, Scene2D scene, string pbfSource)
        {
            StyleOsmStreamSceneTarget target = new StyleOsmStreamSceneTarget(
                interpreter, scene, new WebMercator());
            FileInfo testFile = new FileInfo(string.Format(@".\TestFiles\{0}", pbfSource));
            Stream stream = testFile.OpenRead();
            OsmStreamSource source = new PBFOsmStreamSource(stream);
            OsmStreamFilterProgress progress = new OsmStreamFilterProgress();
            progress.RegisterSource(source);
            target.RegisterSource(progress);

            PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer(string.Format("{0}.Add", name));
            performanceInfo.Start();
            performanceInfo.Report("Interpreting style with objects from {0}...", pbfSource.ToString());

            target.Pull();

            performanceInfo.Stop();

            Console.Write("", scene.BackColor);
            stream.Dispose();

            return testFile.OpenRead();
        }
Пример #52
0
        /// <summary>
        /// Tests routing from a serialized routing file.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="stream"></param>
        /// <param name="box"></param>
        /// <param name="testCount"></param>
        public static void TestSerializedRouting(string name, Stream stream,
            GeoCoordinateBox box, int testCount)
        {
            var router = Router.CreateLiveFrom(new OsmSharp.Osm.PBF.Streams.PBFOsmStreamSource(stream),
                new OsmRoutingInterpreter());

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

            int successCount = 0;
            int totalCount = testCount;
            float latestProgress = -1;
            while (testCount > 0)
            {
                var from = box.GenerateRandomIn();
                var to = box.GenerateRandomIn();

                var fromPoint = router.Resolve(Vehicle.Car, from);
                var toPoint = router.Resolve(Vehicle.Car, to);

                if (fromPoint != null && toPoint != null)
                {
                    var route = router.Calculate(Vehicle.Car, fromPoint, toPoint);
                    if (route != null)
                    {
                        successCount++;
                    }
                }

                testCount--;

                // report progress.
                float progress = (float)System.Math.Round(((double)(totalCount - testCount)  / (double)totalCount) * 100);
                if (progress != latestProgress)
                {
                    OsmSharp.Logging.Log.TraceEvent("LiveEdgePreprocessor", 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));
        }
Пример #53
0
        /// <summary>
        /// Tests read from an array.
        /// </summary>
        public static void TestRead(ArrayProfile profile)
        {
            using (var mapStream = new FileInfo(Global.FileName).Open(
                FileMode.Open, FileAccess.ReadWrite))
            {
                using (var map = new MemoryMapStream(mapStream))
                {
                    var array = new Array<int>(map.CreateInt32(mapStream.Length / 4), profile);

                    var perf = new PerformanceInfoConsumer(
                        string.Format("Read Array: {0}", profile.ToString()),
                            1000);
                    perf.Start();
                    for (var i = 0; i < array.Length; i++)
                    {
                        var val = array[i];
                        if (val != i * 2)
                        { // oeps, something went wrong here!
                            throw new System.Exception();
                        }

                        if (Global.Verbose && i % (array.Length / 100) == 0)
                        {
                            perf.Report("Reading... {0}%", i, array.Length - 1);
                        }
                    }
                    perf.Stop();

                    //var size = 1000000;
                    //perf = new PerformanceInfoConsumer(
                    //    string.Format("Read Random Array: {0} {1}", size, profile.ToString()),
                    //        1000);
                    //perf.Start();
                    //var rand = new Random();
                    //for (var i = 0; i < size; i++)
                    //{
                    //    var ran = (long)rand.Next((int)array.Length);
                    //    var val = array[ran];
                    //    if (val != ran * 2)
                    //    { // oeps, something went wrong here!
                    //        throw new System.Exception();
                    //    }

                    //    if (Global.Verbose && i % (size / 100) == 0)
                    //    {
                    //        perf.Report("Reading... {0}%", i, size);
                    //    }
                    //}
                    //perf.Stop();
                }
            }
        }
Пример #54
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));
        }
        /// <summary>
        /// Tests rendering the given serialized scene.
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="box"></param>
        /// <param name="testCount"></param>
        public static void TestRenderScene(Stream stream, GeoCoordinateBox box, int testCount)
        {
            WebMercator projection = new WebMercator();

            // build a map.
            Map map = new Map();
            IScene2DPrimitivesSource sceneSource = Scene2DLayered.Deserialize(stream, true);
            LayerScene layerScene = map.AddLayerScene(sceneSource);

            // build the target to render to.
            Bitmap imageTarget = new Bitmap(TargetWidth, TargetHeight);
            Graphics target = Graphics.FromImage(imageTarget);
            target.SmoothingMode = SmoothingMode.HighQuality;
            target.PixelOffsetMode = PixelOffsetMode.HighQuality;
            target.CompositingQuality = CompositingQuality.HighQuality;
            target.InterpolationMode = InterpolationMode.HighQualityBicubic;
            MapRenderer<Graphics> mapRenderer = new MapRenderer<Graphics>(
                new GraphicsRenderer2D());

            // render the map.
            PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer("Scene2DLayeredRendering");
            performanceInfo.Start();
            performanceInfo.Report("Rendering {0} random images...", testCount);

            while (testCount > 0)
            {
                // randomize view.
                int zoom = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(10) + 10;
                GeoCoordinate center = box.GenerateRandomIn();
                View2D view = mapRenderer.Create(TargetWidth, TargetHeight, map,
                    (float)projection.ToZoomFactor(zoom), center, false, true);

                layerScene.ViewChanged(map, (float)projection.ToZoomFactor(zoom), center, view);

                mapRenderer.Render(target, map, view);

                if (WriteResults)
                {
                    imageTarget.Save(Guid.NewGuid().ToString() + ".png", ImageFormat.Png);
                }

                testCount--;
            }

            performanceInfo.Stop();
        }
Пример #56
0
        /// <summary>
        /// Tests adding simple tags to the given index.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="index"></param>
        /// <param name="collectionCount"></param>
        public static void TestAdd(string name, ITagsCollectionIndex index,
            int collectionCount)
        {
            PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer(string.Format("{0}.Add", name));
            performanceInfo.Start();
            performanceInfo.Report("Adding {0} tag collections...", collectionCount);

            ITagCollectionIndexTests.FillIndex(index, collectionCount);

            performanceInfo.Stop();

            Console.Write("", index.Max);
        }
        /// <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 performanceInfo = new PerformanceInfoConsumer("SerializerFlatFile.Serialize", 2000);
            performanceInfo.Start();
            performanceInfo.Report("Pulling from {0}...", testFile.Name);

            var stream = testFile.OpenRead();
            var source = new PBFOsmStreamSource(stream);
            var progress = new OsmStreamFilterProgress();
            progress.RegisterSource(source);

            var testOutputFile = new FileInfo(@"test.routing");
            testOutputFile.Delete();
            var writeStream = testOutputFile.Open(FileMode.OpenOrCreate, FileAccess.ReadWrite);

            var tagsIndex = new TagsIndex();
            var interpreter = new OsmRoutingInterpreter();
            var graph = new RouterDataSource<Edge>(new Graph<Edge>(), tagsIndex);
            var routingSerializer = new RoutingDataSourceSerializer();

            var memoryMappedGraph = new Graph<Edge>(1024);
            var coordinates = new HugeCoordinateIndex(1024);
            var memoryData = new RouterDataSource<Edge>(memoryMappedGraph, tagsIndex);
            var targetData = new GraphOsmStreamTarget(memoryData, new OsmRoutingInterpreter(), tagsIndex, coordinates);
            targetData.RegisterSource(progress);
            targetData.Pull();

            performanceInfo.Stop();

            memoryData.Compress();

            performanceInfo = new PerformanceInfoConsumer("SerializerFlatFile.Serialize", 100000);
            performanceInfo.Start();
            performanceInfo.Report("Writing file for {0}...", testFile.Name);

            var metaData = new TagsCollection();
            metaData.Add("some_key", "some_value");
            routingSerializer.Serialize(writeStream, memoryData, metaData);
            stream.Dispose();
            writeStream.Dispose();

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

            ////performanceInfo = new PerformanceInfoConsumer("SerializerFlatFile.Serialize", 100000);
            ////performanceInfo.Start();
            ////performanceInfo.Report("Reading file for {0}...", testFile.Name);

            //var testInputFile = new FileInfo(@"test.routing");
            //var readStream = testInputFile.OpenRead();

            //RoutingTest.TestSerialized(readStream);

            ////var deserializedGraph = routingSerializer.Deserialize(readStream, false);

            ////readStream.Dispose();

            ////OsmSharp.Logging.Log.TraceEvent("SerializerFlatFile", OsmSharp.Logging.TraceEventType.Information,
            ////    string.Format("Read: {0}KB", testInputFile.Length / 1024));

            ////OsmSharp.Logging.Log.TraceEvent("SerializerFlatFile", Logging.TraceEventType.Information, deserializedGraph.ToInvariantString());

            ////performanceInfo.Stop();
        }
Пример #58
0
        /// <summary>
        /// Tests random access to an already filled index.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="index"></param>
        /// <param name="testCount"></param>
        public static void TestRandomAccess(string name, ITagsCollectionIndexReadonly index,
            int testCount)
        {
            PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer(string.Format("{0}.Access", name));
            performanceInfo.Start();
            performanceInfo.Report("Random accessing tags index {0} times...", testCount);

            for (int idx = 0; idx < testCount; idx++)
            {
                uint collectionIndex = (uint)OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(index.Max);
                TagsCollectionBase collection = index.Get(collectionIndex);
            }

            performanceInfo.Stop();
        }
Пример #59
0
        /// <summary>
        /// Tests routing between two points and the associated instructions.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="stream"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        public static void TestSerializeRoutingInstrictions(string name, Stream stream,
            GeoCoordinate from, GeoCoordinate to)
        {
            PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer("CHSerializedRouting");
            performanceInfo.Start();
            performanceInfo.Report("Routing & generating instructions...");

            TagsCollectionBase metaData = null;
            var routingSerializer = new CHEdgeDataDataSourceSerializer(true);
            var graphDeserialized = routingSerializer.Deserialize(
                stream, out metaData, true);

            var interpreter = new OsmRoutingInterpreter();
            var router = Router.CreateCHFrom(
                graphDeserialized, new CHRouter(),
                interpreter);

            RouterPoint fromPoint = router.Resolve(Vehicle.Car, from);
            RouterPoint toPoint = router.Resolve(Vehicle.Car, to);

            List<Instruction> instructions = new List<Instruction>();
            if (fromPoint != null && toPoint != null)
            {
                Route route = router.Calculate(Vehicle.Car, fromPoint, toPoint);
                if (route != null)
                {
                    instructions = InstructionGenerator.Generate(route, interpreter);
                }
            }

            performanceInfo.Stop();

            if (instructions.Count == 0)
            {
                OsmSharp.Logging.Log.TraceEvent("CHSerializedRouting", OsmSharp.Logging.TraceEventType.Information,
                    "Routing unsuccesfull!");
            }
            else
            {
                foreach (Instruction instruction in instructions)
                {
                    OsmSharp.Logging.Log.TraceEvent("CHSerializedRouting", OsmSharp.Logging.TraceEventType.Information,
                        instruction.Text);
                }
            }
        }
        /// <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 performanceInfo = new PerformanceInfoConsumer("LiveSerializerFlatFile.Serialize", 100000);
            performanceInfo.Start();
            performanceInfo.Report("Pulling from {0}...", testFile.Name);

            var stream = testFile.OpenRead();
            var source = new PBFOsmStreamSource(stream);
            var progress = new OsmStreamFilterProgress();
            progress.RegisterSource(source);

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

            var tagsIndex = new TagsTableCollectionIndex();
            var interpreter = new OsmRoutingInterpreter();
            var graph = new DynamicGraphRouterDataSource<LiveEdge>(tagsIndex);
            var routingSerializer = new LiveEdgeFlatfileSerializer();

            // read from the OSM-stream.
            using (var fileFactory = new MemoryMappedFileFactory(@"d:\temp\"))
            {
                using (var memoryMappedGraph = new MemoryMappedGraph<LiveEdge>(10000, fileFactory))
                {
                    using (var coordinates = new HugeCoordinateIndex(fileFactory, 10000))
                    {
                        var memoryData = new DynamicGraphRouterDataSource<LiveEdge>(memoryMappedGraph, tagsIndex);
                        var targetData = new LiveGraphOsmStreamTarget(memoryData, new OsmRoutingInterpreter(), tagsIndex, coordinates);
                        targetData.RegisterSource(progress);
                        targetData.Pull();

                        performanceInfo.Stop();

                        performanceInfo = new PerformanceInfoConsumer("LiveSerializerFlatFile.Serialize", 100000);
                        performanceInfo.Start();
                        performanceInfo.Report("Writing file for {0}...", testFile.Name);

                        var metaData = new TagsCollection();
                        metaData.Add("some_key", "some_value");
                        routingSerializer.Serialize(writeStream, memoryData, metaData);
                    }
                }
            }
            stream.Dispose();
            writeStream.Dispose();

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

            performanceInfo = new PerformanceInfoConsumer("LiveSerializerFlatFile.Serialize", 100000);
            performanceInfo.Start();
            performanceInfo.Report("Reading file for {0}...", testFile.Name);

            var testInputFile = new FileInfo(@"europe-latest.osm.pbf.routing");
            Stream readStream = testInputFile.OpenRead();

            var deserializedGraph = routingSerializer.Deserialize(readStream, false);

            readStream.Dispose();

            OsmSharp.Logging.Log.TraceEvent("LiveSerializerFlatFile", OsmSharp.Logging.TraceEventType.Information,
                string.Format("Read: {0}KB", testInputFile.Length / 1024));

            OsmSharp.Logging.Log.TraceEvent("LiveSerializerFlatFile", Logging.TraceEventType.Information, deserializedGraph.ToInvariantString());

            performanceInfo.Stop();
        }