Exemple #1
0
    public static void Main()
    {
        int[] backtrackingColors;
        int[] greedyColors;
        int n,i,j,mb,mg;
        long counter0, counter1, counter2;
        string[] message1 = { "Zwykly maly graf:",
                              "Maly dwudzielny:",
                              "Mala klika:" };
        int[] bestColorsNumbers1 = { 4, 2, 9 };
        string[] message2 = { "Zwykly graf:",
                              "Graf dwudzielny:",
                              "Cykl parzysty:",
                              "Klika:" };
        int[] bestColorsNumbers2 = { 6, 2, 2, 200 };
        string[] message3 = { "Zwykly duzy graf:",
                              "Duzy dwudzielny:",
                              "Duza klika:" };
        int[] bestColorsNumbers3 = { 59, 2, 4000 };
        IGraph[] g1 = new IGraph[message1.Length];
        IGraph[] g2 = new IGraph[message2.Length];
        IGraph[] g3 = new IGraph[message3.Length];
        var rgg = new RandomGraphGenerator();
        //GraphExport ge = new GraphExport(true, "C:\\Users\\polgrabiat\\Desktop\\Graphviz2.26.3\\Graphviz2.26.3\\bin\\dot.exe");

        Console.WriteLine();
        Console.WriteLine("Generowanie grafow");
        Console.WriteLine();

        rgg.SetSeed(101);
        g1[0] = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph),8,0.5);
        rgg.SetSeed(102);
        g1[1] = rgg.BipariteGraph(typeof(AdjacencyMatrixGraph),5,3,0.75);
        n=9;
        g1[2] = new AdjacencyMatrixGraph(false,n);
        for ( i=0 ; i<n ; ++i )
            for ( j=i+1 ; j<n ; ++ j )
                g1[2].AddEdge(i,j);

        rgg.SetSeed(103);
        g2[0] = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), 20, 0.5);
        rgg.SetSeed(104);
        g2[1] = rgg.BipariteGraph(typeof(AdjacencyMatrixGraph), 30, 20, 0.25);
        n = 50;
        g2[2] = new AdjacencyListsGraph(false, n);
        for (i = 1; i < n; ++i)
            g2[2].AddEdge(i - 1, i);
        g2[2].AddEdge(n - 1, 0);
        rgg.SetSeed(105);
        g2[2] = rgg.Permute(g2[2]);
        n = 200;
        g2[3] = new AdjacencyMatrixGraph(false, n);
        for (i = 0; i < n; ++i)
        {
            for (j = i + 1; j < n; ++j)
                g2[3].AddEdge(i, j);
        }

        rgg.SetSeed(106);
        g3[0] = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), 75, 0.99);
        rgg.SetSeed(107);
        g3[1] = rgg.BipariteGraph(typeof(AdjacencyMatrixGraph), 2000, 2000, 0.55);
        n = 5000;
        g3[2] = new AdjacencyMatrixGraph(false, n);
        for (i = 0; i < n; ++i)
        {
            for (j = i + 1; j < n; ++j)
                g3[2].AddEdge(i, j);
        }

        //Console.WriteLine("{0}", g3[2].EdgesCount);

        Console.WriteLine("Grafy za 1 pkt");
        Console.WriteLine();
        for ( i=0 ; i<g1.Length ; ++i )
            {
           //     ge.Export(g1[i], "ala");
            counter0=Graph.Counter;
            mb=g1[i].BacktrackingColor(out backtrackingColors);
            counter1=Graph.Counter;
            mg=g1[i].GreedyColor(out greedyColors);
            counter2=Graph.Counter;
            Console.WriteLine("{0,-17}  liczba wierzcholkow  {1,4},  optymalna liczba kolorow  {2,4}", message1[i], g1[i].VerticesCount, bestColorsNumbers1[i]);
            Console.WriteLine("  Backtracking:    liczba kolorow  {0,4},  zlozonosc  {1,8}", mb, counter1-counter0);
            Console.WriteLine("  Greedy:          liczba kolorow  {0,4},  zlozonosc  {1,8}", mg, counter2-counter1);
            Console.WriteLine();
            }

        Console.WriteLine("Grafy za 2 pkt");
        Console.WriteLine();
        for (i = 0; i < g2.Length; ++i)
        {
            counter0 = Graph.Counter;
            mb = g2[i].BacktrackingColor(out backtrackingColors);
            counter1 = Graph.Counter;
            mg = g2[i].GreedyColor(out greedyColors);
            counter2 = Graph.Counter;
            Console.WriteLine("{0,-17}  liczba wierzcholkow  {1,4},  optymalna liczba kolorow  {2,4}", message2[i], g2[i].VerticesCount, bestColorsNumbers2[i]);
            Console.WriteLine("  Backtracking:    liczba kolorow  {0,4},  zlozonosc  {1,8}", mb, counter1 - counter0);
            Console.WriteLine("  Greedy:          liczba kolorow  {0,4},  zlozonosc  {1,8}", mg, counter2 - counter1);
            Console.WriteLine();
        }

        Console.WriteLine("Grafy za 3 pkt");
        Console.WriteLine();
        for (i = 0; i < g3.Length; ++i)
        {
            counter0 = Graph.Counter;
            mb = g3[i].BacktrackingColor(out backtrackingColors);
            counter1 = Graph.Counter;
            mg = g3[i].GreedyColor(out greedyColors);
            counter2 = Graph.Counter;
            Console.WriteLine("{0,-17}  liczba wierzcholkow  {1,4},  optymalna liczba kolorow  {2,4}", message3[i], g3[i].VerticesCount, bestColorsNumbers3[i]);
            Console.WriteLine("  Backtracking:    liczba kolorow  {0,4},  zlozonosc  {1,8}", mb, counter1 - counter0);
            Console.WriteLine("  Greedy:          liczba kolorow  {0,4},  zlozonosc  {1,8}", mg, counter2 - counter1);
            Console.WriteLine();
        }

        Console.WriteLine("Koniec");
        Console.WriteLine();
    }
Exemple #2
0
        public override void PrepareTestSets()
        {
            var rgg = new RandomGraphGenerator(2018);
            int n   = 14;
            int n1  = 8;

            Graph[]  graphs       = new Graph[n];
            string[] descriptions = new string[n];

            // do czesci 1
            int[]  sizes        = new int[n];
            bool[] bool_results = new bool[n];
            int[]  limits1      = new int[n];
            // do czesci 2
            double[] maximal_results = new double[n];
            int[]    limits2         = new int[n];


            //przyklady z zajec
            //sciezka P10
            graphs[0] = new AdjacencyMatrixGraph(false, 10);
            graphs[0].AddEdge(0, 1, 5);
            graphs[0].AddEdge(1, 2, 4);
            graphs[0].AddEdge(2, 3, 3);
            graphs[0].AddEdge(3, 4, 2);
            graphs[0].AddEdge(4, 5, 3);
            graphs[0].AddEdge(5, 6, 1);
            graphs[0].AddEdge(6, 7, 6);
            graphs[0].AddEdge(7, 8, 2);
            graphs[0].AddEdge(8, 9, 1);
            descriptions[0]    = "Sciezka P10";
            sizes[0]           = 3;
            bool_results[0]    = true;
            maximal_results[0] = 13;

            //cykl C5
            graphs[1] = new AdjacencyMatrixGraph(false, 5);
            graphs[1].AddEdge(0, 1, 1);
            graphs[1].AddEdge(1, 2, 2);
            graphs[1].AddEdge(2, 3, 3);
            graphs[1].AddEdge(3, 4, 4);
            graphs[1].AddEdge(4, 0, 0);
            descriptions[1]    = "Cykl C5";
            sizes[1]           = 2;
            bool_results[1]    = false;
            maximal_results[1] = 4;

            //cykl C10
            graphs[2] = new AdjacencyMatrixGraph(false, 10);
            graphs[2].AddEdge(0, 1, 1.08);
            graphs[2].AddEdge(1, 2, 6.52);
            graphs[2].AddEdge(2, 3, 3);
            graphs[2].AddEdge(3, 4, 4);
            graphs[2].AddEdge(4, 5, 0);
            graphs[2].AddEdge(5, 6, 1.99);
            graphs[2].AddEdge(6, 7, 2.56);
            graphs[2].AddEdge(7, 8, 3.9);
            graphs[2].AddEdge(8, 9, 4.12);
            graphs[2].AddEdge(9, 0, 0);
            descriptions[2]    = "Cykl C10";
            sizes[2]           = 2;
            bool_results[2]    = true;
            maximal_results[2] = 12.63;

            //klika K5
            graphs[3]          = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), 5, 1, -9, -1);
            descriptions[3]    = "Klika K5";
            sizes[3]           = 1;
            bool_results[3]    = true;
            maximal_results[3] = 0;

            //prawie klika K10 (bez kilku krawedzi)
            graphs[4]       = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), 10, 1, -9, 99);
            descriptions[4] = "Klika K10 bez kilku krawedzi";
            graphs[4].DelEdge(0, 1);
            graphs[4].DelEdge(0, 2);
            graphs[4].DelEdge(0, 3);
            graphs[4].DelEdge(4, 5);
            graphs[4].DelEdge(4, 6);
            graphs[4].DelEdge(4, 7);
            sizes[4]           = 1;
            bool_results[4]    = true;
            maximal_results[4] = 98;

            //jakis sobie graf
            graphs[5] = new AdjacencyListsGraph <SimpleAdjacencyList>(false, 9);
            graphs[5].AddEdge(0, 1, 0.33);
            graphs[5].AddEdge(1, 3, 1.5);
            graphs[5].AddEdge(1, 6, 10.1);
            graphs[5].AddEdge(2, 3, 1);
            graphs[5].AddEdge(2, 4, 1);
            graphs[5].AddEdge(2, 5, 1);
            graphs[5].AddEdge(2, 8, 3);
            graphs[5].AddEdge(3, 7, 3.33);
            graphs[5].AddEdge(4, 5, 3.7);
            graphs[5].AddEdge(7, 8, 0.7);
            descriptions[5]    = "Pewien graf o 9 wierzcholkach";
            sizes[5]           = 3;
            bool_results[5]    = true;
            maximal_results[5] = 14.5;

            //graf dwudzielny
            graphs[6] = new AdjacencyListsGraph <SimpleAdjacencyList>(false, 10);
            graphs[6].AddEdge(0, 5, 3);
            graphs[6].AddEdge(0, 6, 3);
            graphs[6].AddEdge(1, 7, 4);
            graphs[6].AddEdge(1, 8, 4);
            graphs[6].AddEdge(2, 6, 1);
            graphs[6].AddEdge(2, 8, 1);
            graphs[6].AddEdge(2, 9, 1);
            graphs[6].AddEdge(3, 9, 2);
            graphs[6].AddEdge(4, 9, 3);
            descriptions[6]    = "Graf dwudzielny o 10 wierzcholkach";
            sizes[6]           = 3;
            bool_results[6]    = true;
            maximal_results[6] = 10;

            //gwiazda
            int g7vc = 200;

            graphs[7] = new AdjacencyListsGraph <AVLAdjacencyList>(false, g7vc);
            for (int i = 1; i < g7vc; ++i)
            {
                graphs[7].AddEdge(0, i, i);
            }
            descriptions[7]    = "Nieskierowana gwiazda";
            sizes[7]           = 2;
            bool_results[7]    = false;
            maximal_results[7] = 199;


            //Wieksze testy, z wydajnoscia
            //gesty duzy graf losowy nr 1
            int g8vc = 250;

            rgg.SetSeed(123451);
            graphs[8]          = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), g8vc, 0.9, -9, 9);
            descriptions[8]    = "Gesty graf losowy nr 1";
            sizes[8]           = 3;
            bool_results[8]    = true;
            maximal_results[8] = 21;
            limits1[8]         = 600;
            limits2[8]         = 600;

            //gesty duzy graf losowy nr 2
            int g9vc = 200;

            rgg.SetSeed(123452);
            graphs[9]          = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), g9vc, 0.95, -9, 99);
            descriptions[9]    = "Gesty graf losowy nr 2";
            sizes[9]           = 3;
            bool_results[9]    = false;
            maximal_results[9] = 194;
            limits1[9]         = 12;
            limits2[9]         = 12;

            //rzadki graf losowy nr 1
            int g10vc = 45;

            rgg.SetSeed(123453);
            graphs[10]          = rgg.UndirectedGraph(typeof(AdjacencyListsGraph <SimpleAdjacencyList>), g10vc, 0.1, -9, 99);
            descriptions[10]    = "Rzadki graf losowy nr 1";
            sizes[10]           = 5;
            bool_results[10]    = true;
            maximal_results[10] = 743;
            limits1[10]         = 1;
            limits2[10]         = 65;

            //rzadki graf losowy nr 2
            int g11vc = 45;

            rgg.SetSeed(123454);
            graphs[11]          = rgg.UndirectedGraph(typeof(AdjacencyListsGraph <SimpleAdjacencyList>), g11vc, 0.04, -9, 99);
            descriptions[11]    = "Rzadki graf losowy nr 2";
            sizes[11]           = 7;
            bool_results[11]    = true;
            maximal_results[11] = 675;
            limits1[11]         = 1;
            limits2[11]         = 12;

            //cykl C35
            int g12vc = 35;

            graphs[12] = new AdjacencyListsGraph <HashTableAdjacencyList>(false, g12vc);
            for (int i = 1; i < g12vc; ++i)
            {
                graphs[12].AddEdge(i - 1, i, i);
            }
            graphs[12].AddEdge(g12vc - 1, 0, 1);
            descriptions[12]    = "Cykl C35";
            sizes[12]           = 11;
            bool_results[12]    = true;
            maximal_results[12] = 209;
            limits1[12]         = 378903433;
            limits2[12]         = 22;

            //duza klika K200
            int g13vc = 200;

            rgg.SetSeed(123455);
            graphs[13]          = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), g13vc, 1, -9, 99);
            descriptions[13]    = "Klika K200";
            sizes[13]           = 100;
            bool_results[13]    = false;
            maximal_results[13] = 99;
            limits1[13]         = 10;
            limits2[13]         = 10;

            TestSets["LabInducedMatchingTests"]                   = new TestSet(new Lab09(), "Part 1 - induced matching with given size [1.5]");
            TestSets["LabMaximalInducedMatchingTests"]            = new TestSet(new Lab09(), "Part 2 - maximal induced matching [1.5]");
            TestSets["LabInducedMatchingPerformanceTests"]        = new TestSet(new Lab09(), "Part 1 - induced matching with given size - performance tests[0.5]");
            TestSets["LabMaximalInducedMatchingPerformanceTests"] = new TestSet(new Lab09(), "Part 2 - maximal induced matching - performance tests[0.5]");

            for (int i = 0; i < n; ++i)
            {
                if (i < n1)
                {
                    //TestSets["LabInducedMatchingTests"].TestCases.Add(new InducedMatchingTestCase(1, null, descriptions[i], graphs[i], sizes[i], bool_results[i]));
                    TestSets["LabMaximalInducedMatchingTests"].TestCases.Add(new MaximalInducedMatchingTestCase(1, null, descriptions[i], graphs[i], maximal_results[i]));
                }
                else
                {
                    //TestSets["LabInducedMatchingPerformanceTests"].TestCases.Add(new InducedMatchingTestCase(limits1[i], null, descriptions[i], graphs[i], sizes[i], bool_results[i]));
                    TestSets["LabMaximalInducedMatchingPerformanceTests"].TestCases.Add(new MaximalInducedMatchingTestCase(limits2[i], null, descriptions[i], graphs[i], maximal_results[i]));
                }
            }
        }
Exemple #3
0
        public override void PrepareTestSets()
        {
            var rgg = new RandomGraphGenerator(12345);
            int n   = 6;

            Graph[]         graphs     = new Graph[n];
            Graph[]         squares    = new Graph[n];
            Graph[]         linegraphs = new Graph[n];
            List <string[]> names      = new List <string[]>(); //description of edges
            List <int[]>    colors     = new List <int[]>();

            int[]   chn        = new int[n]; //chromatic number
            Graph[] sec_graphs = new Graph[n];
            int[]   schi       = new int[n]; //strong chromatic index


            //graphs[0] = new AdjacencyMatrixGraph(true, 500);
            //graphs[0].AddEdge(1, 432);
            //graphs[0].AddEdge(432, 493);
            //graphs[0].AddEdge(493, 424);

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

            //graphs[0] = new AdjacencyMatrixGraph(true, 2);
            //graphs[0].AddEdge(0, 1);
            //graphs[0].AddEdge(1, 0);
            ////graphs[0].AddEdge(3, 2);


            //graphs[0] = new AdjacencyMatrixGraph(false, 5);
            //graphs[0].AddEdge(0, 1);
            //graphs[0].AddEdge(0, 3);
            //graphs[0].AddEdge(1, 2);
            //graphs[0].AddEdge(2, 0);
            //graphs[0].AddEdge(2, 3);
            //graphs[0].AddEdge(3, 4);

            graphs[1] = new AdjacencyMatrixGraph(false, 6);
            graphs[1].AddEdge(0, 1);
            graphs[1].AddEdge(1, 2);
            graphs[1].AddEdge(2, 3);
            graphs[1].AddEdge(3, 4);
            graphs[1].AddEdge(4, 5);

//            graphs[2] = new AdjacencyListsGraph<SimpleAdjacencyList>(false, 9);
            graphs[2] = new AdjacencyMatrixGraph(false, 9);
            graphs[2].AddEdge(0, 3);
            graphs[2].AddEdge(1, 0);
            graphs[2].AddEdge(6, 0);
            graphs[2].AddEdge(1, 5);
            graphs[2].AddEdge(5, 4);
            graphs[2].AddEdge(5, 2);
            graphs[2].AddEdge(5, 6);
            graphs[2].AddEdge(6, 7);
            graphs[2].AddEdge(7, 8);

            graphs[3] = new AdjacencyMatrixGraph(false, 5);
            graphs[3].AddEdge(0, 1);
            graphs[3].AddEdge(1, 2);
            graphs[3].AddEdge(2, 3);
            graphs[3].AddEdge(3, 4);
            graphs[3].AddEdge(4, 0);

            graphs[4] = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), 5, 1.0);

            int g5vc = 9000;

            graphs[5] = new AdjacencyListsGraph <SimpleAdjacencyList>(true, g5vc);
            for (int i = 1; i < g5vc; ++i)
            {
                graphs[5].AddEdge(i - 1, i);
            }
            graphs[5].AddEdge(g5vc - 1, 0);

            //squares[0] = graphs[0].Clone();
            //squares[0].AddEdge(0, 4);
            //squares[0].AddEdge(1, 3);
            //squares[0].AddEdge(2, 4);

            squares[0] = graphs[0].Clone();


            squares[1] = graphs[1].Clone();
            squares[1].AddEdge(0, 2);
            squares[1].AddEdge(1, 3);
            squares[1].AddEdge(2, 4);
            squares[1].AddEdge(3, 5);

            squares[2] = graphs[2].Clone();
            squares[2].AddEdge(0, 5);
            squares[2].AddEdge(0, 6);
            squares[2].AddEdge(0, 7);
            squares[2].AddEdge(1, 2);
            squares[2].AddEdge(1, 3);
            squares[2].AddEdge(1, 4);
            squares[2].AddEdge(1, 6);
            squares[2].AddEdge(2, 4);
            squares[2].AddEdge(2, 6);
            squares[2].AddEdge(3, 6);
            squares[2].AddEdge(4, 6);
            squares[2].AddEdge(5, 7);
            squares[2].AddEdge(6, 8);

            squares[3] = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), 5, 1.0);
            squares[4] = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), 5, 1.0);

            squares[5] = new AdjacencyListsGraph <SimpleAdjacencyList>(true, g5vc);
            for (int i = 0; i < g5vc; ++i)
            {
                squares[5].AddEdge(i, (i + 1) % g5vc);
                squares[5].AddEdge(i, (i + 2) % g5vc);
            }

            linegraphs[0] = new AdjacencyMatrixGraph(false, 6);
            linegraphs[0].AddEdge(0, 2);
            linegraphs[0].AddEdge(0, 3);
            linegraphs[0].AddEdge(0, 4);

            linegraphs[0].AddEdge(1, 2);
            linegraphs[0].AddEdge(1, 3);
            linegraphs[0].AddEdge(1, 4);
            linegraphs[0].AddEdge(2, 5);
            linegraphs[0].AddEdge(3, 4);
            linegraphs[0].AddEdge(3, 5);
            linegraphs[0].AddEdge(4, 5);



            //



            //linegraphs[0].AddEdge(2, 2);

            //linegraphs[0].AddEdge(0, 1);
            //linegraphs[0].AddEdge(0, 2);
            //linegraphs[0].AddEdge(0, 3);
            //linegraphs[0].AddEdge(1, 2);
            //linegraphs[0].AddEdge(1, 3);
            //linegraphs[0].AddEdge(1, 4);
            //linegraphs[0].AddEdge(2, 4);
            //linegraphs[0].AddEdge(2, 5);
            //linegraphs[0].AddEdge(3, 4);
            //linegraphs[0].AddEdge(4, 5);

            linegraphs[1] = new AdjacencyMatrixGraph(false, 5);
            linegraphs[1].AddEdge(0, 1);
            linegraphs[1].AddEdge(1, 2);
            linegraphs[1].AddEdge(2, 3);
            linegraphs[1].AddEdge(3, 4);

//            linegraphs[2] = new AdjacencyListsGraph<SimpleAdjacencyList>(false, 9);
            linegraphs[2] = new AdjacencyMatrixGraph(false, 9);
            linegraphs[2].AddEdge(0, 1);
            linegraphs[2].AddEdge(0, 2);
            linegraphs[2].AddEdge(0, 3);
            linegraphs[2].AddEdge(1, 2);
            linegraphs[2].AddEdge(2, 6);
            linegraphs[2].AddEdge(2, 7);
            linegraphs[2].AddEdge(3, 4);
            linegraphs[2].AddEdge(3, 5);
            linegraphs[2].AddEdge(3, 6);
            linegraphs[2].AddEdge(4, 5);
            linegraphs[2].AddEdge(4, 6);
            linegraphs[2].AddEdge(5, 6);
            linegraphs[2].AddEdge(6, 7);
            linegraphs[2].AddEdge(7, 8);

            linegraphs[3] = new AdjacencyMatrixGraph(false, 5);
            linegraphs[3].AddEdge(0, 1);
            linegraphs[3].AddEdge(0, 2);
            linegraphs[3].AddEdge(1, 4);
            linegraphs[3].AddEdge(2, 3);
            linegraphs[3].AddEdge(3, 4);

            linegraphs[4] = new AdjacencyMatrixGraph(false, 10);
            linegraphs[4].AddEdge(0, 1);
            linegraphs[4].AddEdge(0, 2);
            linegraphs[4].AddEdge(0, 3);
            linegraphs[4].AddEdge(0, 4);
            linegraphs[4].AddEdge(0, 5);
            linegraphs[4].AddEdge(0, 6);
            linegraphs[4].AddEdge(1, 2);
            linegraphs[4].AddEdge(1, 3);
            linegraphs[4].AddEdge(1, 4);
            linegraphs[4].AddEdge(1, 7);
            linegraphs[4].AddEdge(1, 8);
            linegraphs[4].AddEdge(2, 3);
            linegraphs[4].AddEdge(2, 5);
            linegraphs[4].AddEdge(2, 7);
            linegraphs[4].AddEdge(2, 9);
            linegraphs[4].AddEdge(3, 6);
            linegraphs[4].AddEdge(3, 8);
            linegraphs[4].AddEdge(3, 9);
            linegraphs[4].AddEdge(4, 5);
            linegraphs[4].AddEdge(4, 6);
            linegraphs[4].AddEdge(4, 7);
            linegraphs[4].AddEdge(4, 8);
            linegraphs[4].AddEdge(5, 6);
            linegraphs[4].AddEdge(5, 7);
            linegraphs[4].AddEdge(5, 9);
            linegraphs[4].AddEdge(6, 8);
            linegraphs[4].AddEdge(6, 9);
            linegraphs[4].AddEdge(7, 8);
            linegraphs[4].AddEdge(7, 9);
            linegraphs[4].AddEdge(8, 9);

            linegraphs[5] = new AdjacencyListsGraph <SimpleAdjacencyList>(false, g5vc);
            for (int i = 0; i < g5vc; ++i)
            {
                linegraphs[5].AddEdge(i, (i + 1) % g5vc);
            }

            names.Add(new string[6]);
            names[0][0] = ("[0, 1]");
            names[0][1] = ("[0, 2]");
            names[0][2] = ("[1, 0]");
            names[0][3] = ("[1, 2]");
            names[0][4] = ("[2, 0]");
            names[0][5] = ("[2, 1]");


            //names[0][1] = ("[0, 2]");
            //names[0][2] = ("[0, 3]");
            //names[0][3] = ("[1, 2]");
            //names[0][4] = ("[2, 3]");
            //names[0][5] = ("[3, 4]");

            //names.Add(new string[3]);
            //names[0][0] = ("[0, 1]");
            //names[0][1] = ("[0, 3]");
            //names[0][2] = ("[3, 2]");


            names.Add(new string[5]);
            names[1][0] = ("[0, 1]");
            names[1][1] = ("[1, 2]");
            names[1][2] = ("[2, 3]");
            names[1][3] = ("[3, 4]");
            names[1][4] = ("[4, 5]");

            names.Add(new string[9]);
            names[2][0] = ("[0, 1]");
            names[2][1] = ("[0, 3]");
            names[2][2] = ("[0, 6]");
            names[2][3] = ("[1, 5]");
            names[2][4] = ("[2, 5]");
            names[2][5] = ("[4, 5]");
            names[2][6] = ("[5, 6]");
            names[2][7] = ("[6, 7]");
            names[2][8] = ("[7, 8]");

            names.Add(new string[5]);
            names[3][0] = ("[0, 1]");
            names[3][1] = ("[0, 4]");
            names[3][2] = ("[1, 2]");
            names[3][3] = ("[2, 3]");
            names[3][4] = ("[3, 4]");

            names.Add(new string[10]);
            names[4][0] = ("[0, 1]");
            names[4][1] = ("[0, 2]");
            names[4][2] = ("[0, 3]");
            names[4][3] = ("[0, 4]");
            names[4][4] = ("[1, 2]");
            names[4][5] = ("[1, 3]");
            names[4][6] = ("[1, 4]");
            names[4][7] = ("[2, 3]");
            names[4][8] = ("[2, 4]");
            names[4][9] = ("[3, 4]");

            names.Add(new string[g5vc]);
            for (int i = 0; i < g5vc; ++i)
            {
                names[5][i] = string.Format("[{0}, {1}]", i, (i + 1) % g5vc);
            }

            colors.Add(new int[3]);
            colors[0][0] = 0;
            colors[0][1] = 1;
            colors[0][2] = 2;
            //colors[0][3] = 1;
            //colors[0][2] = 0;
            //colors[0][3] = 1;
            //colors[0][4] = 0;
            chn[0] = 3;

            colors.Add(new int[6]);
            colors[1][0] = 0;
            colors[1][1] = 1;
            colors[1][2] = 0;
            colors[1][3] = 1;
            colors[1][4] = 0;
            colors[1][5] = 1;
            chn[1]       = 2;

            colors.Add(new int[9]);
            colors[2][0] = 0;
            colors[2][1] = 1;
            colors[2][2] = 0;
            colors[2][3] = 1;
            colors[2][4] = 0;
            colors[2][5] = 2;
            colors[2][6] = 1;
            colors[2][7] = 0;
            colors[2][8] = 1;
            chn[2]       = 3;

            colors.Add(new int[5]);
            colors[3][0] = 0;
            colors[3][1] = 1;
            colors[3][2] = 0;
            colors[3][3] = 1;
            colors[3][4] = 2;
            chn[3]       = 3;

            colors.Add(new int[5]);
            colors[4][0] = 0;
            colors[4][1] = 1;
            colors[4][2] = 2;
            colors[4][3] = 3;
            colors[4][4] = 4;
            chn[4]       = 5;

            colors.Add(new int[g5vc]);  // nie bedzie uzywana

            //sec_graphs[0] = new AdjacencyMatrixGraph(false, 5);
            //sec_graphs[0].AddEdge(0, 1, 0);
            //sec_graphs[0].AddEdge(0, 3, 2);
            //sec_graphs[0].AddEdge(1, 2, 3);
            //sec_graphs[0].AddEdge(2, 0, 1);
            //sec_graphs[0].AddEdge(2, 3, 4);
            //sec_graphs[0].AddEdge(3, 4, 5);
            //schi[0] = 6;

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

            //sec_graphs[0].AddEdge(3, 2, 2);
            //sec_graphs[0].AddEdge(2, 0, 1);
            //sec_graphs[0].AddEdge(2, 3, 4);
            //sec_graphs[0].AddEdge(3, 4, 5);
            schi[0] = 6;

            sec_graphs[1] = new AdjacencyMatrixGraph(true, 6);
            sec_graphs[1].AddEdge(0, 1, 0);
            sec_graphs[1].AddEdge(1, 0, 1);
            sec_graphs[1].AddEdge(2, 3, 2);
            sec_graphs[1].AddEdge(3, 4, 0);
            sec_graphs[1].AddEdge(4, 5, 1);
            schi[1] = 3;

            //            sec_graphs[2] = new AdjacencyListsGraph<SimpleAdjacencyList>(false, 9);
            sec_graphs[2] = new AdjacencyMatrixGraph(false, 9);
            sec_graphs[2].AddEdge(0, 3, 1);
            sec_graphs[2].AddEdge(1, 0, 0);
            sec_graphs[2].AddEdge(6, 0, 2);
            sec_graphs[2].AddEdge(1, 5, 3);
            sec_graphs[2].AddEdge(5, 4, 4);
            sec_graphs[2].AddEdge(5, 2, 1);
            sec_graphs[2].AddEdge(5, 6, 5);
            sec_graphs[2].AddEdge(6, 7, 6);
            sec_graphs[2].AddEdge(7, 8, 0);
            schi[2] = 7;

            sec_graphs[3] = new AdjacencyMatrixGraph(false, 5);
            sec_graphs[3].AddEdge(0, 1, 0);
            sec_graphs[3].AddEdge(1, 2, 2);
            sec_graphs[3].AddEdge(2, 3, 3);
            sec_graphs[3].AddEdge(3, 4, 4);
            sec_graphs[3].AddEdge(4, 0, 1);
            schi[3] = 5;

            sec_graphs[4] = new AdjacencyMatrixGraph(false, 5);
            sec_graphs[4].AddEdge(0, 1, 0);
            sec_graphs[4].AddEdge(0, 2, 1);
            sec_graphs[4].AddEdge(0, 3, 2);
            sec_graphs[4].AddEdge(0, 4, 3);
            sec_graphs[4].AddEdge(1, 2, 4);
            sec_graphs[4].AddEdge(1, 3, 5);
            sec_graphs[4].AddEdge(1, 4, 6);
            sec_graphs[4].AddEdge(2, 3, 7);
            sec_graphs[4].AddEdge(2, 4, 8);
            sec_graphs[4].AddEdge(3, 4, 9);
            schi[4] = 10;

            sec_graphs[5] = new AdjacencyListsGraph <SimpleAdjacencyList>(true, g5vc);
            for (int i = 0; i < g5vc; ++i)
            {
                sec_graphs[5].AddEdge(i, (i + 1) % g5vc, i % 3);
            }
            schi[5] = 3;

            TestSets["LabSquareOfGraphTests"]      = new TestSet(new Lab03Helper(), "Part 1 - square of graph [0.5 pkt]", null, false);
            TestSets["LabLineGraphTests"]          = new TestSet(new Lab03Helper(), "Part 2 - line graph [2 pkt]", null, false);
            TestSets["LabVertexColoringTests"]     = new TestSet(new Lab03Helper(), "Part 3 - vertex coloring [1 pkt]", null, false);
            TestSets["LabStrongEdgeColoringTests"] = new TestSet(new Lab03Helper(), "Part 4 - strong edge coloring [0.5 pkt]", null, false);

            for (int i = 0; i < 6; ++i)
            {
                TestSets["LabSquareOfGraphTests"].TestCases.Add(new SquareofGraphTestCase(1, null, "", graphs[i], squares[i]));
                TestSets["LabLineGraphTests"].TestCases.Add(new LineGraphTestCase(1, null, "", graphs[i], linegraphs[i], names[i]));
                TestSets["LabVertexColoringTests"].TestCases.Add(new VertexColoringTestCase(1, graphs[i].Directed?new ArgumentException():null, "", graphs[i], chn[i], colors[i]));
                TestSets["LabStrongEdgeColoringTests"].TestCases.Add(new StrongEdgeColoringTestCase(1, null, "", graphs[i], sec_graphs[i], schi[i]));
            }
        }
Exemple #4
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[9]);


            //Oryginalny kod:

            /*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);*/


            ///----------------------------------------------------------------------
            ///    Autor poniższych testów: Grzegorz Rozdzialik
            ///----------------------------------------------------------------------
            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]);
            }

            ///----------------------------------------------------------------------
        }
Exemple #5
0
    public static void Main()
    {
        bool  b;
        int   mst;
        Graph g, t;

        Edge[] ep;
        var    rgg = new RandomGraphGenerator();
        var    ge  = new GraphExport();

        // nieskierowany - cykl
        rgg.SetSeed(1111);
        g = rgg.EulerGraph(typeof(AdjacencyMatrixGraph), false, 6, 0.5, 2, 4);
        b = g.Lab04_Euler(out ep);
        if (b)
        {
            Console.WriteLine("Znaleziono cykl Eulera w grafie 1 - ma {0} krawedzi", ep.Length);
            ge.Export(Construct(g.VerticesCount, ep), "nieskierowany-cykl");
        }
        else
        {
            Console.WriteLine("Nie znaleziono sciezki Eulera w grafie 1");
        }

        // skierowany - cykl
        rgg.SetSeed(2222);
        g = rgg.EulerGraph(typeof(AdjacencyMatrixGraph), true, 5, 0.2, 1, 3);
        b = g.Lab04_Euler(out ep);
        if (b)
        {
            Console.WriteLine("Znaleziono cykl Eulera w grafie 2 - ma {0} krawedzi", ep.Length);
            ge.Export(Construct(g.VerticesCount, ep), "skierowany-cykl");
        }
        else
        {
            Console.WriteLine("Nie znaleziono sciezki Eulera w grafie 2");
        }

        // nieskierowany - sciezka
        rgg.SetSeed(3333);
        g = rgg.SemiEulerGraph(typeof(AdjacencyMatrixGraph), false, 6, 0.2, 2, 4);
        b = g.Lab04_Euler(out ep);
        if (b)
        {
            Console.WriteLine("Znaleziono sciezke Eulera w grafie 3 - ma {0} krawedzi", ep.Length);
            ge.Export(Construct(g.VerticesCount, ep), "nieskierowany-sciezka");
        }
        else
        {
            Console.WriteLine("Nie znaleziono sciezki Eulera w grafie 3");
        }

        // skierowany - sciezka
        rgg.SetSeed(4444);
        g = rgg.SemiEulerGraph(typeof(AdjacencyMatrixGraph), true, 5, 0.2, 1, 3);
        b = g.Lab04_Euler(out ep);
        if (b)
        {
            Console.WriteLine("Znaleziono sciezke Eulera w grafie 4 - ma {0} krawedzi", ep.Length);
            ge.Export(Construct(g.VerticesCount, ep), "skierowany-sciezka");
        }
        else
        {
            Console.WriteLine("Nie znaleziono sciezki Eulera w grafie 4");
        }

        // drzewo
        rgg.SetSeed(5555);
        g   = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), 20, 0.2, -10, 50);
        mst = g.Lab04_Kruskal(out t);
        Console.WriteLine("Minimalne drzewo ma wage {0}", mst);
        ge.Export(t, "drzewo");
    }
Exemple #6
0
    public static void PrepareTests()
    {
        var rgg = new RandomGraphGenerator();

        cliq_test = new Graph[6];
        izo_test  = new Graph[4, 2];

        cliq_res = new int[] { 4, 20, 19, 19, 9, 3 };
        izo_res  = new bool[] { true, false, true, false };

        if (cliq_test.Length != cliq_res.Length || izo_test.GetLongLength(0) != izo_res.Length)
        {
            throw new ApplicationException("Zle zddefiniowane testy");
        }

        cliq_test[0] = new AdjacencyMatrixGraph(false, 8);
        cliq_test[0].AddEdge(0, 4);
        cliq_test[0].AddEdge(0, 7);
        cliq_test[0].AddEdge(1, 2);
        cliq_test[0].AddEdge(1, 3);
        cliq_test[0].AddEdge(1, 5);
        cliq_test[0].AddEdge(1, 6);
        cliq_test[0].AddEdge(2, 5);
        cliq_test[0].AddEdge(2, 6);
        cliq_test[0].AddEdge(3, 4);
        cliq_test[0].AddEdge(3, 7);
        cliq_test[0].AddEdge(4, 7);
        cliq_test[0].AddEdge(5, 6);

        cliq_test[1] = new AdjacencyMatrixGraph(false, 20);
        for (int i = 0; i < cliq_test[1].VerticesCount; ++i)
        {
            for (int j = i + 1; j < cliq_test[1].VerticesCount; ++j)
            {
                cliq_test[1].AddEdge(i, j);
            }
        }

        cliq_test[2] = cliq_test[1].Clone();
        cliq_test[2].DelEdge(0, 1);

        cliq_test[3] = cliq_test[2].Clone();
        cliq_test[3].DelEdge(0, 2);

        rgg.SetSeed(123);
        cliq_test[4] = rgg.DirectedGraph(typeof(AdjacencyMatrixGraph), 100, 0.7);

        cliq_test[5] = rgg.UndirectedGraph(typeof(AdjacencyListsGraph <AVLAdjacencyList>), 5000, 0.001);

        izo_test[0, 0] = cliq_test[0].Clone();
        izo_test[0, 1] = rgg.Permute(izo_test[0, 0]);

        int n = 50;

        izo_test[1, 0] = new AdjacencyMatrixGraph(true, n);
        for (int i = 0; i < n; ++i)
        {
            for (int j = 0; j < n; ++j)
            {
                if (i != j)
                {
                    izo_test[1, 0].AddEdge(i, j);
                }
            }
        }
        izo_test[1, 1] = izo_test[1, 0].Clone();
        for (int i = 0; i < n; ++i)
        {
            izo_test[1, 0].DelEdge(i, (i + 1) % n);
        }
        for (int i = 0; i < n; i += 2)
        {
            izo_test[1, 1].DelEdge(i, (i + 2) % n);
            izo_test[1, 1].DelEdge(i + 1, (i + 3) % n);
        }

        rgg.SetSeed(1234);
        izo_test[2, 0] = rgg.DirectedGraph(typeof(AdjacencyMatrixGraph), 50, 0.95, 1, 999);
        izo_test[2, 1] = new AdjacencyListsGraph <AVLAdjacencyList>(izo_test[2, 0]);
        izo_test[2, 1] = rgg.Permute(izo_test[2, 1]);

        izo_test[3, 0] = rgg.UndirectedGraph(typeof(AdjacencyListsGraph <AVLAdjacencyList>), 15, 0.01, 1, 3);
        izo_test[3, 0].AddEdge(izo_test[3, 0].VerticesCount / 2, izo_test[3, 0].VerticesCount / 2 + 1, 2);
        izo_test[3, 1] = izo_test[3, 0].Clone();
        izo_test[3, 1].ModifyEdgeWeight(izo_test[3, 0].VerticesCount / 2, izo_test[3, 0].VerticesCount / 2 + 1, 1);
    }
Exemple #7
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();
    }
Exemple #8
0
        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
        }
        private static void TestReverse()
        {
            var rgg = new RandomGraphGenerator(12345);

            Graph[] g = new Graph[ReverseTestSize];
            bool[]  ex = { false, false, true, false, false };
            Graph   r, gg;
            ulong   cr, cgg;

            g[0] = rgg.DirectedGraph(typeof(AdjacencyMatrixGraph), 10, 0.7, -99, 99);
            g[1] = rgg.DirectedGraph(typeof(AdjacencyListsGraph <HashTableAdjacencyList>), 100, 0.1, -999, 999);
            g[2] = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), 10, 0.5);
            g[3] = rgg.DirectedCycle(typeof(AdjacencyListsGraph <SimpleAdjacencyList>), 50000, -99, 99);
            g[4] = new AdjacencyListsGraph <AVLAdjacencyList>(true, 50000);

            for (int i = 0; i < ReverseTestSize; ++i)
            {
                Console.Write($"  Test {i} - ");
                gg = g[i].Clone();
                try
                {
                    cr = Graph.Counter;
                    r  = g[i].Lab03Reverse();
                    cr = Graph.Counter - cr;
                    if (ex[i])
                    {
                        Console.WriteLine("Failed : exception Lab03Exception expected");
                        continue;
                    }
                    if (r == null)
                    {
                        Console.WriteLine("Failed : null returned");
                        continue;
                    }
                    if (!r.Directed)
                    {
                        Console.WriteLine("Failed : returned graph is undirected");
                        continue;
                    }
                    if (r.GetType() != g[i].GetType())
                    {
                        Console.WriteLine("Failed : invalid graph representation");
                        continue;
                    }
                    if (!g[i].IsEqual(gg))
                    {
                        Console.WriteLine("Failed : graph was destroyed");
                        continue;
                    }
                    cgg = Graph.Counter;
                    gg  = g[i].Reverse();
                    cgg = Graph.Counter - cgg;
                    if (!r.IsEqual(gg))
                    {
                        Console.WriteLine("Failed : bad result");
                        continue;
                    }
                    if (cr > 1.5 * cgg)
                    {
                        Console.WriteLine($"Failed : poor efficiency {cr} (should be {cgg})");
                        continue;
                    }
                    Console.WriteLine("Passed");
                }
                catch (Lab03Exception e)
                {
                    if (ex[i])
                    {
                        Console.WriteLine("Passed");
                    }
                    else
                    {
                        Console.WriteLine($"Failed : {e.GetType()} : {e.Message}");
                    }
                }
                catch (System.Exception e) when(maskExceptions)
                {
                    Console.WriteLine($"Failed : {e.GetType()} : {e.Message}");
                }
            }
        }
        private static void TestAcyclic()
        {
            var rgg = new RandomGraphGenerator(12345);

            Graph[] g   = new Graph[AcyclicTestSize];
            bool?[] res = { true, false, null, false, true };
            Graph   gg;
            bool    r;
            ulong   cr;

            ulong[] cgg = { 73, 3724, 1, 300000, 1 };
            g[0] = rgg.TreeGraph(typeof(AdjacencyMatrixGraph), 7, 1.0, -99, 99);
            g[1] = rgg.UndirectedGraph(typeof(AdjacencyListsGraph <HashTableAdjacencyList>), 100, 0.1, -999, 999);
            g[2] = rgg.DirectedGraph(typeof(AdjacencyMatrixGraph), 10, 0.5);
            g[3] = rgg.UndirectedCycle(typeof(AdjacencyListsGraph <SimpleAdjacencyList>), 50000, -99, 99);
            g[4] = new AdjacencyListsGraph <AVLAdjacencyList>(false, 50000);

            for (int i = 0; i < AcyclicTestSize; ++i)
            {
                Console.Write($"  Test {i} - ");
                gg = g[i].Clone();
                try
                {
                    cr = Graph.Counter;
                    r  = g[i].Lab03IsUndirectedAcyclic();
                    cr = Graph.Counter - cr;
                    if (res[i] == null)
                    {
                        Console.WriteLine("Failed : exception Lab03Exception expected");
                        continue;
                    }
                    if (!g[i].IsEqual(gg))
                    {
                        Console.WriteLine("Failed : graph was destroyed");
                        continue;
                    }
                    if (r != res[i])
                    {
                        Console.WriteLine("Failed : bad result");
                        continue;
                    }
                    if (cr > 1.5 * cgg[i])
                    {
                        Console.WriteLine($"Failed : poor efficiency {cr} (should be {cgg[i]})");
                        continue;
                    }
                    Console.WriteLine("Passed");
                }
                catch (Lab03Exception e)
                {
                    if (res[i] == null)
                    {
                        Console.WriteLine("Passed");
                    }
                    else
                    {
                        Console.WriteLine($"Failed : {e.GetType()} : {e.Message}");
                    }
                }
                catch (System.Exception e) when(maskExceptions)
                {
                    Console.WriteLine($"Failed : {e.GetType()} : {e.Message}");
                }
            }
        }