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


Python Graph.add_all_edges方法代码示例

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


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

示例1: main

# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import add_all_edges [as 别名]
def main(script, n='5', *args):

    # create n Vertices
    n = int(n)
    #labels = string.ascii_lowercase + string.ascii_uppercase
    #vs = [Vertex(c) for c in labels[:n]]

    v = Vertex('v')
    v.pos = (1110,-100)

    w = Vertex('w')
    w.pos = (20000,40)

    x = Vertex('x')
    x.pos = (100,-2000)

    y = Vertex('y')
    y.pos = (-15,15000)

    # create a graph and a layout
    g = Graph([v, w, x, y])
    g.add_all_edges()
    # layout = CircleLayout(g)
    # layout = RandomLayout(g)
    layout = CartesianLayout(g)

    # draw the graph
    gw = GraphWorld()
    gw.show_graph(g, layout)
    gw.mainloop()
开发者ID:agarwali,项目名称:CampusTourGuide,代码行数:32,代码来源:GraphWorld.py

示例2: test_add_all_edges

# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import add_all_edges [as 别名]
    def test_add_all_edges(self):

        v = Vertex(1)
        v2 = Vertex(2)

        g = Graph([v, v2])

        self.assertEqual(g.edges(), [])

        g.add_all_edges()

        self.assertEqual(g[v][v2], Edge(v2, v))
        self.assertEqual(g[v2][v], Edge(v2, v))
开发者ID:tsoporan,项目名称:think_complex,代码行数:15,代码来源:tests.py

示例3: main

# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import add_all_edges [as 别名]
def main(script, n='10', *args):
    # create n Vertices
    n = int(n)
    labels = string.ascii_lowercase + string.ascii_uppercase
    vs = [Vertex(c) for c in labels[:n]]

    # create a graph and a layout
    g = Graph(vs)
    g.add_all_edges()
    layout = CircleLayout(g)

    # draw the graph
    gw = GraphWorld()
    gw.show_graph(g, layout)
    gw.mainloop()
开发者ID:kumasento,项目名称:scikuma,代码行数:17,代码来源:GraphWorld.py

示例4: test_graph

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

示例5: test_add_all_edges

# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import add_all_edges [as 别名]
  def test_add_all_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 empty graph
    g.add_all_edges()
    self.assertEqual(g, {})

    # Test on a non-edgeless graph
    g.add_edge(e1)
    g.add_vertex(x)
    g.add_all_edges()
    self.assertEqual(g, {v:{w:e1}, w:{v:e1}, x:{}})

    # Test on a edgeless graph
    g.clear()
    g.add_vertex(v)
    g.add_vertex(w)
    g.add_vertex(x)
    g.add_all_edges()
    self.assertEqual(g, {v:{w:e1, x:e3}, w:{v:e1, x:e2}, x:{w:e2, v:e3}})
开发者ID:shubhamgupta30,项目名称:think_bayes,代码行数:28,代码来源:Graph_test.py

示例6: Edge

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


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