Passed
Push — main ( 2bcd5c...05fcff )
by Eran
01:27
created

math.graphs.spiral_torus_graph()   A

Complexity

Conditions 1

Size

Total Lines 4
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nop 2
1
import itertools
2
import re
3
from collections.abc import Iterable
4
from typing import NewType
5
6
import networkx as nx
7
8
SPECIAL_GRAPHS_ADJACENCY_LISTS = {
9
    'Buckyball - Truncated Icosahedral Graph': {
10
        1: [2, 3, 4],
11
        2: [1, 55, 56],
12
        3: [1, 58, 60],
13
        4: [1, 57, 59],
14
        5: [8, 13, 14],
15
        6: [8, 12, 15],
16
        7: [8, 11, 16],
17
        8: [5, 6, 7],
18
        9: [13, 15, 25],
19
        10: [14, 16, 26],
20
        11: [7, 12, 24],
21
        12: [6, 11, 23],
22
        13: [5, 9, 18],
23
        14: [5, 10, 17],
24
        15: [6, 9, 19],
25
        16: [7, 10, 20],
26
        17: [14, 18, 30],
27
        18: [13, 17, 29],
28
        19: [15, 28, 32],
29
        20: [16, 27, 31],
30
        21: [26, 30, 46],
31
        22: [25, 29, 45],
32
        23: [12, 28, 38],
33
        24: [11, 27, 37],
34
        25: [9, 22, 32],
35
        26: [10, 21, 31],
36
        27: [20, 24, 35],
37
        28: [19, 23, 36],
38
        29: [18, 22, 43],
39
        30: [17, 21, 44],
40
        31: [20, 26, 42],
41
        32: [19, 25, 41],
42
        33: [35, 42, 53],
43
        34: [36, 41, 54],
44
        35: [27, 33, 40],
45
        36: [28, 34, 39],
46
        37: [24, 38, 40],
47
        38: [23, 37, 39],
48
        39: [36, 38, 52],
49
        40: [35, 37, 51],
50
        41: [32, 34, 50],
51
        42: [31, 33, 49],
52
        43: [29, 44, 48],
53
        44: [30, 43, 47],
54
        45: [22, 48, 50],
55
        46: [21, 47, 49],
56
        47: [44, 46, 60],
57
        48: [43, 45, 59],
58
        49: [42, 46, 58],
59
        50: [41, 45, 57],
60
        51: [40, 52, 56],
61
        52: [39, 51, 55],
62
        53: [33, 56, 58],
63
        54: [34, 55, 57],
64
        55: [2, 52, 54],
65
        56: [2, 51, 53],
66
        57: [4, 50, 54],
67
        58: [3, 49, 53],
68
        59: [4, 48, 60],
69
        60: [3, 47, 59]
70
    },
71
    'D30 - Rhombic Triacontahedral Graph': {
72
        1: [21, 22, 23],
73
        2: [24, 27, 30],
74
        3: [24, 29, 30],
75
        4: [26, 29, 32],
76
        5: [26, 28, 32],
77
        6: [25, 27, 31],
78
        7: [25, 28, 31],
79
        8: [24, 26, 29],
80
        9: [24, 25, 27],
81
        10: [25, 26, 28],
82
        11: [24, 25, 26],
83
        12: [22, 29, 30],
84
        13: [21, 27, 30],
85
        14: [23, 28, 32],
86
        15: [23, 28, 31],
87
        16: [22, 29, 32],
88
        17: [21, 27, 31],
89
        18: [21, 22, 30],
90
        19: [22, 23, 32],
91
        20: [21, 23, 31],
92
        21: [1, 13, 17, 18, 20],
93
        22: [1, 12, 16, 18, 19],
94
        23: [1, 14, 15, 19, 20],
95
        24: [2, 3, 8, 9, 11],
96
        25: [6, 7, 9, 10, 11],
97
        26: [4, 5, 8, 10, 11],
98
        27: [2, 6, 9, 13, 17],
99
        28: [5, 7, 10, 14, 15],
100
        29: [3, 4, 8, 12, 16],
101
        30: [2, 3, 12, 13, 18],
102
        31: [6, 7, 15, 17, 20],
103
        32: [4, 5, 14, 16, 19]
104
    },
105
    'Small Rhombicosidodecahedral Graph': {
106
        1: [2, 3, 4, 5],
107
        2: [1, 54, 55, 59],
108
        3: [1, 53, 56, 60],
109
        4: [1, 5, 58, 60],
110
        5: [1, 4, 57, 59],
111
        6: [24, 25, 57, 58],
112
        7: [12, 13, 16, 17],
113
        8: [9, 11, 19, 25],
114
        9: [8, 10, 18, 24],
115
        10: [9, 11, 12, 18],
116
        11: [8, 10, 13, 19],
117
        12: [7, 10, 14, 20],
118
        13: [7, 11, 15, 21],
119
        14: [12, 18, 20, 37],
120
        15: [13, 19, 21, 38],
121
        16: [7, 17, 21, 23],
122
        17: [7, 16, 20, 22],
123
        18: [9, 10, 14, 28],
124
        19: [8, 11, 15, 29],
125
        20: [12, 14, 17, 33],
126
        21: [13, 15, 16, 32],
127
        22: [17, 23, 31, 34],
128
        23: [16, 22, 30, 34],
129
        24: [6, 9, 27, 28],
130
        25: [6, 8, 26, 29],
131
        26: [25, 29, 46, 58],
132
        27: [24, 28, 45, 57],
133
        28: [18, 24, 27, 44],
134
        29: [19, 25, 26, 43],
135
        30: [23, 32, 36, 42],
136
        31: [22, 33, 35, 41],
137
        32: [21, 30, 38, 39],
138
        33: [20, 31, 37, 40],
139
        34: [22, 23, 41, 42],
140
        35: [31, 40, 41, 51],
141
        36: [30, 39, 42, 52],
142
        37: [14, 33, 40, 44],
143
        38: [15, 32, 39, 43],
144
        39: [32, 36, 38, 48],
145
        40: [33, 35, 37, 47],
146
        41: [31, 34, 35, 50],
147
        42: [30, 34, 36, 49],
148
        43: [29, 38, 46, 48],
149
        44: [28, 37, 45, 47],
150
        45: [27, 44, 47, 59],
151
        46: [26, 43, 48, 60],
152
        47: [40, 44, 45, 54],
153
        48: [39, 43, 46, 53],
154
        49: [42, 50, 52, 56],
155
        50: [41, 49, 51, 55],
156
        51: [35, 50, 54, 55],
157
        52: [36, 49, 53, 56],
158
        53: [3, 48, 52, 60],
159
        54: [2, 47, 51, 59],
160
        55: [2, 50, 51, 56],
161
        56: [3, 49, 52, 55],
162
        57: [5, 6, 27, 58],
163
        58: [4, 6, 26, 57],
164
        59: [2, 5, 45, 54],
165
        60: [3, 4, 46, 53]
166
    },
167
    'Small Rhombicuboctahedral Graph': {
168
        1: [2, 3, 4, 5],
169
        2: [1, 18, 22, 24],
170
        3: [1, 19, 22, 23],
171
        4: [1, 5, 21, 24],
172
        5: [1, 4, 20, 23],
173
        6: [10, 11, 20, 21],
174
        7: [10, 11, 12, 13],
175
        8: [10, 14, 20, 23],
176
        9: [11, 15, 21, 24],
177
        10: [6, 7, 8, 14],
178
        11: [6, 7, 9, 15],
179
        12: [7, 13, 15, 17],
180
        13: [7, 12, 14, 16],
181
        14: [8, 10, 13, 19],
182
        15: [9, 11, 12, 18],
183
        16: [13, 17, 19, 22],
184
        17: [12, 16, 18, 22],
185
        18: [2, 15, 17, 24],
186
        19: [3, 14, 16, 23],
187
        20: [5, 6, 8, 21],
188
        21: [4, 6, 9, 20],
189
        22: [2, 3, 16, 17],
190
        23: [3, 5, 8, 19],
191
        24: [2, 4, 9, 18]
192
    },
193
    'Great Rhombicosidodecahedral Graph': {
194
        1: [2, 3, 4],
195
        2: [1, 119, 120],
196
        3: [1, 118, 120],
197
        4: [1, 116, 117],
198
        5: [6, 7, 120],
199
        6: [5, 114, 115],
200
        7: [5, 113, 115],
201
        8: [9, 10, 115],
202
        9: [8, 111, 112],
203
        10: [8, 110, 112],
204
        11: [12, 13, 112],
205
        12: [11, 108, 109],
206
        13: [11, 107, 109],
207
        14: [15, 16, 109],
208
        15: [14, 105, 106],
209
        16: [14, 104, 106],
210
        17: [18, 19, 106],
211
        18: [17, 102, 103],
212
        19: [17, 101, 103],
213
        20: [21, 22, 103],
214
        21: [20, 99, 100],
215
        22: [20, 98, 100],
216
        23: [24, 25, 100],
217
        24: [23, 96, 97],
218
        25: [23, 95, 97],
219
        26: [27, 28, 97],
220
        27: [26, 93, 94],
221
        28: [26, 92, 94],
222
        29: [94, 116, 117],
223
        30: [63, 91, 96],
224
        31: [32, 33, 91],
225
        32: [31, 87, 88],
226
        33: [31, 86, 88],
227
        34: [35, 36, 88],
228
        35: [34, 84, 85],
229
        36: [34, 83, 85],
230
        37: [38, 85, 113],
231
        38: [37, 41, 110],
232
        39: [58, 73, 114],
233
        40: [86, 117, 119],
234
        41: [38, 64, 84],
235
        42: [64, 69, 84],
236
        43: [53, 55, 111],
237
        44: [64, 67, 108],
238
        45: [52, 77, 105],
239
        46: [65, 70, 102],
240
        47: [48, 49, 99],
241
        48: [47, 82, 95],
242
        49: [47, 80, 81],
243
        50: [51, 52, 79],
244
        51: [50, 74, 75],
245
        52: [45, 50, 75],
246
        53: [43, 75, 107],
247
        54: [72, 73, 74],
248
        55: [43, 73, 74],
249
        56: [61, 76, 78],
250
        57: [60, 89, 90],
251
        58: [39, 59, 118],
252
        59: [58, 60, 72],
253
        60: [57, 59, 61],
254
        61: [56, 60, 72],
255
        62: [66, 71, 87],
256
        63: [30, 66, 87],
257
        64: [41, 42, 44],
258
        65: [46, 66, 98],
259
        66: [62, 63, 65],
260
        67: [44, 68, 104],
261
        68: [67, 69, 70],
262
        69: [42, 68, 71],
263
        70: [46, 68, 71],
264
        71: [62, 69, 70],
265
        72: [54, 59, 61],
266
        73: [39, 54, 55],
267
        74: [51, 54, 55],
268
        75: [51, 52, 53],
269
        76: [56, 82, 89],
270
        77: [45, 80, 101],
271
        78: [56, 81, 82],
272
        79: [50, 80, 81],
273
        80: [49, 77, 79],
274
        81: [49, 78, 79],
275
        82: [48, 76, 78],
276
        83: [36, 86, 119],
277
        84: [35, 41, 42],
278
        85: [35, 36, 37],
279
        86: [33, 40, 83],
280
        87: [32, 62, 63],
281
        88: [32, 33, 34],
282
        89: [57, 76, 93],
283
        90: [57, 93, 116],
284
        91: [30, 31, 92],
285
        92: [28, 91, 96],
286
        93: [27, 89, 90],
287
        94: [27, 28, 29],
288
        95: [25, 48, 99],
289
        96: [24, 30, 92],
290
        97: [24, 25, 26],
291
        98: [22, 65, 102],
292
        99: [21, 47, 95],
293
        100: [21, 22, 23],
294
        101: [19, 77, 105],
295
        102: [18, 46, 98],
296
        103: [18, 19, 20],
297
        104: [16, 67, 108],
298
        105: [15, 45, 101],
299
        106: [15, 16, 17],
300
        107: [13, 53, 111],
301
        108: [12, 44, 104],
302
        109: [12, 13, 14],
303
        110: [10, 38, 113],
304
        111: [9, 43, 107],
305
        112: [9, 10, 11],
306
        113: [7, 37, 110],
307
        114: [6, 39, 118],
308
        115: [6, 7, 8],
309
        116: [4, 29, 90],
310
        117: [4, 29, 40],
311
        118: [3, 58, 114],
312
        119: [2, 40, 83],
313
        120: [2, 3, 5]
314
    },
315
    'Disdyakis Dodecahedral Graph': {
316
        1: [13, 14, 21, 22],
317
        2: [17, 19, 21, 23],
318
        3: [18, 20, 22, 24],
319
        4: [16, 17, 23, 25],
320
        5: [15, 19, 23, 26],
321
        6: [15, 18, 24, 26],
322
        7: [16, 20, 24, 25],
323
        8: [15, 16, 23, 24],
324
        9: [14, 17, 21, 25],
325
        10: [13, 18, 22, 26],
326
        11: [13, 19, 21, 26],
327
        12: [14, 20, 22, 25],
328
        13: [1, 10, 11, 21, 22, 26],
329
        14: [1, 9, 12, 21, 22, 25],
330
        15: [5, 6, 8, 23, 24, 26],
331
        16: [4, 7, 8, 23, 24, 25],
332
        17: [2, 4, 9, 21, 23, 25],
333
        18: [3, 6, 10, 22, 24, 26],
334
        19: [2, 5, 11, 21, 23, 26],
335
        20: [3, 7, 12, 22, 24, 25],
336
        21: [1, 2, 9, 11, 13, 14, 17, 19],
337
        22: [1, 3, 10, 12, 13, 14, 18, 20],
338
        23: [2, 4, 5, 8, 15, 16, 17, 19],
339
        24: [3, 6, 7, 8, 15, 16, 18, 20],
340
        25: [4, 7, 9, 12, 14, 16, 17, 20],
341
        26: [5, 6, 10, 11, 13, 15, 18, 19]
342
    },
343
    'Deltoidal Icositetrahedral Graph': {
344
        1: [15, 24, 26],
345
        2: [15, 23, 25],
346
        3: [16, 18, 20],
347
        4: [17, 19, 20],
348
        5: [16, 22, 26],
349
        6: [19, 22, 25],
350
        7: [18, 21, 24],
351
        8: [17, 21, 23],
352
        9: [15, 22, 25, 26],
353
        10: [15, 21, 23, 24],
354
        11: [16, 18, 24, 26],
355
        12: [17, 19, 23, 25],
356
        13: [16, 19, 20, 22],
357
        14: [17, 18, 20, 21],
358
        15: [1, 2, 9, 10],
359
        16: [3, 5, 11, 13],
360
        17: [4, 8, 12, 14],
361
        18: [3, 7, 11, 14],
362
        19: [4, 6, 12, 13],
363
        20: [3, 4, 13, 14],
364
        21: [7, 8, 10, 14],
365
        22: [5, 6, 9, 13],
366
        23: [2, 8, 10, 12],
367
        24: [1, 7, 10, 11],
368
        25: [2, 6, 9, 12],
369
        26: [1, 5, 9, 11]
370
    },
371
    'Icosidodecahedral Graph': {
372
        1: [2, 3, 4, 5],
373
        2: [1, 4, 23, 27],
374
        3: [1, 5, 24, 28],
375
        4: [1, 2, 26, 29],
376
        5: [1, 3, 25, 30],
377
        6: [7, 8, 9, 10],
378
        7: [6, 9, 11, 15],
379
        8: [6, 10, 12, 16],
380
        9: [6, 7, 14, 18],
381
        10: [6, 8, 13, 17],
382
        11: [7, 12, 15, 19],
383
        12: [8, 11, 16, 19],
384
        13: [10, 14, 17, 20],
385
        14: [9, 13, 18, 20],
386
        15: [7, 11, 21, 23],
387
        16: [8, 12, 22, 24],
388
        17: [10, 13, 22, 25],
389
        18: [9, 14, 21, 26],
390
        19: [11, 12, 27, 28],
391
        20: [13, 14, 29, 30],
392
        21: [15, 18, 23, 26],
393
        22: [16, 17, 24, 25],
394
        23: [2, 15, 21, 27],
395
        24: [3, 16, 22, 28],
396
        25: [5, 17, 22, 30],
397
        26: [4, 18, 21, 29],
398
        27: [2, 19, 23, 28],
399
        28: [3, 19, 24, 27],
400
        29: [4, 20, 26, 30],
401
        30: [5, 20, 25, 29]
402
    },
403
    'Deltoidal Hexecontahedral Graph': {
404
        1: [21, 49, 50],
405
        2: [21, 47, 48],
406
        3: [23, 25, 26],
407
        4: [22, 24, 26],
408
        5: [25, 27, 33],
409
        6: [24, 30, 36],
410
        7: [23, 28, 34],
411
        8: [22, 29, 35],
412
        9: [27, 30, 31],
413
        10: [28, 29, 32],
414
        11: [33, 38, 43],
415
        12: [34, 38, 46],
416
        13: [36, 37, 45],
417
        14: [35, 37, 44],
418
        15: [32, 40, 42],
419
        16: [31, 39, 41],
420
        17: [39, 43, 49],
421
        18: [40, 46, 50],
422
        19: [41, 45, 47],
423
        20: [42, 44, 48],
424
        21: [1, 2, 51, 52],
425
        22: [4, 8, 54, 56],
426
        23: [3, 7, 53, 56],
427
        24: [4, 6, 54, 55],
428
        25: [3, 5, 53, 55],
429
        26: [3, 4, 55, 56],
430
        27: [5, 9, 55, 57],
431
        28: [7, 10, 56, 58],
432
        29: [8, 10, 56, 60],
433
        30: [6, 9, 55, 59],
434
        31: [9, 16, 57, 59],
435
        32: [10, 15, 58, 60],
436
        33: [5, 11, 53, 57],
437
        34: [7, 12, 53, 58],
438
        35: [8, 14, 54, 60],
439
        36: [6, 13, 54, 59],
440
        37: [13, 14, 54, 62],
441
        38: [11, 12, 53, 61],
442
        39: [16, 17, 52, 57],
443
        40: [15, 18, 51, 58],
444
        41: [16, 19, 52, 59],
445
        42: [15, 20, 51, 60],
446
        43: [11, 17, 57, 61],
447
        44: [14, 20, 60, 62],
448
        45: [13, 19, 59, 62],
449
        46: [12, 18, 58, 61],
450
        47: [2, 19, 52, 62],
451
        48: [2, 20, 51, 62],
452
        49: [1, 17, 52, 61],
453
        50: [1, 18, 51, 61],
454
        51: [21, 40, 42, 48, 50],
455
        52: [21, 39, 41, 47, 49],
456
        53: [23, 25, 33, 34, 38],
457
        54: [22, 24, 35, 36, 37],
458
        55: [24, 25, 26, 27, 30],
459
        56: [22, 23, 26, 28, 29],
460
        57: [27, 31, 33, 39, 43],
461
        58: [28, 32, 34, 40, 46],
462
        59: [30, 31, 36, 41, 45],
463
        60: [29, 32, 35, 42, 44],
464
        61: [38, 43, 46, 49, 50],
465
        62: [37, 44, 45, 47, 48]
466
    },
467
    'Kocohl74': {
468
        1: [2, 3, 4],
469
        2: [1, 71, 74],
470
        3: [1, 72, 73],
471
        4: [1, 69, 70],
472
        5: [6, 43, 60],
473
        6: [5, 7, 50],
474
        7: [6, 8, 9],
475
        8: [7, 39, 40],
476
        9: [7, 41, 42],
477
        10: [11, 12, 31],
478
        11: [10, 21, 25],
479
        12: [10, 20, 22],
480
        13: [15, 18, 24],
481
        14: [15, 44, 47],
482
        15: [13, 14, 45],
483
        16: [17, 46, 47],
484
        17: [16, 18, 21],
485
        18: [13, 17, 22],
486
        19: [20, 21, 23],
487
        20: [12, 19, 24],
488
        21: [11, 17, 19],
489
        22: [12, 18, 23],
490
        23: [19, 22, 28],
491
        24: [13, 20, 26],
492
        25: [11, 26, 27],
493
        26: [24, 25, 35],
494
        27: [25, 30, 37],
495
        28: [23, 29, 35],
496
        29: [28, 30, 34],
497
        30: [27, 29, 33],
498
        31: [10, 33, 34],
499
        32: [40, 46, 48],
500
        33: [30, 31, 42],
501
        34: [29, 31, 41],
502
        35: [26, 28, 42],
503
        36: [38, 39, 43],
504
        37: [27, 38, 41],
505
        38: [36, 37, 40],
506
        39: [8, 36, 49],
507
        40: [8, 32, 38],
508
        41: [9, 34, 37],
509
        42: [9, 33, 35],
510
        43: [5, 36, 54],
511
        44: [14, 49, 52],
512
        45: [15, 48, 52],
513
        46: [16, 32, 56],
514
        47: [14, 16, 51],
515
        48: [32, 45, 57],
516
        49: [39, 44, 51],
517
        50: [6, 55, 58],
518
        51: [47, 49, 66],
519
        52: [44, 45, 65],
520
        53: [58, 63, 67],
521
        54: [43, 59, 63],
522
        55: [50, 59, 62],
523
        56: [46, 57, 66],
524
        57: [48, 56, 65],
525
        58: [50, 53, 61],
526
        59: [54, 55, 64],
527
        60: [5, 62, 64],
528
        61: [58, 68, 71],
529
        62: [55, 60, 72],
530
        63: [53, 54, 72],
531
        64: [59, 60, 71],
532
        65: [52, 57, 70],
533
        66: [51, 56, 69],
534
        67: [53, 70, 74],
535
        68: [61, 69, 73],
536
        69: [4, 66, 68],
537
        70: [4, 65, 67],
538
        71: [2, 61, 64],
539
        72: [3, 62, 63],
540
        73: [3, 68, 74],
541
        74: [2, 67, 73]
542
    },
543
    'https://houseofgraphs.org/graphs/3312': {
544
        1: [2, 3, 4],
545
        2: [1, 87, 88],
546
        3: [1, 85, 88],
547
        4: [1, 84, 86],
548
        5: [6, 7, 88],
549
        6: [5, 83, 87],
550
        7: [5, 81, 82],
551
        8: [83, 84, 86],
552
        9: [10, 11, 83],
553
        10: [9, 80, 86],
554
        11: [9, 79, 82],
555
        12: [28, 29, 80],
556
        13: [28, 45, 80],
557
        14: [16, 19, 81],
558
        15: [19, 78, 81],
559
        16: [14, 17, 82],
560
        17: [16, 18, 79],
561
        18: [17, 19, 20],
562
        19: [14, 15, 18],
563
        20: [18, 77, 78],
564
        21: [22, 23, 76],
565
        22: [21, 72, 75],
566
        23: [21, 73, 74],
567
        24: [25, 34, 85],
568
        25: [24, 26, 27],
569
        26: [25, 33, 38],
570
        27: [25, 32, 34],
571
        28: [12, 13, 31],
572
        29: [12, 30, 37],
573
        30: [29, 31, 36],
574
        31: [28, 30, 39],
575
        32: [27, 33, 40],
576
        33: [26, 32, 35],
577
        34: [24, 27, 43],
578
        35: [33, 38, 44],
579
        36: [30, 37, 42],
580
        37: [29, 36, 41],
581
        38: [26, 35, 41],
582
        39: [31, 42, 45],
583
        40: [32, 43, 44],
584
        41: [37, 38, 47],
585
        42: [36, 39, 47],
586
        43: [34, 40, 46],
587
        44: [35, 40, 50],
588
        45: [13, 39, 51],
589
        46: [43, 65, 85],
590
        47: [41, 42, 64],
591
        48: [53, 57, 63],
592
        49: [52, 56, 60],
593
        50: [44, 52, 61],
594
        51: [45, 53, 62],
595
        52: [49, 50, 65],
596
        53: [48, 51, 64],
597
        54: [59, 63, 71],
598
        55: [58, 60, 70],
599
        56: [49, 58, 61],
600
        57: [48, 59, 62],
601
        58: [55, 56, 67],
602
        59: [54, 57, 69],
603
        60: [49, 55, 66],
604
        61: [50, 56, 67],
605
        62: [51, 57, 69],
606
        63: [48, 54, 68],
607
        64: [47, 53, 68],
608
        65: [46, 52, 66],
609
        66: [60, 65, 72],
610
        67: [58, 61, 75],
611
        68: [63, 64, 74],
612
        69: [59, 62, 73],
613
        70: [55, 72, 75],
614
        71: [54, 73, 74],
615
        72: [22, 66, 70],
616
        73: [23, 69, 71],
617
        74: [23, 68, 71],
618
        75: [22, 67, 70],
619
        76: [21, 77, 78],
620
        77: [20, 76, 79],
621
        78: [15, 20, 76],
622
        79: [11, 17, 77],
623
        80: [10, 12, 13],
624
        81: [7, 14, 15],
625
        82: [7, 11, 16],
626
        83: [6, 8, 9],
627
        84: [4, 8, 87],
628
        85: [3, 24, 46],
629
        86: [4, 8, 10],
630
        87: [2, 6, 84],
631
        88: [2, 3, 5]
632
    },
633
    'https://houseofgraphs.org/graphs/31104': {
634
        1: [2, 3, 4, 5],
635
        2: [1, 4, 9, 10],
636
        3: [1, 5, 8, 10],
637
        4: [1, 2, 6, 8],
638
        5: [1, 3, 7, 9],
639
        6: [4, 7, 8, 10],
640
        7: [5, 6, 9, 10],
641
        8: [3, 4, 6, 9],
642
        9: [2, 5, 7, 8],
643
        10: [2, 3, 6, 7]
644
    },
645
    'Utility Graph': {
646
        1: [2, 3, 4],
647
        2: [1, 5, 6],
648
        3: [1, 5, 6],
649
        4: [1, 5, 6],
650
        5: [2, 3, 4],
651
        6: [2, 3, 4]
652
    },
653
    'Errara Graph': {
654
        1: [3, 4, 5, 11, 12],
655
        2: [6, 7, 8, 9, 10],
656
        3: [1, 4, 5, 13, 14],
657
        4: [1, 3, 11, 13, 16],
658
        5: [1, 3, 12, 14, 17],
659
        6: [2, 7, 8, 15, 16],
660
        7: [2, 6, 9, 15, 17],
661
        8: [2, 6, 10, 13, 16],
662
        9: [2, 7, 10, 14, 17],
663
        10: [2, 8, 9, 13, 14],
664
        11: [1, 4, 12, 15, 16],
665
        12: [1, 5, 11, 15, 17],
666
        13: [3, 4, 8, 10, 14, 16],
667
        14: [3, 5, 9, 10, 13, 17],
668
        15: [6, 7, 11, 12, 16, 17],
669
        16: [4, 6, 8, 11, 13, 15],
670
        17: [5, 7, 9, 12, 14, 15]
671
    },
672
    'Dragon Curve Blob 6': {
673
        1: [4, 15],
674
        2: [8, 17],
675
        3: [8, 17],
676
        4: [1, 14],
677
        5: [7, 14],
678
        6: [7, 14],
679
        7: [5, 6],
680
        8: [2, 3],
681
        9: [11, 16],
682
        10: [13, 15],
683
        11: [9, 12],
684
        12: [11, 16, 17],
685
        13: [10, 16, 17],
686
        14: [4, 5, 6, 15],
687
        15: [1, 10, 14, 16],
688
        16: [9, 12, 13, 15],
689
        17: [2, 3, 12, 13]
690
    }
691
}
692
693
AdjacencyList = NewType('AdjacencyList', dict[int, list[int]])
694
695
696
def ladder_ring_graph(size: int) -> nx.Graph:
697
    g: nx.Graph = nx.ladder_graph(size)
698
    g.add_edge(size, size * 2 - 1)
699
    g.add_edge(0, size - 1)
700
    g.name = f'Ladder Ring[{size}]'
701
    return g
702
703
704
def ladder_mobius_graph(size: int) -> nx.Graph:
705
    g = nx.ladder_graph(size)
706
    g.add_edge(size, size - 1)
707
    g.add_edge(0, size * 2 - 1)
708
    g.name = f'Ladder Möbius Ring[{size}]'
709
    return g
710
711
712
def _cylinder_edges(circumference: int, length: int) -> Iterable[tuple[int, int]]:
713
    for k in range(length):
714
        start = k * circumference
715
        stop = (k + 1) * circumference - 1
716
        if k > 0:
717
            yield start, start - circumference
718
            yield stop, stop - circumference
719
        for i in range(start, stop):
720
            yield i, i + 1
721
            if k > 0:
722
                yield i, i - circumference
723
        yield stop, start
724
725
726
def cylinder_graph(circumference: int, length: int) -> nx.Graph:
727
    g = nx.Graph(_cylinder_edges(circumference, length))
728
    g.name = f'Cylinder[circumference={circumference},length={length}]'
729
    return g
730
731
732
def _spiral_edges(n, k) -> Iterable[tuple[int, int]]:
733
    for i in range(n):
734
        yield i, i + 1
735
        if i - k >= 0:
736
            yield i, i - k
737
    yield n, n - k
738
739
740
def spiral_graph(n, k) -> nx.Graph:
741
    g = nx.Graph(_spiral_edges(n, k))
742
    g.name = f'Spiral[n={n},k={k}]'
743
    return g
744
745
746
def _spiral_torus_edges(n, k) -> Iterable[tuple[int, int]]:
747
    yield from _spiral_edges(n - 1, k)
748
    yield n - 1, 0
749
    for i in range(k):
750
        yield i, n - k + i
751
752
753
def spiral_torus_graph(n, k) -> nx.Graph:
754
    g = nx.Graph(_spiral_torus_edges(n, k))
755
    g.name = f'Spiral Torus[n={n},k={k}]'
756
    return g
757
758
759
def k_regular_edges(n, k) -> Iterable[tuple[int, int]]:
760
    yield from itertools.chain.from_iterable(
761
        ((i, j) for j in range(i + 1, i + k + 1))
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable j does not seem to be defined.
Loading history...
762
        for i in range(n-k))
763
764
def k_regular_graph(n, k) -> nx.Graph:
765
    g = nx.Graph(k_regular_edges(n, k))
766
    g.name = f'Generalized Buckyball[n={n},k={k}]'
767
    return g
768
769
770
def adjacency_edges(adjacency_list: AdjacencyList) -> Iterable[tuple[int, int]]:
771
    yield from itertools.chain.from_iterable(
772
        ((k, t) for t in v)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable t does not seem to be defined.
Loading history...
773
        for k, v
774
        in adjacency_list.items()
775
    )
776
777
778
def from_adjacency_lists(adjacency_lists: dict[str, AdjacencyList]) -> dict[str, nx.Graph]:
779
    items = (
780
        (name, adjacency_edges(adjacency_list))
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable adjacency_list does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable name does not seem to be defined.
Loading history...
781
        for name, adjacency_list
782
        in adjacency_lists.items()
783
    )
784
785
    return {n: nx.Graph(list(e)) for n, e in items}
786
787
788
def special_graphs():
789
    return from_adjacency_lists(SPECIAL_GRAPHS_ADJACENCY_LISTS)
790
791
792
def atlas():
793
    """
794
    Generate a dictionary of various graph structures and models based on the provided atlas.
795
    The function creates different types of graphs and models using NetworkX library.
796
    The generated graphs include Tetrahedron, Cube, Octahedron, Dodecahedron, Icosahedron, Tesseract, Truncated Cube,
797
    Truncated Tetrahedron, Ladder, Ring, Möbius, Cylinder, Spiral, Spiral Torus, and Circulant[10,[2]].
798
    Additionally, the function includes adjacency mappings for specific named graphs like
799
    Buckyball - Truncated Icosahedral Graph, D30 - Rhombic Triacontahedral Graph, Small Rhombicosidodecahedral Graph,
800
    Small Rhombicuboctahedral Graph, Great Rhombicosidodecahedral Graph, Disdyakis Dodecahedral Graph,
801
    Deltoidal Icositetrahedral Graph, Icosidodecahedral Graph, Deltoidal Hexecontahedral Graph, Kocohl74,
802
    Utility Graph, Errara Graph, and Dragon Curve Blob 6.
803
    The adjacency mappings define the connections between nodes in each named graph.
804
    The function returns a dictionary
805
    containing the named graphs as keys and their corresponding NetworkX graph objects as values.
806
    """
807
808
    graph_atlas = {
809
        'Triangle': nx.cycle_graph(3),
810
        'Square': nx.cycle_graph(4),
811
        'Square Lattice[3,3]': nx.grid_2d_graph(3, 3),
812
        'Pentagon': nx.cycle_graph(5),
813
        'Hexagon': nx.cycle_graph(6),
814
        'Heptagon': nx.cycle_graph(7),
815
        'Octagon': nx.cycle_graph(8),
816
        'Tetrahedron': nx.tetrahedral_graph(),
817
        'Cube': nx.hypercube_graph(3),
818
        'Octahedron': nx.octahedral_graph(),
819
        'Dodecahedron': nx.dodecahedral_graph(),
820
        'Icosahedron': nx.icosahedral_graph(),
821
        'Tesseract': nx.hypercube_graph(4),
822
        'Hypercube[5]': nx.hypercube_graph(5),
823
        'Truncated Cube': nx.truncated_cube_graph(),
824
        'Truncated Tetrahedron': nx.truncated_tetrahedron_graph(),
825
        'Ladder[16]': nx.ladder_graph(16),
826
        'Ladder Ring[16]': ladder_ring_graph(16),
827
        'Ladder Möbius Ring[16]': ladder_mobius_graph(16),
828
        'Cylinder[6,8]': cylinder_graph(6, 8),
829
        'Spiral[128,8]': spiral_graph(128, 8),
830
        'Spiral Torus[128,8]': spiral_torus_graph(128, 8),
831
        'Chvátal': nx.chvatal_graph(),
832
        'Circulant[10,[2]]': nx.circulant_graph(10, [2]),
833
        'Desargues': nx.desargues_graph(),
834
        'Dorogovtsev-Goltsev-Mendes[4]': nx.dorogovtsev_goltsev_mendes_graph(4),
835
        'Frucht': nx.frucht_graph(),
836
        'Heawood': nx.heawood_graph(),
837
        'Hoffman-Singleton': nx.hoffman_singleton_graph(),
838
        # 'Margulis-Gabber-Galil[8]': nx.margulis_gabber_galil_graph(8),
839
        'Papus': nx.pappus_graph(),
840
        'Petersen': nx.petersen_graph(),
841
        'Sedgewick Maze': nx.sedgewick_maze_graph(),
842
        'Tutte': nx.tutte_graph(),
843
    }
844
845
    graph_atlas.update(special_graphs())
846
847
    def clean(s: str):
848
        # Remove invalid characters
849
        s = re.sub('[^0-9a-zA-Z_]', '_', s)
850
851
        # Remove leading characters until we find a letter or underscore
852
        s = re.sub('^[^a-zA-Z_]+', '', s)
853
854
        return s
855
856
    for name, g in graph_atlas.items():
857
        _type = clean(name).capitalize()
858
        nx.set_node_attributes(g, _type, 'type')
859
        nx.set_edge_attributes(g, _type, 'type')
860
861
    return graph_atlas
862
863