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


Python networkx.dfs_postorder_nodes方法代码示例

本文整理汇总了Python中networkx.dfs_postorder_nodes方法的典型用法代码示例。如果您正苦于以下问题:Python networkx.dfs_postorder_nodes方法的具体用法?Python networkx.dfs_postorder_nodes怎么用?Python networkx.dfs_postorder_nodes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在networkx的用法示例。


在下文中一共展示了networkx.dfs_postorder_nodes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _quasi_topological_sort

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import dfs_postorder_nodes [as 别名]
def _quasi_topological_sort(self):
        """
        Perform a quasi-topological sort on an already constructed CFG graph (a networkx DiGraph)

        :return: None
        """

        # Clear the existing sorting result
        self._quasi_topological_order = {}

        ctr = self._graph.number_of_nodes()

        for ep in self._entry_points:
            # FIXME: This is not always correct. We'd better store CFGNodes in self._entry_points
            ep_node = self.get_any_node(ep)

            if not ep_node:
                continue

            for n in networkx.dfs_postorder_nodes(self._graph, source=ep_node):
                if n not in self._quasi_topological_order:
                    self._quasi_topological_order[n] = ctr
                    ctr -= 1 
开发者ID:angr,项目名称:angr,代码行数:25,代码来源:cfg_emulated.py

示例2: reverse_post_order_sort_nodes

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import dfs_postorder_nodes [as 别名]
def reverse_post_order_sort_nodes(graph, nodes=None):
        """
        Sort a given set of nodes in reverse post ordering.

        :param networkx.DiGraph graph: A local transition graph of a function.
        :param iterable nodes: A collection of nodes to sort.
        :return: A list of sorted nodes.
        :rtype: list
        """

        post_order = networkx.dfs_postorder_nodes(graph)

        if nodes is None:
            return reversed(list(post_order))

        addrs_to_index = {}
        for i, n in enumerate(post_order):
            addrs_to_index[n.addr] = i
        return sorted(nodes, key=lambda n: addrs_to_index[n.addr], reverse=True) 
开发者ID:angr,项目名称:angr,代码行数:21,代码来源:cfg_utils.py

示例3: _merge_single_entry_node

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import dfs_postorder_nodes [as 别名]
def _merge_single_entry_node(self, graph):

        r = False

        while True:
            for node in networkx.dfs_postorder_nodes(graph):
                preds = graph.predecessors(node)
                if len(preds) == 1:
                    # merge the two nodes
                    self._absorb_node(graph, preds[0], node)
                    r = True
                    break
            else:
                break

        return r 
开发者ID:angr,项目名称:angr,代码行数:18,代码来源:region_identifier.py

示例4: compute_sfs

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import dfs_postorder_nodes [as 别名]
def compute_sfs(cls, leaf_states, demo):
        liklist = cls(leaf_states, demo)
        for event in nx.dfs_postorder_nodes(
                demo._event_tree):
            liklist._process_event(event)
        assert len(liklist.likelihood_list) == 1
        lik, = liklist.likelihood_list
        return lik.sfs 
开发者ID:popgenmethods,项目名称:momi2,代码行数:10,代码来源:compute_sfs.py

示例5: get_dag

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import dfs_postorder_nodes [as 别名]
def get_dag(dag):
    sorted_dag = dag.copy()

    # The children of a node are traversed in a random order. Therefore,
    # copy the graph, sort the children and then traverse it
    for adj in sorted_dag.adj:
        sorted_dag.adj[adj] = OrderedDict(
            sorted(sorted_dag.adj[adj].items(), key=lambda item: item[0]))

    nodes = nx.dfs_postorder_nodes(sorted_dag,
                                   source='__HPOlib_configuration_space_root__')
    nodes = [node for node in nodes if node !=
             '__HPOlib_configuration_space_root__']
    return nodes 
开发者ID:automl,项目名称:HPOlib,代码行数:16,代码来源:configuration_space.py

示例6: dfs_postorder_nodes

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import dfs_postorder_nodes [as 别名]
def dfs_postorder_nodes(G,source=None):
    """Produce nodes in a depth-first-search post-ordering starting
    from source.

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

    source : node, optional
       Specify starting node for depth-first search and return edges in
       the component reachable from source.

    Returns
    -------
    nodes: generator
       A generator of nodes in a depth-first-search post-ordering.

    Examples
    --------
    >>> G = nx.Graph()
    >>> G.add_path([0,1,2])
    >>> print(list(nx.dfs_postorder_nodes(G,0)))
    [2, 1, 0]

    Notes
    -----
    Based on http://www.ics.uci.edu/~eppstein/PADS/DFS.py
    by D. Eppstein, July 2004.

    If a source is not specified then a source is chosen arbitrarily and
    repeatedly until all components in the graph are searched.
    """
    post=(v for u,v,d in nx.dfs_labeled_edges(G,source=source)
          if d['dir']=='reverse')
    # potential modification: chain source to end of post-ordering
    # return chain(post,[source])
    return post 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:39,代码来源:depth_first_search.py

示例7: test_postorder_nodes

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import dfs_postorder_nodes [as 别名]
def test_postorder_nodes(self):
        assert_equal(list(nx.dfs_postorder_nodes(self.G,source=0)),
                     [3, 4, 2, 1, 0])
        assert_equal(list(nx.dfs_postorder_nodes(self.D)),[1, 0, 3, 2]) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:6,代码来源:test_dfs.py

示例8: dfs_postorder

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import dfs_postorder_nodes [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

示例9: test_postorder_nodes

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import dfs_postorder_nodes [as 别名]
def test_postorder_nodes(self):
        assert_equal(list(nx.dfs_postorder_nodes(self.G, source=0)),
                     [3, 4, 2, 1, 0])
        assert_equal(list(nx.dfs_postorder_nodes(self.D)), [1, 0, 3, 2]) 
开发者ID:holzschu,项目名称:Carnets,代码行数:6,代码来源:test_dfs.py

示例10: dls_test_postorder_nodes

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import dfs_postorder_nodes [as 别名]
def dls_test_postorder_nodes(self):
        assert_equal(list(nx.dfs_postorder_nodes(self.G,
                                                 source=3, depth_limit=3)), [1, 7, 2, 5, 4, 3])
        assert_equal(list(nx.dfs_postorder_nodes(self.D,
                                                 source=2, depth_limit=2)), ([3, 7, 2])) 
开发者ID:holzschu,项目名称:Carnets,代码行数:7,代码来源:test_dfs.py

示例11: dls_test_postorder_nodes

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import dfs_postorder_nodes [as 别名]
def dls_test_postorder_nodes(self):
        assert_equal(list(nx.dfs_postorder_nodes(self.G,
                     source=3, depth_limit=3)), [1, 7, 2, 5, 4, 3])
        assert_equal(list(nx.dfs_postorder_nodes(self.D,
                     source=2, depth_limit=2)),([3, 7, 2])) 
开发者ID:aws-samples,项目名称:aws-kube-codesuite,代码行数:7,代码来源:test_dfs.py

示例12: compute_dominance_frontier

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import dfs_postorder_nodes [as 别名]
def compute_dominance_frontier(graph, domtree):
    """
    Compute a dominance frontier based on the given post-dominator tree.

    This implementation is based on figure 2 of paper An Efficient Method of Computing Static Single Assignment
    Form by Ron Cytron, etc.

    :param graph:   The graph where we want to compute the dominance frontier.
    :param domtree: The dominator tree
    :returns:       A dict of dominance frontier
    """

    df = {}

    # Perform a post-order search on the dominator tree
    for x in networkx.dfs_postorder_nodes(domtree):

        if x not in graph:
            # Skip nodes that are not in the graph
            continue

        df[x] = set()

        # local set
        for y in graph.successors(x):
            if x not in domtree.predecessors(y):
                df[x].add(y)

        # up set
        if x is None:
            continue

        for z in domtree.successors(x):
            if z is x:
                continue
            if z not in df:
                continue
            for y in df[z]:
                if x not in list(domtree.predecessors(y)):
                    df[x].add(y)

    return df


#
# Dominators and post-dominators
# 
开发者ID:angr,项目名称:angr,代码行数:49,代码来源:graph.py

示例13: _make_cyclic_region

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import dfs_postorder_nodes [as 别名]
def _make_cyclic_region(self, head, graph):

        l.debug("Found cyclic region at %#08x", head.addr)
        initial_loop_nodes = self._find_initial_loop_nodes(graph, head)
        l.debug("Initial loop nodes %s", self._dbg_block_list(initial_loop_nodes))

        # Make sure there is no other loop contained in the current loop
        if {n for n in initial_loop_nodes if n.addr != head.addr}.intersection(self._loop_headers):
            return None

        normal_entries = {n for n in graph.predecessors(head) if n not in initial_loop_nodes}
        abnormal_entries = set()
        for n in initial_loop_nodes:
            if n == head:
                continue
            preds = set(graph.predecessors(n))
            abnormal_entries |= (preds - initial_loop_nodes)
        l.debug("Normal entries %s", self._dbg_block_list(normal_entries))
        l.debug("Abnormal entries %s", self._dbg_block_list(abnormal_entries))

        initial_exit_nodes = set()
        for n in initial_loop_nodes:
            succs = set(graph.successors(n))
            initial_exit_nodes |= (succs - initial_loop_nodes)

        l.debug("Initial exit nodes %s", self._dbg_block_list(initial_exit_nodes))

        refined_loop_nodes, refined_exit_nodes = self._refine_loop(graph, head, initial_loop_nodes,
                                                                   initial_exit_nodes)
        l.debug("Refined loop nodes %s", self._dbg_block_list(refined_loop_nodes))
        l.debug("Refined exit nodes %s", self._dbg_block_list(refined_exit_nodes))

        if len(refined_exit_nodes) > 1:
            # self._get_start_node(graph)
            node_post_order = list(networkx.dfs_postorder_nodes(graph, head))
            sorted_exit_nodes = sorted(list(refined_exit_nodes), key=node_post_order.index)
            normal_exit_node = sorted_exit_nodes[0]
            abnormal_exit_nodes = set(sorted_exit_nodes[1:])
        else:
            normal_exit_node = next(iter(refined_exit_nodes)) if len(refined_exit_nodes) > 0 else None
            abnormal_exit_nodes = set()

        region = self._abstract_cyclic_region(graph, refined_loop_nodes, head, normal_entries, abnormal_entries,
                                              normal_exit_node, abnormal_exit_nodes)
        if len(region.successors) > 1:
            # multi-successor region. refinement is required
            self._refine_loop_successors(region, graph)

        return region 
开发者ID:angr,项目名称:angr,代码行数:51,代码来源:region_identifier.py

示例14: kosaraju_strongly_connected_components

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import dfs_postorder_nodes [as 别名]
def kosaraju_strongly_connected_components(G, source=None):
    """Generate nodes in strongly connected components of graph.

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

    Returns
    -------
    comp : generator of sets
        A genrator of sets of nodes, one for each strongly connected
        component of G.

    Raises
    ------
    NetworkXNotImplemented:
        If G is undirected.

    Examples
    --------
    Generate a sorted list of strongly connected components, largest first.

    >>> G = nx.cycle_graph(4, create_using=nx.DiGraph())
    >>> G.add_cycle([10, 11, 12])
    >>> [len(c) for c in sorted(nx.kosaraju_strongly_connected_components(G),
    ...                         key=len, reverse=True)]
    [4, 3]

    If you only want the largest component, it's more efficient to
    use max instead of sort.

    >>> largest = max(nx.kosaraju_strongly_connected_components(G), key=len)

    See Also
    --------
    connected_components
    weakly_connected_components

    Notes
    -----
    Uses Kosaraju's algorithm.

    """
    with nx.utils.reversed(G):
        post = list(nx.dfs_postorder_nodes(G, source=source))

    seen = set()
    while post:
        r = post.pop()
        if r in seen:
            continue
        c = nx.dfs_preorder_nodes(G, r)
        new = {v for v in c if v not in seen}
        yield new
        seen.update(new) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:58,代码来源:strongly_connected.py

示例15: dfs_postorder_nodes

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import dfs_postorder_nodes [as 别名]
def dfs_postorder_nodes(G, source=None, depth_limit=None):
    """Generate nodes in a depth-first-search post-ordering starting at source.

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

    source : node, optional
       Specify starting node for depth-first search and return edges in
       the component reachable from source.

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

    Returns
    -------
    nodes: generator
       A generator of nodes in a depth-first-search post-ordering.

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

    Notes
    -----
    If a source is not specified then a source is chosen arbitrarily and
    repeatedly until all components in the graph are searched.

    The implementation of this function is adapted from David Eppstein's
    depth-first search function in `PADS`_, with modifications
    to allow depth limits based on the Wikipedia article
    "`Depth-limited search`_".

    .. _PADS: http://www.ics.uci.edu/~eppstein/PADS
    .. _Depth-limited search: https://en.wikipedia.org/wiki/Depth-limited_search

    See Also
    --------
    dfs_edges
    dfs_preorder_nodes
    dfs_labeled_edges
    """
    edges = nx.dfs_labeled_edges(G, source=source, depth_limit=depth_limit)
    return (v for u, v, d in edges if d == 'reverse') 
开发者ID:holzschu,项目名称:Carnets,代码行数:50,代码来源:depth_first_search.py


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