本文整理汇总了Python中sage.graphs.graph.Graph.distance_all_pairs方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.distance_all_pairs方法的具体用法?Python Graph.distance_all_pairs怎么用?Python Graph.distance_all_pairs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sage.graphs.graph.Graph
的用法示例。
在下文中一共展示了Graph.distance_all_pairs方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: second_dist_to_set
# 需要导入模块: from sage.graphs.graph import Graph [as 别名]
# 或者: from sage.graphs.graph.Graph import distance_all_pairs [as 别名]
def second_dist_to_set(G, v, W):
"""
For vertices adjacent to W, return the lenght of the second shortest
path to W. Otherwise return G.order(). WARNING: Not very efficient.
"""
if v in W:
return 0
# Neighbors in W
nw = set(G.neighbors(v)).intersection(set(W))
if len(nw) == 0:
return G.order()
if len(nw) >= 2:
return 1
G2 = Graph(G) # always undirected, copy
G2.delete_edge(v, nw.pop())
ds2 = G2.distance_all_pairs()
dist2 = min([ds2[v][u] for u in W])
assert dist2 >= 2
return dist2