ó žÃÒYc@sidZddlmZddlZddlmZdjdgƒZddgZ dd „Z d „Z dS( s3Functions for computing dominating sets in a graph.iÿÿÿÿ(tchainN(tarbitrary_elements s%Jordi Torrents tdominating_settis_dominating_setcCsÇt|ƒ}|dkr't|ƒ}n||krNtjdj|ƒƒ‚n|h}t||ƒ}|||}xK|rÂ|jƒ}t||ƒ|}|j|ƒ||O}||8}qxW|S(s\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 snode {} is not in GN(tsettNoneRtnxt NetworkXErrortformattpoptadd(tGt start_witht all_nodesRtdominated_nodestremaining_nodestvtundominated_neighbors((st/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/dominating.pyR s$        cs_t‡fd†|Dƒƒ}ttj‡fd†|Dƒƒƒ}ttˆƒ||ƒdkS(sÛ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 c3s!|]}|ˆkr|VqdS(N((t.0tn(R (st/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/dominating.pys \sc3s|]}ˆ|VqdS(N((RR(R (st/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/dominating.pys ]si(RRt from_iterabletlen(R tnbunchttestsettnbrs((R st/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/dominating.pyREs%( t__doc__t itertoolsRtnetworkxRtnetworkx.utilsRtjoint __author__t__all__RRR(((st/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/dominating.pyts   9