Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/networkx/classes/ordered.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 """ | |
2 Consistently ordered variants of the default base classes. | |
3 Note that if you are using Python 3.6+, you shouldn't need these classes | |
4 because the dicts in Python 3.6+ are ordered. | |
5 Note also that there are many differing expectations for the word "ordered" | |
6 and that these classes may not provide the order you expect. | |
7 The intent here is to give a consistent order not a particular order. | |
8 | |
9 The Ordered (Di/Multi/MultiDi) Graphs give a consistent order for reporting of | |
10 nodes and edges. The order of node reporting agrees with node adding, but for | |
11 edges, the order is not necessarily the order that the edges were added. | |
12 | |
13 In general, you should use the default (i.e., unordered) graph classes. | |
14 However, there are times (e.g., when testing) when you may need the | |
15 order preserved. | |
16 | |
17 Special care is required when using subgraphs of the Ordered classes. | |
18 The order of nodes in the subclass is not necessarily the same order | |
19 as the original class. In general it is probably better to avoid using | |
20 subgraphs and replace with code similar to: | |
21 | |
22 .. code-block:: python | |
23 | |
24 # instead of SG = G.subgraph(ordered_nodes) | |
25 SG = nx.OrderedGraph() | |
26 SG.add_nodes_from(ordered_nodes) | |
27 SG.add_edges_from((u, v) for (u, v) in G.edges() if u in SG if v in SG) | |
28 | |
29 """ | |
30 from collections import OrderedDict | |
31 | |
32 from .graph import Graph | |
33 from .multigraph import MultiGraph | |
34 from .digraph import DiGraph | |
35 from .multidigraph import MultiDiGraph | |
36 | |
37 __all__ = [] | |
38 | |
39 __all__.extend( | |
40 ["OrderedGraph", "OrderedDiGraph", "OrderedMultiGraph", "OrderedMultiDiGraph"] | |
41 ) | |
42 | |
43 | |
44 class OrderedGraph(Graph): | |
45 """Consistently ordered variant of :class:`~networkx.Graph`.""" | |
46 | |
47 node_dict_factory = OrderedDict | |
48 adjlist_outer_dict_factory = OrderedDict | |
49 adjlist_inner_dict_factory = OrderedDict | |
50 edge_attr_dict_factory = OrderedDict | |
51 | |
52 | |
53 class OrderedDiGraph(DiGraph): | |
54 """Consistently ordered variant of :class:`~networkx.DiGraph`.""" | |
55 | |
56 node_dict_factory = OrderedDict | |
57 adjlist_outer_dict_factory = OrderedDict | |
58 adjlist_inner_dict_factory = OrderedDict | |
59 edge_attr_dict_factory = OrderedDict | |
60 | |
61 | |
62 class OrderedMultiGraph(MultiGraph): | |
63 """Consistently ordered variant of :class:`~networkx.MultiGraph`.""" | |
64 | |
65 node_dict_factory = OrderedDict | |
66 adjlist_outer_dict_factory = OrderedDict | |
67 adjlist_inner_dict_factory = OrderedDict | |
68 edge_key_dict_factory = OrderedDict | |
69 edge_attr_dict_factory = OrderedDict | |
70 | |
71 | |
72 class OrderedMultiDiGraph(MultiDiGraph): | |
73 """Consistently ordered variant of :class:`~networkx.MultiDiGraph`.""" | |
74 | |
75 node_dict_factory = OrderedDict | |
76 adjlist_outer_dict_factory = OrderedDict | |
77 adjlist_inner_dict_factory = OrderedDict | |
78 edge_key_dict_factory = OrderedDict | |
79 edge_attr_dict_factory = OrderedDict |