コード例 #1
0
def kosaraju_strongly_connected_components(G,source=None):
    """Return nodes in strongly connected components of graph.

    Parameters
    ----------
    G : NetworkX Graph
       An directed graph.

    Returns
    -------
    comp : list of lists
       A list of nodes for each component of G.
       The list is ordered from largest connected component to smallest.

    See Also       
    --------
    connected_components

    Notes
    -----
    Uses Kosaraju's algorithm.
    """
    components=[]
    post=nx.dfs_postorder(G,source=source,reverse_graph=True)
    seen={}
    while post:
        r=post.pop()
        if r in seen:
            continue
        c=nx.dfs_preorder(G,r)
        new=[v for v in c if v not in seen]
        seen.update([(u,True) for u in new])
        components.append(new)
    components.sort(key=len,reverse=True)            
    return components            
コード例 #2
0
def kosaraju_strongly_connected_components(G,source=None):
    """Return nodes in strongly connected components of graph.

    Parameters
    ----------
    G : NetworkX Graph
       An directed graph.

    Returns
    -------
    comp : list of lists
       A list of nodes for each component of G.
       The list is ordered from largest connected component to smallest.

    See Also       
    --------
    connected_components

    Notes
    -----
    Uses Kosaraju's algorithm.
    """
    components=[]
    post=nx.dfs_postorder(G,source=source,reverse_graph=True)
    seen={}
    while post:
        r=post.pop()
        if r in seen:
            continue
        c=nx.dfs_preorder(G,r)
        new=[v for v in c if v not in seen]
        seen.update([(u,True) for u in new])
        components.append(new)
    components.sort(key=len,reverse=True)            
    return components            
コード例 #3
0
ファイル: pipeline.py プロジェクト: benkehoe/python
 def restrict_to_target(self, target):
     revgraph = self.graph.reverse()
     nodes = nx.dfs_postorder(revgraph, target)
     new_graph = self.graph.subgraph(nodes)
     new_pipeline = Pipeline()
     new_pipeline.graph = new_graph
     new_pipeline.env = self.env
     return new_pipeline
コード例 #4
0
 def restrict_to_target(self, target):
     revgraph = self.graph.reverse()
     nodes = nx.dfs_postorder(revgraph, target)
     new_graph = self.graph.subgraph(nodes)
     new_pipeline = Pipeline()
     new_pipeline.graph = new_graph
     new_pipeline.env = self.env
     return new_pipeline
コード例 #5
0
ファイル: test_dfs.py プロジェクト: c0ns0le/zenoss-4
 def test_postorder(self):
     assert_equal(nx.dfs_postorder(self.G,source=0),[3, 4, 2, 1, 0])
コード例 #6
0
ファイル: test_dfs.py プロジェクト: c0ns0le/zenoss-4
 def test_postorder(self):
     assert_equal(nx.dfs_postorder(self.G, source=0), [3, 4, 2, 1, 0])