本文整理汇总了Python中sage.graphs.graph.Graph.allow_loops方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.allow_loops方法的具体用法?Python Graph.allow_loops怎么用?Python Graph.allow_loops使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sage.graphs.graph.Graph
的用法示例。
在下文中一共展示了Graph.allow_loops方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: underlying_graph
# 需要导入模块: from sage.graphs.graph import Graph [as 别名]
# 或者: from sage.graphs.graph.Graph import allow_loops [as 别名]
def underlying_graph(G):
r"""
Given a graph `G` with multi-edges, returns a graph where all the
multi-edges are replaced with a single edge.
EXAMPLES::
sage: from sage.graphs.tutte_polynomial import underlying_graph
sage: G = Graph(multiedges=True)
sage: G.add_edges([(0,1,'a'),(0,1,'b')])
sage: G.edges()
[(0, 1, 'a'), (0, 1, 'b')]
sage: underlying_graph(G).edges()
[(0, 1, None)]
"""
g = Graph()
g.allow_loops(True)
for edge in set(G.edges(labels=False)):
g.add_edge(edge)
return g