ó
 ,ĩ[c           @   sM   d  Z  d d l m Z d Z d d g Z d e e d d  Z d d  Z d S(	   sY  Routines to find the boundary of a set of nodes.

An edge boundary is a set of edges, each of which has exactly one
endpoint in a given set of nodes (or, in the case of directed graphs,
the set of edges whose source node is in the set).

A node boundary of a set *S* of nodes is the set of (out-)neighbors of
nodes in *S* that are outside *S*.

iĸĸĸĸ(   t   chains^   Aric Hagberg (hagberg@lanl.gov)
Pieter Swart (swart@lanl.gov)
Dan Schult (dschult@colgate.edu)t   edge_boundaryt   node_boundaryc            sĪ     f d   |  D  |  j    rF |  j  d | d | d | } n |  j  d | d | } | d k r  f d   | D St |     f d   | D S(   sm  Returns the edge boundary of `nbunch1`.

    The *edge boundary* of a set *S* with respect to a set *T* is the
    set of edges (*u*, *v*) such that *u* is in *S* and *v* is in *T*.
    If *T* is not specified, it is assumed to be the set of all nodes
    not in *S*.

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

    nbunch1 : iterable
        Iterable of nodes in the graph representing the set of nodes
        whose edge boundary will be returned. (This is the set *S* from
        the definition above.)

    nbunch2 : iterable
        Iterable of nodes representing the target (or "exterior") set of
        nodes. (This is the set *T* from the definition above.) If not
        specified, this is assumed to be the set of all nodes in `G`
        not in `nbunch1`.

    keys : bool
        This parameter has the same meaning as in
        :meth:`MultiGraph.edges`.

    data : bool or object
        This parameter has the same meaning as in
        :meth:`MultiGraph.edges`.

    default : object
        This parameter has the same meaning as in
        :meth:`MultiGraph.edges`.

    Returns
    -------
    iterator
        An iterator over the edges in the boundary of `nbunch1` with
        respect to `nbunch2`. If `keys`, `data`, or `default`
        are specified and `G` is a multigraph, then edges are returned
        with keys and/or data, as in :meth:`MultiGraph.edges`.

    Notes
    -----
    Any element of `nbunch` that is not in the graph `G` will be
    ignored.

    `nbunch1` and `nbunch2` are usually meant to be disjoint, but in
    the interest of speed and generality, that is not required here.

    c            s"   h  |  ] } |   k r |  q S(    (    (   t   .0t   v(   t   nbunch1(    s;   lib/python2.7/site-packages/networkx/algorithms/boundary.pys	   <setcomp>N   s   	 t   datat   keyst   defaultc         3   s3   |  ]) } | d    k | d   k Ar | Vq d S(   i    i   N(    (   R   t   e(   t   nset1(    s;   lib/python2.7/site-packages/networkx/algorithms/boundary.pys	   <genexpr>]   s    c         3   sU   |  ]K } | d    k r) | d  k sI | d   k r | d   k r | Vq d S(   i    i   N(    (   R   R	   (   R
   t   nset2(    s;   lib/python2.7/site-packages/networkx/algorithms/boundary.pys	   <genexpr>_   s     N(   t   is_multigrapht   edgest   Nonet   set(   t   GR   t   nbunch2R   R   R   R   (    (   R   R
   R   s;   lib/python2.7/site-packages/networkx/algorithms/boundary.pyR      s    5$c            sb     f d   | D } t  t j   f d   | D   | } | d k	 r^ | t  |  M} n  | S(   s|  Returns the node boundary of `nbunch1`.

    The *node boundary* of a set *S* with respect to a set *T* is the
    set of nodes *v* in *T* such that for some *u* in *S*, there is an
    edge joining *u* to *v*. If *T* is not specified, it is assumed to
    be the set of all nodes not in *S*.

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

    nbunch1 : iterable
        Iterable of nodes in the graph representing the set of nodes
        whose node boundary will be returned. (This is the set *S* from
        the definition above.)

    nbunch2 : iterable
        Iterable of nodes representing the target (or "exterior") set of
        nodes. (This is the set *T* from the definition above.) If not
        specified, this is assumed to be the set of all nodes in `G`
        not in `nbunch1`.

    Returns
    -------
    set
        The node boundary of `nbunch1` with respect to `nbunch2`.

    Notes
    -----
    Any element of `nbunch` that is not in the graph `G` will be
    ignored.

    `nbunch1` and `nbunch2` are usually meant to be disjoint, but in
    the interest of speed and generality, that is not required here.

    c            s"   h  |  ] } |   k r |  q S(    (    (   R   t   n(   R   (    s;   lib/python2.7/site-packages/networkx/algorithms/boundary.pys	   <setcomp>   s   	 c         3   s   |  ] }   | Vq d  S(   N(    (   R   R   (   R   (    s;   lib/python2.7/site-packages/networkx/algorithms/boundary.pys	   <genexpr>   s    N(   R   R    t   from_iterableR   (   R   R   R   R
   t   bdy(    (   R   s;   lib/python2.7/site-packages/networkx/algorithms/boundary.pyR   d   s
    %)N(	   t   __doc__t	   itertoolsR    t
   __author__t   __all__R   t   FalseR   R   (    (    (    s;   lib/python2.7/site-packages/networkx/algorithms/boundary.pyt   <module>   s   	J