本文整理汇总了Python中Graph.Graph.out_edges方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.out_edges方法的具体用法?Python Graph.out_edges怎么用?Python Graph.out_edges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Graph.Graph
的用法示例。
在下文中一共展示了Graph.out_edges方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_out_edges
# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import out_edges [as 别名]
def test_out_edges(self):
g = Graph()
v = Vertex('v')
w = Vertex('w')
x = Vertex('x')
e1 = Edge(v,w)
e2 = Edge(w,x)
e3 = Edge(v,x)
# Test on a non existent vertex
g.add_vertex(v)
self.verify_list_equal_unordered(g.out_edges(w), [])
# Test on a edgeless graph
g.add_vertex(w)
g.add_vertex(x)
self.verify_list_equal_unordered(g.out_edges(v), [])
# Test on a non-edgeless graph
g.add_edge(e1)
self.verify_list_equal_unordered(g.out_edges(x), [])
g.add_edge(e2)
g.add_edge(e3)
self.verify_list_equal_unordered(g.out_edges(x), [e2, e3])
示例2: test_list_connected_edges
# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import out_edges [as 别名]
def test_list_connected_edges(self):
v = Vertex(1)
v2 = Vertex(2)
v3 = Vertex(3)
e = Edge(v, v2)
e2 = Edge(v2, v3)
e3 = Edge(v3, v)
g = Graph([v, v2, v3], [e, e2, e3])
connected_edges = g.out_edges(v)
# Vertex v is connected by edges e and e3
self.assertTrue(e in connected_edges)
self.assertTrue(e3 in connected_edges)
self.assertTrue(len(connected_edges), 2)
示例3: test_graph
# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import out_edges [as 别名]
def test_graph(self):
v = Vertex('v')
w = Vertex('w')
self.assertEqual(repr(v), "Vertex('v')")
e = Edge(v, w)
self.assertEqual(repr(e), "Edge(Vertex('v'), Vertex('w'))")
g = Graph([v, w], [e])
self.assertEqual(repr(g), "{Vertex('w'): {Vertex('v'): Edge(Vertex('v'), Vertex('w'))}, Vertex('v'): {Vertex('w'): Edge(Vertex('v'), Vertex('w'))}}")
e2 = g.get_edge(v, w)
self.assertEqual(e, e2)
e3 = g.get_edge(v, v)
self.assertEqual(e3, None)
vs = [Vertex(c) for c in 'abcd']
g = Graph(vs)
g.add_regular_edges(3)
for v in g.vertices():
es = g.out_edges(v)
self.assertEqual(len(es), 3)
vs = g.out_vertices(v)
self.assertEqual(len(vs), 3)
g.remove_edge(Edge(Vertex('a'), Vertex('c')))
vs = g.vertices()
self.assertEqual(len(vs), 4)
es = g.edges()
self.assertEqual(len(es), 5)
g.add_all_edges()
es = g.edges()
self.assertEqual(len(es), 6)
g2 = eval(repr(g))
self.assertEqual(g, g2)
示例4: Edge
# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import out_edges [as 别名]
e2 = Edge(w, w)
g = Graph([v, w], [e, e1, e2])
g.remove_edge(Edge(v, v))
pprint(g, width=1)
print g.vertices()
print g.edges()
u = Vertex('u')
g = Graph([u, v, w])
pprint(g, width=1)
g.add_all_edges()
pprint(g, width=1)
print g.out_edges(v)
print g.out_vertices(v)
# test creation of Graph of degree d
alphabet = 'abcdefghijklmnopqrstuvwxyz'
vs = []
for v in range(10):
vs.append(Vertex(alphabet[v]))
g = Graph(vs)
layout = CircleLayout(g)
g.add_regular_edges(9, 100)
# draw the graph
gw = GraphWorld()
gw.show_graph(g, layout)
gw.mainloop()