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


Python Graph.is_connected方法代码示例

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


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

示例1: main

# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import is_connected [as 别名]
def main(script, n="13", *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_regular_edges(12)
    print g.is_connected()

    layout = CircleLayout(g)

    # draw the graph
    gw = GraphWorld()
    gw.show_graph(g, layout)
    gw.mainloop()
开发者ID:ericmjl,项目名称:Complexity-Science,代码行数:20,代码来源:GraphWorld.py

示例2: test_is_connected

# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import is_connected [as 别名]
  def test_is_connected(self):
    v = Vertex('v')
    w = Vertex('w')
    x = Vertex('x')
    e1 = Edge(v,w)
    e2 = Edge(w,x)
    e3 = Edge(v,x)

    # Check on an empty graph
    g = Graph()
    self.assertTrue(g.is_connected())

    # Check on an edgeless graph
    g = Graph([v,w,x], [])
    self.assertFalse(g.is_connected())

    # Check on a disconnected graph
    g = Graph([v,w,x], [e1])
    self.assertFalse(g.is_connected())

    # Check on a connected graph
    g = Graph([v,w,x], [e1, e2])
    self.assertTrue(g.is_connected())
开发者ID:shubhamgupta30,项目名称:think_bayes,代码行数:25,代码来源:Graph_test.py

示例3: Graph

# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import is_connected [as 别名]
       "e" : ["c"],
       "f" : ["a"]
}

g5 = { "a" : ["d","f"],
       "b" : ["c","b"],
       "c" : ["b", "c", "d", "e"],
       "d" : ["a", "c"],
       "e" : ["c"],
       "f" : ["a"]
}


graph = Graph(g3)
print(graph)
print(graph.is_connected())

graph = Graph(g4)
print(graph)
print(graph.is_connected())

graph = Graph(g5)
print(graph)
print(graph.is_connected())

g6 = { "a" : ["c"],
      "b" : ["c","e","f"],
      "c" : ["a","b","d","e"],
      "d" : ["c"],
      "e" : ["b","c","f"],
      "f" : ["b","e"]
开发者ID:Lieto,项目名称:Python,代码行数:33,代码来源:graph_demo.py

示例4: CircleLayout

# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import is_connected [as 别名]
 layout = CircleLayout(g)
 g.add_regular_edges(9, 100)
 
 # draw the graph
 gw = GraphWorld()
 gw.show_graph(g, layout)
 gw.mainloop()
 
 # test random graph
 alphabet = 'abcdefghijklmnopqrstuvwxyz'
 vs = []
 for v in range(24):
     vs.append(Vertex(alphabet[v]))   
 g = RandomGraph(vs)
 layout = CircleLayout(g)
 g.add_random_edges(0.05)
 
 # test connectedness of graphs
 if g.is_connected():
     print "The graph is connected."
 else:
     print "The graph is not connected."
 print "done"
 
 # draw the graph
 gw = GraphWorld()
 gw.show_graph(g, layout)
 gw.mainloop()
 
 
 
开发者ID:nikos-daniilidis,项目名称:python-complexity,代码行数:30,代码来源:GraphTest.py


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