예제 #1
0
        public void TestBuildPath()
        {
            // build graph.
            var graph  = new DirectedDynamicGraph(5, 1);
            var edge01 = graph.AddEdge(0, 1, 100, null);
            //graph.AddEdge(1, 0, 101, null);
            //graph.AddEdge(1, 2, 102, null);
            var edge21 = graph.AddEdge(2, 1, 103, null);
            //graph.AddEdge(1, 3, 104, null);
            var edge31 = graph.AddEdge(3, 1, 105, null);
            //graph.AddEdge(1, 4, 106, null);
            var edge41 = graph.AddEdge(4, 1, 107, null);
            var edge23 = graph.AddEdge(2, 3, 108, null);
            //graph.AddEdge(3, 2, 109, null);

            var path = graph.BuildPath(new uint[] { 1 });

            Assert.IsNotNull(path);
            Assert.AreEqual(1, path.Vertex);
            Assert.IsNull(path.From);
            Assert.AreEqual(0, path.Weight);

            path = graph.BuildPath(new uint[] { 1, 2 });
            Assert.IsNotNull(path);
            Assert.AreEqual(2, path.Vertex);
            Assert.IsNotNull(path.From);
            Assert.AreEqual(103, path.Weight);
            Assert.AreEqual(-graph.GetOriginal(2, 1).IdDirected(), path.Edge);
            path = path.From;
            Assert.IsNotNull(path);
            Assert.AreEqual(1, path.Vertex);
            Assert.IsNull(path.From);
            Assert.AreEqual(0, path.Weight);

            path = graph.BuildPath(new uint[] { 2, 1 }, true);
            Assert.IsNotNull(path);
            Assert.AreEqual(2, path.Vertex);
            Assert.IsNotNull(path.From);
            Assert.AreEqual(103, path.Weight);
            Assert.AreEqual(-graph.GetOriginal(2, 1).IdDirected(), path.Edge);
            path = path.From;
            Assert.IsNotNull(path);
            Assert.AreEqual(1, path.Vertex);
            Assert.IsNull(path.From);
            Assert.AreEqual(0, path.Weight);

            path = graph.BuildPath(new uint[] { 2, 1 });
            Assert.IsNotNull(path);
            Assert.AreEqual(1, path.Vertex);
            Assert.IsNotNull(path.From);
            Assert.AreEqual(103, path.Weight);
            Assert.AreEqual(graph.GetOriginal(2, 1).IdDirected(), path.Edge);
            path = path.From;
            Assert.IsNotNull(path);
            Assert.AreEqual(2, path.Vertex);
            Assert.IsNull(path.From);
            Assert.AreEqual(0, path.Weight);

            path = graph.BuildPath(new uint[] { 1, 2 }, true);
            Assert.IsNotNull(path);
            Assert.AreEqual(1, path.Vertex);
            Assert.IsNotNull(path.From);
            Assert.AreEqual(103, path.Weight);
            Assert.AreEqual(graph.GetOriginal(2, 1).IdDirected(), path.Edge);
            path = path.From;
            Assert.IsNotNull(path);
            Assert.AreEqual(2, path.Vertex);
            Assert.IsNull(path.From);
            Assert.AreEqual(0, path.Weight);

            path = graph.BuildPath(new uint[] { 1, 2 }, true, true);
            Assert.IsNotNull(path);
            Assert.AreEqual(1, path.Vertex);
            Assert.IsNotNull(path.From);
            Assert.AreEqual(103, path.Weight);
            Assert.AreEqual(graph.GetOriginal(2, 1).IdDirected(), path.Edge);
            path = path.From;
            Assert.IsNotNull(path);
            Assert.AreEqual(2, path.Vertex);
            Assert.IsNull(path.From);
            Assert.AreEqual(0, path.Weight);
        }