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()); }
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); }
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()); }
//[TestMethod] public void performanceTest() { for (int i = 0; i < 6; ++i) { int repeat = 10; long avg = 0; for (int j = 0; j < repeat; ++j) { TestCase testCase = TestCase.completeGraphTestCase((i + 1) * 5, 100000000); var tcp = new TSP <String, EquatableEdge <String>, BidirectionalGraph <String, EquatableEdge <String> > >(testCase.Graph, testCase.GetFuncWeights()); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); tcp.Compute(); stopWatch.Stop(); avg += stopWatch.ElapsedMilliseconds; } Trace.WriteLine((i + 1) * 5 + " vertices complete, avg time: " + avg / repeat); } }
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); }