當前位置: 首頁>>代碼示例>>Python>>正文


Python networkx.dfs_tree方法代碼示例

本文整理匯總了Python中networkx.dfs_tree方法的典型用法代碼示例。如果您正苦於以下問題:Python networkx.dfs_tree方法的具體用法?Python networkx.dfs_tree怎麽用?Python networkx.dfs_tree使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在networkx的用法示例。


在下文中一共展示了networkx.dfs_tree方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: dfs_tree

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import dfs_tree [as 別名]
def dfs_tree(G, source):
    """Return oriented tree constructed from a depth-first-search from source.

    Parameters
    ----------
    G : NetworkX graph

    source : node, optional
       Specify starting node for depth-first search.

    Returns
    -------
    T : NetworkX DiGraph
       An oriented tree

    Examples
    --------
    >>> G = nx.Graph()
    >>> G.add_path([0,1,2])
    >>> T = nx.dfs_tree(G,0)
    >>> print(T.edges())
    [(0, 1), (1, 2)]
    """
    T = nx.DiGraph()
    if source is None:
        T.add_nodes_from(G)
    else:
        T.add_node(source)
    T.add_edges_from(dfs_edges(G,source))
    return T 
開發者ID:SpaceGroupUCL,項目名稱:qgisSpaceSyntaxToolkit,代碼行數:32,代碼來源:depth_first_search.py

示例2: test_dfs_tree

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import dfs_tree [as 別名]
def test_dfs_tree(self):
        T=nx.dfs_tree(self.G,source=0)
        assert_equal(sorted(T.nodes()),sorted(self.G.nodes()))
        assert_equal(sorted(T.edges()),[(0, 1), (1, 2), (2, 4), (4, 3)]) 
開發者ID:SpaceGroupUCL,項目名稱:qgisSpaceSyntaxToolkit,代碼行數:6,代碼來源:test_dfs.py

示例3: test_dfs_tree_isolates

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import dfs_tree [as 別名]
def test_dfs_tree_isolates(self):
        G = nx.Graph()
        G.add_node(1)
        G.add_node(2)
        T=nx.dfs_tree(G,source=1)
        assert_equal(sorted(T.nodes()),[1])
        assert_equal(sorted(T.edges()),[])
        T=nx.dfs_tree(G,source=None)
        assert_equal(sorted(T.nodes()),[1, 2])
        assert_equal(sorted(T.edges()),[]) 
開發者ID:SpaceGroupUCL,項目名稱:qgisSpaceSyntaxToolkit,代碼行數:12,代碼來源:test_dfs.py

示例4: dfs_postorder

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import dfs_tree [as 別名]
def dfs_postorder(self, root):
        G = nx.Graph(self.E)
        tree_graph = nx.dfs_tree(G,root)
        clique_ordering = list(nx.dfs_postorder_nodes(tree_graph,root))
        return clique_ordering 
開發者ID:ncullen93,項目名稱:pyBN,代碼行數:7,代碼來源:cliquetree.py

示例5: dfs_tree

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import dfs_tree [as 別名]
def dfs_tree(G, source=None, depth_limit=None):
    """Returns oriented tree constructed from a depth-first-search from source.

    Parameters
    ----------
    G : NetworkX graph

    source : node, optional
       Specify starting node for depth-first search.

    depth_limit : int, optional (default=len(G))
       Specify the maximum search depth.

    Returns
    -------
    T : NetworkX DiGraph
       An oriented tree

    Examples
    --------
    >>> G = nx.path_graph(5)
    >>> T = nx.dfs_tree(G, source=0, depth_limit=2)
    >>> list(T.edges())
    [(0, 1), (1, 2)]
    >>> T = nx.dfs_tree(G, source=0)
    >>> list(T.edges())
    [(0, 1), (1, 2), (2, 3), (3, 4)]

    """
    T = nx.DiGraph()
    if source is None:
        T.add_nodes_from(G)
    else:
        T.add_node(source)
    T.add_edges_from(dfs_edges(G, source, depth_limit))
    return T 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:38,代碼來源:depth_first_search.py

示例6: test_dfs_tree

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import dfs_tree [as 別名]
def test_dfs_tree(self):
        exp_nodes = sorted(self.G.nodes())
        exp_edges = [(0, 1), (1, 2), (2, 4), (4, 3)]
        # Search from first node
        T = nx.dfs_tree(self.G, source=0)
        assert_equal(sorted(T.nodes()), exp_nodes)
        assert_equal(sorted(T.edges()), exp_edges)
        # Check source=None
        T = nx.dfs_tree(self.G, source=None)
        assert_equal(sorted(T.nodes()), exp_nodes)
        assert_equal(sorted(T.edges()), exp_edges)
        # Check source=None is the default
        T = nx.dfs_tree(self.G)
        assert_equal(sorted(T.nodes()), exp_nodes)
        assert_equal(sorted(T.edges()), exp_edges) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:17,代碼來源:test_dfs.py

示例7: test_dfs_tree_isolates

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import dfs_tree [as 別名]
def test_dfs_tree_isolates(self):
        G = nx.Graph()
        G.add_node(1)
        G.add_node(2)
        T = nx.dfs_tree(G, source=1)
        assert_equal(sorted(T.nodes()), [1])
        assert_equal(sorted(T.edges()), [])
        T = nx.dfs_tree(G, source=None)
        assert_equal(sorted(T.nodes()), [1, 2])
        assert_equal(sorted(T.edges()), []) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:12,代碼來源:test_dfs.py

示例8: test_dls_tree

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import dfs_tree [as 別名]
def test_dls_tree(self):
        T = nx.dfs_tree(self.G, source=3, depth_limit=1)
        assert_equal(sorted(T.edges()), [(3, 2), (3, 4)]) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:5,代碼來源:test_dfs.py

示例9: dfs_tree

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import dfs_tree [as 別名]
def dfs_tree(G, source=None, depth_limit=None):
    """Return oriented tree constructed from a depth-first-search from source.

    Parameters
    ----------
    G : NetworkX graph

    source : node, optional
       Specify starting node for depth-first search.

    depth_limit : int, optional (default=len(G))
       Specify the maximum search depth.

    Returns
    -------
    T : NetworkX DiGraph
       An oriented tree

    Examples
    --------
    >>> G = nx.path_graph(5)
    >>> T = nx.dfs_tree(G, source=0, depth_limit=2)
    >>> list(T.edges())
    [(0, 1), (1, 2)]
    >>> T = nx.dfs_tree(G, source=0)
    >>> list(T.edges())
    [(0, 1), (1, 2), (2, 3), (3, 4)]

    """
    T = nx.DiGraph()
    if source is None:
        T.add_nodes_from(G)
    else:
        T.add_node(source)
    T.add_edges_from(dfs_edges(G, source, depth_limit))
    return T 
開發者ID:aws-samples,項目名稱:aws-kube-codesuite,代碼行數:38,代碼來源:depth_first_search.py

示例10: test_dfs_tree

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import dfs_tree [as 別名]
def test_dfs_tree(self):
        exp_nodes = sorted(self.G.nodes())
        exp_edges = [(0, 1), (1, 2), (2, 4), (4, 3)]
        # Search from first node
        T=nx.dfs_tree(self.G,source=0)
        assert_equal(sorted(T.nodes()), exp_nodes)
        assert_equal(sorted(T.edges()), exp_edges)
        # Check source=None
        T = nx.dfs_tree(self.G, source=None)
        assert_equal(sorted(T.nodes()), exp_nodes)
        assert_equal(sorted(T.edges()), exp_edges)
        # Check source=None is the default
        T = nx.dfs_tree(self.G)
        assert_equal(sorted(T.nodes()), exp_nodes)
        assert_equal(sorted(T.edges()), exp_edges) 
開發者ID:aws-samples,項目名稱:aws-kube-codesuite,代碼行數:17,代碼來源:test_dfs.py


注:本文中的networkx.dfs_tree方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。