introduce_cycles_to_DAG.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:breaking_cycles_in_noisy_hierarchies 作者: zhenv5 项目源码 文件源码
def introduce_cycles_2_DAG(graph_file,num_extra_edges,path_length):

    if path_length <= 0:
        print("no constraints on path length")
    else:
        print("path length: %d" % path_length)

    g = nx.read_edgelist(graph_file,create_using = nx.DiGraph(),nodetype = int)
    extra_edges = introduce_cycles(g,num_extra_edges,path_length = path_length)

    extra_edges_file = graph_file[:len(graph_file)-6] + "_extra_" + str(num_extra_edges) + "_path_len_" + str(path_length) + ".edges"
    graph_with_extra_edges_file = graph_file[:len(graph_file)-6] + "_graph_w_extra_" + str(num_extra_edges) + "_path_len_" + str(path_length) + ".edges"

    print("extra edges saved in: %s" % extra_edges_file)
    print("graph with extra edges saved in: %s" % graph_with_extra_edges_file)
    from file_io import write_pairs_to_file

    write_pairs_to_file(extra_edges,extra_edges_file)
    write_pairs_to_file(extra_edges + g.edges(),graph_with_extra_edges_file)    

    return (extra_edges_file,graph_with_extra_edges_file)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号