generate-graph.py 文件源码

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

项目:mlss-2016 作者: Networks-Learning 项目源码 文件源码
def run(output_path, graph_type, force,
        seed, num_nodes, edge_prob, solution_path):

    any_op_file_exists = (P.exists(output_path) or P.exists(solution_path))

    if any_op_file_exists and not force:
        print('Cannot overwrite without --force', file=sys.stderr)
        sys.exit(-1)

    g = None
    if graph_type == 'erdos':
        g = nx.erdos_renyi_graph(num_nodes, edge_prob,
                                 seed=seed, directed=True)
    else:
        print('Unknown graph type: ', graph_type, file=sys.stderr)
        sys.exit(-1)

    A = np.zeros((num_nodes, num_nodes), dtype='float')
    # All edges are given uniformly random weights.
    for u, v, d in g.edges(data=True):
        d['act_prob'] = R.random()
        A[u, v] = d['act_prob']

    nx.write_edgelist(g, output_path)
    np.savetxt(solution_path, A, delimiter=',')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号