本文整理汇总了Python中networkx.is_tree方法的典型用法代码示例。如果您正苦于以下问题:Python networkx.is_tree方法的具体用法?Python networkx.is_tree怎么用?Python networkx.is_tree使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkx
的用法示例。
在下文中一共展示了networkx.is_tree方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_ghz_program
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import is_tree [as 别名]
def create_ghz_program(tree: nx.DiGraph):
"""
Create a Bell/GHZ state with CNOTs described by tree.
:param tree: A tree that describes the CNOTs to perform to create a bell/GHZ state.
:return: the program
"""
assert nx.is_tree(tree), 'Needs to be a tree'
nodes = list(nx.topological_sort(tree))
n_qubits = len(nodes)
program = Program(H(nodes[0]))
for node in nodes:
for child in tree.successors(node):
program += CNOT(node, child)
ro = program.declare('ro', 'BIT', n_qubits)
for i, q in enumerate(nodes):
program += MEASURE(q, ro[i])
return program
示例2: read_hierarchy
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import is_tree [as 别名]
def read_hierarchy(fname, log):
# format directed edge list (parent, child)
# parent, child are nodes:
# -- a network name if leaf node
# -- arbitrary name if internal node
# nodes must have unique names
# graph should be a tree
G = nx.DiGraph()
with open(fname) as fin:
# print 'Reading: %s' % fname
for line in fin:
p, c = line.strip().split()
p = p.replace('/', '_')
c = c.replace('/', '_')
G.add_edge(p, c)
assert nx.is_tree(G), 'Hierarchy should be a tree'
log.info('Hierarchy nodes: %s' % ', '.join(G.nodes()))
return G
示例3: __init__
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import is_tree [as 别名]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# Check that G is a tree
if not nx.is_tree(self.G):
raise ValueError(
f"G is not a tree with edges {self.edges}. "
"If a tree is not required, use the generic TaskGraph class."
)
示例4: test_prune_dead_branches
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import is_tree [as 别名]
def test_prune_dead_branches(self, tree):
leafs = tree.get_leaf_nodes()
tree.prune_dead_branches(dead_leafs=set(leafs[:2]), alive_leafs=set(leafs[2:]))
for le in leafs[:2]:
assert le not in tree.leafs
assert le not in tree.data
assert networkx.is_tree(tree.data)
示例5: test_tree_from_sdf
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import is_tree [as 别名]
def test_tree_from_sdf(sdf_file):
tree = sg.ScaffoldTree.from_sdf(sdf_file)
assert tree.num_scaffold_nodes == 5
assert tree.num_molecule_nodes == 2
assert nx.is_tree(tree)
示例6: test_tree_from_smiles
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import is_tree [as 别名]
def test_tree_from_smiles(smiles_file):
tree = sg.ScaffoldTree.from_smiles_file(smiles_file)
assert tree.num_scaffold_nodes == 5
assert tree.num_molecule_nodes == 2
assert nx.is_tree(tree)
示例7: test_null_tree
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import is_tree [as 别名]
def test_null_tree(self):
nx.is_tree(self.graph())
nx.is_tree(self.multigraph())
示例8: test_is_tree
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import is_tree [as 别名]
def test_is_tree(self):
assert_true(nx.is_tree(self.T2))
assert_true(nx.is_tree(self.T3))
assert_true(nx.is_tree(self.T5))
示例9: test_is_not_tree
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import is_tree [as 别名]
def test_is_not_tree(self):
assert_false(nx.is_tree(self.N4))
assert_false(nx.is_tree(self.N5))
assert_false(nx.is_tree(self.N6))
示例10: test_disconnected_graph
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import is_tree [as 别名]
def test_disconnected_graph():
# https://github.com/networkx/networkx/issues/1144
G = nx.Graph()
G.add_edges_from([(0, 1), (1, 2), (2, 0), (3, 4)])
assert_false(nx.is_tree(G))
G = nx.DiGraph()
G.add_edges_from([(0, 1), (1, 2), (2, 0), (3, 4)])
assert_false(nx.is_tree(G))
示例11: test_dag_nontree
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import is_tree [as 别名]
def test_dag_nontree():
G = nx.DiGraph()
G.add_edges_from([(0,1), (0,2), (1,2)])
assert_false(nx.is_tree(G))
assert_true(nx.is_directed_acyclic_graph(G))
示例12: test_dag_nontree
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import is_tree [as 别名]
def test_dag_nontree():
G = nx.DiGraph()
G.add_edges_from([(0, 1), (0, 2), (1, 2)])
assert_false(nx.is_tree(G))
assert_true(nx.is_directed_acyclic_graph(G))
示例13: test_default_flow_function_karate_club_graph
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import is_tree [as 别名]
def test_default_flow_function_karate_club_graph(self):
G = nx.karate_club_graph()
nx.set_edge_attributes(G, 1, 'capacity')
T = nx.gomory_hu_tree(G)
assert_true(nx.is_tree(T))
for u, v in combinations(G, 2):
cut_value, edge = self.minimum_edge_weight(T, u, v)
assert_equal(nx.minimum_cut_value(G, u, v),
cut_value)
示例14: test_karate_club_graph
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import is_tree [as 别名]
def test_karate_club_graph(self):
G = nx.karate_club_graph()
nx.set_edge_attributes(G, 1, 'capacity')
for flow_func in flow_funcs:
T = nx.gomory_hu_tree(G, flow_func=flow_func)
assert_true(nx.is_tree(T))
for u, v in combinations(G, 2):
cut_value, edge = self.minimum_edge_weight(T, u, v)
assert_equal(nx.minimum_cut_value(G, u, v),
cut_value)
示例15: test_davis_southern_women_graph
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import is_tree [as 别名]
def test_davis_southern_women_graph(self):
G = nx.davis_southern_women_graph()
nx.set_edge_attributes(G, 1, 'capacity')
for flow_func in flow_funcs:
T = nx.gomory_hu_tree(G, flow_func=flow_func)
assert_true(nx.is_tree(T))
for u, v in combinations(G, 2):
cut_value, edge = self.minimum_edge_weight(T, u, v)
assert_equal(nx.minimum_cut_value(G, u, v),
cut_value)