當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。