comparison planemo/lib/python3.7/site-packages/networkx/classes/ordered.py @ 1:56ad4e20f292 draft

"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
author guerler
date Fri, 31 Jul 2020 00:32:28 -0400
parents
children
comparison
equal deleted inserted replaced
0:d30785e31577 1:56ad4e20f292
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',
41 'OrderedDiGraph',
42 'OrderedMultiGraph',
43 'OrderedMultiDiGraph',
44 ])
45
46
47 class OrderedGraph(Graph):
48 """Consistently ordered variant of :class:`~networkx.Graph`."""
49 node_dict_factory = OrderedDict
50 adjlist_outer_dict_factory = OrderedDict
51 adjlist_inner_dict_factory = OrderedDict
52 edge_attr_dict_factory = OrderedDict
53
54
55 class OrderedDiGraph(DiGraph):
56 """Consistently ordered variant of :class:`~networkx.DiGraph`."""
57 node_dict_factory = OrderedDict
58 adjlist_outer_dict_factory = OrderedDict
59 adjlist_inner_dict_factory = OrderedDict
60 edge_attr_dict_factory = OrderedDict
61
62
63 class OrderedMultiGraph(MultiGraph):
64 """Consistently ordered variant of :class:`~networkx.MultiGraph`."""
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 node_dict_factory = OrderedDict
75 adjlist_outer_dict_factory = OrderedDict
76 adjlist_inner_dict_factory = OrderedDict
77 edge_key_dict_factory = OrderedDict
78 edge_attr_dict_factory = OrderedDict