ó
 ,µ[c           @   si   d  Z  d d l m Z d d l Z d d l m Z d j d g ƒ Z d d g Z	 d d	 „ Z d
 „  Z d S(   s3   Functions for computing dominating sets in a graph.iÿÿÿÿ(   t   chainN(   t   arbitrary_elements   
s%   Jordi Torrents <jtorrents@milnou.net>t   dominating_sett   is_dominating_setc         C   sÇ   t  |  ƒ } | d k r' t | ƒ } n  | |  k rN t j d j | ƒ ƒ ‚ n  | h } t  |  | ƒ } | | | } xK | rÂ | j ƒ  } t  |  | ƒ | } | j | ƒ | | O} | | 8} qx W| S(   s\  Finds a dominating set for the graph G.

    A *dominating set* for a graph with node set *V* is a subset *D* of
    *V* such that every node not in *D* is adjacent to at least one
    member of *D* [1]_.

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

    start_with : node (default=None)
        Node to use as a starting point for the algorithm.

    Returns
    -------
    D : set
        A dominating set for G.

    Notes
    -----
    This function is an implementation of algorithm 7 in [2]_ which
    finds some dominating set, not necessarily the smallest one.

    See also
    --------
    is_dominating_set

    References
    ----------
    .. [1] https://en.wikipedia.org/wiki/Dominating_set

    .. [2] Abdol-Hossein Esfahanian. Connectivity Algorithms.
        http://www.cse.msu.edu/~cse835/Papers/Graph_connectivity_revised.pdf

    s   node {} is not in GN(   t   sett   NoneR   t   nxt   NetworkXErrort   formatt   popt   add(   t   Gt
   start_witht	   all_nodesR   t   dominated_nodest   remaining_nodest   vt   undominated_neighbors(    (    s=   lib/python2.7/site-packages/networkx/algorithms/dominating.pyR      s    $		
c            s_   t  ‡  f d †  | Dƒ ƒ } t  t j ‡  f d †  | Dƒ ƒ ƒ } t t  ˆ  ƒ | | ƒ d k S(   sÛ  Checks if `nbunch` is a dominating set for `G`.

    A *dominating set* for a graph with node set *V* is a subset *D* of
    *V* such that every node not in *D* is adjacent to at least one
    member of *D* [1]_.

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

    nbunch : iterable
        An iterable of nodes in the graph `G`.

    See also
    --------
    dominating_set

    References
    ----------
    .. [1] https://en.wikipedia.org/wiki/Dominating_set

    c         3   s!   |  ] } | ˆ  k r | Vq d  S(   N(    (   t   .0t   n(   R   (    s=   lib/python2.7/site-packages/networkx/algorithms/dominating.pys	   <genexpr>\   s    c         3   s   |  ] } ˆ  | Vq d  S(   N(    (   R   R   (   R   (    s=   lib/python2.7/site-packages/networkx/algorithms/dominating.pys	   <genexpr>]   s    i    (   R   R    t   from_iterablet   len(   R   t   nbuncht   testsett   nbrs(    (   R   s=   lib/python2.7/site-packages/networkx/algorithms/dominating.pyR   E   s    %(   t   __doc__t	   itertoolsR    t   networkxR   t   networkx.utilsR   t   joint
   __author__t   __all__R   R   R   (    (    (    s=   lib/python2.7/site-packages/networkx/algorithms/dominating.pyt   <module>   s   9