diff options
| author | Kemal Maulana <kemskems12@gmail.com> | 2014-04-28 16:58:49 +0900 |
|---|---|---|
| committer | Kemal Maulana <kemskems12@gmail.com> | 2014-04-28 16:58:49 +0900 |
| commit | 0b19c537ca74cef26b02359cb406726cbae05eab (patch) | |
| tree | 6a44f02be4b7e6276a7f22f745720a8e36a21a7f /networkx/classes/function.py | |
| parent | 6874465da5c603f4949d81fc1318c1ae08ec9b09 (diff) | |
| download | networkx-0b19c537ca74cef26b02359cb406726cbae05eab.tar.gz | |
Added non-edges enumeration function
Diffstat (limited to 'networkx/classes/function.py')
| -rw-r--r-- | networkx/classes/function.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/networkx/classes/function.py b/networkx/classes/function.py index 321d8be5..f08fec1e 100644 --- a/networkx/classes/function.py +++ b/networkx/classes/function.py @@ -18,7 +18,7 @@ __all__ = ['nodes', 'edges', 'degree', 'degree_histogram', 'neighbors', 'freeze','is_frozen','subgraph','create_empty_copy', 'set_node_attributes','get_node_attributes', 'set_edge_attributes','get_edge_attributes', - 'all_neighbors','non_neighbors'] + 'all_neighbors','non_neighbors', 'non_edges'] def nodes(G): """Return a copy of the graph nodes in a list.""" @@ -425,3 +425,25 @@ def non_neighbors(graph, node): """ nbors = set(neighbors(graph, node)) | set([node]) return (nnode for nnode in graph if nnode not in nbors) + +def non_edges(graph): + """Returns the non-existent edges in the graph. + + Parameters + ---------- + graph : NetworkX graph. + Graph to find non-existent edges. + + Returns + ------- + non_edges : iterator + Iterator of edges that are not in the graph. + """ + S = set() + for u in graph.nodes_iter(): + for v in non_neighbors(graph, u): + if (u, v) not in S: + S.add((u, v)) + if not graph.is_directed(): + S.add((v, u)) + yield (u, v) |
