Exemple #1
0
    public static void PrepareTests2()
    {
        int n;
        var rgg = new RandomGraphGenerator();

        cliq_test2 = new Graph[3];
        izo_test2  = new Graph[2, 2];

        cliq_res2 = new int[] { 3, 3, 5 };
        izo_res2  = new bool[] { false, true };

        if (cliq_test2.Length != cliq_res2.Length || izo_test2.GetLongLength(0) != izo_res2.Length)
        {
            throw new ApplicationException("Zle zddefiniowane testy");
        }

        rgg.SetSeed(123);
        cliq_test2[0] = rgg.UndirectedGraph(typeof(AdjacencyListsGraph <HashTableAdjacencyList>), 4000, 0.001);
        rgg.SetSeed(125);
        cliq_test2[1] = rgg.DirectedGraph(typeof(AdjacencyListsGraph <HashTableAdjacencyList>), 3000, 0.05);

        n             = 1500;
        cliq_test2[2] = new AdjacencyListsGraph <HashTableAdjacencyList>(false, n);
        for (int i = 0; i < n; ++i)
        {
            for (int j = 1; j <= 4; ++j)
            {
                cliq_test2[2].AddEdge(i, (i + j) % n);
            }
        }

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

        rgg.SetSeed(1234);
        izo_test2[1, 0] = rgg.DirectedGraph(typeof(AdjacencyMatrixGraph), 2500, 0.95, 1, 999);
        izo_test2[1, 1] = new AdjacencyListsGraph <HashTableAdjacencyList>(izo_test2[1, 0]);
        izo_test2[1, 1] = rgg.Permute(izo_test2[1, 1]);
    }
Exemple #2
0
 private static void ConstrainedMaxFlow()
 {
     for (int j = 0; j < 5; ++j)
     {
         Graph network = generator.DirectedGraph(typeof(AdjacencyMatrixGraph), random.Next(20) + 5, 0.6, 1, 10);
         for (int i = 0; i < network.VerticesCount; ++i)
         {
             network.DelEdge(i, 0);
             network.DelEdge(1, i);
         }
         int[] capacites = new int[network.VerticesCount];
         capacites[0] = capacites[1] = int.MaxValue;
         for (int i = 2; i < network.VerticesCount; ++i)
         {
             capacites[i] = random.Next(9) + 1;
         }
         int   flow1, flow2;
         Graph flow;
         flow1 = network.FordFulkersonMaxFlow(0, 1, out flow);
         flow2 = network.ConstrainedMaxFlow(0, 1, capacites, out flow);
         if (IsFlowFeasible(network, 0, 1, capacites, flow))
         {
             Console.WriteLine("g{0}\n bez ogr: {1} \n   z ogr: {2}", j + 1, flow1, flow2);
         }
         else
         {
             Console.WriteLine("g{0}\n bez ogr: {1} \n   z ogr: przeplyw niedopuszczalny", j + 1, flow1);
         }
     }
 }
Exemple #3
0
        public static void Main()
        {
            Random rng = new Random();
            RandomGraphGenerator rgg = new RandomGraphGenerator();

            for (int i = 1; i <= testRnds; i++)
            {
                foreach (Type type in types)
                {
                    TestGraph(rgg.UndirectedGraph(type, size, rng.NextDouble()), "Random undirected graph");
                    TestGraph(rgg.DirectedGraph(type, size, rng.NextDouble()), "Random directed graph");
                    TestGraph(rgg.UndirectedGraph(type, size, rng.NextDouble() * 2 / size, 0, 100), "Sparse undirected graph");
                    int k = rng.Next() % (size - 1) + 1;
                    TestGraph(rgg.BipariteGraph(type, k, size - k, rng.NextDouble()), "Bipartite graph");
                }
            }
            Console.WriteLine("Test summary:\n Reverse graphs:\t{0}/{3}, \n Bipartite graphs:\t{1}/{3},\n Kruskal's algorithm:\t{2}/{3}",
                              reverseOk,
                              bipartiteOk,
                              kruskalOk,
                              totalTestCount);
        }
        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);
        }
Exemple #5
0
    public static void Main()
    {
        int?   m;
        IGraph g0, g1, g2, g3, g4, g5, g6, g7;

        Edge[] c;

        RandomGraphGenerator gen = new RandomGraphGenerator(1);

        g0 = gen.UndirectedEuclidGraph(typeof(AdjacencyMatrixGraph), 5, 1.0, 0.0, 100.0, 0.0, 100.0);
        g1 = gen.UndirectedEuclidGraph(typeof(AdjacencyMatrixGraph), 100, 1.0, 0.0, 100.0, 0.0, 100.0);
        g2 = gen.UndirectedGraph(typeof(AdjacencyMatrixGraph), 100, 1.0, 1, 99);
        g3 = gen.DirectedGraph(typeof(AdjacencyMatrixGraph), 100, 1.0, 1, 99);
        g4 = gen.UndirectedGraph(typeof(AdjacencyMatrixGraph), 100, 0.9, 1, 99);
        g5 = gen.DirectedGraph(typeof(AdjacencyMatrixGraph), 100, 0.9, 1, 99);
        g6 = gen.UndirectedGraph(typeof(AdjacencyListsGraph), 100, 0.2, 1, 99);
        g7 = gen.DirectedGraph(typeof(AdjacencyListsGraph), 100, 0.2, 1, 99);

        Console.WriteLine("\nAlgorytm \"Kruskalopodobny\"");

        Console.Write("  maly graf euklidesowy     -  ");
        m = g0.TSP_Kruskal(out c);
        Test(g0, c, m);
        if (m == null)
        {
            Console.WriteLine("    Nie znaleziono cyklu Hamiltona");
        }
        else
        {
            Console.Write("    ");
            for (int i = 0; i < g0.VerticesCount; ++i)
            {
                Console.Write("  {0}", c[i]);
            }
            Console.WriteLine();
        }

        Console.Write("  graf pelny euklidesowy    -  ");
        m = g1.TSP_Kruskal(out c);
        Test(g1, c, m);

        Console.Write("  graf pelny nieskierowany  -  ");
        m = g2.TSP_Kruskal(out c);
        Test(g2, c, m);

        Console.Write("  graf pelny skierowany     -  ");
        m = g3.TSP_Kruskal(out c);
        Test(g3, c, m);

        Console.Write("  graf nieskierowany        -  ");
        m = g4.TSP_Kruskal(out c);
        Test(g4, c, m);

        Console.Write("  graf skierowany           -  ");
        m = g5.TSP_Kruskal(out c);
        Test(g5, c, m);

        Console.Write("  graf rzadki nieskierowany -  ");
        m = g6.TSP_Kruskal(out c);
        Test(g6, c, m);

        Console.Write("  graf rzadki skierowany    -  ");
        m = g7.TSP_Kruskal(out c);
        Test(g7, c, m);

        Console.WriteLine("\nAlgorytm na podstawie drzewa");

        Console.Write("  maly graf euklidesowy     -  ");
        m = g0.TSP_TreeBased(out c);
        Test(g0, c, m);
        if (m == null)
        {
            Console.WriteLine("    Nie znaleziono cyklu Hamiltona");
        }
        else
        {
            Console.Write("    ");
            for (int i = 0; i < g0.VerticesCount; ++i)
            {
                Console.Write("  {0}", c[i]);
            }
            Console.WriteLine();
        }

        Console.Write("  graf pelny euklidesowy    -  ");
        m = g1.TSP_TreeBased(out c);
        Test(g1, c, m);

        Console.Write("  graf pelny nieskierowany  -  ");
        m = g2.TSP_TreeBased(out c);
        Test(g2, c, m);

        Console.Write("  graf pelny skierowany     -  ");
        try
        {
            m = g3.TSP_TreeBased(out c);
            Console.WriteLine("BLAD 3  !!!");
        }
        catch (ArgumentException)
        {
            Console.WriteLine("wyjatek (to dobrze)");
        }

        Console.Write("  graf nieskierowany        -  ");
        m = g4.TSP_TreeBased(out c);
        Test(g4, c, m);

        Console.Write("  graf skierowany           -  ");
        try
        {
            m = g5.TSP_TreeBased(out c);
            Console.WriteLine("BLAD 3  !!!");
        }
        catch (ArgumentException)
        {
            Console.WriteLine("wyjatek (to dobrze)");
        }

        Console.Write("  graf rzadki nieskierowany -  ");
        m = g6.TSP_TreeBased(out c);
        Test(g6, c, m);

        Console.Write("  graf rzadki skierowany    -  ");
        try
        {
            m = g7.TSP_TreeBased(out c);
            Console.WriteLine("BLAD 3  !!!");
        }
        catch (ArgumentException)
        {
            Console.WriteLine("wyjatek (to dobrze)");
        }
    }
Exemple #6
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");
        }
    }
Exemple #7
0
    public static void Main()
    {
        Graph[]  g = new Graph[4];
        string[] m = new string[] { "Matrix    ",
                                    "HashTable ",
                                    "SimplyList",
                                    "AVL tree  " };
        int      s, n = 2000;
        ulong    c1, c2;
        DateTime t1, t2;

        RandomGraphGenerator rgg = new RandomGraphGenerator(12345);

// Elementy tabgicy g zawierają ten sam graf w różnych reprezentacjach
        g[0] = rgg.DirectedGraph(typeof(AdjacencyMatrixGraph), n, 0.05, -99, 99);
        g[1] = new AdjacencyListsGraph <HashTableAdjacencyList>(g[0]);
        g[2] = new AdjacencyListsGraph <SimplyAdjacencyList>(g[0]);
        g[3] = new AdjacencyListsGraph <AVLAdjacencyList>(g[0]);

// Liczymy sumę wag wszystkich krawędzi grafu

// Sposób 1 - najlepszy, korzystamy jedynie z metody OutEdges
        Console.WriteLine();
        for (int i = 0; i < g.Length; ++i)
        {
            c1 = Graph.Counter;
            t1 = DateTime.Now;
            s  = 0;
            for (int v = 0; v < n; ++v)
            {
                foreach (var e in g[i].OutEdges(v))
                {
                    s += e.Weight;
                }
            }
            t2 = DateTime.Now;
            c2 = Graph.Counter;
            Console.WriteLine(" A {0} # suma {1}  -  licznik:  {2,11} , czas:  {3}", m[i], s, c2 - c1, t2 - t1);
        }

// Sposób 2 - gorszy, korzystamy z metod OutEdges i GetEdgeWeight
        Console.WriteLine();
        for (int i = 0; i < g.Length; ++i)
        {
            c1 = Graph.Counter;
            t1 = DateTime.Now;
            s  = 0;
            for (int v = 0; v < n; ++v)
            {
                foreach (var e in g[i].OutEdges(v))
                {
                    s += (int)g[i].GetEdgeWeight(e.From, e.To);
                }
            }
            t2 = DateTime.Now;
            c2 = Graph.Counter;
            Console.WriteLine(" B {0} # suma {1}  -  licznik:  {2,11} , czas:  {3}", m[i], s, c2 - c1, t2 - t1);
        }

// Sposób 3 - najgorszy, korzystamy jedynie z metody GetEdgeWeight - nie robić tak!
        Console.WriteLine();
        int?w;

        for (int i = 0; i < g.Length; ++i)
        {
            c1 = Graph.Counter;
            t1 = DateTime.Now;
            s  = 0;
            for (int v = 0; v < n; ++v)
            {
                for (int vv = 0; vv < n; ++vv)
                {
                    w = g[i].GetEdgeWeight(v, vv);
                    if (w != null)
                    {
                        s += (int)w;
                    }
                }
            }
            t2 = DateTime.Now;
            c2 = Graph.Counter;
            Console.WriteLine(" C {0} # suma {1}  -  licznik:  {2,11} , czas:  {3}", m[i], s, c2 - c1, t2 - t1);
        }

        Console.WriteLine();
    }
Exemple #8
0
        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 <SimplyAdjacencyList>), 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}");
                }
            }
        }
Exemple #9
0
        private static void TestBipartite()
        {
            var rgg = new RandomGraphGenerator(12345);

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

            int[] part;
            ulong cr;

            ulong[] cgg = { 77, 457, 1, 2500007, 1 };
            g[0] = rgg.BipariteGraph(typeof(AdjacencyMatrixGraph), 4, 3, 0.4, -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>), 50001, -99, 99);
            g[4] = new AdjacencyListsGraph <AVLAdjacencyList>(false, 50000);

            for (int i = 0; i < BipartiteTestSize; ++i)
            {
                Console.Write($"  Test {i} - ");
                gg = g[i].Clone();
                try
                {
                    cr = Graph.Counter;
                    r  = g[i].Lab03IsBipartite(out part);
                    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 (r && !IsProperPartition(g[i], part))
                    {
                        Console.WriteLine("Failed : invalid partition");
                        continue;
                    }
                    if (!r && part != null)
                    {
                        Console.WriteLine("Failed : part==null expected");
                        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}");
                }
            }
        }
Exemple #10
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
        }
Exemple #11
0
    public static void PrepareTests()
    {
        var rgg = new RandomGraphGenerator();

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

        cliq_res = new int[] { 4, 20, 19, 19, 9 };
        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);

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

        izo_test[1, 0] = izo_test[0, 0].Clone();
        izo_test[1, 1] = izo_test[0, 1].Clone();
        izo_test[1, 0].ModifyEdgeWeight(2, 5, 3);

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

        izo_test[3, 0] = rgg.UndirectedGraph(typeof(AdjacencyListsGraph <HashTableAdjacencyList>), 5000, 0.01, 1, 3);
        izo_test[3, 1] = new AdjacencyListsGraph <HashTableAdjacencyList>(true, 5000);
        for (int v = 0; v < 5000; ++v)
        {
            foreach (Edge e in izo_test[3, 0].OutEdges(v))
            {
                izo_test[3, 1].AddEdge(e);
            }
        }
    }
Exemple #12
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 <SimplyAdjacencyList>), 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 <SimplyAdjacencyList>(izo_test[2, 0]);
        izo_test[2, 1] = rgg.Permute(izo_test[2, 1]);

        izo_test[3, 0] = rgg.UndirectedGraph(typeof(AdjacencyListsGraph <SimplyAdjacencyList>), 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 #13
0
        public override void PrepareTestSets()
        {
            Random random            = new Random(20180310);
            RandomGraphGenerator rgg = new RandomGraphGenerator(2018);

            TestSets["LabIsTree"]          = new TestSet(new CyclesFinder(), "Część 1 - czy graf jest drzewem (0.5 pkt)");
            TestSets["LabFindCyclesTests"] = new TestSet(new CyclesFinder(), "Część 2 - cykle fundamentalne (2.5 pkt)");
            TestSets["LabAddCyclesTests"]  = new TestSet(new CyclesFinder(), "Część 3 - dodawanie cykli fundamentalnych (1 pkt)");

            List <(Graph g, Graph t)> testCases = new List <(Graph g, Graph t)>
            {
                Test01(), Test02(), Test03(), Test04(), Test05()
            };

            //testy losowe
            testCases.Add(FullGraph(rgg, 7));
            testCases.Add(FullGraph(rgg, 30));
            testCases.Add(FullGraph(rgg, 75));
            testCases.Add(RandomTest(random, 20, 4));
            testCases.Add(RandomTest(random, 30, 5));
            testCases.Add(RandomTest(random, 200, 7));

            TestSets["LabIsTree"].TestCases.AddRange(new[] {
                new IsTreeTestCase(1, null, "", testCases[2].t, true),
                new IsTreeTestCase(1, null, "Z cyklami", testCases[4].g, false),
                new IsTreeTestCase(1, null, "Bez krawędzi", testCases[6].g.IsolatedVerticesGraph(), false),
                new IsTreeTestCase(1, null, "Skojarzenie doskonałe", IsTreeTest01(), false),
                new IsTreeTestCase(1, null, "Niespójny", IsTreeTest02(), false),
                new IsTreeTestCase(1, null, "", testCases[9].t, true)
            });
            TestSets["LabIsTree"].TestCases.Add(new CyclesTestCase(1, new ArgumentException(), "Skierowany",
                                                                   rgg.DirectedGraph(typeof(AdjacencyListsGraph <AVLAdjacencyList>), 9, 0.3), null));

            List <string> desc = new List <string>
            {
                "cykl + krawędź", "3 cykle fund.", "drzewo", "krawędzie między poziomami",
                "głębokie drzewo", "pełny-7", "pełny-30", "pełny-75", "losowy-20", "losowy-30", "losowy-200"
            };

            for (int i = 0; i < testCases.Count; ++i)
            {
                var(g, t) = testCases[i];
                TestSets["LabFindCyclesTests"].TestCases.Add(new CyclesTestCase(1, null, desc[i], g, t));
            }
            TestSets["LabFindCyclesTests"].TestCases.Add(new CyclesTestCase(1, new ArgumentException(), "Skierowany",
                                                                            rgg.DirectedGraph(typeof(AdjacencyListsGraph <AVLAdjacencyList>), 8, 0.7), null));

            var addCases = new List <(Graph g, List <int> c1, List <int> c2, List <int> c)>
            {
                AddTest01(), AddTest02(), AddTest03(), AddTest04(),
                AddTest05(), AddTest06(), AddTest07(), AddTest08(), AddTest09()
            };
            List <string> addDesc = new List <string>
            {
                "wspólny wierzchołek", "dłuższy cykl wynikowy", "krótszy cykl wynikowy",
                "krótszy cykl wynikowy 2", "dłuższy cykl wynikowy 2", "2 wspólne krawędzie",
                "3 wspólne krawędzie", "całkowicie rozłączne", "bez min i max"
            };

            for (int i = 0; i < addCases.Count; ++i)
            {
                TestSets["LabAddCyclesTests"].TestCases.Add(new AddCyclesTestCase(1, null, addDesc[i], addCases[i]));
            }
        }
Exemple #14
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]);
            }
        }
Exemple #15
0
    public static void Main()
    {
        var ge  = new GraphExport();
        var rgg = new RandomGraphGenerator();

        Graph g1 = new AdjacencyMatrixGraph(true, 15);

        g1.AddEdge(0, 2);
        g1.AddEdge(0, 7);
        g1.AddEdge(1, 0);
        g1.AddEdge(2, 1);
        g1.AddEdge(2, 3);
        g1.AddEdge(2, 7);
        g1.AddEdge(3, 5);
        g1.AddEdge(4, 3);
        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, 0);
        g1.AddEdge(12, 13);
        g1.AddEdge(13, 14);
        g1.AddEdge(14, 12);
        //ge.Export(g1,null, "g1");

        int[] scc;
        int   n;

        n = g1.StronglyConnectedComponents(out scc);
        Console.WriteLine("\nLiczba silnie spojnych skladowych: {0} (powinno byc 8)", n);
        for (int c = 0; c < n; ++c)
        {
            Console.WriteLine();
            Console.Write("skladowa {0}:", c);
            for (int v = 0; v < g1.VerticesCount; ++v)
            {
                if (scc[v] == c)
                {
                    Console.Write(" {0}", v);
                }
            }
        }
        Console.WriteLine();

        Graph k1 = g1.Kernel();

        //ge.Export(k1, null, "k1");

        rgg.SetSeed(500);
        Graph g2 = rgg.DirectedGraph(typeof(AdjacencyMatrixGraph), 1000, 0.005);

        n = g2.StronglyConnectedComponents(out scc);
        Console.WriteLine("\nLiczba silnie spojnych skladowych: {0} (powinno byc 17)", n);

        Graph g3 = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), 1000, 0.1);

        try
        {
            n = g3.StronglyConnectedComponents(out scc);
            Console.WriteLine("\nBlad - powinien byc wyjatek");
        }
        catch (ArgumentException e)
        {
            Console.WriteLine("\n" + e.Message + "  - dobrze");
        }

        Console.WriteLine("\nSciezka maksymalnie powiekszajaca");
        PathsInfo[] d;
        bool        b;
        Graph       m1 = new AdjacencyMatrixGraph(true, 7);

        m1.AddEdge(0, 2, 10);
        m1.AddEdge(2, 3, 4);
        m1.AddEdge(2, 5, 3);
        m1.AddEdge(2, 4, 7);
        m1.AddEdge(3, 1, 2);
        m1.AddEdge(4, 1, 1);
        m1.AddEdge(5, 6, 5);
        m1.AddEdge(6, 1, 4);
        //ge.Export(m1, null, "m1");

        b = m1.MaxFlowPathsLab05(2, out d);
        Console.WriteLine("graf m1");
        for (int v = 0; v < m1.VerticesCount; ++v)
        {
            Console.WriteLine("przepustowosc od 2 do {0} wynosi {1}", v, d[v].Dist ?? 0);
        }

        int[] p = { 55, 33, 65, 73, 0, 73, 84, 76, 45, 78 };
        rgg.SetSeed(200);
        Graph m2 = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), 200, 0.02, 1, 99);

        b = m2.MaxFlowPathsLab05(5, out d);
        Console.WriteLine("graf m2");
        for (int v = 10; v < 20; ++v)
        {
            Console.WriteLine("przepustowosc od 5 do do {0} wynosi {1} ({2})", v, d[v].Dist ?? 0, (d[v].Dist ?? 0) == p[v - 10]?"OK":"blad");
        }

        Console.WriteLine("\nTesty Acyklicznosci\n");
        Graph a1, a2, a3, a4, a5;
        bool  b1, b2, b3, b4, b5;

        rgg.SetSeed(101);
        a1 = rgg.TreeGraph(typeof(AdjacencyListsGraph <SimplyAdjacencyList>), 10, 1);
//        ge.Export(a1,"a1");
        b1 = a1.IsUndirectedAcyclic();
        Console.WriteLine("Czy graf a1 jest acykliczny ? : {0} (powinno byc True)", b1);

        rgg.SetSeed(102);
        a2 = rgg.TreeGraph(typeof(AdjacencyListsGraph <SimplyAdjacencyList>), 15, 1);
        a2.DelEdge(1, 7);
        a2.DelEdge(6, 12);
//        ge.Export(a2,"a2");
        b2 = a2.IsUndirectedAcyclic();
        Console.WriteLine("Czy graf a2 jest acykliczny ? : {0} (powinno byc True)", b2);

        rgg.SetSeed(103);
        a3 = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), 10, 0.3);
//        ge.Export(a3,"a3");
        b3 = a3.IsUndirectedAcyclic();
        Console.WriteLine("Czy graf a3 jest acykliczny ? : {0} (powinno byc False)", b3);

        rgg.SetSeed(104);
        a4 = rgg.DirectedGraph(typeof(AdjacencyMatrixGraph), 1000, 0.1);
        try
        {
            b4 = a4.IsUndirectedAcyclic();
            Console.WriteLine("Blad - powinien byc wyjatek");
        }
        catch (ArgumentException e)
        {
            Console.WriteLine(e.Message);
        }
        Console.WriteLine("Czy graf a4 jest acykliczny ? (przed chwila powinien byc wyjatek)");

        rgg.SetSeed(105);
        a5 = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), 2000, 0.8);
        b5 = a5.IsUndirectedAcyclic();
        Console.WriteLine("Czy graf a5 jest acykliczny ? : {0} (powinno byc False)", b5);

        Console.WriteLine("KONIEC !!!\n");
    }
Exemple #16
0
        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 <SimplyAdjacencyList>), 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}");
                }
            }
        }
        private static List <CirculationTestCase> GetTestCases()
        {
            List <CirculationTestCase> testCases = new List <CirculationTestCase>();

            IGraph testGraph1 = Graph.IsolatedVerticesGraph(true, 6, typeof(AdjacencyMatrixGraph));

            testGraph1.AddEdge(0, 1, 10);
            testGraph1.AddEdge(0, 2, 3);
            testGraph1.AddEdge(1, 2, 6);
            testGraph1.AddEdge(3, 2, 7);
            testGraph1.AddEdge(1, 4, 7);
            testGraph1.AddEdge(4, 3, 4);
            testGraph1.AddEdge(3, 5, 9);
            testGraph1.AddEdge(4, 5, 4);

            int[] demands1 = new int[6] {
                -7, -8, 10, -6, 0, 11
            };

            testCases.Add(new CirculationTestCase()
            {
                TestGraph = testGraph1, Demands = demands1, ExpectedResult = true
            });

            var rgg    = new RandomGraphGenerator();
            var random = new Random(0);

            var testGraph2 = rgg.DirectedGraph(typeof(AdjacencyMatrixGraph), 10, 0.7, 1, 20);

            int[] demands2 = new[] { -4, -6, 2, 7, 0, -5, 8, 0, -2, 0 };
            int[] demands3 = new[] { -4, -6, 2, 7, 0, -5, 8, 0, -3, -5 };

            testCases.Add(new CirculationTestCase()
            {
                TestGraph = testGraph2, Demands = demands2, ExpectedResult = true
            });
            testCases.Add(new CirculationTestCase()
            {
                TestGraph = testGraph2, Demands = demands3, ExpectedResult = false
            });

            var lowerBounds1 = testGraph1.IsolatedVerticesGraph();

            lowerBounds1.AddEdge(0, 1, 8);

            testCases.Add(new CirculationTestCase()
            {
                TestGraph = testGraph1, Demands = demands1, LowerBounds = lowerBounds1, ExpectedResult = false
            });

            var lowerBounds2 = testGraph1.IsolatedVerticesGraph();

            lowerBounds2.AddEdge(0, 1, 4);
            lowerBounds2.AddEdge(0, 2, 3);
            lowerBounds2.AddEdge(1, 2, 6);
            lowerBounds2.AddEdge(3, 2, 1);
            lowerBounds2.AddEdge(1, 4, 6);
            lowerBounds2.AddEdge(4, 3, 2);
            lowerBounds2.AddEdge(3, 5, 7);
            lowerBounds2.AddEdge(4, 5, 4);

            testCases.Add(new CirculationTestCase()
            {
                TestGraph = testGraph1, Demands = demands1, LowerBounds = lowerBounds2, ExpectedResult = true
            });

            var lowerBounds3 = testGraph2.Clone();

            for (int v = 0; v < lowerBounds3.VerticesCount; v++)
            {
                foreach (var e in lowerBounds3.OutEdges(v))
                {
                    lowerBounds3.ModifyEdgeWeight(e.From, e.To, -e.Weight + 1);
                }
            }

            testCases.Add(new CirculationTestCase()
            {
                TestGraph = testGraph2, Demands = demands2, LowerBounds = lowerBounds3, ExpectedResult = true
            });


            return(testCases);
        }
Exemple #18
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();
    }