def read_net(fname, weighted, directed, log):
if weighted:
G = nx.read_edgelist(inodetype=int, data=(('weight', float),),
create_using=nx.DiGraph())
else:
G = nx.read_edgelist(fname, nodetype=int, create_using=nx.DiGraph())
for edge in G.edges():
G[edge[0]][edge[1]]['weight'] = 1
if not directed:
G = G.to_undirected()
log.info('N: %d E: %d' % (G.number_of_nodes(), G.number_of_edges()))
log.info('CC: %d' % nx.number_connected_components(G))
giant = max(nx.connected_component_subgraphs(G), key=len)
log.info('N: %d E: %d' % (giant.number_of_nodes(), giant.number_of_edges()))
return giant
评论列表
文章目录