U
    ¹mœde
  ã                   @   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   úW/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/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