K i+dZddlZddlZddlmZddlZddgZdZ ejjddz Z d Z ejdd d Zejdd d Zy)z' Generators for the small graph atlas. N)islice graph_atlas graph_atlas_giznetworkx.generatorsz atlas.dat.gzc#Ktjtd5}|j}|r+|j drt |ddj }|j}t |ddj }g}|j}|rT|j dsC|j|j |j}|r|j dsCtj}d||_ |jt||jd|D||r|j drdddy#1swYyxYww)zSequentially read the file containing the edge list data for the graphs in the atlas and generate the graphs one at a time. This function reads the file given in :data:`.ATLAS_FILE`. rbsGRAPHNGc3jK|]+}ttt|j-yw)N)tuplemapintsplit).0es _/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/networkx/generators/atlas.py z#_generate_graphs..Vs"JAU3sAGGI#67Js13)gzipopen ATLAS_FILEreadline startswithr rstripappendnxGraphnameadd_nodes_fromrangeadd_edges_from)fline graph_index num_nodesedgelistr s r_generate_graphsr%8s$ :t $zz|tx0d12hoo/0K::>> from pprint import pprint >>> atlas = nx.graph_atlas_g() There are 1253 graphs in the atlas >>> len(atlas) 1253 The number of graphs with *n* nodes, where *n* ranges from 0 to 7: >>> from collections import Counter >>> num_nodes_per_graph = [len(G) for G in atlas] >>> Counter(num_nodes_per_graph) Counter({7: 1044, 6: 156, 5: 34, 4: 11, 3: 4, 2: 2, 0: 1, 1: 1}) Since the atlas is ordered by the number of nodes in the graph, all graphs with *n* nodes can be obtained by slicing the atlas. For example, all graphs with 5 nodes: >>> G5_list = atlas[19:53] >>> all(len(G) == 5 for G in G5_list) True Or all graphs with at least 3 nodes but fewer than 7 nodes: >>> G3_6_list = atlas[4:209] More generally, the indices that partition the atlas by the number of nodes per graph: >>> import itertools >>> partition_indices = [0] + list( ... itertools.accumulate(Counter(num_nodes_per_graph).values()) # cumsum ... ) >>> partition_indices [0, 1, 2, 4, 8, 19, 53, 209, 1253] >>> partition_mapping = dict(enumerate(itertools.pairwise(partition_indices))) >>> pprint(partition_mapping) {0: (0, 1), 1: (1, 2), 2: (2, 4), 3: (4, 8), 4: (8, 19), 5: (19, 53), 6: (53, 209), 7: (209, 1253)} See also -------- graph_atlas Notes ----- This function may be expensive in both time and space, since it reads a large file sequentially in order to populate the list. Although the NetworkX atlas functions match the order of graphs given in the "Atlas of Graphs" book, there are (at least) three errors in the ordering described in the book. The following three pairs of nodes violate the lexicographically nondecreasing sorted degree sequence rule: - graphs 55 and 56 with degree sequences 001111 and 000112, - graphs 1007 and 1008 with degree sequences 3333444 and 3333336, - graphs 1012 and 1213 with degree sequences 1244555 and 1244456. References ---------- .. [atlas] Ronald C. Read and Robin J. Wilson, *An Atlas of Graphs*. Oxford University Press, 1998. )listr%r-rrrsD  " ##r-)__doc__rimportlib.resources importlib itertoolsrnetworkxr__all__r) resourcesfilesrr% _dispatchablerrr0r-rr:s  / *  H & &'< = N DT2#53#5LT2a$3a$r-