Exemplo n.º 1
0
    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);
    }
Exemplo n.º 2
0
    void Start()
    {
        Digraph G = new Digraph(txt);

        TransitiveClosure tc = new TransitiveClosure(G);

        // print header
        string str = ("     ");

        for (int v = 0; v < G.V(); v++)
        {
            str += v;
        }
        print(str);

        // print transitive closure
        for (int v = 0; v < G.V(); v++)
        {
            str = (v + ": ");
            for (int w = 0; w < G.V(); w++)
            {
                if (tc.reachable(v, w))
                {
                    str += ("  T");
                }
                else
                {
                    str += ("   ");
                }
            }
            print(str);
        }
    }
    private bool check(Digraph digraph)
    {
        TransitiveClosure transitiveClosure = new TransitiveClosure(digraph);

        for (int i = 0; i < digraph.V(); i++)
        {
            for (int j = 0; j < digraph.V(); j++)
            {
                if (this.stronglyConnected(i, j) != ((!transitiveClosure.reachable(i, j) || !transitiveClosure.reachable(j, i)) ? false : true))
                {
                    return(false);
                }
            }
        }
        return(true);
    }
Exemplo n.º 4
0
 public static bool Reachable(this DiGraph dg, int first, int second)
 {
     TransitiveClosure ts=new TransitiveClosure(dg);
     return ts.reachable(first, second);
 }