o
    hm
                     @   sN   d Z ddlmZ ddlZddlmZ ddgZej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u rt|}|| vrtd| d|h}t | | }|| | }|rE| }t | | | }|| ||O }||8 }|s*|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   nxNetworkXErrorpopadd)G
start_with	all_nodesr   dominated_nodesremaining_nodesvundominated_nbrs r   r/var/www/html/construction_image-detection-poc/venv/lib/python3.10/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 | ]}| v 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   nbunchtestsetnbrsr   r   r   r   E   s   r   )__doc__	itertoolsr   networkxr   networkx.utilsr   __all___dispatchabler   r   r   r   r   r   <module>   s    9