コード例 #1
0
def n_edges_between(g, nbunch1, nbunch2):
    """Number of edges betwen nbunches.

    This returns the edges that begin in nbunch1 and end in nbunch2.
    This interpertation holds true for directed and undirected graphs.
    If nbunch1==nbunch2 and the graph is undirected, returns **double
    the number of edges**.  Any edges with both ends in the
    intersection of nbunch1 and nbunch2 will be included twice for
    directed graphs.

    Return value:
        Set of all edges (tuples ``(n1, n2)``) between two sets of
        nodes nbunch1 and nbunch2.


    Complexity:
        time: ``O(len(nbunch1))``  or  ``O( min(len(nbunch1), len(nbunch2)) )``
            For undirected graphs, nbunch1 and nbunch2 will be can be
            switched for efficiency purposes.

            nbunch2 (or nbunch1, if switched) MUST be sets or support
            ``O(1)`` ``__contains__`` in order to achieve this optimal
            efficiency, otherwise complexity is
            ``O(len(nbunch1)*len(nbunch2))``

        space: O(1)

    See also:
        n_edges_between for a version that returns only the
        counts between two nbunches.
    """
    import verkko.misc.testutil as testutil
    testutil.warn_untested()
    n = 0
    # switch so nbunch1 is the smaller set.
    if (isinstance(g, networkx.Graph) and not isinstance(g, networkx.DiGraph)
            and len(nbunch1) > len(nbunch2)):
        nbunch1, nbunch2 = nbunch2, nbunch1
    for n1 in nbunch1:
        for neighbor in g.adj[n1]:  # iterate neighbors (or successors)
            if neighbor in nbunch2:
                n += 1
    return n
コード例 #2
0
ファイル: nxutil.py プロジェクト: CxAalto/verkko
def n_edges_between(g, nbunch1, nbunch2):
    """Number of edges betwen nbunches.

    This returns the edges that begin in nbunch1 and end in nbunch2.
    This interpertation holds true for directed and undirected graphs.
    If nbunch1==nbunch2 and the graph is undirected, returns **double
    the number of edges**.  Any edges with both ends in the
    intersection of nbunch1 and nbunch2 will be included twice for
    directed graphs.

    Return value:
        Set of all edges (tuples ``(n1, n2)``) between two sets of
        nodes nbunch1 and nbunch2.


    Complexity:
        time: ``O(len(nbunch1))``  or  ``O( min(len(nbunch1), len(nbunch2)) )``
            For undirected graphs, nbunch1 and nbunch2 will be can be
            switched for efficiency purposes.

            nbunch2 (or nbunch1, if switched) MUST be sets or support
            ``O(1)`` ``__contains__`` in order to achieve this optimal
            efficiency, otherwise complexity is
            ``O(len(nbunch1)*len(nbunch2))``

        space: O(1)

    See also:
        n_edges_between for a version that returns only the
        counts between two nbunches.
    """
    import verkko.misc.testutil as testutil ; testutil.warn_untested()
    n = 0
    # switch so nbunch1 is the smaller set.
    if (isinstance(g, networkx.Graph) and not isinstance(g, networkx.DiGraph)
            and len(nbunch1) > len(nbunch2) ):
        nbunch1, nbunch2 = nbunch2, nbunch1
    for n1 in nbunch1:
        for neighbor in g.adj[n1]:  # iterate neighbors (or successors)
            if neighbor in nbunch2:
                n += 1
    return n
コード例 #3
0
ファイル: nxutil.py プロジェクト: CxAalto/verkko
def edges_between(g, nbunch1, nbunch2):
    """List of edges between two node sets.

    For all information on this function, see documentation on
    ``n_edges_between``.

    Return value: list of tuples ``(node1, node2)``
        List of edges between nbunch1 and nbunch2.  For directed
        graphs, tuples are (from, to).
    """
    import verkko.misc.testutil as testutil ; testutil.warn_untested()
    # switch so nbunch1 is the smaller set.
    if (isinstance(g, networkx.Graph) and not isinstance(g, networkx.DiGraph)
            and len(nbunch1) > len(nbunch2) ):
        nbunch1, nbunch2 = nbunch2, nbunch1
    edges = [ ]
    for n1 in nbunch1:
        for neighbor in g.adj[n1]:  # iterate neighbors (or successors)
            if neighbor in nbunch2:
                edges.append((n1, neighbor))
    return edges
コード例 #4
0
def edges_between(g, nbunch1, nbunch2):
    """List of edges between two node sets.

    For all information on this function, see documentation on
    ``n_edges_between``.

    Return value: list of tuples ``(node1, node2)``
        List of edges between nbunch1 and nbunch2.  For directed
        graphs, tuples are (from, to).
    """
    import verkko.misc.testutil as testutil
    testutil.warn_untested()
    # switch so nbunch1 is the smaller set.
    if (isinstance(g, networkx.Graph) and not isinstance(g, networkx.DiGraph)
            and len(nbunch1) > len(nbunch2)):
        nbunch1, nbunch2 = nbunch2, nbunch1
    edges = []
    for n1 in nbunch1:
        for neighbor in g.adj[n1]:  # iterate neighbors (or successors)
            if neighbor in nbunch2:
                edges.append((n1, neighbor))
    return edges