Esempio n. 1
0
def edgelist_dimacs_graph(orig_graph, peo_h, prn_tw=False):
    fname = orig_graph
    gname = os.path.basename(fname).split(".")
    gname = sorted(gname, reverse=True, key=len)[0]

    if ".tar.bz2" in fname:
        from tdec.read_tarbz2 import read_tarbz2_file
        edglst = read_tarbz2_file(fname)
        df = pd.DataFrame(edglst, dtype=int)
        G = nx.from_pandas_dataframe(df, source=0, target=1)
    else:
        G = nx.read_edgelist(fname, comments="%", data=False, nodetype=int)
    # print "...",	G.number_of_nodes(), G.number_of_edges()
    # from numpy import max
    # print "...",	max(G.nodes()) ## to handle larger 300K+ nodes with much larger labels

    N = max(G.nodes())
    M = G.number_of_edges()
    # +++ Graph Checks
    if G is None: sys.exit(1)
    G.remove_edges_from(G.selfloop_edges())
    giant_nodes = max(nx.connected_component_subgraphs(G), key=len)
    G = nx.subgraph(G, giant_nodes)
    graph_checks(G)
    # --- graph checks

    G.name = gname

    # print "...",	G.number_of_nodes(), G.number_of_edges()
    if G.number_of_nodes() > 500 and not prn_tw:
        return (nx_edges_to_nddgo_graph_sampling(G, n=N, m=M,
                                                 peo_h=peo_h), gname)
    else:
        return (nx_edges_to_nddgo_graph(G, n=N, m=M, varel=peo_h), gname)
Esempio n. 2
0
def convert_nx_gObjs_to_dimacs_gObjs(nx_gObjs):
    '''
	Take list of graphs and convert to dimacs
	'''
    dimacs_glst = []
    for G in nx_gObjs:
        N = max(G.nodes())
        M = G.number_of_edges()
        # +++ Graph Checks
        if G is None: sys.exit(1)

        G.remove_edges_from(G.selfloop_edges())
        giant_nodes = max(nx.connected_component_subgraphs(G), key=len)
        G = nx.subgraph(G, giant_nodes)
        graph_checks(G)
        # --- graph checks
        G.name = "synthG_{}_{}".format(N, M)

        from tdec.arbolera import nx_edges_to_nddgo_graph
        dimacs_glst.append(nx_edges_to_nddgo_graph(G, n=N, m=M, save_g=True))

    return dimacs_glst