Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/networkx/generators/triads.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 # See https://github.com/networkx/networkx/pull/1474 | |
2 # Copyright 2011 Reya Group <http://www.reyagroup.com> | |
3 # Copyright 2011 Alex Levenson <alex@isnotinvain.com> | |
4 # Copyright 2011 Diederik van Liere <diederik.vanliere@rotman.utoronto.ca> | |
5 """Functions that generate the triad graphs, that is, the possible | |
6 digraphs on three nodes. | |
7 | |
8 """ | |
9 from networkx.classes import DiGraph | |
10 | |
11 __all__ = ["triad_graph"] | |
12 | |
13 #: Dictionary mapping triad name to list of directed edges in the | |
14 #: digraph representation of that triad (with nodes 'a', 'b', and 'c'). | |
15 TRIAD_EDGES = { | |
16 "003": [], | |
17 "012": ["ab"], | |
18 "102": ["ab", "ba"], | |
19 "021D": ["ba", "bc"], | |
20 "021U": ["ab", "cb"], | |
21 "021C": ["ab", "bc"], | |
22 "111D": ["ac", "ca", "bc"], | |
23 "111U": ["ac", "ca", "cb"], | |
24 "030T": ["ab", "cb", "ac"], | |
25 "030C": ["ba", "cb", "ac"], | |
26 "201": ["ab", "ba", "ac", "ca"], | |
27 "120D": ["bc", "ba", "ac", "ca"], | |
28 "120U": ["ab", "cb", "ac", "ca"], | |
29 "120C": ["ab", "bc", "ac", "ca"], | |
30 "210": ["ab", "bc", "cb", "ac", "ca"], | |
31 "300": ["ab", "ba", "bc", "cb", "ac", "ca"], | |
32 } | |
33 | |
34 | |
35 def triad_graph(triad_name): | |
36 """Returns the triad graph with the given name. | |
37 | |
38 Each string in the following tuple is a valid triad name:: | |
39 | |
40 ('003', '012', '102', '021D', '021U', '021C', '111D', '111U', | |
41 '030T', '030C', '201', '120D', '120U', '120C', '210', '300') | |
42 | |
43 Each triad name corresponds to one of the possible valid digraph on | |
44 three nodes. | |
45 | |
46 Parameters | |
47 ---------- | |
48 triad_name : string | |
49 The name of a triad, as described above. | |
50 | |
51 Returns | |
52 ------- | |
53 :class:`~networkx.DiGraph` | |
54 The digraph on three nodes with the given name. The nodes of the | |
55 graph are the single-character strings 'a', 'b', and 'c'. | |
56 | |
57 Raises | |
58 ------ | |
59 ValueError | |
60 If `triad_name` is not the name of a triad. | |
61 | |
62 See also | |
63 -------- | |
64 triadic_census | |
65 | |
66 """ | |
67 if triad_name not in TRIAD_EDGES: | |
68 raise ValueError( | |
69 f'unknown triad name "{triad_name}"; use one of the triad names' | |
70 " in the TRIAD_NAMES constant" | |
71 ) | |
72 G = DiGraph() | |
73 G.add_nodes_from("abc") | |
74 G.add_edges_from(TRIAD_EDGES[triad_name]) | |
75 return G |