U
    9vfe
                     @   sH   d Z ddlmZ ddlZddlmZ ddgZd	ddZej	dd Z
dS )
z3Functions for computing dominating sets in a graph.    )chainN)arbitrary_elementdominating_setis_dominating_setc                 C   s   t | }|dkrt|}|| kr2td| d|h}t | | }|| | }|r| }t | | | }|| ||O }||8 }qP|S )a\  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

    Nznode z is not in G)setr   nxZNetworkXErrorpopadd)GZ
start_withZ	all_nodesr   Zdominated_nodesZremaining_nodesvZundominated_neighbors r   B/tmp/pip-unpacked-wheel-_lngutwb/networkx/algorithms/dominating.pyr   
   s    $

c                    sF    fdd|D }t t fdd|D }tt  | | dkS )a  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                    s   h | ]}| kr|qS r   r   .0nr
   r   r   	<setcomp>[   s      z$is_dominating_set.<locals>.<setcomp>c                 3   s   | ]} | V  qd S )Nr   r   r   r   r   	<genexpr>\   s     z$is_dominating_set.<locals>.<genexpr>r   )r   r   from_iterablelen)r
   ZnbunchZtestsetZnbrsr   r   r   r   C   s    )N)__doc__	itertoolsr   Znetworkxr   Znetworkx.utilsr   __all__r   	_dispatchr   r   r   r   r   <module>   s   
9