{"action":"created","comment":{"url":"https://api.github.com/repos/networkx/networkx/pulls/comments/47142928","id":47142928,"diff_hunk":"@@ -0,0 +1,63 @@\n+\"\"\"\n+An edge cover of a graph is a set of edges such that every vertex of\n+the graph is incident to at least one edge of the set.\n+A minimum edge cover is an edge covering of smallest possible size.\n+\n+`Edge Cover <https://en.wikipedia.org/wiki/Edge_cover>`_\n+\"\"\"\n+#    Copyright (C) 2015 by\n+#    Nishant Nikhil <nishantiam@gmail.com>\n+#    All rights reserved.\n+#    BSD license.\n+\n+import networkx as nx\n+from networkx.utils import not_implemented_for\n+\n+\n+@not_implemented_for('directed')\n+@not_implemented_for('multigraph')\n+def min_edge_cover(G):\n+    \"\"\"Returns a set of edges which constitute the minimum edge cover of the graph.\n+    A smallest edge cover can be found in polynomial time by finding\n+    a maximum matching and extending it greedily so that all vertices\n+    are covered.\n+\n+    Parameters\n+    ----------\n+    G : An undirected, unweighted graph.\n+\n+    Returns\n+    -------\n+    min_cover : set\n+        The covering is returned as a set, ``min_cover``.\n+        It contains all the edges of minimum edge cover\n+        in form of tuples.\n+\n+    Notes\n+    -----\n+    Worst Case runtime of ``nx.max_weight_matching(G, maxcardinality=True)``\n+    is `O(number_of_nodes^{3})`\n+    And the greedy extension works in `O(n\\log{}n)`\n+    So worst case run time of the function is `O(number_of_nodes^{3})`.\n+    \"\"\"\n+    maximum_matching = {}\n+    is_cover_exist = True\n+    for node in G.nodes():\n+        if not G[node]:\n+            is_cover_exist = False\n+            break\n+    if not is_cover_exist:\n+        # min_cover does not exist\n+        # raise an exception\n+        raise nx.NetworkXException(\"No Edge Cover Exist\")\n+    maximum_matching = nx.max_weight_matching(G, maxcardinality=True)\n+    min_cover = set()\n+    # ``min_cover`` is superset of ``maximum_matching``\n+    for node in maximum_matching:\n+        min_cover.add((node, maximum_matching[node]))\n+\n+    # iterate for uncovered nodes\n+    for node in set(G.nodes()) - set(x[0] for x in min_cover):","path":"networkx/algorithms/covering.py","position":60,"original_position":60,"commit_id":"9a042bed1e0d0894e8b8ebdeebf1f29bc7165437","original_commit_id":"9a042bed1e0d0894e8b8ebdeebf1f29bc7165437","user":{"login":"jfinkels","id":121755,"avatar_url":"https://avatars.githubusercontent.com/u/121755?v=3","gravatar_id":"","url":"https://api.github.com/users/jfinkels","html_url":"https://github.com/jfinkels","followers_url":"https://api.github.com/users/jfinkels/followers","following_url":"https://api.github.com/users/jfinkels/following{/other_user}","gists_url":"https://api.github.com/users/jfinkels/gists{/gist_id}","starred_url":"https://api.github.com/users/jfinkels/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jfinkels/subscriptions","organizations_url":"https://api.github.com/users/jfinkels/orgs","repos_url":"https://api.github.com/users/jfinkels/repos","events_url":"https://api.github.com/users/jfinkels/events{/privacy}","received_events_url":"https://api.github.com/users/jfinkels/received_events","type":"User","site_admin":false},"body":"How about this instead? I think it's more readable:\r\n\r\n    from networkx.utils import arbitrary_element\r\n    ...\r\n        uncovered_nodes = set(G) - {v for u, v in min_cover}\r\n        for u in uncovered_nodes:\r\n            # Since `v` is uncovered, each edge incident to `v` will join it\r\n            # with a covered node (otherwise, if there were an edge joining\r\n            # uncovered nodes `u` and `v`, the maximum matching algorithm\r\n            # would have found it), so we can choose an arbitrary edge\r\n            # incident to `v`. (This applies only in a simple graph, not a\r\n            # multigraph.)\r\n            #\r\n            # Since the graph is guaranteed to be undirected, we need only\r\n            # add a single orientation of the edge.\r\n            v = arbitrary_element(G[v])\r\n            min_cover.add((u, v))\r\n","created_at":"2015-12-09T19:56:43Z","updated_at":"2015-12-09T19:56:43Z","html_url":"https://github.com/networkx/networkx/pull/1869#discussion_r47142928","pull_request_url":"https://api.github.com/repos/networkx/networkx/pulls/1869","_links":{"self":{"href":"https://api.github.com/repos/networkx/networkx/pulls/comments/47142928"},"html":{"href":"https://github.com/networkx/networkx/pull/1869#discussion_r47142928"},"pull_request":{"href":"https://api.github.com/repos/networkx/networkx/pulls/1869"}}},"pull_request":{"url":"https://api.github.com/repos/networkx/networkx/pulls/1869","id":52758190,"html_url":"https://github.com/networkx/networkx/pull/1869","diff_url":"https://github.com/networkx/networkx/pull/1869.diff","patch_url":"https://github.com/networkx/networkx/pull/1869.patch","issue_url":"https://api.github.com/repos/networkx/networkx/issues/1869","number":1869,"state":"open","locked":false,"title":"Issue #1831: Added Minimum Edge Cover function","user":{"login":"nishnik","id":9252491,"avatar_url":"https://avatars.githubusercontent.com/u/9252491?v=3","gravatar_id":"","url":"https://api.github.com/users/nishnik","html_url":"https://github.com/nishnik","followers_url":"https://api.github.com/users/nishnik/followers","following_url":"https://api.github.com/users/nishnik/following{/other_user}","gists_url":"https://api.github.com/users/nishnik/gists{/gist_id}","starred_url":"https://api.github.com/users/nishnik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nishnik/subscriptions","organizations_url":"https://api.github.com/users/nishnik/orgs","repos_url":"https://api.github.com/users/nishnik/repos","events_url":"https://api.github.com/users/nishnik/events{/privacy}","received_events_url":"https://api.github.com/users/nishnik/received_events","type":"User","site_admin":false},"body":"TODO: Add Test Cases\r\nAddres: #1831 ","created_at":"2015-12-05T16:28:52Z","updated_at":"2015-12-09T19:56:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a84c6c2fd6760d7dbc54c89f79e5aed6b1cf2976","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/networkx/networkx/pulls/1869/commits","review_comments_url":"https://api.github.com/repos/networkx/networkx/pulls/1869/comments","review_comment_url":"https://api.github.com/repos/networkx/networkx/pulls/comments{/number}","comments_url":"https://api.github.com/repos/networkx/networkx/issues/1869/comments","statuses_url":"https://api.github.com/repos/networkx/networkx/statuses/9a042bed1e0d0894e8b8ebdeebf1f29bc7165437","head":{"label":"nishnik:min_edge_cover","ref":"min_edge_cover","sha":"9a042bed1e0d0894e8b8ebdeebf1f29bc7165437","user":{"login":"nishnik","id":9252491,"avatar_url":"https://avatars.githubusercontent.com/u/9252491?v=3","gravatar_id":"","url":"https://api.github.com/users/nishnik","html_url":"https://github.com/nishnik","followers_url":"https://api.github.com/users/nishnik/followers","following_url":"https://api.github.com/users/nishnik/following{/other_user}","gists_url":"https://api.github.com/users/nishnik/gists{/gist_id}","starred_url":"https://api.github.com/users/nishnik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nishnik/subscriptions","organizations_url":"https://api.github.com/users/nishnik/orgs","repos_url":"https://api.github.com/users/nishnik/repos","events_url":"https://api.github.com/users/nishnik/events{/privacy}","received_events_url":"https://api.github.com/users/nishnik/received_events","type":"User","site_admin":false},"repo":{"id":47353440,"name":"networkx","full_name":"nishnik/networkx","owner":{"login":"nishnik","id":9252491,"avatar_url":"https://avatars.githubusercontent.com/u/9252491?v=3","gravatar_id":"","url":"https://api.github.com/users/nishnik","html_url":"https://github.com/nishnik","followers_url":"https://api.github.com/users/nishnik/followers","following_url":"https://api.github.com/users/nishnik/following{/other_user}","gists_url":"https://api.github.com/users/nishnik/gists{/gist_id}","starred_url":"https://api.github.com/users/nishnik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nishnik/subscriptions","organizations_url":"https://api.github.com/users/nishnik/orgs","repos_url":"https://api.github.com/users/nishnik/repos","events_url":"https://api.github.com/users/nishnik/events{/privacy}","received_events_url":"https://api.github.com/users/nishnik/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/nishnik/networkx","description":"Official NetworkX source code repository.  ","fork":true,"url":"https://api.github.com/repos/nishnik/networkx","forks_url":"https://api.github.com/repos/nishnik/networkx/forks","keys_url":"https://api.github.com/repos/nishnik/networkx/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nishnik/networkx/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nishnik/networkx/teams","hooks_url":"https://api.github.com/repos/nishnik/networkx/hooks","issue_events_url":"https://api.github.com/repos/nishnik/networkx/issues/events{/number}","events_url":"https://api.github.com/repos/nishnik/networkx/events","assignees_url":"https://api.github.com/repos/nishnik/networkx/assignees{/user}","branches_url":"https://api.github.com/repos/nishnik/networkx/branches{/branch}","tags_url":"https://api.github.com/repos/nishnik/networkx/tags","blobs_url":"https://api.github.com/repos/nishnik/networkx/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nishnik/networkx/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nishnik/networkx/git/refs{/sha}","trees_url":"https://api.github.com/repos/nishnik/networkx/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nishnik/networkx/statuses/{sha}","languages_url":"https://api.github.com/repos/nishnik/networkx/languages","stargazers_url":"https://api.github.com/repos/nishnik/networkx/stargazers","contributors_url":"https://api.github.com/repos/nishnik/networkx/contributors","subscribers_url":"https://api.github.com/repos/nishnik/networkx/subscribers","subscription_url":"https://api.github.com/repos/nishnik/networkx/subscription","commits_url":"https://api.github.com/repos/nishnik/networkx/commits{/sha}","git_commits_url":"https://api.github.com/repos/nishnik/networkx/git/commits{/sha}","comments_url":"https://api.github.com/repos/nishnik/networkx/comments{/number}","issue_comment_url":"https://api.github.com/repos/nishnik/networkx/issues/comments{/number}","contents_url":"https://api.github.com/repos/nishnik/networkx/contents/{+path}","compare_url":"https://api.github.com/repos/nishnik/networkx/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nishnik/networkx/merges","archive_url":"https://api.github.com/repos/nishnik/networkx/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nishnik/networkx/downloads","issues_url":"https://api.github.com/repos/nishnik/networkx/issues{/number}","pulls_url":"https://api.github.com/repos/nishnik/networkx/pulls{/number}","milestones_url":"https://api.github.com/repos/nishnik/networkx/milestones{/number}","notifications_url":"https://api.github.com/repos/nishnik/networkx/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nishnik/networkx/labels{/name}","releases_url":"https://api.github.com/repos/nishnik/networkx/releases{/id}","created_at":"2015-12-03T19:00:04Z","updated_at":"2015-12-03T19:00:07Z","pushed_at":"2015-12-08T22:55:25Z","git_url":"git://github.com/nishnik/networkx.git","ssh_url":"git@github.com:nishnik/networkx.git","clone_url":"https://github.com/nishnik/networkx.git","svn_url":"https://github.com/nishnik/networkx","homepage":"http://networkx.github.io","size":13439,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"networkx:master","ref":"master","sha":"226a7ac86932772265a4d2d1d936bcb49d85fb29","user":{"login":"networkx","id":388785,"avatar_url":"https://avatars.githubusercontent.com/u/388785?v=3","gravatar_id":"","url":"https://api.github.com/users/networkx","html_url":"https://github.com/networkx","followers_url":"https://api.github.com/users/networkx/followers","following_url":"https://api.github.com/users/networkx/following{/other_user}","gists_url":"https://api.github.com/users/networkx/gists{/gist_id}","starred_url":"https://api.github.com/users/networkx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/networkx/subscriptions","organizations_url":"https://api.github.com/users/networkx/orgs","repos_url":"https://api.github.com/users/networkx/repos","events_url":"https://api.github.com/users/networkx/events{/privacy}","received_events_url":"https://api.github.com/users/networkx/received_events","type":"Organization","site_admin":false},"repo":{"id":890377,"name":"networkx","full_name":"networkx/networkx","owner":{"login":"networkx","id":388785,"avatar_url":"https://avatars.githubusercontent.com/u/388785?v=3","gravatar_id":"","url":"https://api.github.com/users/networkx","html_url":"https://github.com/networkx","followers_url":"https://api.github.com/users/networkx/followers","following_url":"https://api.github.com/users/networkx/following{/other_user}","gists_url":"https://api.github.com/users/networkx/gists{/gist_id}","starred_url":"https://api.github.com/users/networkx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/networkx/subscriptions","organizations_url":"https://api.github.com/users/networkx/orgs","repos_url":"https://api.github.com/users/networkx/repos","events_url":"https://api.github.com/users/networkx/events{/privacy}","received_events_url":"https://api.github.com/users/networkx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/networkx/networkx","description":"Official NetworkX source code repository.  ","fork":false,"url":"https://api.github.com/repos/networkx/networkx","forks_url":"https://api.github.com/repos/networkx/networkx/forks","keys_url":"https://api.github.com/repos/networkx/networkx/keys{/key_id}","collaborators_url":"https://api.github.com/repos/networkx/networkx/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/networkx/networkx/teams","hooks_url":"https://api.github.com/repos/networkx/networkx/hooks","issue_events_url":"https://api.github.com/repos/networkx/networkx/issues/events{/number}","events_url":"https://api.github.com/repos/networkx/networkx/events","assignees_url":"https://api.github.com/repos/networkx/networkx/assignees{/user}","branches_url":"https://api.github.com/repos/networkx/networkx/branches{/branch}","tags_url":"https://api.github.com/repos/networkx/networkx/tags","blobs_url":"https://api.github.com/repos/networkx/networkx/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/networkx/networkx/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/networkx/networkx/git/refs{/sha}","trees_url":"https://api.github.com/repos/networkx/networkx/git/trees{/sha}","statuses_url":"https://api.github.com/repos/networkx/networkx/statuses/{sha}","languages_url":"https://api.github.com/repos/networkx/networkx/languages","stargazers_url":"https://api.github.com/repos/networkx/networkx/stargazers","contributors_url":"https://api.github.com/repos/networkx/networkx/contributors","subscribers_url":"https://api.github.com/repos/networkx/networkx/subscribers","subscription_url":"https://api.github.com/repos/networkx/networkx/subscription","commits_url":"https://api.github.com/repos/networkx/networkx/commits{/sha}","git_commits_url":"https://api.github.com/repos/networkx/networkx/git/commits{/sha}","comments_url":"https://api.github.com/repos/networkx/networkx/comments{/number}","issue_comment_url":"https://api.github.com/repos/networkx/networkx/issues/comments{/number}","contents_url":"https://api.github.com/repos/networkx/networkx/contents/{+path}","compare_url":"https://api.github.com/repos/networkx/networkx/compare/{base}...{head}","merges_url":"https://api.github.com/repos/networkx/networkx/merges","archive_url":"https://api.github.com/repos/networkx/networkx/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/networkx/networkx/downloads","issues_url":"https://api.github.com/repos/networkx/networkx/issues{/number}","pulls_url":"https://api.github.com/repos/networkx/networkx/pulls{/number}","milestones_url":"https://api.github.com/repos/networkx/networkx/milestones{/number}","notifications_url":"https://api.github.com/repos/networkx/networkx/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/networkx/networkx/labels{/name}","releases_url":"https://api.github.com/repos/networkx/networkx/releases{/id}","created_at":"2010-09-06T00:53:44Z","updated_at":"2015-12-09T18:26:17Z","pushed_at":"2015-12-09T19:00:09Z","git_url":"git://github.com/networkx/networkx.git","ssh_url":"git@github.com:networkx/networkx.git","clone_url":"https://github.com/networkx/networkx.git","svn_url":"https://github.com/networkx/networkx","homepage":"http://networkx.github.io","size":18791,"stargazers_count":1752,"watchers_count":1752,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":562,"mirror_url":null,"open_issues_count":299,"forks":562,"open_issues":299,"watchers":1752,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/networkx/networkx/pulls/1869"},"html":{"href":"https://github.com/networkx/networkx/pull/1869"},"issue":{"href":"https://api.github.com/repos/networkx/networkx/issues/1869"},"comments":{"href":"https://api.github.com/repos/networkx/networkx/issues/1869/comments"},"review_comments":{"href":"https://api.github.com/repos/networkx/networkx/pulls/1869/comments"},"review_comment":{"href":"https://api.github.com/repos/networkx/networkx/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/networkx/networkx/pulls/1869/commits"},"statuses":{"href":"https://api.github.com/repos/networkx/networkx/statuses/9a042bed1e0d0894e8b8ebdeebf1f29bc7165437"}}}}