static void Main(string[] args) { AlignmentFinder af1 = new AlignmentFinder(); AlignmentFinder af2 = new AlignmentFinder(ScoringMatrix.PAM250, -5); TestSet unweightedTests = new TestSet(); unweightedTests.TestCases.Add(new AlignmentTestCase(1, "AGT", "AGT", af1, 0)); unweightedTests.TestCases.Add(new AlignmentTestCase(1, "CCCP", "AAAACCCPAAAAAAAAAA", af1, -14)); unweightedTests.TestCases.Add(new AlignmentTestCase(1, "AAACAC", "CACA", af1, -3)); unweightedTests.TestCases.Add(new AlignmentTestCase(1, "AGGCTACTTTCA", "GGCTACTATATCA", af1, -3)); unweightedTests.TestCases.Add(new AlignmentTestCase(1, "CCGCCT", "AGTGGGGTAAGA", af1, -10)); unweightedTests.TestCases.Add(new AlignmentTestCase(1, "AAAAAAAAAAAAAAAAAAAA", "AAGAAGAAGAAGAGAA", af1, -9)); unweightedTests.TestCases.Add(new AlignmentTestCase(1, "AAAAWWW", "WWWAAAA", af1, -6)); unweightedTests.TestCases.Add(new AlignmentTestCase(1, "WWSRWWW", "EWWW", af1, -4)); unweightedTests.TestCases.Add(new AlignmentTestCase(2, PheA, Dhv, af1, -397)); unweightedTests.TestCases.Add(new AlignmentTestCase(3, Yp0, Yp5, af1, -1137)); TestSet weightedTests = new TestSet(); weightedTests.TestCases.Add(new AlignmentTestCase(1, "AGT", "AGT", af2, 10)); weightedTests.TestCases.Add(new AlignmentTestCase(1, "CCCP", "AAAACCCPAAAAAAAAAA", af2, -28)); weightedTests.TestCases.Add(new AlignmentTestCase(1, "AAACAC", "CACA", af2, 6)); weightedTests.TestCases.Add(new AlignmentTestCase(1, "AGGCTACTTTCA", "GGCTACTATATCA", af2, 47)); weightedTests.TestCases.Add(new AlignmentTestCase(1, "CCGCCT", "AGTGGGGTAAGA", af2, -32)); weightedTests.TestCases.Add(new AlignmentTestCase(1, "AAAAAAAAAAAAAAAAAAAA", "AAGAAGAAGAAGAGAA", af2, 7)); weightedTests.TestCases.Add(new AlignmentTestCase(1, "AAAAWWW", "WWWAAAA", af2, 11)); weightedTests.TestCases.Add(new AlignmentTestCase(1, "WWSRWWW", "EWWW", af2, 36)); weightedTests.TestCases.Add(new AlignmentTestCase(2, PheA, Dhv, af2, 464)); weightedTests.TestCases.Add(new AlignmentTestCase(5, Yp0, Yp5, af2, 1062)); TestSet subsequenceTests = new TestSet(); subsequenceTests.TestCases.Add(new AlignmentTestCase(1, "AGT", "AGT", af2, 10, true)); subsequenceTests.TestCases.Add(new AlignmentTestCase(1, "CCCP", "AAAACCCPAAAAAAAAAA", af2, 42, true)); subsequenceTests.TestCases.Add(new AlignmentTestCase(1, "AAACAC", "CACA", af2, 26, true)); subsequenceTests.TestCases.Add(new AlignmentTestCase(1, "AGGCTACTTTCA", "CTAACT", af2, 30, true)); subsequenceTests.TestCases.Add(new AlignmentTestCase(1, "AGGCTACTTTCA", "CTCT", af2, 25, true)); subsequenceTests.TestCases.Add(new AlignmentTestCase(1, "AGGCTCTTTCA", "CTACT", af2, 25, true)); subsequenceTests.TestCases.Add(new AlignmentTestCase(1, "AAAAWWW", "WWWAAAA", af2, 51, true)); subsequenceTests.TestCases.Add(new AlignmentTestCase(1, "WSRWW", "EWWW", af2, 41, true)); subsequenceTests.TestCases.Add(new AlignmentTestCase(2, PheA, Dhv, af2, 658, true)); subsequenceTests.TestCases.Add(new AlignmentTestCase(5, Yp0, Yp5, af2, 1344, true)); Console.WriteLine("Część 1: bez wag dopasowań"); unweightedTests.PreformTests(true, false); Console.WriteLine("Część 2: z wagami dopasowań"); weightedTests.PreformTests(true, false); Console.WriteLine("Część 3: dopasowanie podciągów"); subsequenceTests.PreformTests(true, false); }
public static void WeightedTest() { Console.Out.WriteLine("Grafy ważone"); Graph grid3 = new AdjacencyListsGraph <SimpleAdjacencyList>(false, 9); for (int i = 0; i < 9; i += 3) { grid3.AddEdge(i, i + 1, 3); grid3.AddEdge(i + 1, i + 2, 2); } for (int i = 0; i < 3; i++) { grid3.AddEdge(i + 0, i + 3, 2); grid3.AddEdge(i + 3, i + 6, 1); } RandomGraphGenerator rgg = new RandomGraphGenerator(240044); Graph eCycle24 = rgg.UndirectedCycle(typeof(AdjacencyListsGraph <SimpleAdjacencyList>), 24, 1, 5, true); Graph oCycle23 = rgg.UndirectedCycle(typeof(AdjacencyListsGraph <SimpleAdjacencyList>), 23, 1, 5, true); Graph g3 = rgg.UndirectedGraph(typeof(AdjacencyListsGraph <SimpleAdjacencyList>), 20, 0.2, 1, 11, true); TestSet set2 = new TestSet(); set2.TestCases.Add(new MatchingTestCase(10, grid3, 0, 4, 5)); set2.TestCases.Add(new MatchingTestCase(10, grid3, 1, 5, 7)); set2.TestCases.Add(new MatchingTestCase(10, grid3, 2 * grid3.EdgesCount - grid3.VerticesCount, grid3.EdgesCount, 3 + 6 + 6 + 9)); set2.TestCases.Add(new MatchingTestCase(10, grid3, 2 * grid3.EdgesCount - grid3.VerticesCount - 1, grid3.EdgesCount - 1, 3 + 6 + 6 + 6)); set2.TestCases.Add(new MatchingTestCase(10, eCycle24, 0, 12, 33)); set2.TestCases.Add(new MatchingTestCase(10, oCycle23, 0, 11, 30)); set2.TestCases.Add(new MatchingTestCase(10, eCycle24, 1, 12, 24)); set2.TestCases.Add(new MatchingTestCase(10, oCycle23, 1, 12, 32)); set2.TestCases.Add(new MatchingTestCase(10, g3, 0, 10, 45)); set2.TestCases.Add(new MatchingTestCase(10, g3, 2, 11, 43)); set2.TestCases.Add(new MatchingTestCase(10, g3, 3, 11, 35)); set2.PreformTests(true, false); }
public static void Main(string[] args) { if (GraphLibraryVersion.ToString() != "7.0.2") { Console.WriteLine("Pobierz nową wersję biblioteki"); return; } Graph triplePath = new AdjacencyListsGraph <SimpleAdjacencyList>(false, 5); triplePath.AddEdge(0, 1); triplePath.AddEdge(0, 2); triplePath.AddEdge(0, 3); triplePath.AddEdge(4, 1); triplePath.AddEdge(4, 2); triplePath.AddEdge(4, 3); Graph grid5 = new AdjacencyListsGraph <SimpleAdjacencyList>(false, 25); for (int i = 0; i < 5; i++) { for (int j = 0; j < 4; j++) { grid5.AddEdge(5 * i + j, 5 * i + j + 1); grid5.AddEdge(5 * j + i, 5 * (j + 1) + i); } } Graph crossing = new AdjacencyListsGraph <SimpleAdjacencyList>(false, 5); crossing.AddEdge(0, 4); crossing.AddEdge(1, 4); crossing.AddEdge(2, 4); crossing.AddEdge(3, 4); MuseumTestCase triplePathCase = new MuseumTestCase(10, triplePath, new int[] { 3, 1, 1, 1, 3 }, new int[] { 0 }, new int[] { 4 }, 3); MuseumTestCase doublePathCase = new MuseumTestCase(10, triplePath, new int[] { 1, 1, 1, 1, 1 }, new int[] { 0, 4 }, new int[] { 0, 4 }, 2); MuseumTestCase singleVertexCase1 = new MuseumTestCase(10, triplePath, new int[] { 1, 1, 1, 1, 1 }, new int[] { 0 }, new int[] { 0 }, 1); MuseumTestCase singleVertexCase2 = new MuseumTestCase(10, triplePath, new int[] { 2, 1, 1, 1, 2 }, new int[] { 0 }, new int[] { 4 }, 2); MuseumTestCase doubledPathCase = new MuseumTestCase(10, triplePath, new int[] { 6, 2, 2, 2, 6 }, new int[] { 0 }, new int[] { 4 }, 6); MuseumTestCase almostDoubledPathCase = new MuseumTestCase(10, triplePath, new int[] { 6, 2, 2, 2, 5 }, new int[] { 0 }, new int[] { 4 }, 5); MuseumTestCase almostDoubledPathCase2 = new MuseumTestCase(10, triplePath, new int[] { 5, 2, 2, 2, 6 }, new int[] { 0 }, new int[] { 4 }, 5); MuseumTestCase middleVertexLimit = new MuseumTestCase(10, crossing, new int[] { 1, 1, 1, 1, 1 }, new int[] { 0, 1 }, new int[] { 2, 3 }, 1); MuseumTestCase centerToCornersGrid = new MuseumTestCase(10, grid5, new int[] { 1, 3, 3, 3, 2, 0, 3, 0, 0, 0, 0, 4, 6, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1 }, new int[] { 12 }, new int[] { 0, 4, 20, 24 }, 5); MuseumTestCase cornersToCenterGrid = new MuseumTestCase(10, grid5, new int[] { 1, 3, 3, 3, 2, 0, 3, 0, 0, 0, 0, 4, 6, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1 }, new int[] { 0, 4, 20, 24 }, new int[] { 12 }, 5); TestSet set = new TestSet(); set.TestCases.Add(triplePathCase); set.TestCases.Add(doublePathCase); set.TestCases.Add(singleVertexCase1); set.TestCases.Add(singleVertexCase2); set.TestCases.Add(doubledPathCase); set.TestCases.Add(almostDoubledPathCase); set.TestCases.Add(almostDoubledPathCase2); set.TestCases.Add(middleVertexLimit); set.TestCases.Add(centerToCornersGrid); set.TestCases.Add(cornersToCenterGrid); set.TestCases.Add(MuseumTestCase.RandomTest(100, 1337, 10, 204)); set.TestCases.Add(MuseumTestCase.RandomTest(100, 1410, 10, 181)); set.TestCases.Add(MuseumTestCase.RandomTest(100, 240044, 10, 128)); MuseumTestCase.NumberOnly = true; Console.WriteLine("\nCzesc I\n"); set.PreformTests(verbose: true, checkTimeLimit: false); MuseumTestCase.NumberOnly = false; Console.WriteLine("\nCzesc II\n"); set.PreformTests(verbose: true, checkTimeLimit: false); }
static void Main(string[] args) { Random rnd = new Random(100); TestSet undirectedRep = new TestSet(); TestSet directedRep = new TestSet(); TestSet undirectedSimple = new TestSet(); TestSet directedSimple = new TestSet(); Graph g; #region undirected, with repetitions g = new AdjacencyListsGraph <HashTableAdjacencyList>(false, 5); g.AddEdge(0, 1, 1); g.AddEdge(1, 2, 1); g.AddEdge(0, 2, 1); g.AddEdge(3, 4, 1); undirectedRep.TestCases.Add(new RepSecondPathTestCase(10, g, 0, 4, null)); g = new AdjacencyListsGraph <HashTableAdjacencyList>(false, 5); g.AddEdge(0, 1, 1); g.AddEdge(1, 2, 1); g.AddEdge(2, 3, 1); g.AddEdge(3, 4, 1); undirectedRep.TestCases.Add(new RepSecondPathTestCase(10, g, 0, 4, 6)); g = new AdjacencyListsGraph <HashTableAdjacencyList>(false, 5); g.AddEdge(0, 1, 1); g.AddEdge(1, 2, 1); g.AddEdge(2, 3, 1); g.AddEdge(3, 4, 1); g.AddEdge(0, 4, 7); undirectedRep.TestCases.Add(new RepSecondPathTestCase(10, g, 0, 4, 6)); g = new AdjacencyListsGraph <HashTableAdjacencyList>(false, 5); g.AddEdge(0, 1, 2); g.AddEdge(1, 2, 2); g.AddEdge(2, 3, 2); g.AddEdge(3, 4, 2); g.AddEdge(2, 4, 5); undirectedRep.TestCases.Add(new RepSecondPathTestCase(10, g, 0, 4, 9)); g = new AdjacencyListsGraph <HashTableAdjacencyList>(false, 6); g.AddEdge(0, 1, 1); g.AddEdge(1, 2, 1); g.AddEdge(2, 3, 1); g.AddEdge(0, 4, 1); g.AddEdge(4, 5, 1); g.AddEdge(5, 3, 1); undirectedRep.TestCases.Add(new RepSecondPathTestCase(10, g, 0, 3, 3)); g = new AdjacencyListsGraph <HashTableAdjacencyList>(false, 100); for (int i = 0; i < 100; ++i) { for (int j = i + 1; j < 100; ++j) { if (rnd.Next(10) <= 2) { g.AddEdge(i, j, 1 + rnd.Next(100)); } } } undirectedRep.TestCases.Add(new RepSecondPathTestCase(10, g, 0, 99, 21)); g = new AdjacencyListsGraph <HashTableAdjacencyList>(false, 100); for (int i = 0; i < 100; ++i) { for (int j = i + 1; j < 100; ++j) { if (rnd.Next(10) <= 3) { g.AddEdge(i, j, 1 + rnd.Next(100)); } } } undirectedRep.TestCases.Add(new RepSecondPathTestCase(10, g, 0, 99, 23)); g = new AdjacencyListsGraph <HashTableAdjacencyList>(false, 1000); for (int i = 0; i < 1000; ++i) { for (int j = i + 1; j < 1000; ++j) { if (rnd.Next(10) <= 3) { g.AddEdge(i, j, 1 + rnd.Next(100)); } } } undirectedRep.TestCases.Add(new RepSecondPathTestCase(10, g, 0, 99, 6)); #endregion #region directed, with repetitions g = new AdjacencyListsGraph <HashTableAdjacencyList>(true, 5); g.AddEdge(0, 1, 1); g.AddEdge(1, 2, 1); g.AddEdge(0, 2, 1); g.AddEdge(3, 4, 1); directedRep.TestCases.Add(new RepSecondPathTestCase(10, g, 0, 4, null)); g = new AdjacencyListsGraph <HashTableAdjacencyList>(true, 5); g.AddEdge(0, 1, 1); g.AddEdge(1, 2, 1); g.AddEdge(2, 3, 1); g.AddEdge(3, 4, 1); directedRep.TestCases.Add(new RepSecondPathTestCase(10, g, 0, 4, null)); g = new AdjacencyListsGraph <HashTableAdjacencyList>(true, 5); g.AddEdge(0, 1, 1); g.AddEdge(1, 2, 1); g.AddEdge(2, 3, 1); g.AddEdge(3, 4, 1); g.AddEdge(0, 4, 7); directedRep.TestCases.Add(new RepSecondPathTestCase(10, g, 0, 4, 7)); g = new AdjacencyListsGraph <HashTableAdjacencyList>(true, 5); g.AddEdge(0, 1, 2); g.AddEdge(1, 2, 2); g.AddEdge(2, 3, 2); g.AddEdge(3, 4, 2); g.AddEdge(2, 4, 5); directedRep.TestCases.Add(new RepSecondPathTestCase(10, g, 0, 4, 9)); g = new AdjacencyListsGraph <HashTableAdjacencyList>(true, 6); g.AddEdge(0, 1, 1); g.AddEdge(1, 2, 1); g.AddEdge(2, 3, 1); g.AddEdge(0, 4, 1); g.AddEdge(4, 5, 1); g.AddEdge(5, 3, 1); directedRep.TestCases.Add(new RepSecondPathTestCase(10, g, 0, 3, 3)); g = new AdjacencyListsGraph <HashTableAdjacencyList>(true, 100); for (int i = 0; i < 100; ++i) { for (int j = i + 1; j < 100; ++j) { if (rnd.Next(10) <= 2) { g.AddEdge(i, j, 1 + rnd.Next(100)); } if (rnd.Next(10) <= 2) { g.AddEdge(j, i, 1 + rnd.Next(100)); } } } directedRep.TestCases.Add(new RepSecondPathTestCase(10, g, 0, 4, 24)); g = new AdjacencyListsGraph <HashTableAdjacencyList>(true, 100); for (int i = 0; i < 100; ++i) { for (int j = i + 1; j < 100; ++j) { if (rnd.Next(10) <= 2) { g.AddEdge(i, j, 1 + rnd.Next(100)); } if (rnd.Next(10) <= 2) { g.AddEdge(j, i, 1 + rnd.Next(100)); } } } directedRep.TestCases.Add(new RepSecondPathTestCase(10, g, 0, 99, 22)); g = new AdjacencyListsGraph <HashTableAdjacencyList>(true, 1000); for (int i = 0; i < 1000; ++i) { for (int j = i + 1; j < 1000; ++j) { if (rnd.Next(10) <= 3) { g.AddEdge(i, j, 1 + rnd.Next(100)); } if (rnd.Next(10) <= 3) { g.AddEdge(j, i, 1 + rnd.Next(100)); } } } directedRep.TestCases.Add(new RepSecondPathTestCase(10, g, 0, 99, 5)); #endregion #region undirected, without repetitions g = new AdjacencyListsGraph <HashTableAdjacencyList>(false, 5); g.AddEdge(0, 1, 1); g.AddEdge(1, 2, 1); g.AddEdge(0, 2, 1); g.AddEdge(3, 4, 1); undirectedSimple.TestCases.Add(new SimpleSecondPathTestCase(10, g, 0, 4, null)); g = new AdjacencyListsGraph <HashTableAdjacencyList>(false, 5); g.AddEdge(0, 1, 1); g.AddEdge(1, 2, 1); g.AddEdge(2, 3, 1); g.AddEdge(3, 4, 1); undirectedSimple.TestCases.Add(new SimpleSecondPathTestCase(10, g, 0, 4, null)); g = new AdjacencyListsGraph <HashTableAdjacencyList>(false, 5); g.AddEdge(0, 1, 1); g.AddEdge(1, 2, 1); g.AddEdge(2, 3, 1); g.AddEdge(3, 4, 1); g.AddEdge(0, 4, 7); undirectedSimple.TestCases.Add(new SimpleSecondPathTestCase(10, g, 0, 4, 7)); g = new AdjacencyListsGraph <HashTableAdjacencyList>(false, 5); g.AddEdge(0, 1, 2); g.AddEdge(1, 2, 2); g.AddEdge(2, 3, 2); g.AddEdge(3, 4, 2); g.AddEdge(2, 4, 5); undirectedSimple.TestCases.Add(new SimpleSecondPathTestCase(10, g, 0, 4, 9)); g = new AdjacencyListsGraph <HashTableAdjacencyList>(false, 6); g.AddEdge(0, 1, 1); g.AddEdge(1, 2, 1); g.AddEdge(2, 3, 1); g.AddEdge(0, 4, 1); g.AddEdge(4, 5, 1); g.AddEdge(5, 3, 1); undirectedSimple.TestCases.Add(new SimpleSecondPathTestCase(10, g, 0, 3, 3)); g = new AdjacencyListsGraph <HashTableAdjacencyList>(false, 100); for (int i = 0; i < 100; ++i) { for (int j = i + 1; j < 100; ++j) { if (rnd.Next(10) <= 2) { g.AddEdge(i, j, 1 + rnd.Next(100)); } } } undirectedSimple.TestCases.Add(new SimpleSecondPathTestCase(10, g, 0, 99, 14)); g = new AdjacencyListsGraph <HashTableAdjacencyList>(false, 100); for (int i = 0; i < 100; ++i) { for (int j = i + 1; j < 100; ++j) { if (rnd.Next(10) <= 2) { g.AddEdge(i, j, 1 + rnd.Next(100)); } } } undirectedSimple.TestCases.Add(new SimpleSecondPathTestCase(10, g, 0, 99, 29)); g = new AdjacencyListsGraph <HashTableAdjacencyList>(false, 100); for (int i = 0; i < 100; ++i) { for (int j = i + 1; j < 100; ++j) { if (rnd.Next(10) <= 2) { g.AddEdge(i, j, 1 + rnd.Next(100)); } } } undirectedSimple.TestCases.Add(new SimpleSecondPathTestCase(10, g, 0, 99, 24)); #endregion #region directed, without repetitions g = new AdjacencyListsGraph <HashTableAdjacencyList>(true, 5); g.AddEdge(0, 1, 1); g.AddEdge(1, 2, 1); g.AddEdge(0, 2, 1); g.AddEdge(3, 4, 1); directedSimple.TestCases.Add(new SimpleSecondPathTestCase(10, g, 0, 4, null)); g = new AdjacencyListsGraph <HashTableAdjacencyList>(true, 5); g.AddEdge(0, 1, 1); g.AddEdge(1, 2, 1); g.AddEdge(2, 3, 1); g.AddEdge(3, 4, 1); directedSimple.TestCases.Add(new SimpleSecondPathTestCase(10, g, 0, 4, null)); g = new AdjacencyListsGraph <HashTableAdjacencyList>(true, 5); g.AddEdge(0, 1, 1); g.AddEdge(1, 2, 1); g.AddEdge(2, 3, 1); g.AddEdge(3, 4, 1); g.AddEdge(0, 4, 7); directedSimple.TestCases.Add(new SimpleSecondPathTestCase(10, g, 0, 4, 7)); g = new AdjacencyListsGraph <HashTableAdjacencyList>(true, 5); g.AddEdge(0, 1, 2); g.AddEdge(1, 2, 2); g.AddEdge(2, 3, 2); g.AddEdge(3, 4, 2); g.AddEdge(2, 4, 5); directedSimple.TestCases.Add(new SimpleSecondPathTestCase(10, g, 0, 4, 9)); g = new AdjacencyListsGraph <HashTableAdjacencyList>(true, 6); g.AddEdge(0, 1, 1); g.AddEdge(1, 2, 1); g.AddEdge(2, 3, 1); g.AddEdge(0, 4, 1); g.AddEdge(4, 5, 1); g.AddEdge(5, 3, 1); directedSimple.TestCases.Add(new SimpleSecondPathTestCase(10, g, 0, 3, 3)); // Test 6 g = new AdjacencyListsGraph <HashTableAdjacencyList>(true, 100); for (int i = 0; i < 100; ++i) { for (int j = i + 1; j < 100; ++j) { if (rnd.Next(10) <= 2) { g.AddEdge(i, j, 1 + rnd.Next(100)); } if (rnd.Next(10) <= 2) { g.AddEdge(j, i, 1 + rnd.Next(100)); } } } directedSimple.TestCases.Add(new SimpleSecondPathTestCase(10, g, 0, 4, 29)); g = new AdjacencyListsGraph <HashTableAdjacencyList>(true, 100); for (int i = 0; i < 100; ++i) { for (int j = i + 1; j < 100; ++j) { if (rnd.Next(10) <= 2) { g.AddEdge(i, j, 1 + rnd.Next(100)); } if (rnd.Next(10) <= 2) { g.AddEdge(j, i, 1 + rnd.Next(100)); } } } directedSimple.TestCases.Add(new SimpleSecondPathTestCase(10, g, 0, 99, 23)); g = new AdjacencyListsGraph <HashTableAdjacencyList>(true, 1000); for (int i = 0; i < 1000; ++i) { for (int j = i + 1; j < 1000; ++j) { if (rnd.Next(10) <= 3) { g.AddEdge(i, j, 1 + rnd.Next(100)); } if (rnd.Next(10) <= 3) { g.AddEdge(j, i, 1 + rnd.Next(100)); } } } directedSimple.TestCases.Add(new SimpleSecondPathTestCase(10, g, 0, 99, 5)); #endregion Console.WriteLine("Path with repetitions, undirected graphs"); undirectedRep.PreformTests(true, false); Console.WriteLine("Path with repetitions, directed graphs"); directedRep.PreformTests(true, false); Console.WriteLine("Path without repetitions, undirected graphs"); undirectedSimple.PreformTests(true, false); Console.WriteLine("Path without repetitions, directed graphs"); directedSimple.PreformTests(true, false); #region custom, additional tests RandomGraphGenerator rgg = new RandomGraphGenerator(1234); Console.WriteLine("Custom tests"); Console.WriteLine("Timing a boilerplate task"); long boilerplateTaskTimeElapsed = PerformBoilerplateTask(); Console.WriteLine("Boilerplate task done. Results will be shown below"); Console.WriteLine("Generating test cases, this may take a while..."); #region custom undirected, with repetitions TestSet undirectedWithRepetitions = new TestSet(); g = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), 100, 0.8, 1, 100, true); undirectedWithRepetitions.TestCases.Add(new RepSecondPathTestCase(10, g, 0, 99, 9)); g = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), 100, 0.5, 1, 100, true); undirectedWithRepetitions.TestCases.Add(new RepSecondPathTestCase(10, g, 0, 99, 11)); g = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), 100, 0.2, 1, 100, true); undirectedWithRepetitions.TestCases.Add(new RepSecondPathTestCase(10, g, 0, 99, 24)); g = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), 1000, 0.8, 1, 100, true); undirectedWithRepetitions.TestCases.Add(new RepSecondPathTestCase(10, g, 0, 999, 4)); g = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), 1000, 0.2, 1, 100, true); undirectedWithRepetitions.TestCases.Add(new RepSecondPathTestCase(10, g, 0, 999, 7)); g = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), 1000, 1, 1, 100, true); undirectedWithRepetitions.TestCases.Add(new RepSecondPathTestCase(10, g, 0, 999, 4)); g = rgg.UndirectedGraph(typeof(AdjacencyListsGraph <AVLAdjacencyList>), 1500, 0.75, 1, 100, true); undirectedWithRepetitions.TestCases.Add(new RepSecondPathTestCase(10, g, 0, 1499, 3)); g = rgg.UndirectedGraph(typeof(AdjacencyListsGraph <AVLAdjacencyList>), 1500, 0, 1, 100, true); undirectedWithRepetitions.TestCases.Add(new RepSecondPathTestCase(10, g, 0, 1499, null)); #endregion #region custom directed, with repetitions TestSet directedWithRepetitions = new TestSet(); g = new AdjacencyMatrixGraph(true, 3); g.AddEdge(0, 1, 20); g.AddEdge(0, 2, 30); g.AddEdge(1, 2, 1); g.AddEdge(2, 1, 2); directedWithRepetitions.TestCases.Add(new RepSecondPathTestCase(10, g, 0, 2, 30)); g = rgg.DirectedGraph(typeof(AdjacencyMatrixGraph), 100, 0.8, 1, 100, true); directedWithRepetitions.TestCases.Add(new RepSecondPathTestCase(10, g, 0, 99, 10)); g = rgg.DirectedGraph(typeof(AdjacencyMatrixGraph), 100, 0.5, 1, 100, true); directedWithRepetitions.TestCases.Add(new RepSecondPathTestCase(10, g, 0, 99, 14)); g = rgg.DirectedGraph(typeof(AdjacencyMatrixGraph), 100, 0.2, 1, 100, true); directedWithRepetitions.TestCases.Add(new RepSecondPathTestCase(10, g, 0, 99, 30)); g = rgg.DirectedGraph(typeof(AdjacencyMatrixGraph), 1000, 0.8, 1, 100, true); directedWithRepetitions.TestCases.Add(new RepSecondPathTestCase(10, g, 0, 999, 5)); g = rgg.DirectedGraph(typeof(AdjacencyMatrixGraph), 1000, 0.2, 1, 100, true); directedWithRepetitions.TestCases.Add(new RepSecondPathTestCase(10, g, 0, 999, 9)); g = rgg.DirectedGraph(typeof(AdjacencyMatrixGraph), 1000, 1, 1, 100, true); directedWithRepetitions.TestCases.Add(new RepSecondPathTestCase(10, g, 0, 999, 3)); g = rgg.DirectedGraph(typeof(AdjacencyListsGraph <AVLAdjacencyList>), 1500, 0.75, 1, 100, true); directedWithRepetitions.TestCases.Add(new RepSecondPathTestCase(10, g, 0, 1499, 4)); g = rgg.DirectedGraph(typeof(AdjacencyListsGraph <AVLAdjacencyList>), 1500, 0, 1, 100, true); directedWithRepetitions.TestCases.Add(new RepSecondPathTestCase(10, g, 0, 1499, null)); #endregion #region custom undirected, without repetitions TestSet undirectedWithoutRepetitions = new TestSet(); g = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), 100, 0.8, 1, 100, true); undirectedWithoutRepetitions.TestCases.Add(new SimpleSecondPathTestCase(10, g, 0, 99, 8)); g = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), 100, 0.5, 1, 100, true); undirectedWithoutRepetitions.TestCases.Add(new SimpleSecondPathTestCase(10, g, 0, 99, 11)); g = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), 100, 0.2, 1, 100, true); undirectedWithoutRepetitions.TestCases.Add(new SimpleSecondPathTestCase(10, g, 0, 99, 20)); g = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), 1000, 0.8, 1, 100, true); undirectedWithoutRepetitions.TestCases.Add(new SimpleSecondPathTestCase(10, g, 0, 999, 4)); g = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), 1000, 0.2, 1, 100, true); undirectedWithoutRepetitions.TestCases.Add(new SimpleSecondPathTestCase(10, g, 0, 999, 9)); g = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), 1000, 1, 1, 100, true); undirectedWithoutRepetitions.TestCases.Add(new SimpleSecondPathTestCase(10, g, 0, 999, 4)); g = rgg.UndirectedGraph(typeof(AdjacencyListsGraph <AVLAdjacencyList>), 1500, 0.75, 1, 100, true); undirectedWithoutRepetitions.TestCases.Add(new SimpleSecondPathTestCase(10, g, 0, 1499, 3)); g = rgg.UndirectedGraph(typeof(AdjacencyListsGraph <AVLAdjacencyList>), 1500, 0, 1, 100, true); undirectedWithoutRepetitions.TestCases.Add(new SimpleSecondPathTestCase(10, g, 0, 1499, null)); #endregion #region custom directed, without repetitions TestSet directedWithoutRepetitions = new TestSet(); g = new AdjacencyMatrixGraph(true, 3); g.AddEdge(0, 1, 20); g.AddEdge(0, 2, 30); g.AddEdge(1, 2, 1); g.AddEdge(2, 1, 2); directedWithoutRepetitions.TestCases.Add(new SimpleSecondPathTestCase(10, g, 0, 2, 30)); g = rgg.DirectedGraph(typeof(AdjacencyMatrixGraph), 100, 0.8, 1, 100, true); directedWithoutRepetitions.TestCases.Add(new SimpleSecondPathTestCase(10, g, 0, 99, 6)); g = rgg.DirectedGraph(typeof(AdjacencyMatrixGraph), 100, 0.5, 1, 100, true); directedWithoutRepetitions.TestCases.Add(new SimpleSecondPathTestCase(10, g, 0, 99, 8)); g = rgg.DirectedGraph(typeof(AdjacencyMatrixGraph), 100, 0.2, 1, 100, true); directedWithoutRepetitions.TestCases.Add(new SimpleSecondPathTestCase(10, g, 0, 99, 12)); g = rgg.DirectedGraph(typeof(AdjacencyMatrixGraph), 1000, 0.8, 1, 100, true); directedWithoutRepetitions.TestCases.Add(new SimpleSecondPathTestCase(10, g, 0, 999, 4)); g = rgg.DirectedGraph(typeof(AdjacencyMatrixGraph), 1000, 0.2, 1, 100, true); directedWithoutRepetitions.TestCases.Add(new SimpleSecondPathTestCase(10, g, 0, 999, 6)); g = rgg.DirectedGraph(typeof(AdjacencyMatrixGraph), 1000, 1, 1, 100, true); directedWithoutRepetitions.TestCases.Add(new SimpleSecondPathTestCase(10, g, 0, 999, 4)); g = rgg.DirectedGraph(typeof(AdjacencyListsGraph <AVLAdjacencyList>), 1500, 0.75, 1, 100, true); directedWithoutRepetitions.TestCases.Add(new SimpleSecondPathTestCase(10, g, 0, 1499, 3)); g = rgg.DirectedGraph(typeof(AdjacencyListsGraph <AVLAdjacencyList>), 1500, 0, 1, 100, true); directedWithoutRepetitions.TestCases.Add(new SimpleSecondPathTestCase(10, g, 0, 1499, null)); #endregion System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); long[] elapsedTime = new long[4]; Console.WriteLine("Custom path with repetitions, undirected graphs"); stopwatch.Start(); undirectedWithRepetitions.PreformTests(true, false); stopwatch.Stop(); elapsedTime[0] = stopwatch.ElapsedMilliseconds; Console.WriteLine("Custom path with repetitions, directed graphs"); stopwatch.Restart(); directedWithRepetitions.PreformTests(true, false); stopwatch.Stop(); elapsedTime[1] = stopwatch.ElapsedMilliseconds; Console.WriteLine("Custom path without repetitions, undirected graphs"); stopwatch.Restart(); undirectedWithoutRepetitions.PreformTests(true, false); stopwatch.Stop(); elapsedTime[2] = stopwatch.ElapsedMilliseconds; Console.WriteLine("Custom path without repetitions, directed graphs"); stopwatch.Restart(); directedWithoutRepetitions.PreformTests(true, false); stopwatch.Stop(); elapsedTime[3] = stopwatch.ElapsedMilliseconds; Console.WriteLine(String.Empty); Console.WriteLine(String.Empty); Console.WriteLine("Performance metrics"); for (int i = 0; i < elapsedTime.Length; i++) { Console.WriteLine("Test case {0}: {1,5} ms ({2:F3} times the boilerplate time)", i + 1, elapsedTime[i], (double)elapsedTime[i] / boilerplateTaskTimeElapsed); } #endregion }
public static void UnweightedTest() { Console.Out.WriteLine("Grafy nieważone"); Graph grid3 = new AdjacencyListsGraph <SimpleAdjacencyList>(false, 9); for (int i = 0; i < 9; i += 3) { grid3.AddEdge(i, i + 1); grid3.AddEdge(i + 1, i + 2); } for (int i = 0; i < 3; i++) { grid3.AddEdge(i + 0, i + 3); grid3.AddEdge(i + 3, i + 6); } Graph path20 = new AdjacencyListsGraph <SimpleAdjacencyList>(false, 20); for (int i = 1; i < path20.VerticesCount; i++) { path20.AddEdge(i - 1, i); } Graph shiftedPath20 = new AdjacencyListsGraph <SimpleAdjacencyList>(false, 20); shiftedPath20.AddEdge(18, 19); shiftedPath20.AddEdge(0, 1); shiftedPath20.AddEdge(19, 1); for (int i = 2; i < shiftedPath20.VerticesCount; i++) { shiftedPath20.AddEdge(i - 1, i); } RandomGraphGenerator rgg = new RandomGraphGenerator(240044); Graph eCycle24 = rgg.UndirectedCycle(typeof(AdjacencyListsGraph <SimpleAdjacencyList>), 24, 1, 1, true); Graph oCycle23 = rgg.UndirectedCycle(typeof(AdjacencyListsGraph <SimpleAdjacencyList>), 23, 1, 1, true); Graph iso = new AdjacencyListsGraph <SimpleAdjacencyList>(false, 1024); TestSet set1 = new TestSet(); set1.TestCases.Add(new MatchingTestCase(10, path20, 0, 10, 10)); set1.TestCases.Add(new MatchingTestCase(10, shiftedPath20, 0, 10, 10)); set1.TestCases.Add(new MatchingTestCase(10, eCycle24, 0, 12, 12)); set1.TestCases.Add(new MatchingTestCase(10, oCycle23, 0, 11, 11)); set1.TestCases.Add(new MatchingTestCase(10, grid3, 0, 4, 4)); set1.TestCases.Add(new MatchingTestCase(10, grid3, 1, 5, 5)); set1.TestCases.Add(new MatchingTestCase(10, grid3, 2 * grid3.EdgesCount - grid3.VerticesCount, grid3.EdgesCount, grid3.EdgesCount)); set1.TestCases.Add(new MatchingTestCase(10, path20, 0, 10, 10)); set1.TestCases.Add(new MatchingTestCase(10, shiftedPath20, 0, 10, 10)); set1.TestCases.Add(new MatchingTestCase(10, path20, 1, 10, 10)); set1.TestCases.Add(new MatchingTestCase(10, shiftedPath20, 1, 10, 10)); set1.TestCases.Add(new MatchingTestCase(10, eCycle24, 0, 12, 12)); set1.TestCases.Add(new MatchingTestCase(10, oCycle23, 0, 11, 11)); set1.TestCases.Add(new MatchingTestCase(10, eCycle24, 1, 12, 12)); set1.TestCases.Add(new MatchingTestCase(10, oCycle23, 1, 12, 12)); set1.TestCases.Add(new MatchingTestCase(10, iso, 0, 0, 0)); set1.TestCases.Add(new MatchingTestCase(10, iso, 10000, 0, 0)); set1.PreformTests(true, false); }
public static void Main(string[] args) { if (GraphLibraryVersion.ToString() != "7.0.2") { Console.WriteLine("Pobierz nową wersję biblioteki"); return; } Graph triplePath = new AdjacencyListsGraph <SimpleAdjacencyList>(false, 5); triplePath.AddEdge(0, 1); triplePath.AddEdge(0, 2); triplePath.AddEdge(0, 3); triplePath.AddEdge(4, 1); triplePath.AddEdge(4, 2); triplePath.AddEdge(4, 3); Graph grid5 = new AdjacencyListsGraph <SimpleAdjacencyList>(false, 25); for (int i = 0; i < 5; i++) { for (int j = 0; j < 4; j++) { grid5.AddEdge(5 * i + j, 5 * i + j + 1); grid5.AddEdge(5 * j + i, 5 * (j + 1) + i); } } Graph crossing = new AdjacencyListsGraph <SimpleAdjacencyList>(false, 5); crossing.AddEdge(0, 4); crossing.AddEdge(1, 4); crossing.AddEdge(2, 4); crossing.AddEdge(3, 4); MuseumTestCase triplePathCase = new MuseumTestCase(10, triplePath, new int[] { 3, 1, 1, 1, 3 }, new int[] { 0 }, new int[] { 4 }, 3); MuseumTestCase doublePathCase = new MuseumTestCase(10, triplePath, new int[] { 1, 1, 1, 1, 1 }, new int[] { 0, 4 }, new int[] { 0, 4 }, 2); MuseumTestCase singleVertexCase1 = new MuseumTestCase(10, triplePath, new int[] { 1, 1, 1, 1, 1 }, new int[] { 0 }, new int[] { 0 }, 1); MuseumTestCase singleVertexCase2 = new MuseumTestCase(10, triplePath, new int[] { 2, 1, 1, 1, 2 }, new int[] { 0 }, new int[] { 4 }, 2); MuseumTestCase doubledPathCase = new MuseumTestCase(10, triplePath, new int[] { 6, 2, 2, 2, 6 }, new int[] { 0 }, new int[] { 4 }, 6); MuseumTestCase almostDoubledPathCase = new MuseumTestCase(10, triplePath, new int[] { 6, 2, 2, 2, 5 }, new int[] { 0 }, new int[] { 4 }, 5); MuseumTestCase almostDoubledPathCase2 = new MuseumTestCase(10, triplePath, new int[] { 5, 2, 2, 2, 6 }, new int[] { 0 }, new int[] { 4 }, 5); MuseumTestCase middleVertexLimit = new MuseumTestCase(10, crossing, new int[] { 1, 1, 1, 1, 1 }, new int[] { 0, 1 }, new int[] { 2, 3 }, 1); MuseumTestCase centerToCornersGrid = new MuseumTestCase(10, grid5, new int[] { 1, 3, 3, 3, 2, 0, 3, 0, 0, 0, 0, 4, 6, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1 }, new int[] { 12 }, new int[] { 0, 4, 20, 24 }, 5); MuseumTestCase cornersToCenterGrid = new MuseumTestCase(10, grid5, new int[] { 1, 3, 3, 3, 2, 0, 3, 0, 0, 0, 0, 4, 6, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1 }, new int[] { 0, 4, 20, 24 }, new int[] { 12 }, 5); TestSet set = new TestSet(); set.TestCases.Add(triplePathCase); set.TestCases.Add(doublePathCase); set.TestCases.Add(singleVertexCase1); set.TestCases.Add(singleVertexCase2); set.TestCases.Add(doubledPathCase); set.TestCases.Add(almostDoubledPathCase); set.TestCases.Add(almostDoubledPathCase2); set.TestCases.Add(middleVertexLimit); set.TestCases.Add(centerToCornersGrid); set.TestCases.Add(cornersToCenterGrid); set.TestCases.Add(MuseumTestCase.RandomTest(100, 1337, 10, 204)); set.TestCases.Add(MuseumTestCase.RandomTest(100, 1410, 10, 181)); set.TestCases.Add(MuseumTestCase.RandomTest(100, 240044, 10, 128)); MuseumTestCase.NumberOnly = true; Console.WriteLine("\nCzesc I\n"); set.PreformTests(verbose: true, checkTimeLimit: false); MuseumTestCase.NumberOnly = false; Console.WriteLine("\nCzesc II\n"); set.PreformTests(verbose: true, checkTimeLimit: false); // Custom tests Console.WriteLine("\nPerforming boilerplate task"); long boilerplateTaskTime = PerformBoilerplateTask(); Console.WriteLine("Custom tests\n"); TestSet customSet = new TestSet(); customSet.TestCases.Add(MuseumTestCase.RandomTest(100, 69, 10, 116)); customSet.TestCases.Add(MuseumTestCase.RandomTest(150, 70, 10, 91)); customSet.TestCases.Add(MuseumTestCase.RandomTest(150, 71, 10, 170)); customSet.TestCases.Add(MuseumTestCase.RandomTest(150, 72, 10, 95)); customSet.TestCases.Add(MuseumTestCase.RandomTest(150, 73, 10, 99)); customSet.TestCases.Add(MuseumTestCase.RandomTest(150, 74, 10, 307)); customSet.TestCases.Add(MuseumTestCase.RandomTest(200, 75, 10, 485)); customSet.TestCases.Add(MuseumTestCase.RandomTest(200, 76, 10, 219)); customSet.TestCases.Add(MuseumTestCase.RandomTest(200, 77, 10, 0)); customSet.TestCases.Add(MuseumTestCase.RandomTest(200, 78, 10, 536)); customSet.TestCases.Add(MuseumTestCase.RandomTest(250, 79, 10, 424)); customSet.TestCases.Add(MuseumTestCase.RandomTest(250, 80, 10, 58)); customSet.TestCases.Add(MuseumTestCase.RandomTest(250, 81, 10, 387)); customSet.TestCases.Add(MuseumTestCase.RandomTest(250, 82, 10, 635)); customSet.TestCases.Add(MuseumTestCase.RandomTest(300, 83, 10, 657)); customSet.TestCases.Add(MuseumTestCase.RandomTest(300, 84, 10, 551)); customSet.TestCases.Add(MuseumTestCase.RandomTest(500, 85, 10, 289)); customSet.TestCases.Add(MuseumTestCase.RandomTest(500, 86, 10, 969)); customSet.TestCases.Add(MuseumTestCase.RandomTest(500, 87, 10, 1238)); customSet.TestCases.Add(MuseumTestCase.RandomTest(750, 88, 10, 1722)); customSet.TestCases.Add(MuseumTestCase.RandomTest(1000, 89, 10, 2257)); var stopwatch = System.Diagnostics.Stopwatch.StartNew(); customSet.PreformTests(verbose: true, checkTimeLimit: false); stopwatch.Stop(); long customTestsTime = stopwatch.ElapsedMilliseconds; Console.WriteLine("Custom tests: {0,5} ms ({1:F3} times the boilerplate time)", customTestsTime, (double)customTestsTime / boilerplateTaskTime); }