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=',')
评论列表
文章目录