Beispiel #1
0
        public void Run()
        {
            // create random bipartite graph with V vertices and E edges; then add F random edges
            const int v1 = 10;
            const int v2 = 10;
            const int e  = 20;
            const int f  = 5;

            // create random bipartite graph with V1 vertices on left side,
            // V2 vertices on right side, and E edges; then add F random edges
            var graph = GraphGenerator.Bipartite(v1, v2, e);

            for (var i = 0; i < f; i++)
            {
                var v = StdRandom.Uniform(v1 + v2);
                var w = StdRandom.Uniform(v1 + v2);
                graph.AddEdge(v, w);
            }

            Console.WriteLine(graph);


            var b = new BipartiteX(graph);

            if (b.IsBipartite())
            {
                Console.WriteLine("Graph is bipartite");
                for (var v = 0; v < graph.V; v++)
                {
                    Console.WriteLine($"{v}: {b.Color(v)}");
                }
            }
            else
            {
                Console.WriteLine("Graph has an odd-length cycle: ");
                foreach (int x in b.OddCycle())
                {
                    Console.Write($"{x} ");
                }
                Console.WriteLine();
            }

            Console.ReadLine();
        }
Beispiel #2
0
        public void Run()
        {
            const int v  = 50;
            const int e  = 100;
            const int v1 = v / 2;
            const int v2 = v - v1;

            Console.WriteLine("complete graph");
            var g1 = GraphGenerator.Complete(v);

            Console.WriteLine(g1);
            Console.WriteLine("---------------------------------------------------------------");

            Console.WriteLine("simple");
            var g2 = GraphGenerator.Simple(v, e);

            Console.WriteLine(g2);
            Console.WriteLine("---------------------------------------------------------------");

            Console.WriteLine("Erdos-Renyi");
            var p  = e / (v * (v - 1) / 2.0);
            var g3 = GraphGenerator.Simple(v, p);

            Console.WriteLine(g3);
            Console.WriteLine("---------------------------------------------------------------");


            Console.WriteLine("complete bipartite");
            var g4 = GraphGenerator.CompleteBipartite(v1, v2);

            Console.WriteLine(g4);
            Console.WriteLine("---------------------------------------------------------------");

            Console.WriteLine("bipartite");
            var g5 = GraphGenerator.Bipartite(v1, v2, e);

            Console.WriteLine(g5);
            Console.WriteLine("---------------------------------------------------------------");


            Console.WriteLine("Erdos Renyi bipartite");
            var q  = (double)e / (v1 * v2);
            var g6 = GraphGenerator.Bipartite(v1, v2, q);

            Console.WriteLine(g6);
            Console.WriteLine("---------------------------------------------------------------");

            Console.WriteLine("path");
            var g7 = GraphGenerator.Path(v);

            Console.WriteLine(g7);
            Console.WriteLine("---------------------------------------------------------------");

            Console.WriteLine("cycle");
            var g8 = GraphGenerator.Cycle(v);

            Console.WriteLine(g8);
            Console.WriteLine("---------------------------------------------------------------");

            Console.WriteLine("binary tree");
            var g9 = GraphGenerator.BinaryTree(v);

            Console.WriteLine(g9);
            Console.WriteLine("---------------------------------------------------------------");

            Console.WriteLine("tree");
            var g10 = GraphGenerator.Tree(v);

            Console.WriteLine(g10);
            Console.WriteLine("---------------------------------------------------------------");


            Console.WriteLine("4-regular");
            var g11 = GraphGenerator.Regular(v, 4);

            Console.WriteLine(g11);
            Console.WriteLine("---------------------------------------------------------------");

            Console.WriteLine("star");
            var g12 = GraphGenerator.Star(v);

            Console.WriteLine(g12);
            Console.WriteLine("---------------------------------------------------------------");

            Console.WriteLine("wheel");
            var g13 = GraphGenerator.Wheel(v);

            Console.WriteLine(g13);
            Console.WriteLine("---------------------------------------------------------------");

            Console.ReadLine();
        }