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


Python networkx.bfs_successors方法代码示例

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


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

示例1: bfs_seq

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import bfs_successors [as 别名]
def bfs_seq(G, start_id):
    '''
    get a bfs node sequence
    :param G:
    :param start_id:
    :return:
    '''
    dictionary = dict(nx.bfs_successors(G, start_id))
    start = [start_id]
    output = [start_id]
    while len(start) > 0:
        next = []
        while len(start) > 0:
            current = start.pop(0)
            neighbor = dictionary.get(current)
            if neighbor is not None:
                #### a wrong example, should not permute here!
                # shuffle(neighbor)
                next = next + neighbor
        output = output + next
        start = next
    return output 
开发者ID:JiaxuanYou,项目名称:graph-generation,代码行数:24,代码来源:data.py

示例2: reroot_graph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import bfs_successors [as 别名]
def reroot_graph(G: nx.DiGraph, node: str) -> nx.DiGraph:
    """Return a copy of the graph rooted at the given node"""
    G = G.copy()
    for n, successors in list(nx.bfs_successors(G, source=node)):
        for s in successors:
            G.add_edge(s, n, **G.edges[n, s])
            G.remove_edge(n, s)
    return G 
开发者ID:remix,项目名称:partridge,代码行数:10,代码来源:config.py

示例3: bfs_successors

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import bfs_successors [as 别名]
def bfs_successors(self, node):
        """
        Returns an iterator of tuples of (DAGNode, [DAGNodes]) where the DAGNode is the current node
        and [DAGNode] is its successors in  BFS order.
        """
        return ((self._id_to_node[idx], [self._id_to_node[succ] for succ in succ_list])
                for idx, succ_list in nx.bfs_successors(self._multi_graph, node._node_id)) 
开发者ID:Qiskit,项目名称:qiskit-terra,代码行数:9,代码来源:networkx_dagcircuit.py

示例4: bfs_successors

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import bfs_successors [as 别名]
def bfs_successors(G, source):
    """Return dictionary of successors in breadth-first-search from source.

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

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

    Returns
    -------
    succ: dict
       A dictionary with nodes as keys and list of succssors nodes as values.

    Examples
    --------
    >>> G = nx.Graph()
    >>> G.add_path([0,1,2])
    >>> print(nx.bfs_successors(G,0))
    {0: [1], 1: [2]}

    Notes
    -----
    Based on http://www.ics.uci.edu/~eppstein/PADS/BFS.py
    by D. Eppstein, July 2004.
    """
    d = defaultdict(list)
    for s,t in bfs_edges(G,source):
        d[s].append(t)
    return dict(d) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:34,代码来源:breadth_first_search.py

示例5: test_successor

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

示例6: test_successor

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import bfs_successors [as 别名]
def test_successor(self):
        assert_equal(dict(nx.bfs_successors(self.G, source=0)),
                     {0: [1], 1: [2, 3], 2: [4]}) 
开发者ID:holzschu,项目名称:Carnets,代码行数:5,代码来源:test_bfs.py

示例7: bfs_test_successor

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import bfs_successors [as 别名]
def bfs_test_successor(self):
        assert_equal(dict(nx.bfs_successors(self.G, source=1, depth_limit=3)),
                     {1: [0, 2], 2: [3, 7], 3: [4], 7: [8]})
        result = {n: sorted(s) for n, s in nx.bfs_successors(self.D, source=7,
                                                             depth_limit=2)}
        assert_equal(result, {8: [9], 2: [3], 7: [2, 8]}) 
开发者ID:holzschu,项目名称:Carnets,代码行数:8,代码来源:test_bfs.py

示例8: _single_adsorption

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import bfs_successors [as 别名]
def _single_adsorption(
            self,
            adsorbate,
            bond,
            slab=None,
            site_index=0,
            auto_construct=True,
            symmetric=True):
        """Bond and adsorbate by a single atom."""
        if slab is None:
            slab = self.slab.copy()
        atoms = adsorbate.copy()
        atoms.set_cell(slab.cell)

        if symmetric:
            ind = self.get_symmetric_sites()[site_index]
            vector = self.get_adsorption_vectors()[site_index]
        else:
            ind = self.get_periodic_sites()[site_index]
            vector = self.get_adsorption_vectors(unique=False)[site_index]

        # Improved position estimate for site.
        u = self.r1_topology[ind]
        r = radii[slab[self.index[u]].numbers]
        top_sites = self.coordinates[self.connectivity == 1]

        numbers = atoms.numbers[bond]
        R = radii[numbers]
        base_position = utils.trilaterate(top_sites[u], r + R, vector)

        branches = nx.bfs_successors(atoms.graph, bond)
        atoms.translate(-atoms.positions[bond])

        if auto_construct:
            atoms = catkit.gen.molecules.get_3D_positions(atoms, bond)

            # Align with the adsorption vector
            atoms.rotate([0, 0, 1], vector)

        atoms.translate(base_position)
        n = len(slab)
        slab += atoms

        # Add graph connections
        for metal_index in self.index[u]:
            slab.graph.add_edge(metal_index, bond + n)

        return slab 
开发者ID:SUNCAT-Center,项目名称:CatKit,代码行数:50,代码来源:adsorption.py

示例9: bfs_successors

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import bfs_successors [as 别名]
def bfs_successors(G, source, depth_limit=None):
    """Returns an iterator of successors in breadth-first-search from source.

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

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

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

    Returns
    -------
    succ: iterator
       (node, successors) iterator where successors is the list of
       successors of the node.

    Examples
    --------
    >>> G = nx.path_graph(3)
    >>> print(dict(nx.bfs_successors(G,0)))
    {0: [1], 1: [2]}
    >>> H = nx.Graph()
    >>> H.add_edges_from([(0, 1), (0, 2), (1, 3), (1, 4), (2, 5), (2, 6)])
    >>> print(dict(nx.bfs_successors(H, 0)))
    {0: [1, 2], 1: [3, 4], 2: [5, 6]}
    >>> G = nx.Graph()
    >>> nx.add_path(G, [0, 1, 2, 3, 4, 5, 6])
    >>> nx.add_path(G, [2, 7, 8, 9, 10])
    >>> print(dict(nx.bfs_successors(G, source=1, depth_limit=3)))
    {1: [0, 2], 2: [3, 7], 3: [4], 7: [8]}


    Notes
    -----
    Based on http://www.ics.uci.edu/~eppstein/PADS/BFS.py
    by D. Eppstein, July 2004.The modifications
    to allow depth limits based on the Wikipedia article
    "`Depth-limited-search`_".

    .. _Depth-limited-search: https://en.wikipedia.org/wiki/Depth-limited_search
    """
    parent = source
    children = []
    for p, c in bfs_edges(G, source, depth_limit=depth_limit):
        if p == parent:
            children.append(c)
            continue
        yield (parent, children)
        children = [c]
        parent = p
    yield (parent, children) 
开发者ID:holzschu,项目名称:Carnets,代码行数:57,代码来源:breadth_first_search.py

示例10: bfs_successors

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import bfs_successors [as 别名]
def bfs_successors(G, source):
    """Returns an iterator of successors in breadth-first-search from source.

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

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

    Returns
    -------
    succ: iterator
       (node, successors) iterator where successors is the list of
       successors of the node.

    Examples
    --------
    >>> G = nx.path_graph(3)
    >>> print(dict(nx.bfs_successors(G,0)))
    {0: [1], 1: [2]}
    >>> H = nx.Graph()
    >>> H.add_edges_from([(0, 1), (0, 2), (1, 3), (1, 4), (2, 5), (2, 6)])
    >>> dict(nx.bfs_successors(H, 0))
    {0: [1, 2], 1: [3, 4], 2: [5, 6]}


    Notes
    -----
    Based on http://www.ics.uci.edu/~eppstein/PADS/BFS.py
    by D. Eppstein, July 2004.
    """
    parent = source
    children = []
    for p, c in bfs_edges(G, source):
        if p == parent:
            children.append(c)
            continue
        yield (parent, children)
        children = [c]
        parent = p
    yield (parent, children) 
开发者ID:aws-samples,项目名称:aws-kube-codesuite,代码行数:45,代码来源:breadth_first_search.py


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