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


Python networkx.is_tree方法代码示例

本文整理汇总了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 
开发者ID:rigetti,项目名称:forest-benchmarking,代码行数:23,代码来源:entangled_states.py

示例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 
开发者ID:mims-harvard,项目名称:ohmnet,代码行数:20,代码来源:utility.py

示例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."
            ) 
开发者ID:HazyResearch,项目名称:metal,代码行数:11,代码来源:task_graph.py

示例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) 
开发者ID:FragileTech,项目名称:fragile,代码行数:10,代码来源:test_tree.py

示例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) 
开发者ID:UCLCheminformatics,项目名称:ScaffoldGraph,代码行数:7,代码来源:test_tree.py

示例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) 
开发者ID:UCLCheminformatics,项目名称:ScaffoldGraph,代码行数:7,代码来源:test_tree.py

示例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()) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:5,代码来源:test_recognition.py

示例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)) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:6,代码来源:test_recognition.py

示例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)) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:6,代码来源:test_recognition.py

示例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)) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:11,代码来源:test_recognition.py

示例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)) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:7,代码来源:test_recognition.py

示例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)) 
开发者ID:holzschu,项目名称:Carnets,代码行数:7,代码来源:test_recognition.py

示例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) 
开发者ID:holzschu,项目名称:Carnets,代码行数:11,代码来源:test_gomory_hu.py

示例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) 
开发者ID:holzschu,项目名称:Carnets,代码行数:12,代码来源:test_gomory_hu.py

示例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) 
开发者ID:holzschu,项目名称:Carnets,代码行数:12,代码来源:test_gomory_hu.py


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