Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/networkx/algorithms/operators/unary.py @ 0:4f3585e2f14b draft default tip
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author | shellac |
---|---|
date | Mon, 22 Mar 2021 18:12:50 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4f3585e2f14b |
---|---|
1 """Unary operations on graphs""" | |
2 import networkx as nx | |
3 | |
4 __all__ = ["complement", "reverse"] | |
5 | |
6 | |
7 def complement(G): | |
8 """Returns the graph complement of G. | |
9 | |
10 Parameters | |
11 ---------- | |
12 G : graph | |
13 A NetworkX graph | |
14 | |
15 Returns | |
16 ------- | |
17 GC : A new graph. | |
18 | |
19 Notes | |
20 ------ | |
21 Note that complement() does not create self-loops and also | |
22 does not produce parallel edges for MultiGraphs. | |
23 | |
24 Graph, node, and edge data are not propagated to the new graph. | |
25 """ | |
26 R = G.__class__() | |
27 R.add_nodes_from(G) | |
28 R.add_edges_from( | |
29 ((n, n2) for n, nbrs in G.adjacency() for n2 in G if n2 not in nbrs if n != n2) | |
30 ) | |
31 return R | |
32 | |
33 | |
34 def reverse(G, copy=True): | |
35 """Returns the reverse directed graph of G. | |
36 | |
37 Parameters | |
38 ---------- | |
39 G : directed graph | |
40 A NetworkX directed graph | |
41 copy : bool | |
42 If True, then a new graph is returned. If False, then the graph is | |
43 reversed in place. | |
44 | |
45 Returns | |
46 ------- | |
47 H : directed graph | |
48 The reversed G. | |
49 | |
50 """ | |
51 if not G.is_directed(): | |
52 raise nx.NetworkXError("Cannot reverse an undirected graph.") | |
53 else: | |
54 return G.reverse(copy=copy) |