コード例 #1
0
        public void UndirectedSparseGraph()
        {
            var testCase = new TestCase();

            testCase
            .AddVertex("n1")
            .AddVertex("n2")
            .AddVertex("n3")
            .AddVertex("n4")
            .AddVertex("n5")
            .AddVertex("n6");

            testCase
            .AddUndirectedEdge("n1", "n2", 10)
            .AddUndirectedEdge("n2", "n3", 8)
            .AddUndirectedEdge("n3", "n4", 11)
            .AddUndirectedEdge("n4", "n5", 6)
            .AddUndirectedEdge("n5", "n6", 9)
            .AddUndirectedEdge("n1", "n6", 3)
            .AddUndirectedEdge("n2", "n6", 5)
            .AddUndirectedEdge("n3", "n6", 18)
            .AddUndirectedEdge("n3", "n5", 21);

            var tsp = new TSP <string, EquatableEdge <string>, BidirectionalGraph <string, EquatableEdge <string> > >(
                testCase.Graph, testCase.GetWeightsFunc());

            tsp.Compute();

            Assert.AreEqual(47, tsp.BestCost);
            Assert.IsNotNull(tsp.ResultPath);
            Assert.IsFalse(tsp.ResultPath.IsDirectedAcyclicGraph());
        }
コード例 #2
0
ファイル: TSPTests.cs プロジェクト: OwenMcDonnell/QuikGraph
        public void UndirectedFullGraph()
        {
            var testCase = new TestCase();

            testCase.AddVertex("n1")
            .AddVertex("n2")
            .AddVertex("n3")
            .AddVertex("n4")
            .AddVertex("n5");

            testCase.AddUndirectedEdge("n1", "n2", 16)
            .AddUndirectedEdge("n1", "n3", 9)
            .AddUndirectedEdge("n1", "n4", 15)
            .AddUndirectedEdge("n1", "n5", 3)
            .AddUndirectedEdge("n2", "n3", 14)
            .AddUndirectedEdge("n2", "n4", 4)
            .AddUndirectedEdge("n2", "n5", 5)
            .AddUndirectedEdge("n3", "n4", 4)
            .AddUndirectedEdge("n3", "n5", 2)
            .AddUndirectedEdge("n4", "n5", 1);

            var tsp = new TSP <string, EquatableEdge <string>, BidirectionalGraph <string, EquatableEdge <string> > >(
                testCase.Graph, testCase.GetFuncWeights());

            tsp.Compute();

            Assert.AreEqual(tsp.BestCost, 25);
            Assert.IsFalse(tsp.ResultPath.IsDirectedAcyclicGraph());
        }