ó žÃÒYc@s‘dZddlZddlmZmZddlmZddlm Z ddgZ edƒed ƒdd „ƒƒZ edƒd „ƒZ dS( s# Functions related to graph covers.iÿÿÿÿN(tnot_implemented_fortarbitrary_element(tpartial(tchaintmin_edge_covert is_edge_covertdirectedt multigraphcCsÎtj|ƒdkr'tjdƒ‚n|dkrKttjdtƒ}n||ƒ}t|jƒƒ}t|ƒd„|Dƒ}xD|D]<}t ||ƒ}|j ||fƒ|j ||fƒqŠW|S(s—Returns a set of edges which constitutes the minimum edge cover of the graph. A smallest edge cover can be found in polynomial time by finding a maximum matching and extending it greedily so that all nodes are covered. Parameters ---------- G : NetworkX graph An undirected bipartite graph. matching_algorithm : function A function that returns a maximum cardinality matching in a given bipartite graph. The function must take one input, the graph ``G``, and return a dictionary mapping each node to its mate. If not specified, :func:`~networkx.algorithms.bipartite.matching.hopcroft_karp_matching` will be used. Other possibilities include :func:`~networkx.algorithms.bipartite.matching.eppstein_matching`, or matching algorithms in the :mod:`networkx.algorithms.matching` module. Returns ------- min_cover : set It contains all the edges of minimum edge cover in form of tuples. It contains both the edges `(u, v)` and `(v, u)` for given nodes `u` and `v` among the edges of minimum edge cover. Notes ----- An edge cover of a graph is a set of edges such that every node of the graph is incident to at least one edge of the set. The minimum edge cover is an edge covering of smallest cardinality. Due to its implementation, the worst-case running time of this algorithm is bounded by the worst-case running time of the function ``matching_algorithm``. Minimum edge cover for bipartite graph can also be found using the function present in :mod:`networkx.algorithms.bipartite.covering` isFGraph has a node with no edge incident on it, so no edge cover exists.tmaxcardinalitycSsh|]\}}|’qS(((t.0tutv((sr/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/covering.pys Ms N( tnxtnumber_of_isolatestNetworkXExceptiontNoneRtmax_weight_matchingtTruetsettitemsRtadd(tGtmatching_algorithmtmaximum_matchingt min_covertuncovered_nodesR R ((sr/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/covering.pyRs/      cCst|ƒttj|ƒƒkS(s‚Decides whether a set of edges is a valid edge cover of the graph. Given a set of edges, whether it is an edge covering can be decided if we just check whether all nodes of the graph has an edge from the set, incident on it. Parameters ---------- G : NetworkX graph An undirected bipartite graph. cover : set Set of edges to be checked. Returns ------- bool Whether the set of edges is a valid edge cover of the graph. Notes ----- An edge cover of a graph is a set of edges such that every node of the graph is incident to at least one edge of the set. (RRt from_iterable(Rtcover((sr/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/covering.pyR[s(t__doc__tnetworkxR tnetworkx.utilsRRt functoolsRt itertoolsRt__all__RRR(((sr/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/covering.pyts    G