コード例 #1
0
        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);
            }
        }
コード例 #2
0
        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);
                });
            }
        }
コード例 #3
0
        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);
            }
        }