本文整理汇总了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()
示例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())
示例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"]
示例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()