当前位置: 首页>>代码示例>>Python>>正文


Python Graph.out_vertices方法代码示例

本文整理汇总了Python中Graph.Graph.out_vertices方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.out_vertices方法的具体用法?Python Graph.out_vertices怎么用?Python Graph.out_vertices使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Graph.Graph的用法示例。


在下文中一共展示了Graph.out_vertices方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_out_vertices

# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import out_vertices [as 别名]
  def test_out_vertices(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_vertices(w), [])

    # Test on a edgeless graph
    g.add_vertex(w)
    g.add_vertex(x)
    self.verify_list_equal_unordered(g.out_vertices(v), [])

    # Test on a non-edgeless graph
    g.add_edge(e1)
    self.verify_list_equal_unordered(g.out_vertices(x), [])
    g.add_edge(e2)
    g.add_edge(e3)
    self.verify_list_equal_unordered(g.out_vertices(x), [v, w])
开发者ID:shubhamgupta30,项目名称:think_bayes,代码行数:26,代码来源:Graph_test.py

示例2: test_list_adjacent_vertices

# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import out_vertices [as 别名]
    def test_list_adjacent_vertices(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])
        adjacent = g.out_vertices(v)

        # Vertex v is connected to v2 and v3
        self.assertTrue(v2 in adjacent)
        self.assertTrue(v3 in adjacent)
        self.assertTrue(len(adjacent), 2)
开发者ID:tsoporan,项目名称:think_complex,代码行数:20,代码来源:tests.py

示例3: test_graph

# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import out_vertices [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)
开发者ID:paulmouzas,项目名称:think-complexity,代码行数:44,代码来源:GraphTest.py

示例4: Graph

# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import out_vertices [as 别名]
 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()
 
开发者ID:nikos-daniilidis,项目名称:python-complexity,代码行数:32,代码来源:GraphTest.py


注:本文中的Graph.Graph.out_vertices方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。