Beispiel #1
0
        // does the id[] array contain the strongly connected components?
        private bool check(Digraph G)
        {
            TransitiveClosure tc = new TransitiveClosure(G);

            for (int v = 0; v < G.V; v++)
            {
                for (int w = 0; w < G.V; w++)
                {
                    if (StronglyConnected(v, w) != (tc.Reachable(v, w) && tc.Reachable(w, v)))
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Beispiel #2
0
        public static void MainTest(string[] args)
        {
            TextInput input = new TextInput(args[0]);
            Digraph   G     = new Digraph(input);

            TransitiveClosure tc = new TransitiveClosure(G);

            // print header
            Console.Write("     ");
            for (int v = 0; v < G.V; v++)
            {
                Console.Write(" {0,2}", v);
            }
            Console.WriteLine();
            Console.WriteLine("--------------------------------------------");

            // print transitive closure
            for (int v = 0; v < G.V; v++)
            {
                Console.Write(" {0,2}: ", v);
                for (int w = 0; w < G.V; w++)
                {
                    if (tc.Reachable(v, w))
                    {
                        Console.Write("  T");
                    }
                    else
                    {
                        Console.Write("   ");
                    }
                }
                Console.WriteLine();
            }
        }