示例#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();
        }
示例#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();
        }
示例#3
0
        public static void MainTest(string[] args)
        {
            int V = int.Parse(args[0]);
            int E = int.Parse(args[1]);

            // Eulerian cycle
            Digraph G1 = DigraphGenerator.EulerianCycle(V, E);

            DirectedEulerianPath.UnitTest(G1, "Eulerian cycle");

            // Eulerian path
            Digraph G2 = DigraphGenerator.EulerianPath(V, E);

            DirectedEulerianPath.UnitTest(G2, "Eulerian path");

            // add one random edge
            Digraph G3 = new Digraph(G2);

            G3.AddEdge(StdRandom.Uniform(V), StdRandom.Uniform(V));
            DirectedEulerianPath.UnitTest(G3, "one random edge added to Eulerian path");

            // self loop
            Digraph G4 = new Digraph(V);
            int     v4 = StdRandom.Uniform(V);

            G4.AddEdge(v4, v4);
            DirectedEulerianPath.UnitTest(G4, "single self loop");

            // single edge
            Digraph G5 = new Digraph(V);

            G5.AddEdge(StdRandom.Uniform(V), StdRandom.Uniform(V));
            DirectedEulerianPath.UnitTest(G5, "single edge");

            // empty digraph
            Digraph G6 = new Digraph(V);

            DirectedEulerianPath.UnitTest(G6, "empty digraph");

            // random digraph
            Digraph G7 = DigraphGenerator.Simple(V, E);

            DirectedEulerianPath.UnitTest(G7, "simple digraph");

            // 4-vertex digraph
            //Digraph G8 = new Digraph(new TextInput("eulerianD.txt"));
            //DirectedEulerianPath.UnitTest(G8, "4-vertex Eulerian digraph");
        }
示例#4
0
        public static void MainTest(string[] args)
        {
            int V = int.Parse(args[0]);
            int E = int.Parse(args[1]);

            // Eulerian cycle
            Digraph G1 = DigraphGenerator.EulerianCycle(V, E);

            DirectedEulerianCycle.UnitTest(G1, "Eulerian cycle");

            // Eulerian path
            Digraph G2 = DigraphGenerator.EulerianPath(V, E);

            DirectedEulerianCycle.UnitTest(G2, "Eulerian path");

            // empty digraph
            Digraph G3 = new Digraph(V);

            DirectedEulerianCycle.UnitTest(G3, "empty digraph");

            // self loop
            Digraph G4 = new Digraph(V);
            int     v4 = StdRandom.Uniform(V);

            G4.AddEdge(v4, v4);
            DirectedEulerianCycle.UnitTest(G4, "single self loop");

            // union of two disjoint cycles
            Digraph H1 = DigraphGenerator.EulerianCycle(V / 2, E / 2);
            Digraph H2 = DigraphGenerator.EulerianCycle(V - V / 2, E - E / 2);

            int[] perm = new int[V];
            for (int i = 0; i < V; i++)
            {
                perm[i] = i;
            }
            StdRandom.Shuffle(perm);
            Digraph G5 = new Digraph(V);

            for (int v = 0; v < H1.V; v++)
            {
                foreach (int w in H1.Adj(v))
                {
                    G5.AddEdge(perm[v], perm[w]);
                }
            }
            for (int v = 0; v < H2.V; v++)
            {
                foreach (int w in H2.Adj(v))
                {
                    G5.AddEdge(perm[V / 2 + v], perm[V / 2 + w]);
                }
            }
            DirectedEulerianCycle.UnitTest(G5, "Union of two disjoint cycles");

            // random digraph
            Digraph G6 = DigraphGenerator.Simple(V, E);

            DirectedEulerianCycle.UnitTest(G6, "simple digraph");

            // 4-vertex digraph - no data file
            //Digraph G7 = new Digraph(new TextInput("eulerianD.txt"));
            //DirectedEulerianCycle.UnitTest(G7, "4-vertex Eulerian digraph");
        }