本文整理汇总了Python中sage.graphs.graph.Graph.shortest_path方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.shortest_path方法的具体用法?Python Graph.shortest_path怎么用?Python Graph.shortest_path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sage.graphs.graph.Graph
的用法示例。
在下文中一共展示了Graph.shortest_path方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: apply
# 需要导入模块: from sage.graphs.graph import Graph [as 别名]
# 或者: from sage.graphs.graph.Graph import shortest_path [as 别名]
def apply(solver, model, structures):
g = structures[0]
vertices = solver.get_objects_in_model(model, g, g.internal_graph.vertices())
dims = int(math.log(g.order, 2))
#print(vertices)
#print(dims)
edges = solver.get_objects_in_model(model, g, g.internal_graph.edges(labels=False))
#print(edges)
#create temp graph
t = Graph()
t.add_vertices(vertices)
t.add_edges(edges)
for i in range(g.order/2):
antipod = g.order - 1 - i
#print(i, antipod)
if i in vertices and antipod in vertices:
path = t.shortest_path(i, antipod)
if path:
#print(path)
return (True, [g, path])
print("COUNTER")
return (False, [])