ó žÃÒYc@ smdZddlmZddlmZddlmZddgZd Zed ƒd d „ƒZ d „Z d S(sFunctions for finding node and edge dominating sets. A `dominating set`_ for an undirected graph *G* with vertex set *V* and edge set *E* is a subset *D* of *V* such that every vertex not in *D* is adjacent to at least one member of *D*. An `edge dominating set`_ is a subset *F* of *E* such that every edge not in *F* is incident to an endpoint of at least one edge in *F*. .. _dominating set: https://en.wikipedia.org/wiki/Dominating_set .. _edge dominating set: https://en.wikipedia.org/wiki/Edge_dominating_set iÿÿÿÿ(tdivisioni(tmaximal_matchingi(tnot_implemented_fortmin_weighted_dominating_settmin_edge_dominating_sets)Nicholas Mancuso (nick.mancuso@gmail.com)tdirectedc s¦tˆƒdkrtƒStƒ‰‡‡‡fd†}tˆƒ}‡fd†ˆDƒ}xF|r¡t|jƒd|ƒ\}}ˆj|ƒ||=||8}q\WˆS(s[Returns a dominating set that approximates the minimum weight node dominating set. Parameters ---------- G : NetworkX graph Undirected graph. weight : string The node attribute storing the weight of an edge. If provided, the node attribute with this key must be a number for each node. If not provided, each node is assumed to have weight one. Returns ------- min_weight_dominating_set : set A set of nodes, the sum of whose weights is no more than `(\log w(V)) w(V^*)`, where `w(V)` denotes the sum of the weights of each node in the graph and `w(V^*)` denotes the sum of the weights of each node in the minimum weight dominating set. Notes ----- This algorithm computes an approximate minimum weighted dominating set for the graph `G`. The returned solution has weight `(\log w(V)) w(V^*)`, where `w(V)` denotes the sum of the weights of each node in the graph and `w(V^*)` denotes the sum of the weights of each node in the minimum weight dominating set for the graph. This implementation of the algorithm runs in $O(m)$ time, where $m$ is the number of edges in the graph. References ---------- .. [1] Vazirani, Vijay V. *Approximation Algorithms*. Springer Science & Business Media, 2001. ic s1|\}}ˆj|jˆdƒt|ˆƒS(s¼Returns the cost-effectiveness of greedily choosing the given node. `node_and_neighborhood` is a two-tuple comprising a node and its closed neighborhood. i(tnodestgettlen(tnode_and_neighborhoodtvt neighborhood(tGtdom_settweight(s†/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/approximation/dominating_set.pyt_costNs c s*i|] }|htˆ|ƒB|“qS((tset(t.0R (R (s†/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/approximation/dominating_set.pys ^s tkey(RRtmintitemstadd(R RRtverticest neighborhoodstdom_nodetmin_set((R R Rs†/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/approximation/dominating_set.pyRs*    cC s|stdƒ‚nt|ƒS(sâReturn minimum cardinality edge dominating set. Parameters ---------- G : NetworkX graph Undirected graph Returns ------- min_edge_dominating_set : set Returns a set of dominating edges whose size is no more than 2 * OPT. Notes ----- The algorithm computes an approximate solution to the edge dominating set problem. The result is no more than 2 * OPT in terms of size of the set. Runtime of the algorithm is $O(|E|)$. s"Expected non-empty NetworkX graph!(t ValueErrorR(R ((s†/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/approximation/dominating_set.pyRosN( t__doc__t __future__RtmatchingRtutilsRt__all__t __author__tNoneRR(((s†/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/approximation/dominating_set.pyts  P