def getOwnerRobustness(self, graph):
""" compute the "owner robustness """
ownerNodes, nodeOwner = self.get_owner_distribution(graph)
print "# owner".rjust(long_align_space), ",",\
"main C. size".rjust(long_align_space), ",",\
"number of components".rjust(long_align_space)
for owner, nodes in sorted(ownerNodes.items(),
key=lambda(x): -len(x[1])):
purged_graph = nx.Graph(graph)
for n in nodes:
purged_graph.remove_node(n)
comp_list = list(nx.connected_components(purged_graph))
main_comp = sorted(comp_list, key=len, reverse=True)[0]
print owner.rjust(long_align_space), ",",\
str(len(main_comp)).rjust(long_align_space), ",", \
str(len(comp_list)).rjust(long_align_space)
print ""
print ""
# ################# helper functions
# These functions are needed to handle data structures from
# other sources of data. You can use a database and dump the
# data in XML from a db. You probably do not need these functions.
owner_graph_metrics.py 文件源码
python
阅读 31
收藏 0
点赞 0
评论 0
评论列表
文章目录