Ejemplo n.º 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]);
    }
Ejemplo n.º 2
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 };
        Graph[]  g1  = new Graph[message1.Length];
        Graph[]  g2  = new Graph[message2.Length];
        Graph[]  g3  = new Graph[message3.Length];
        var      rgg = new RandomGraphGenerator();

        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 <SimpleAdjacencyList>(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("Grafy za 1 pkt");
        Console.WriteLine();
        for (i = 0; i < g1.Length; ++i)
        {
            counter0 = (long)Graph.Counter;
            mb       = g1[i].BacktrackingColor(out backtrackingColors);
            counter1 = (long)Graph.Counter;
            mg       = g1[i].GreedyColor(out greedyColors);
            counter2 = (long)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 = (long)Graph.Counter;
            mb       = g2[i].BacktrackingColor(out backtrackingColors);
            counter1 = (long)Graph.Counter;
            mg       = g2[i].GreedyColor(out greedyColors);
            counter2 = (long)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 = (long)Graph.Counter;
            mb       = g3[i].BacktrackingColor(out backtrackingColors);
            counter1 = (long)Graph.Counter;
            mg       = g3[i].GreedyColor(out greedyColors);
            counter2 = (long)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();
    }
Ejemplo n.º 3
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();
    }
Ejemplo n.º 4
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);
            }
        }
    }
Ejemplo n.º 5
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);
    }