コード例 #1
0
ファイル: TSPTest.cs プロジェクト: auduchinok/QuickGraph
        public void UndirectedSparseGraph()
        {
            TestCase 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 tcp = new TSP<String, EquatableEdge<String>, BidirectionalGraph<String, EquatableEdge<String>>>(testCase.Graph, testCase.GetFuncWeights());
            tcp.Compute();

            Assert.AreEqual(tcp.BestCost, 47);
            Assert.IsFalse(tcp.ResultPath.IsDirectedAcyclicGraph());
        }
コード例 #2
0
ファイル: TSPTest.cs プロジェクト: auduchinok/QuickGraph
        public void DirectedSparseGraphWithoutPath()
        {
            TestCase testCase = new TestCase();
            testCase.AddVertex("n1")
                .AddVertex("n2")
                .AddVertex("n3")
                .AddVertex("n4")
                .AddVertex("n5")
                .AddVertex("n6");

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

            var tcp = new TSP<String, EquatableEdge<String>, BidirectionalGraph<String, EquatableEdge<String>>>(testCase.Graph, testCase.GetFuncWeights());
            tcp.Compute();

            Assert.AreEqual(tcp.BestCost, Double.PositiveInfinity);
            Assert.IsTrue(tcp.ResultPath == null);
        }
コード例 #3
0
ファイル: TSPTest.cs プロジェクト: auduchinok/QuickGraph
 public static TestCase completeGraphTestCase(int vertices, int maxWeight)
 {
     var random = new Random();
     TestCase testCase = new TestCase();
     for (int i = 0; i < vertices; ++i)
     {
         testCase.AddVertex("n" + i);
     }
     foreach (var v1 in testCase.Graph.Vertices)
     {
         foreach (var v2 in testCase.Graph.Vertices)
         {
             testCase.AddDirectedEdge(v1, v2, random.Next(maxWeight));
         }
     }
     return testCase;
 }