
    ިsgm
                     z    d Z ddlmZ ddlZddlmZ ddgZej                  d	d       Z	ej                  d        Z
y)
z3Functions for computing dominating sets in a graph.    )chainN)arbitrary_elementdominating_setis_dominating_setc                 $   t        |       }|t        |      }|| vrt        j                  d| d      |h}t        | |         }||z
  |z
  }|r?|j	                         }t        | |         |z
  }|j                  |       ||z  }||z  }|r?|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

    znode z is not in G)setr   nxNetworkXErrorpopadd)G
start_with	all_nodesr   dominated_nodesremaining_nodesvundominated_nbrss           Q/var/www/html/venv/lib/python3.12/site-packages/networkx/algorithms/dominating.pyr   r      s    J AI&y1
zl,?@@ \N!J-(O/1NBO
!qt9~5 	1++++      c                      |D ch c]	  }| v s| }}t        t        j                   fd|D                    }t        t               |z
  |z
        dk(  S c c}w )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              3   (   K   | ]	  }|     y wN ).0nr   s     r   	<genexpr>z$is_dominating_set.<locals>.<genexpr>^   s     "9A1Q4"9s   r   )r   r   from_iterablelen)r   nbunchr   testsetnbrss   `    r   r   r   E   s\    0 !+QAFq+G+u"""9"99:Ds1v$&'1,, ,s
   	AAr   )__doc__	itertoolsr   networkxr	   networkx.utilsr   __all___dispatchabler   r   r   r   r   <module>r(      sQ    9   ,0
1 6 6r - -r   