Ejemplo n.º 1
0
        public static void MainTest(string[] args)
        {
            // create random DAG with V vertices and E edges; then add F random edges
            int     V = int.Parse(args[0]);
            int     E = int.Parse(args[1]);
            int     F = int.Parse(args[2]);
            Digraph G = DigraphGenerator.Dag(V, E);

            // add F extra edges
            for (int i = 0; i < F; i++)
            {
                int v = StdRandom.Uniform(V);
                int w = StdRandom.Uniform(V);
                G.AddEdge(v, w);
            }

            Console.WriteLine(G);

            DirectedCycleX finder = new DirectedCycleX(G);

            if (finder.HasCycle)
            {
                Console.Write("Directed cycle: ");
                foreach (int v in finder.GetCycle())
                {
                    Console.Write(v + " ");
                }
                Console.WriteLine();
            }
            else
            {
                Console.WriteLine("No directed cycle");
            }
            Console.WriteLine();
        }
Ejemplo n.º 2
0
        public static void MainTest(string[] args)
        {
            int V = int.Parse(args[0]);
            int E = int.Parse(args[1]);

            Console.WriteLine("Complete graph");
            Console.WriteLine(DigraphGenerator.Complete(V));
            Console.WriteLine();

            Console.WriteLine("Simple");
            Console.WriteLine(DigraphGenerator.Simple(V, E));
            Console.WriteLine();

            Console.WriteLine("Path");
            Console.WriteLine(DigraphGenerator.Path(V));
            Console.WriteLine();

            Console.WriteLine("Cycle");
            Console.WriteLine(DigraphGenerator.Cycle(V));
            Console.WriteLine();

            Console.WriteLine("Eulierian path");
            Console.WriteLine(DigraphGenerator.EulerianPath(V, E));
            Console.WriteLine();

            Console.WriteLine("Eulierian cycle");
            Console.WriteLine(DigraphGenerator.EulerianCycle(V, E));
            Console.WriteLine();

            Console.WriteLine("Binary tree");
            Console.WriteLine(DigraphGenerator.BinaryTree(V));
            Console.WriteLine();

            Console.WriteLine("Tournament");
            Console.WriteLine(DigraphGenerator.Tournament(V));
            Console.WriteLine();

            Console.WriteLine("DAG");
            Console.WriteLine(DigraphGenerator.Dag(V, E));
            Console.WriteLine();

            Console.WriteLine("Rooted-in DAG");
            Console.WriteLine(DigraphGenerator.RootedInDAG(V, E));
            Console.WriteLine();

            Console.WriteLine("Rooted-out DAG");
            Console.WriteLine(DigraphGenerator.RootedOutDAG(V, E));
            Console.WriteLine();

            Console.WriteLine("Rooted-in tree");
            Console.WriteLine(DigraphGenerator.RootedInTree(V));
            Console.WriteLine();

            Console.WriteLine("Rooted-out DAG");
            Console.WriteLine(DigraphGenerator.RootedOutTree(V));
            Console.WriteLine();
        }