static void Main(string[] args)
        {
            GraphExport          ge  = new GraphExport();
            RandomGraphGenerator rgg = new RandomGraphGenerator();

            Graph[] directedGraphs = new Graph[8];
            directedGraphs[0] = new AdjacencyListsGraph <AVLAdjacencyList>(true, 3)
            {
                new Edge(0, 1), new Edge(1, 2), new Edge(2, 0)
            };
            directedGraphs[1] = new AdjacencyListsGraph <SimpleAdjacencyList>(true, 3)
            {
                new Edge(0, 1), new Edge(1, 2), new Edge(2, 1)
            };
            directedGraphs[2] = new AdjacencyMatrixGraph(true, 4)
            {
                new Edge(0, 1), new Edge(0, 2), new Edge(1, 3), new Edge(2, 3)
            };
            directedGraphs[3] = new AdjacencyListsGraph <HashTableAdjacencyList>(true, 10);
            directedGraphs[4] = new AdjacencyMatrixGraph(true, 10)
            {
                new Edge(0, 1), new Edge(0, 2), new Edge(0, 3), new Edge(2, 4), new Edge(2, 5), new Edge(2, 6),
                new Edge(5, 7), new Edge(5, 8), new Edge(5, 9), new Edge(6, 5), new Edge(7, 8), new Edge(8, 2)
            };
            rgg.SetSeed(111);
            directedGraphs[5] = rgg.DirectedGraph(typeof(AdjacencyMatrixGraph), 100, 0.2);
            rgg.SetSeed(222);
            directedGraphs[6] = rgg.DirectedCycle(typeof(AdjacencyListsGraph <SimpleAdjacencyList>), 1000);
            rgg.SetSeed(333);
            directedGraphs[7] = rgg.DAG(typeof(AdjacencyMatrixGraph), 200, 0.2, 1, 1);

            TestSet findCycleDirected = new TestSet();

            findCycleDirected.TestCases.Add(new FindCycleTestCase(5, null, directedGraphs[0], true));
            findCycleDirected.TestCases.Add(new FindCycleTestCase(5, null, directedGraphs[1], true));
            findCycleDirected.TestCases.Add(new FindCycleTestCase(5, null, directedGraphs[2], false));
            findCycleDirected.TestCases.Add(new FindCycleTestCase(5, null, directedGraphs[3], false));
            findCycleDirected.TestCases.Add(new FindCycleTestCase(5, null, directedGraphs[4], true));
            findCycleDirected.TestCases.Add(new FindCycleTestCase(5, null, directedGraphs[5], true));
            findCycleDirected.TestCases.Add(new FindCycleTestCase(5, null, directedGraphs[6], true));
            findCycleDirected.TestCases.Add(new FindCycleTestCase(5, null, directedGraphs[7], false));

            Graph[] undirectedGraphs = new Graph[6];
            undirectedGraphs[0] = new AdjacencyListsGraph <AVLAdjacencyList>(false, 3)
            {
                new Edge(0, 1), new Edge(1, 2), new Edge(2, 0)
            };
            undirectedGraphs[1] = new AdjacencyListsGraph <SimpleAdjacencyList>(false, 4)
            {
                new Edge(0, 1), new Edge(1, 2), new Edge(2, 3), new Edge(3, 1)
            };
            undirectedGraphs[2] = new AdjacencyListsGraph <HashTableAdjacencyList>(false, 10);
            undirectedGraphs[3] = new AdjacencyMatrixGraph(false, 10)
            {
                new Edge(0, 1), new Edge(0, 2), new Edge(0, 3), new Edge(2, 4), new Edge(2, 5), new Edge(2, 6),
                new Edge(5, 7), new Edge(5, 8), new Edge(5, 9), new Edge(8, 2)
            };
            rgg.SetSeed(444);
            undirectedGraphs[4] = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), 100, 0.2);
            rgg.SetSeed(555);
            undirectedGraphs[5] = rgg.TreeGraph(typeof(AdjacencyListsGraph <SimpleAdjacencyList>), 1000, 1.0);

            TestSet findCycleUndirected = new TestSet();

            findCycleUndirected.TestCases.Add(new FindCycleTestCase(5, null, undirectedGraphs[0], true));
            findCycleUndirected.TestCases.Add(new FindCycleTestCase(5, null, undirectedGraphs[1], true));
            findCycleUndirected.TestCases.Add(new FindCycleTestCase(5, null, undirectedGraphs[2], false));
            findCycleUndirected.TestCases.Add(new FindCycleTestCase(5, null, undirectedGraphs[3], true));
            findCycleUndirected.TestCases.Add(new FindCycleTestCase(5, null, undirectedGraphs[4], true));
            findCycleUndirected.TestCases.Add(new FindCycleTestCase(5, null, undirectedGraphs[5], false));

            Graph[] trees = new Graph[10];
            trees[0] = new AdjacencyListsGraph <AVLAdjacencyList>(false, 3)
            {
                new Edge(0, 1), new Edge(1, 2)
            };
            trees[1] = new AdjacencyListsGraph <SimpleAdjacencyList>(false, 4)
            {
                new Edge(0, 1), new Edge(1, 2), new Edge(2, 3)
            };
            trees[2] = new AdjacencyListsGraph <HashTableAdjacencyList>(false, 1);
            trees[3] = new AdjacencyListsGraph <HashTableAdjacencyList>(false, 2)
            {
                new Edge(0, 1)
            };
            trees[4] = new AdjacencyMatrixGraph(false, 5)
            {
                new Edge(1, 3), new Edge(2, 4)
            };
            trees[5] = new AdjacencyMatrixGraph(true, 3)
            {
                new Edge(0, 1), new Edge(0, 2)
            };
            rgg.SetSeed(777);
            trees[6] = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), 100, 0.2);
            rgg.SetSeed(888);
            trees[7] = rgg.TreeGraph(typeof(AdjacencyListsGraph <SimpleAdjacencyList>), 1000, 1.0);
            rgg.SetSeed(999);
            trees[8] = rgg.TreeGraph(typeof(AdjacencyListsGraph <SimpleAdjacencyList>), 1001, 1.0);
            trees[9] = new AdjacencyListsGraph <SimpleAdjacencyList>(false, 10);
            for (int i = 1; i < 10; ++i)
            {
                trees[9].AddEdge(i - 1, i);
            }

            TestSet treeCenter = new TestSet();

            treeCenter.TestCases.Add(new TreeCenterTestCase(5, null, trees[0], true, new int[] { 1 }));
            treeCenter.TestCases.Add(new TreeCenterTestCase(5, null, trees[1], true, new int[] { 1, 2 }));
            treeCenter.TestCases.Add(new TreeCenterTestCase(5, null, trees[2], true, new int[] { 0 }));
            treeCenter.TestCases.Add(new TreeCenterTestCase(5, null, trees[3], true, new int[] { 0, 1 }));
            treeCenter.TestCases.Add(new TreeCenterTestCase(5, null, trees[4], false, null));
            treeCenter.TestCases.Add(new TreeCenterTestCase(5, new ArgumentException(), trees[5], false, null));
            treeCenter.TestCases.Add(new TreeCenterTestCase(5, null, trees[6], false, null));
            treeCenter.TestCases.Add(new TreeCenterTestCase(5, null, trees[7], true, new int[] { 305, 786 }));
            treeCenter.TestCases.Add(new TreeCenterTestCase(5, null, trees[8], true, new int[] { 60 }));
            treeCenter.TestCases.Add(new TreeCenterTestCase(5, null, trees[9], true, new int[] { 4, 5 }));

            //
            // Odkomentuj odpowiednią linię aby zobaczyć wybrany graf
            // Pamiętaj, że przykłady numerowane są od 1
            //
//        ge.Export(directedGraphs[0]);
//        ge.Export(directedGraphs[1]);
//        ge.Export(directedGraphs[2]);
//        ge.Export(directedGraphs[3]);
//        ge.Export(directedGraphs[4]);
//        ge.Export(directedGraphs[5]);
//        ge.Export(directedGraphs[6]);
//        ge.Export(directedGraphs[7]);
//        ge.Export(undirectedGraphs[0]);
//        ge.Export(undirectedGraphs[1]);
//        ge.Export(undirectedGraphs[2]);
//        ge.Export(undirectedGraphs[3]);
//        ge.Export(undirectedGraphs[4]);
//        ge.Export(undirectedGraphs[5]);
//        ge.Export(trees[0]);
//        ge.Export(trees[1]);
//        ge.Export(trees[2]);
//        ge.Export(trees[3]);
//        ge.Export(trees[4]);
//        ge.Export(trees[5]);
//        ge.Export(trees[6]);
//        ge.Export(trees[7]);
//        ge.Export(trees[8]);

            Console.WriteLine("\nCycle Finding\n");

            FindCycleTestCase.ResultOnly = true;
            Console.WriteLine("\nDirected Graphs - result only");
            findCycleDirected.PreformTests(verbose: true, checkTimeLimit: false);
            Console.WriteLine("\nUndirected Graphs - result only");
            findCycleUndirected.PreformTests(verbose: true, checkTimeLimit: false);

            FindCycleTestCase.ResultOnly = false;
            Console.WriteLine("\nDirected Graphs - full funcionality");
            findCycleDirected.PreformTests(verbose: true, checkTimeLimit: false, forceExecution: false);
            Console.WriteLine("\nUndirected Graphs - full funcionality");
            findCycleUndirected.PreformTests(verbose: true, checkTimeLimit: false, forceExecution: false);

            Console.WriteLine("\nTree Center\n");
            TreeCenterTestCase.ResultOnly = true;
            Console.WriteLine("\nResult only");
            treeCenter.PreformTests(verbose: true, checkTimeLimit: false);
            Console.WriteLine("\nFull funcionality");
            TreeCenterTestCase.ResultOnly = false;
            treeCenter.PreformTests(verbose: true, checkTimeLimit: false, forceExecution: false);
        }
Example #2
0
        static void Main(string[] args)
        {
            GraphExport          ge  = new GraphExport();
            RandomGraphGenerator rgg = new RandomGraphGenerator();

            Graph[] directedGraphs = new Graph[8];
            directedGraphs[0] = new AdjacencyListsGraph <AVLAdjacencyList>(true, 3)
            {
                new Edge(0, 1), new Edge(1, 2), new Edge(2, 0)
            };
            directedGraphs[1] = new AdjacencyListsGraph <SimpleAdjacencyList>(true, 3)
            {
                new Edge(0, 1), new Edge(1, 2), new Edge(2, 1)
            };
            directedGraphs[2] = new AdjacencyMatrixGraph(true, 4)
            {
                new Edge(0, 1), new Edge(0, 2), new Edge(1, 3), new Edge(2, 3)
            };
            directedGraphs[3] = new AdjacencyListsGraph <HashTableAdjacencyList>(true, 10);
            directedGraphs[4] = new AdjacencyMatrixGraph(true, 10)
            {
                new Edge(0, 1), new Edge(0, 2), new Edge(0, 3), new Edge(2, 4), new Edge(2, 5), new Edge(2, 6),
                new Edge(5, 7), new Edge(5, 8), new Edge(5, 9), new Edge(6, 5), new Edge(7, 8), new Edge(8, 2)
            };
            rgg.SetSeed(111);
            directedGraphs[5] = rgg.DirectedGraph(typeof(AdjacencyMatrixGraph), 100, 0.2);
            rgg.SetSeed(222);
            directedGraphs[6] = rgg.DirectedCycle(typeof(AdjacencyListsGraph <SimpleAdjacencyList>), 1000);
            rgg.SetSeed(333);
            directedGraphs[7] = rgg.DAG(typeof(AdjacencyMatrixGraph), 200, 0.2, 1, 1);

            TestSet findCycleDirected = new TestSet();

            findCycleDirected.TestCases.Add(new FindCycleTestCase(5, null, directedGraphs[0], true));
            findCycleDirected.TestCases.Add(new FindCycleTestCase(5, null, directedGraphs[1], true));
            findCycleDirected.TestCases.Add(new FindCycleTestCase(5, null, directedGraphs[2], false));
            findCycleDirected.TestCases.Add(new FindCycleTestCase(5, null, directedGraphs[3], false));
            findCycleDirected.TestCases.Add(new FindCycleTestCase(5, null, directedGraphs[4], true));
            findCycleDirected.TestCases.Add(new FindCycleTestCase(5, null, directedGraphs[5], true));
            findCycleDirected.TestCases.Add(new FindCycleTestCase(5, null, directedGraphs[6], true));
            findCycleDirected.TestCases.Add(new FindCycleTestCase(5, null, directedGraphs[7], false));

            Graph[] undirectedGraphs = new Graph[6];
            undirectedGraphs[0] = new AdjacencyListsGraph <AVLAdjacencyList>(false, 3)
            {
                new Edge(0, 1), new Edge(1, 2), new Edge(2, 0)
            };
            undirectedGraphs[1] = new AdjacencyListsGraph <SimpleAdjacencyList>(false, 4)
            {
                new Edge(0, 1), new Edge(1, 2), new Edge(2, 3), new Edge(3, 1)
            };
            undirectedGraphs[2] = new AdjacencyListsGraph <HashTableAdjacencyList>(false, 10);
            undirectedGraphs[3] = new AdjacencyMatrixGraph(false, 10)
            {
                new Edge(0, 1), new Edge(0, 2), new Edge(0, 3), new Edge(2, 4), new Edge(2, 5), new Edge(2, 6),
                new Edge(5, 7), new Edge(5, 8), new Edge(5, 9), new Edge(8, 2)
            };
            rgg.SetSeed(444);
            undirectedGraphs[4] = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), 100, 0.2);
            rgg.SetSeed(555);
            undirectedGraphs[5] = rgg.TreeGraph(typeof(AdjacencyListsGraph <SimpleAdjacencyList>), 1000, 1.0);

            TestSet findCycleUndirected = new TestSet();

            findCycleUndirected.TestCases.Add(new FindCycleTestCase(5, null, undirectedGraphs[0], true));
            findCycleUndirected.TestCases.Add(new FindCycleTestCase(5, null, undirectedGraphs[1], true));
            findCycleUndirected.TestCases.Add(new FindCycleTestCase(5, null, undirectedGraphs[2], false));
            findCycleUndirected.TestCases.Add(new FindCycleTestCase(5, null, undirectedGraphs[3], true));
            findCycleUndirected.TestCases.Add(new FindCycleTestCase(5, null, undirectedGraphs[4], true));
            findCycleUndirected.TestCases.Add(new FindCycleTestCase(5, null, undirectedGraphs[5], false));

            Graph[] trees = new Graph[10];
            trees[0] = new AdjacencyListsGraph <AVLAdjacencyList>(false, 3)
            {
                new Edge(0, 1), new Edge(1, 2)
            };
            trees[1] = new AdjacencyListsGraph <SimpleAdjacencyList>(false, 4)
            {
                new Edge(0, 1), new Edge(1, 2), new Edge(2, 3)
            };
            trees[2] = new AdjacencyListsGraph <HashTableAdjacencyList>(false, 1);
            trees[3] = new AdjacencyListsGraph <HashTableAdjacencyList>(false, 2)
            {
                new Edge(0, 1)
            };
            trees[4] = new AdjacencyMatrixGraph(false, 5)
            {
                new Edge(1, 3), new Edge(2, 4)
            };
            trees[5] = new AdjacencyMatrixGraph(true, 3)
            {
                new Edge(0, 1), new Edge(0, 2)
            };
            rgg.SetSeed(777);
            trees[6] = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), 100, 0.2);
            rgg.SetSeed(888);
            trees[7] = rgg.TreeGraph(typeof(AdjacencyListsGraph <SimpleAdjacencyList>), 1000, 1.0);
            rgg.SetSeed(999);
            trees[8] = rgg.TreeGraph(typeof(AdjacencyListsGraph <SimpleAdjacencyList>), 1001, 1.0);
            trees[9] = new AdjacencyListsGraph <SimpleAdjacencyList>(false, 10);
            for (int i = 1; i < 10; ++i)
            {
                trees[9].AddEdge(i - 1, i);
            }

            TestSet treeCenter = new TestSet();

            treeCenter.TestCases.Add(new TreeCenterTestCase(5, null, trees[0], true, new int[] { 1 }));
            treeCenter.TestCases.Add(new TreeCenterTestCase(5, null, trees[1], true, new int[] { 1, 2 }));
            treeCenter.TestCases.Add(new TreeCenterTestCase(5, null, trees[2], true, new int[] { 0 }));
            treeCenter.TestCases.Add(new TreeCenterTestCase(5, null, trees[3], true, new int[] { 0, 1 }));
            treeCenter.TestCases.Add(new TreeCenterTestCase(5, null, trees[4], false, null));
            treeCenter.TestCases.Add(new TreeCenterTestCase(5, new ArgumentException(), trees[5], false, null));
            treeCenter.TestCases.Add(new TreeCenterTestCase(5, null, trees[6], false, null));
            treeCenter.TestCases.Add(new TreeCenterTestCase(5, null, trees[7], true, new int[] { 305, 786 }));
            treeCenter.TestCases.Add(new TreeCenterTestCase(5, null, trees[8], true, new int[] { 60 }));
            treeCenter.TestCases.Add(new TreeCenterTestCase(5, null, trees[9], true, new int[] { 4, 5 }));

            //
            // Odkomentuj odpowiednią linię aby zobaczyć wybrany graf
            // Pamiętaj, że przykłady numerowane są od 1
            //
            //ge.Export(directedGraphs[0]);
            //ge.Export(directedGraphs[1]);
            //ge.Export(directedGraphs[2]);
            //ge.Export(directedGraphs[3]);
            //ge.Export(directedGraphs[4]);
            //ge.Export(directedGraphs[5]);
            //ge.Export(directedGraphs[6]);
            //ge.Export(directedGraphs[7]);
            //ge.Export(undirectedGraphs[0]);
            //ge.Export(undirectedGraphs[1]);
            //ge.Export(undirectedGraphs[2]);
            ge.Export(undirectedGraphs[3]);
            //ge.Export(undirectedGraphs[4]);
            //ge.Export(undirectedGraphs[5]);
            //ge.Export(trees[0]);
            //ge.Export(trees[1]);
            //ge.Export(trees[2]);
            //ge.Export(trees[3]);
            //ge.Export(trees[4]);
            //ge.Export(trees[5]);
            //ge.Export(trees[6]);
            //ge.Export(trees[7]);
            //ge.Export(trees[8]);

            long[]    timeElapsed = new long[9];
            Stopwatch stopwatch   = new Stopwatch();


            Console.WriteLine("\nCycle Finding\n");

            FindCycleTestCase.ResultOnly = true;
            Console.WriteLine("\nDirected Graphs - result only");
            stopwatch.Start();
            findCycleDirected.PreformTests(verbose: true, checkTimeLimit: false);
            stopwatch.Stop();
            timeElapsed[0] = stopwatch.ElapsedMilliseconds;
            Console.WriteLine("\nUndirected Graphs - result only");
            stopwatch.Restart();
            findCycleUndirected.PreformTests(verbose: true, checkTimeLimit: false);
            stopwatch.Stop();
            timeElapsed[1] = stopwatch.ElapsedMilliseconds;

            FindCycleTestCase.ResultOnly = false;
            Console.WriteLine("\nDirected Graphs - full funcionality");
            stopwatch.Restart();
            findCycleDirected.PreformTests(verbose: true, checkTimeLimit: false, forceExecution: false);
            stopwatch.Stop();
            timeElapsed[2] = stopwatch.ElapsedMilliseconds;
            Console.WriteLine("\nUndirected Graphs - full funcionality");
            stopwatch.Restart();
            findCycleUndirected.PreformTests(verbose: true, checkTimeLimit: false, forceExecution: false);
            stopwatch.Stop();
            timeElapsed[3] = stopwatch.ElapsedMilliseconds;

            Console.WriteLine("\nTree Center\n");
            TreeCenterTestCase.ResultOnly = true;
            Console.WriteLine("\nResult only");
            stopwatch.Restart();
            treeCenter.PreformTests(verbose: true, checkTimeLimit: false);
            stopwatch.Stop();
            timeElapsed[4] = stopwatch.ElapsedMilliseconds;
            Console.WriteLine("\nFull funcionality");
            TreeCenterTestCase.ResultOnly = false;

            stopwatch.Restart();
            treeCenter.PreformTests(verbose: true, checkTimeLimit: false, forceExecution: false);
            stopwatch.Stop();
            timeElapsed[5] = stopwatch.ElapsedMilliseconds;

            Console.WriteLine("\n\nPerformance metrics for the initial task tests");
            for (int i = 0; i < 6; i++)
            {
                Console.WriteLine("Testset {0}: {1,5} ms", i + 1, timeElapsed[i]);
            }



            // Nie radzę tych grafów próbować eksportować za pomocą GraphViz (mają sporo wierzchołków)
            // Wyjątek stanowi customTrees[0]
            Console.WriteLine("\n\nCustom tests");
            Console.WriteLine("Generating graphs. This may take a while");

            // Cycle in directed graphs
            Graph[] customDirectedGraphs = new Graph[5];
            customDirectedGraphs[0] = rgg.DirectedGraph(typeof(AdjacencyMatrixGraph), 100, 0.7);
            customDirectedGraphs[1] = rgg.DAG(typeof(AdjacencyListsGraph <AVLAdjacencyList>), 1000, 0.9, 1, 1);
            customDirectedGraphs[2] = rgg.DirectedCycle(typeof(AdjacencyListsGraph <AVLAdjacencyList>), 1000);
            customDirectedGraphs[3] = rgg.DirectedGraph(typeof(AdjacencyListsGraph <AVLAdjacencyList>), 1000, 0.5);
            customDirectedGraphs[4] = rgg.DirectedGraph(typeof(AdjacencyListsGraph <AVLAdjacencyList>), 1000, 0.7);

            TestSet customDirectedGraphsTestSet = new TestSet();

            customDirectedGraphsTestSet.TestCases.Add(new FindCycleTestCase(5, null, customDirectedGraphs[0], true));
            customDirectedGraphsTestSet.TestCases.Add(new FindCycleTestCase(5, null, customDirectedGraphs[1], false));
            customDirectedGraphsTestSet.TestCases.Add(new FindCycleTestCase(5, null, customDirectedGraphs[2], true));
            customDirectedGraphsTestSet.TestCases.Add(new FindCycleTestCase(5, null, customDirectedGraphs[3], true));
            customDirectedGraphsTestSet.TestCases.Add(new FindCycleTestCase(5, null, customDirectedGraphs[4], true));


            // Cycle in undirected graphs
            Graph[] customUndirectedGraphs = new Graph[5];
            customUndirectedGraphs[0] = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), 100, 0.7);
            customUndirectedGraphs[1] = rgg.TreeGraph(typeof(AdjacencyListsGraph <AVLAdjacencyList>), 1000, 1);
            customUndirectedGraphs[2] = rgg.UndirectedCycle(typeof(AdjacencyListsGraph <AVLAdjacencyList>), 1000);
            customUndirectedGraphs[3] = rgg.UndirectedGraph(typeof(AdjacencyListsGraph <AVLAdjacencyList>), 1000, 0.5);
            customUndirectedGraphs[4] = rgg.UndirectedGraph(typeof(AdjacencyListsGraph <AVLAdjacencyList>), 1000, 0.7);

            TestSet customUndirectedGraphsTestSet = new TestSet();

            customUndirectedGraphsTestSet.TestCases.Add(new FindCycleTestCase(5, null, customUndirectedGraphs[0], true));
            customUndirectedGraphsTestSet.TestCases.Add(new FindCycleTestCase(5, null, customUndirectedGraphs[1], false));
            customUndirectedGraphsTestSet.TestCases.Add(new FindCycleTestCase(5, null, customUndirectedGraphs[2], true));
            customUndirectedGraphsTestSet.TestCases.Add(new FindCycleTestCase(5, null, customUndirectedGraphs[3], true));
            customUndirectedGraphsTestSet.TestCases.Add(new FindCycleTestCase(5, null, customUndirectedGraphs[4], true));

            // Tree center
            Graph[] customTrees = new Graph[5];
            customTrees[0] = new AdjacencyMatrixGraph(false, 1);
            customTrees[1] = rgg.TreeGraph(typeof(AdjacencyMatrixGraph), 100, 0.5);
            customTrees[2] = rgg.TreeGraph(typeof(AdjacencyListsGraph <SimpleAdjacencyList>), 100, 1);
            customTrees[3] = rgg.TreeGraph(typeof(AdjacencyListsGraph <AVLAdjacencyList>), 1000, 1);
            customTrees[4] = rgg.TreeGraph(typeof(AdjacencyListsGraph <AVLAdjacencyList>), 10000, 1);

            TestSet customTreeSet = new TestSet();

            customTreeSet.TestCases.Add(new TreeCenterTestCase(5, null, customTrees[0], true, new int[] { 0 }));
            customTreeSet.TestCases.Add(new TreeCenterTestCase(5, null, customTrees[1], false, null));
            customTreeSet.TestCases.Add(new TreeCenterTestCase(5, null, customTrees[2], true, new int[] { 77 }));
            customTreeSet.TestCases.Add(new TreeCenterTestCase(5, null, customTrees[3], true, new int[] { 146, 282 }));
            customTreeSet.TestCases.Add(new TreeCenterTestCase(5, null, customTrees[4], true, new int[] { 6780, 8396 }));



            Console.WriteLine("Custom cycle finding in directed graphs");
            stopwatch.Restart();
            customDirectedGraphsTestSet.PreformTests(verbose: true, checkTimeLimit: false, forceExecution: false);
            stopwatch.Stop();
            timeElapsed[6] = stopwatch.ElapsedMilliseconds;

            Console.WriteLine("Custom cycle finding in undirected graphs");
            stopwatch.Restart();
            customUndirectedGraphsTestSet.PreformTests(verbose: true, checkTimeLimit: false, forceExecution: false);
            stopwatch.Stop();
            timeElapsed[7] = stopwatch.ElapsedMilliseconds;

            Console.WriteLine("Custom tree center");
            stopwatch.Restart();
            customTreeSet.PreformTests(verbose: true, checkTimeLimit: false, forceExecution: false);
            stopwatch.Stop();
            timeElapsed[8] = stopwatch.ElapsedMilliseconds;


            Console.WriteLine("\n\nPerformance metrics for the custom tests");
            for (int i = 6; i < timeElapsed.Length; i++)
            {
                Console.WriteLine("Testset {0}: {1,5} ms", i + 1, timeElapsed[i]);
            }
        }
Example #3
0
    public static void Main()
    {
        var ge  = new GraphExport();
        var rgg = new RandomGraphGenerator(123);

        int[]    order;
        string[] desc;
        int[]    ec = new int[3];

        Graph g = new AdjacencyMatrixGraph(false, 5);

        g.AddEdge(0, 1);
        g.AddEdge(0, 4);
        g.AddEdge(1, 2);
        g.AddEdge(2, 0);
        g.AddEdge(2, 3);
        g.AddEdge(3, 4);
        g.AddEdge(4, 3);
        ge.Export(g, null, "G");

        Graph lg = Lab03.LineGraph(g, out desc);

        ge.Export(lg, desc, "LG");

        Graph[] g2 = new Graph[3];
        g2[0] = new AdjacencyMatrixGraph(true, 4);
        g2[0].AddEdge(0, 1);
        g2[0].AddEdge(0, 3);
        g2[0].AddEdge(1, 2);
        g2[0].AddEdge(3, 2);

        g2[1] = rgg.DAG(typeof(AdjacencyMatrixGraph), 100, 0.9, 1, 1);
        g2[2] = rgg.DAG(typeof(AdjacencyListsGraph <SimplyAdjacencyList>), 1000, 0.2, 1, 1);

        ec[0] = g2[0].EdgesCount;
        ec[1] = g2[1].EdgesCount;
        ec[2] = g2[2].EdgesCount;

        Console.WriteLine("Sortowanie topologiczne - DFS");
        for (int i = 0; i < 3; ++i)
        {
            order = Lab03.TopologicalSort_DFS(g2[i]);
            Console.WriteLine("  test {0} : {1}", i, TopologicalSortTest(g2[i], order));
        }

        if (ec[0] != g2[0].EdgesCount || ec[1] != g2[1].EdgesCount || ec[2] != g2[2].EdgesCount)
        {
            Console.WriteLine("  Blad - zmieniono graf");
        }

        ec[0] = g2[0].EdgesCount;
        ec[1] = g2[1].EdgesCount;
        ec[2] = g2[2].EdgesCount;

        Console.WriteLine("Sortowanie topologiczne - zrodla 1");
        for (int i = 0; i < 3; ++i)
        {
            order = Lab03.TopologicalSort_V0(g2[i]);
            Console.WriteLine("  test {0} : {1}", i, TopologicalSortTest(g2[i], order));
        }

        if (ec[0] != g2[0].EdgesCount || ec[1] != g2[1].EdgesCount || ec[2] != g2[2].EdgesCount)
        {
            Console.WriteLine("  Blad - zmieniono graf");
        }

        Graph[] g3 = new Graph[3];
        g3[0] = g2[0].Clone();
        g3[0].AddEdge(1, 0);
        g3[1] = rgg.DirectedGraph(typeof(AdjacencyMatrixGraph), 100, 0.9, 1, 1);
        g3[2] = rgg.DirectedGraph(typeof(AdjacencyListsGraph <SimplyAdjacencyList>), 1000, 0.2, 1, 1);

        ec[0] = g3[0].EdgesCount;
        ec[1] = g3[1].EdgesCount;
        ec[2] = g3[2].EdgesCount;

        Console.WriteLine("Sortowanie topologiczne - zrodla 2");
        for (int i = 0; i < 3; ++i)
        {
            order = Lab03.TopologicalSort_V0(g3[i]);
            Console.WriteLine("  test {0} : {1}", i, order == null);
        }

        if (ec[0] != g3[0].EdgesCount || ec[1] != g3[1].EdgesCount || ec[2] != g3[2].EdgesCount)
        {
            Console.WriteLine("  Blad - zmieniono graf");
        }
    }
Example #4
0
    public static void Main()
    {
        var ge  = new GraphExport();
        var rgg = new RandomGraphGenerator();

        int[] scc;
        int   n, w;

        string[] desc;
        int[]    sccc = { 8, 17, 1000 };
        IGraph   mst;

        int[] mstw = { 47, 3998, 40533 };


        IGraph g1 = new AdjacencyMatrixGraph(true, 16);

        g1.AddEdge(0, 5);
        g1.AddEdge(1, 0);
        g1.AddEdge(1, 2);
        g1.AddEdge(1, 7);
        g1.AddEdge(2, 3);
        g1.AddEdge(3, 1);
        g1.AddEdge(3, 7);
        g1.AddEdge(4, 15);
        g1.AddEdge(5, 4);
        g1.AddEdge(5, 6);
        g1.AddEdge(6, 7);
        g1.AddEdge(7, 6);
        g1.AddEdge(7, 8);
        g1.AddEdge(8, 9);
        g1.AddEdge(10, 3);
        g1.AddEdge(12, 13);
        g1.AddEdge(13, 14);
        g1.AddEdge(14, 12);
        g1.AddEdge(15, 0);

        IGraph g2 = new AdjacencyMatrixGraph(false, 15);

        g2.AddEdge(0, 1, 3);
        g2.AddEdge(0, 4, 5);
        g2.AddEdge(1, 4, 6);
        g2.AddEdge(1, 5, 4);
        g2.AddEdge(2, 6, 5);
        g2.AddEdge(4, 7, 8);
        g2.AddEdge(4, 8, 2);
        g2.AddEdge(4, 10, 12);
        g2.AddEdge(5, 8, 1);
        g2.AddEdge(5, 9, 7);
        g2.AddEdge(6, 11, 4);
        g2.AddEdge(6, 14, 5);
        g2.AddEdge(7, 8, 9);
        g2.AddEdge(8, 12, 3);
        g2.AddEdge(10, 12, 2);
        g2.AddEdge(10, 13, 3);

        IGraph[] scc_test = new IGraph[3];
        scc_test[0] = g1;
        rgg.SetSeed(500);
        scc_test[1] = rgg.DirectedGraph(typeof(AdjacencyListsGraph), 1000, 0.005);
        scc_test[2] = rgg.DAG(typeof(AdjacencyMatrixGraph), 1000, 0.3, 1, 1);

        IGraph[] mst_test = new IGraph[3];
        mst_test[0] = g2;
        mst_test[1] = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), 100, 0.3, 1, 1000);
        mst_test[2] = rgg.UndirectedGraph(typeof(AdjacencyListsGraph), 1000, 0.03, 1, 1000);

        Console.WriteLine();
        for (int i = 0; i < scc_test.Length; ++i)
        {
            n = scc_test[i].Tarjan(out scc);
            Console.WriteLine("Liczba silnie spojnych skladowych: {0,4},    powinno byc {1,4}", n, sccc[i]);
            if (i > 0)
            {
                continue;
            }
            desc = new string[scc_test[i].VerticesCount];
            for (int v = 0; v < scc_test[i].VerticesCount; ++v)
            {
                desc[v] = string.Format("{0}:{1}", v, scc[v]);
            }
            ge.Export(scc_test[i], desc, "scc");
        }

        Console.WriteLine();
        for (int i = 0; i < mst_test.Length; ++i)
        {
            w = mst_test[i].Boruvka(out mst);
            Console.WriteLine("Waga minimalnego drzewa rozpinajacego: {0,5},    powinno byc {1,5}", w, mstw[i]);
            if (i > 0)
            {
                continue;
            }
            ge.Export(mst_test[i], null, "graph");
            ge.Export(mst, null, "mst");
        }

        Console.WriteLine();
    }