public void TestLiveEdgeDynamicGraphEdge10000()
        {
            using (var graph = new MemoryMappedFileDynamicGraph <LiveEdge>(1000, 1024))
            {
                int  count   = 10000;
                uint vertex1 = graph.AddVertex(51, 1);
                while (count > 0)
                {
                    uint vertex2 = graph.AddVertex(51, 1);

                    graph.AddEdge(vertex1, vertex2, new LiveEdge()
                    {
                        Tags    = 0,
                        Forward = true
                    }, null);

                    var arcs = graph.GetEdges(vertex1);
                    Assert.AreEqual(10000 - count + 1, arcs.Length);

                    arcs = graph.GetEdges(vertex2);
                    Assert.AreEqual(1, arcs.Length);
                    Assert.AreEqual(0, arcs[0].Value.Tags);
                    Assert.AreEqual(vertex1, arcs[0].Key);

                    count--;
                }
            }
        }
        public void TestLiveEdgeDynamicGraphAddRemove1()
        {
            using (var graph = new MemoryMappedFileDynamicGraph <LiveEdge>(1000, 1024))
            {
                uint tagsId  = 10;
                var  vertex1 = graph.AddVertex(51, 1);
                var  vertex2 = graph.AddVertex(51, 2);

                graph.AddEdge(vertex1, vertex2, new LiveEdge()
                {
                    Forward = true,
                    Tags    = tagsId
                }, null);

                // test forward edge.
                var arcs = graph.GetEdges(vertex1);
                Assert.AreEqual(1, arcs.Length);
                Assert.AreEqual(tagsId, arcs[0].Value.Tags);
                Assert.AreEqual(vertex2, arcs[0].Key);
                Assert.AreEqual(true, arcs[0].Value.Forward);

                // remove edge again.
                graph.RemoveEdge(vertex1, vertex2);

                // check if the edge is gone.
                arcs = graph.GetEdges(vertex1);
                Assert.AreEqual(0, arcs.Length);
            }
        }
        public void TestLiveEdgeDynamicGraphEdge()
        {
            using (var graph = new MemoryMappedFileDynamicGraph <LiveEdge>(1000, 1024))
            {
                var vertex1 = graph.AddVertex(51, 1);
                var vertex2 = graph.AddVertex(51, 2);

                graph.AddEdge(vertex1, vertex2, new LiveEdge()
                {
                    Forward = true,
                    Tags    = 0
                }, null);

                var arcs = graph.GetEdges(vertex1);
                Assert.AreEqual(1, arcs.Length);
                Assert.AreEqual(0, arcs[0].Value.Tags);
                Assert.AreEqual(vertex2, arcs[0].Key);

                arcs = graph.GetEdges(vertex2);
                Assert.AreEqual(1, arcs.Length);
                Assert.AreEqual(0, arcs[0].Value.Tags);
                Assert.AreEqual(vertex1, arcs[0].Key);

                LiveEdge edge;
                Assert.IsTrue(graph.GetEdge(vertex1, vertex2, out edge));
                Assert.AreEqual(0, edge.Tags);
                Assert.AreEqual(true, edge.Forward);
                Assert.IsTrue(graph.GetEdge(vertex2, vertex1, out edge));
                Assert.AreEqual(0, edge.Tags);
                Assert.AreEqual(false, edge.Forward);
            }
        }
Esempio n. 4
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 MemoryMappedFileDynamicGraph <LiveEdge>(1000000, @"c:\temp\");
            var memoryData  = new DynamicGraphRouterDataSource <LiveEdge>(memoryGraph, 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();
        }
        public void TestLiveEdgeDynamicGraphEdge1()
        {
            using (var graph = new MemoryMappedFileDynamicGraph <LiveEdge>(1000, 1024))
            {
                uint tagsId  = 10;
                var  vertex1 = graph.AddVertex(51, 1);
                var  vertex2 = graph.AddVertex(51, 2);

                graph.AddEdge(vertex1, vertex2, new LiveEdge()
                {
                    Forward = true,
                    Tags    = tagsId
                }, null);

                // test forward edge.
                var arcs = graph.GetEdges(vertex1);
                Assert.AreEqual(1, arcs.Length);
                Assert.AreEqual(tagsId, arcs[0].Value.Tags);
                Assert.AreEqual(vertex2, arcs[0].Key);
                Assert.AreEqual(true, arcs[0].Value.Forward);

                // test backward edge: backward edge is added automatically.
                arcs = graph.GetEdges(vertex2);
                Assert.AreEqual(1, arcs.Length);
                Assert.AreEqual(tagsId, arcs[0].Value.Tags);
                Assert.AreEqual(vertex1, arcs[0].Key);
                Assert.AreEqual(false, arcs[0].Value.Forward);

                // add a third vertex.
                var vertex3 = graph.AddVertex(51, 2);
                var edge    = new LiveEdge()
                {
                    Forward = true,
                    Tags    = tagsId
                };
                graph.AddEdge(vertex1, vertex3, edge, null);

                // test forward edges.
                arcs = graph.GetEdges(vertex1);
                Assert.AreEqual(2, arcs.Length);
                Assert.AreEqual(tagsId, arcs[0].Value.Tags);
                Assert.AreEqual(vertex2, arcs[0].Key);
                Assert.AreEqual(true, arcs[0].Value.Forward);
                Assert.AreEqual(tagsId, arcs[1].Value.Tags);
                Assert.AreEqual(vertex3, arcs[1].Key);
                Assert.AreEqual(true, arcs[1].Value.Forward);

                // test backward edge: backward edge is added automatically.
                arcs = graph.GetEdges(vertex3);
                Assert.AreEqual(1, arcs.Length);
                Assert.AreEqual(tagsId, arcs[0].Value.Tags);
                Assert.AreEqual(vertex1, arcs[0].Key);
                Assert.AreEqual(false, arcs[0].Value.Forward);
            }
        }
        public void TestLiveEdgeDynamicGraphAddRemove2()
        {
            using (var graph = new MemoryMappedFileDynamicGraph <LiveEdge>(1000, 1024))
            {
                uint tagsId  = 10;
                var  vertex1 = graph.AddVertex(51, 1);
                var  vertex2 = graph.AddVertex(51, 2);
                var  vertex3 = graph.AddVertex(51, 3);

                graph.AddEdge(vertex1, vertex2, new LiveEdge()
                {
                    Forward = true,
                    Tags    = tagsId
                }, null);

                graph.AddEdge(vertex2, vertex3, new LiveEdge()
                {
                    Forward = true,
                    Tags    = tagsId
                }, null);

                // test edges.
                var edges = graph.GetEdges(vertex1);
                Assert.AreEqual(1, edges.Length);
                Assert.AreEqual(tagsId, edges[0].Value.Tags);
                Assert.AreEqual(vertex2, edges[0].Key);
                Assert.AreEqual(true, edges[0].Value.Forward);
                edges = graph.GetEdges(vertex2);
                Assert.AreEqual(2, edges.Length);
                edges = graph.GetEdges(vertex3);
                Assert.AreEqual(1, edges.Length);
                Assert.AreEqual(tagsId, edges[0].Value.Tags);
                Assert.AreEqual(vertex2, edges[0].Key);
                Assert.AreEqual(false, edges[0].Value.Forward);

                // remove edge again.
                graph.RemoveEdge(vertex1, vertex2);

                // test edges.
                edges = graph.GetEdges(vertex1);
                Assert.AreEqual(0, edges.Length);
                edges = graph.GetEdges(vertex2);
                Assert.AreEqual(1, edges.Length);
                Assert.AreEqual(tagsId, edges[0].Value.Tags);
                Assert.AreEqual(vertex3, edges[0].Key);
                Assert.AreEqual(true, edges[0].Value.Forward);
                edges = graph.GetEdges(vertex3);
                Assert.AreEqual(1, edges.Length);
                Assert.AreEqual(tagsId, edges[0].Value.Tags);
                Assert.AreEqual(vertex2, edges[0].Key);
                Assert.AreEqual(false, edges[0].Value.Forward);
            }
        }
        public void TestLiveEdgeDynamicGraphArguments()
        {
            using (var graph = new MemoryMappedFileDynamicGraph <LiveEdge>(1000, 1024))
            {
                uint vertex1 = graph.AddVertex(0, 0);
                uint vertex2 = graph.AddVertex(0, 0);
                uint vertex3 = 3;

                Assert.Catch <ArgumentOutOfRangeException>(() =>
                {
                    graph.AddEdge(vertex3, vertex1, new LiveEdge(), null);
                });
                Assert.Catch <ArgumentOutOfRangeException>(() =>
                {
                    graph.AddEdge(vertex1, vertex3, new LiveEdge(), null);
                });
                Assert.Catch <ArgumentException>(() =>
                {
                    graph.AddEdge(vertex1, vertex1, new LiveEdge(), null);
                });
                Assert.Catch <ArgumentException>(() =>
                {
                    graph.AddEdge(vertex1, vertex1, new LiveEdge(), null);
                });
                Assert.Catch <ArgumentOutOfRangeException>(() =>
                {
                    graph.ContainsEdge(vertex3, vertex1);
                });
                Assert.Catch <ArgumentOutOfRangeException>(() =>
                {
                    graph.ContainsEdge(vertex1, vertex3);
                });
                LiveEdge edge;
                Assert.Catch <ArgumentOutOfRangeException>(() =>
                {
                    graph.GetEdge(vertex3, vertex1, out edge);
                });
                Assert.Catch <ArgumentOutOfRangeException>(() =>
                {
                    graph.GetEdge(vertex1, vertex3, out edge);
                });
                Assert.Catch <ArgumentOutOfRangeException>(() =>
                {
                    graph.GetEdges(vertex3);
                });
                Assert.Catch <ArgumentOutOfRangeException>(() =>
                {
                    graph.SetVertex(vertex3, 10, 10);
                });
            }
        }
        public void TestLiveEdgeDynamicGraphCompressVertices()
        {
            using (var graph = new MemoryMappedFileDynamicGraph <LiveEdge>(1000, 1024))
            {
                var vertex1 = graph.AddVertex(51, 1);
                var vertex2 = graph.AddVertex(51, 2);
                var vertex3 = graph.AddVertex(51, 3);
                var vertex4 = graph.AddVertex(51, 3);

                graph.AddEdge(vertex1, vertex2, new LiveEdge()
                {
                    Forward = true,
                    Tags    = 1
                }, null);
                graph.AddEdge(vertex2, vertex3, new LiveEdge()
                {
                    Forward = true,
                    Tags    = 2
                }, null);
                graph.AddEdge(vertex3, vertex4, new LiveEdge()
                {
                    Forward = true,
                    Tags    = 3
                }, null);

                graph.AddEdge(vertex4, vertex2, new LiveEdge()
                {
                    Forward = true,
                    Tags    = 4
                }, null);

                // make vertex4 obsolete.
                graph.RemoveEdges(vertex4);

                graph.Compress();

                Assert.AreEqual(3, graph.VertexCount);

                Assert.AreEqual(graph.GetEdges(vertex1).Length, 1);
                Assert.AreEqual(graph.GetEdges(vertex2).Length, 2);
                Assert.AreEqual(graph.GetEdges(vertex3).Length, 1);
            }
        }
        public void TestLiveEdgeDynamicGraphAddReverse()
        {
            using (var graph = new MemoryMappedFileDynamicGraph <LiveEdge>(1000, 1024))
            {
                var vertex1 = graph.AddVertex(51, 1);
                var vertex2 = graph.AddVertex(51, 2);

                graph.AddEdge(vertex1, vertex2, new LiveEdge()
                {
                    Forward = true,
                    Tags    = 1
                }, null);

                graph.AddEdge(vertex2, vertex1, new LiveEdge()
                {
                    Forward = true,
                    Tags    = 2
                }, null);
            }
        }
        public void TestLiveEdgeDynamicGraphRemoveAll()
        {
            using (var graph = new MemoryMappedFileDynamicGraph <LiveEdge>(1000, 1024))
            {
                var vertex1 = graph.AddVertex(51, 1);
                var vertex2 = graph.AddVertex(51, 2);
                var vertex3 = graph.AddVertex(51, 3);
                var vertex4 = graph.AddVertex(51, 3);

                graph.AddEdge(vertex1, vertex2, new LiveEdge()
                {
                    Forward = true,
                    Tags    = 1
                });
                graph.AddEdge(vertex2, vertex3, new LiveEdge()
                {
                    Forward = true,
                    Tags    = 2
                });
                graph.AddEdge(vertex3, vertex4, new LiveEdge()
                {
                    Forward = true,
                    Tags    = 3
                });

                graph.AddEdge(vertex4, vertex2, new LiveEdge()
                {
                    Forward = true,
                    Tags    = 4
                });

                graph.RemoveEdge(vertex2, vertex1);
                graph.RemoveEdge(vertex2, vertex3);
                graph.RemoveEdge(vertex4, vertex3);
                graph.RemoveEdge(vertex4, vertex2);
                Assert.IsFalse(graph.ContainsEdge(vertex2, vertex1));
                Assert.IsFalse(graph.ContainsEdge(vertex2, vertex3));
                Assert.IsFalse(graph.ContainsEdge(vertex4, vertex3));
                Assert.IsFalse(graph.ContainsEdge(vertex4, vertex2));
            }
        }
        public void TestLiveEdgeDynamicGraphRemoveBegin()
        {
            using (var graph = new MemoryMappedFileDynamicGraph <LiveEdge>(1000, 1024))
            {
                var vertex1 = graph.AddVertex(51, 1);
                var vertex2 = graph.AddVertex(51, 2);
                var vertex3 = graph.AddVertex(51, 3);
                var vertex4 = graph.AddVertex(51, 3);

                graph.AddEdge(vertex1, vertex2, new LiveEdge()
                {
                    Forward = true,
                    Tags    = 1
                }, null);
                graph.AddEdge(vertex2, vertex3, new LiveEdge()
                {
                    Forward = true,
                    Tags    = 2
                }, null);
                graph.AddEdge(vertex3, vertex4, new LiveEdge()
                {
                    Forward = true,
                    Tags    = 3
                }, null);

                graph.AddEdge(vertex4, vertex2, new LiveEdge()
                {
                    Forward = true,
                    Tags    = 4
                }, null);

                graph.RemoveEdge(vertex2, vertex1);
                Assert.IsFalse(graph.ContainsEdge(vertex2, vertex1));
                Assert.IsFalse(graph.ContainsEdge(vertex1, vertex2));

                Assert.AreEqual(graph.GetEdges(vertex1).Length, 0);
                Assert.AreEqual(graph.GetEdges(vertex2).Length, 2);
                Assert.AreEqual(graph.GetEdges(vertex3).Length, 2);
                Assert.AreEqual(graph.GetEdges(vertex4).Length, 2);
            }
        }
        public void TestLiveEdgeDynamicGraphVertex()
        {
            using (var graph = new MemoryMappedFileDynamicGraph <LiveEdge>(1000, 1024))
            {
                var vertex = graph.AddVertex(51, 4);

                float latitude, longitude;
                graph.GetVertex(vertex, out latitude, out longitude);
                Assert.AreEqual(51, latitude);
                Assert.AreEqual(4, longitude);
                graph.SetVertex(vertex, 52, 5);
                graph.GetVertex(vertex, out latitude, out longitude);
                Assert.AreEqual(52, latitude);
                Assert.AreEqual(5, longitude);

                var arcs = graph.GetEdges(vertex);
                Assert.AreEqual(0, arcs.Length);

                Assert.IsFalse(graph.GetVertex(100, out latitude, out longitude));
            }
        }
        public void TestLiveEdgeDynamicGraphVertex10000()
        {
            using (var graph = new MemoryMappedFileDynamicGraph <LiveEdge>(1000, 1024))
            {
                int count = 10000;
                while (count > 0)
                {
                    var vertex = graph.AddVertex(51, 4);

                    float latitude, longitude;
                    graph.GetVertex(vertex, out latitude, out longitude);

                    Assert.AreEqual(51, latitude);
                    Assert.AreEqual(4, longitude);

                    var arcs = graph.GetEdges(vertex);
                    Assert.AreEqual(0, arcs.Length);

                    count--;
                }

                Assert.AreEqual((uint)10000, graph.VertexCount);
            }
        }
        public void TestLiveEdgeDynamicGraphCompressEdges()
        {
            using (var graph = new MemoryMappedFileDynamicGraph <LiveEdge>(1000, 1024))
            {
                var vertex1 = graph.AddVertex(51, 1);
                var vertex2 = graph.AddVertex(51, 2);
                var vertex3 = graph.AddVertex(51, 3);
                var vertex4 = graph.AddVertex(51, 3);

                graph.AddEdge(vertex1, vertex2, new LiveEdge()
                {
                    Forward = true,
                    Tags    = 1
                }, null);
                graph.AddEdge(vertex2, vertex3, new LiveEdge()
                {
                    Forward = true,
                    Tags    = 2
                }, null);
                graph.AddEdge(vertex3, vertex4, new LiveEdge()
                {
                    Forward = true,
                    Tags    = 3
                }, null);

                graph.AddEdge(vertex4, vertex2, new LiveEdge()
                {
                    Forward = true,
                    Tags    = 4
                }, null);

                graph.RemoveEdge(vertex2, vertex3);

                graph.Compress();

                Assert.IsFalse(graph.ContainsEdge(vertex2, vertex3));
                Assert.IsFalse(graph.ContainsEdge(vertex3, vertex2));

                Assert.AreEqual(graph.GetEdges(vertex1).Length, 1);
                Assert.AreEqual(graph.GetEdges(vertex2).Length, 2);
                Assert.AreEqual(graph.GetEdges(vertex3).Length, 1);
                Assert.AreEqual(graph.GetEdges(vertex4).Length, 2);
            }

            using (var graph = new MemoryMappedFileDynamicGraph <LiveEdge>(1000, 1024))
            {
                uint vertex1 = graph.AddVertex(51, 1);
                uint vertex2 = graph.AddVertex(51, 2);
                uint vertex3 = graph.AddVertex(51, 3);
                uint vertex4 = graph.AddVertex(51, 3);

                graph.AddEdge(vertex1, vertex2, new LiveEdge()
                {
                    Forward = true,
                    Tags    = 1
                }, null);
                graph.AddEdge(vertex2, vertex3, new LiveEdge()
                {
                    Forward = true,
                    Tags    = 2
                }, null);
                graph.AddEdge(vertex3, vertex4, new LiveEdge()
                {
                    Forward = true,
                    Tags    = 3
                }, null);

                graph.AddEdge(vertex4, vertex2, new LiveEdge()
                {
                    Forward = true,
                    Tags    = 4
                }, null);

                graph.RemoveEdge(vertex3, vertex4);

                graph.Compress();

                Assert.IsFalse(graph.ContainsEdge(vertex3, vertex4));
                Assert.IsFalse(graph.ContainsEdge(vertex4, vertex3));

                Assert.AreEqual(graph.GetEdges(vertex1).Length, 1);
                Assert.AreEqual(graph.GetEdges(vertex2).Length, 3);
                Assert.AreEqual(graph.GetEdges(vertex3).Length, 1);
                Assert.AreEqual(graph.GetEdges(vertex4).Length, 1);

                LiveEdge edge;
                Assert.IsTrue(graph.GetEdge(vertex1, vertex2, out edge));
                Assert.AreEqual(1, edge.Tags);
                Assert.IsTrue(graph.GetEdge(vertex2, vertex3, out edge));
                Assert.AreEqual(2, edge.Tags);
                Assert.IsTrue(graph.GetEdge(vertex4, vertex2, out edge));
                Assert.AreEqual(4, edge.Tags);
            }
        }