Example #1
0
def scc_compress(E):
    sccs = scc.strongly_connected_components(E)

    #print "*** SCCS", sccs

    node_to_comp = {}
    comp_to_node = {}
    C = {}
    Crev = {}
    for i, comp in enumerate(sccs):
        C[i] = {}
        Crev[i] = {}
        comp_to_node[i] = set()
        for u in comp:
            node_to_comp[u] = i
            comp_to_node[i].add(u)

    for u in E:
        cu = node_to_comp[u]
        for v in E[u]:
            cv = node_to_comp[v]
            if cu != cv:
                C[cu][cv] = 1
                Crev[cv][cu] = 1

    return C, Crev, node_to_comp, comp_to_node
Example #2
0
def main():
    G, G_rev = read_directed_graph('../data/SCC.txt', reversed=True)
    scc = strongly_connected_components(G, G_rev, 875714)
    print sorted(map(lambda v: len(v), scc.itervalues()), reverse=True)[:5]
"""
Entry point to execute code for strongly connected components
"""
import sys
from scc import strongly_connected_components

if __name__ == "__main__":
    if len(sys.argv) > 1:
        strongly_connected_components(sys.argv[1])
    else:
        sys.exit("usage:  python main.py <input_file_path>")
Example #4
0
def is_cyclic(E):
    sccs = scc.strongly_connected_components(E)
    for comp in sccs:
        if len(comp) > 1:
            return True
    return False
Example #5
0
#!/usr/bin/python

from scc import strongly_connected_components

G = {}
G['a'] = []
G['a'].append('b')
G['b'] = []
G['c'] = []
G['c'].append('d')
G['c'].append('g')
G['d'] = []
G['d'].append('h')
G['d'].append('c')
G['h'] = []
G['h'].append('g')
G['h'].append('d')
G['b'].append('c')
G['b'].append('e')
G['b'].append('f')
G['e'] = []
G['e'].append('a')
G['e'].append('f')
G['f'] = []
G['f'].append('g')
G['g'] = []
G['g'].append('f')

components = strongly_connected_components(G)
print components
Example #6
0
#!/usr/bin/python

from scc import strongly_connected_components

G = {}
G["a"] = []
G["a"].append("b")
G["b"] = []
G["c"] = []
G["c"].append("d")
G["c"].append("g")
G["d"] = []
G["d"].append("h")
G["d"].append("c")
G["h"] = []
G["h"].append("g")
G["h"].append("d")
G["b"].append("c")
G["b"].append("e")
G["b"].append("f")
G["e"] = []
G["e"].append("a")
G["e"].append("f")
G["f"] = []
G["f"].append("g")
G["g"] = []
G["g"].append("f")

components = strongly_connected_components(G)
print components