本文整理汇总了Python中networkx.null_graph函数的典型用法代码示例。如果您正苦于以下问题:Python null_graph函数的具体用法?Python null_graph怎么用?Python null_graph使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了null_graph函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_null
def test_null(self):
dimacs = """\
p cnf 0 0
"""
graph=nx.null_graph()
F = TseitinFormula(graph)
self.assertCnfEqualsDimacs(F,dimacs)
示例2: test_cartesian_product_null
def test_cartesian_product_null():
null=nx.null_graph()
empty10=nx.empty_graph(10)
K3=nx.complete_graph(3)
K10=nx.complete_graph(10)
P3=nx.path_graph(3)
P10=nx.path_graph(10)
# null graph
G=cartesian_product(null,null)
assert_true(nx.is_isomorphic(G,null))
# null_graph X anything = null_graph and v.v.
G=cartesian_product(null,empty10)
assert_true(nx.is_isomorphic(G,null))
G=cartesian_product(null,K3)
assert_true(nx.is_isomorphic(G,null))
G=cartesian_product(null,K10)
assert_true(nx.is_isomorphic(G,null))
G=cartesian_product(null,P3)
assert_true(nx.is_isomorphic(G,null))
G=cartesian_product(null,P10)
assert_true(nx.is_isomorphic(G,null))
G=cartesian_product(empty10,null)
assert_true(nx.is_isomorphic(G,null))
G=cartesian_product(K3,null)
assert_true(nx.is_isomorphic(G,null))
G=cartesian_product(K10,null)
assert_true(nx.is_isomorphic(G,null))
G=cartesian_product(P3,null)
assert_true(nx.is_isomorphic(G,null))
G=cartesian_product(P10,null)
assert_true(nx.is_isomorphic(G,null))
示例3: test_null_graph
def test_null_graph(self):
null = nx.null_graph()
assert_equal(list(nx.edge_boundary(null, [])), [])
assert_equal(list(nx.edge_boundary(null, [], [])), [])
assert_equal(list(nx.edge_boundary(null, [1, 2, 3])), [])
assert_equal(list(nx.edge_boundary(null, [1, 2, 3], [4, 5, 6])), [])
assert_equal(list(nx.edge_boundary(null, [1, 2, 3], [3, 4, 5])), [])
示例4: test_empty_subgraph
def test_empty_subgraph(self):
# Subgraph of an empty graph is an empty graph. test 1
nullgraph = nx.null_graph()
E5 = nx.empty_graph(5)
E10 = nx.empty_graph(10)
H = E10.subgraph([])
assert_true(nx.is_isomorphic(H, nullgraph))
H = E10.subgraph([1, 2, 3, 4, 5])
assert_true(nx.is_isomorphic(H, E5))
示例5: test_strong_product
def test_strong_product():
null=nx.null_graph()
empty1=nx.empty_graph(1)
empty10=nx.empty_graph(10)
K2=nx.complete_graph(2)
K3=nx.complete_graph(3)
K5=nx.complete_graph(5)
K10=nx.complete_graph(10)
P2=nx.path_graph(2)
P3=nx.path_graph(3)
P5=nx.path_graph(5)
P10=nx.path_graph(10)
# null graph
G=strong_product(null,null)
assert_true(nx.is_isomorphic(G,null))
# null_graph X anything = null_graph and v.v.
G=strong_product(null,empty10)
assert_true(nx.is_isomorphic(G,null))
G=strong_product(null,K3)
assert_true(nx.is_isomorphic(G,null))
G=strong_product(null,K10)
assert_true(nx.is_isomorphic(G,null))
G=strong_product(null,P3)
assert_true(nx.is_isomorphic(G,null))
G=strong_product(null,P10)
assert_true(nx.is_isomorphic(G,null))
G=strong_product(empty10,null)
assert_true(nx.is_isomorphic(G,null))
G=strong_product(K3,null)
assert_true(nx.is_isomorphic(G,null))
G=strong_product(K10,null)
assert_true(nx.is_isomorphic(G,null))
G=strong_product(P3,null)
assert_true(nx.is_isomorphic(G,null))
G=strong_product(P10,null)
assert_true(nx.is_isomorphic(G,null))
G=strong_product(P5,K3)
assert_equal(nx.number_of_nodes(G),5*3)
G=strong_product(K3,K5)
assert_equal(nx.number_of_nodes(G),3*5)
#No classic easily found classic results for strong product
G = nx.erdos_renyi_graph(10,2/10.)
H = nx.erdos_renyi_graph(10,2/10.)
GH = strong_product(G,H)
for (u_G,u_H) in GH.nodes_iter():
for (v_G,v_H) in GH.nodes_iter():
if (u_G==v_G and H.has_edge(u_H,v_H)) or \
(u_H==v_H and G.has_edge(u_G,v_G)) or \
(G.has_edge(u_G,v_G) and H.has_edge(u_H,v_H)):
assert_true(GH.has_edge((u_G,u_H),(v_G,v_H)))
else:
assert_true(not GH.has_edge((u_G,u_H),(v_G,v_H)))
示例6: setUp
def setUp(self):
self.null = nx.null_graph()
self.P1 = cnlti(nx.path_graph(1), first_label=1)
self.P3 = cnlti(nx.path_graph(3), first_label=1)
self.P10 = cnlti(nx.path_graph(10), first_label=1)
self.K1 = cnlti(nx.complete_graph(1), first_label=1)
self.K3 = cnlti(nx.complete_graph(3), first_label=1)
self.K4 = cnlti(nx.complete_graph(4), first_label=1)
self.K5 = cnlti(nx.complete_graph(5), first_label=1)
self.K10 = cnlti(nx.complete_graph(10), first_label=1)
self.G = nx.Graph
示例7: test_write_path
def test_write_path(self):
# On Windows, we can't reopen a file that is open
# So, for test we get a valid name from tempfile but close it.
with tempfile.NamedTemporaryFile() as f:
fullfilename = f.name
# file should be closed now, so write_sparse6 can open it
nx.write_sparse6(nx.null_graph(), fullfilename)
fh = open(fullfilename, mode='rb')
self.assertEqual(fh.read(), b'>>sparse6<<:?\n')
fh.close()
import os
os.remove(fullfilename)
示例8: test_subgraph_nbunch
def test_subgraph_nbunch(self):
nullgraph = nx.null_graph()
K1 = nx.complete_graph(1)
K3 = nx.complete_graph(3)
K5 = nx.complete_graph(5)
# Test G.subgraph(nbunch), where nbunch is a single node
H = K5.subgraph(1)
assert_true(nx.is_isomorphic(H, K1))
# Test G.subgraph(nbunch), where nbunch is a set
H = K5.subgraph(set([1]))
assert_true(nx.is_isomorphic(H, K1))
# Test G.subgraph(nbunch), where nbunch is an iterator
H = K5.subgraph(iter(K3))
assert_true(nx.is_isomorphic(H, K3))
# Test G.subgraph(nbunch), where nbunch is another graph
H = K5.subgraph(K3)
assert_true(nx.is_isomorphic(H, K3))
H = K5.subgraph([9])
assert_true(nx.is_isomorphic(H, nullgraph))
示例9: test_null_subgraph
def test_null_subgraph(self):
# Subgraph of a null graph is a null graph
nullgraph = nx.null_graph()
G = nx.null_graph()
H = G.subgraph([])
assert_true(nx.is_isomorphic(H, nullgraph))
示例10: test_null
def test_null(self):
null = nx.null_graph()
assert_equal(list(null.degree()), [])
assert_equal(dict(null.degree()), {})
示例11: setUp
def setUp(self):
self.null=nx.null_graph()
self.P10=cnlti(nx.path_graph(10),first_label=1)
self.K10=cnlti(nx.complete_graph(10),first_label=1)
示例12: test_null_graph
def test_null_graph(self):
G = nx.null_graph()
assert_equal(len(max_clique(G)), 0)
示例13: test_null_graph
def test_null_graph(self):
nx.average_shortest_path_length(nx.null_graph())
示例14: test_null_graph
def test_null_graph(self):
result = BytesIO()
nx.write_graph6(nx.null_graph(), result)
self.assertEqual(result.getvalue(), b'>>graph6<<?\n')
示例15: test_write_path
def test_write_path(self):
with tempfile.NamedTemporaryFile() as f:
g6.write_graph6_file(nx.null_graph(), f)
f.seek(0)
self.assertEqual(f.read(), b'>>graph6<<?\n')