
    hm
                     |    S r SSKJr  SSKrSSKJr  SS/r\R                  S	S j5       r	\R                  S 5       r
g)
z3Functions for computing dominating sets in a graph.    )chainN)arbitrary_elementdominating_setis_dominating_setc                 6   [        U 5      nUc  [        U5      nX;  a  [        R                  " SU S35      eU1n[        X   5      nX$-
  U-
  nU(       aB  UR	                  5       n[        X   5      U-
  nUR                  U5        XG-  nXW-  nU(       a  MB  U$ )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           P/var/www/html/env/lib/python3.13/site-packages/networkx/algorithms/dominating.pyr   r      s    J AI&y1
zl,?@@ \N!-(O1NBO
!qt9~5 	1++ /     c                    ^  U Vs1 s H  o"T ;   d  M
  UiM     nn[        [        R                  " U 4S jU 5       5      5      n[        [        T 5      U-
  U-
  5      S:H  $ s  snf )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   .   >#    U  H
  nTU   v   M     g 7fN ).0nr   s     r   	<genexpr>$is_dominating_set.<locals>.<genexpr>^   s     "9A1Q4s   r   )r   r   from_iterablelen)r   nbunchr   testsetnbrss   `    r   r   r   E   s[    0 !+&Q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   