本文整理汇总了Python中graphs.Graph.edges方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.edges方法的具体用法?Python Graph.edges怎么用?Python Graph.edges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graphs.Graph
的用法示例。
在下文中一共展示了Graph.edges方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_add_all_edges
# 需要导入模块: from graphs import Graph [as 别名]
# 或者: from graphs.Graph import edges [as 别名]
def test_add_all_edges(self):
# Adds an edge to edge-less graph
v, w, e = self.v, self.w, self.e
g = Graph([v, w], [])
g.add_all_edges()
eq_(g.edges(), [e])
# Adds edges between all pairs of vertices in edge-less graph
x = Vertex('x')
e2 = Edge(v, x)
e3 = Edge(w, x)
g = Graph([v, w, x], [])
g.add_all_edges()
eq_(g.edges(), [e, e2, e3])
示例2: test_add_regular_edges
# 需要导入模块: from graphs import Graph [as 别名]
# 或者: from graphs.Graph import edges [as 别名]
def test_add_regular_edges(self):
# Adds an edge to edge-less graph
v, w, e = self.v, self.w, self.e
g = Graph([v, w], [])
g.add_regular_edges(1)
eq_(g.edges(), [e])
# Can make a regular graph of three vertices and degree 2
x = Vertex('x')
e2 = Edge(v, x)
e3 = Edge(w, x)
g = Graph([v, w, x], [])
g.add_regular_edges(2)
eq_(g.edges(), [e, e2, e3])
# Cannot make a regular graph of three vertices and degree 1
g = Graph([v, w, x], [])
assert_raises(GraphError, g.add_regular_edges, 1)
# Cannot make a regular graph of three vertices and degree 3
g = Graph([v, w, x], [])
assert_raises(GraphError, g.add_regular_edges, 3)
# Can make a regular graph of five vertices and even degree
y = Vertex('y')
z = Vertex('z')
g = Graph([v, w, x, y, z], [])
g.add_regular_edges(2)
eq_(g.num_edges(), 5)
# Can make a regular graph of 4 vertices and odd degree
g = Graph([v, w, x, y], [])
g.add_regular_edges(3)
eq_(g.num_edges(), 6)
# Cannot make a regular graph of five vertices and degree 3
g = Graph([v, w, x, y, z], [])
assert_raises(GraphError, g.add_regular_edges, 3)