Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public void DirectedSparseGraph()
        {
            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)
            .AddDirectedEdge("n6", "n1", 1);

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

            tcp.Compute();

            Assert.AreEqual(tcp.BestCost, 45);
            Assert.IsFalse(tcp.ResultPath.IsDirectedAcyclicGraph());
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        public void DirectedSparseGraph()
        {
            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)
                .AddDirectedEdge("n6", "n1", 1);

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

            Assert.AreEqual(tcp.BestCost, 45);
            Assert.IsFalse(tcp.ResultPath.IsDirectedAcyclicGraph());
        }
Exemplo n.º 6
0
 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;
 }