K indZgdZddlmZddlZddlmZddlm Z m Z m Z m Z dZ ejdd d!d Ze ejdd d!d Ze ejdd d!d Ze ejdd d!d Zejdd d!dZe ejdd d!dZejdd d!dZejdd d!dZejdd d!dZejdd dZe ejdd d!dZe ejdd d!dZe ejdd d!dZe ejdd d!dZejdd d!dZe ejdd d!dZejdd dZe ejdd d!dZ ejdd d!dZ!ejdd d!dZ"e ejdd d!dZ#ejdd d!dZ$e ejdd d!d Z%y)"zI Various small and named graphs, together with some compact generators. ) LCF_graph bull_graph chvatal_graph cubical_graphdesargues_graph diamond_graphdodecahedral_graph frucht_graph heawood_graphhoffman_singleton_graph house_graph house_x_graphicosahedral_graphkrackhardt_kite_graphmoebius_kantor_graphoctahedral_graph pappus_graphpetersen_graphsedgewick_maze_graphtetrahedral_graphtruncated_cube_graphtruncated_tetrahedron_graph tutte_graphwrapsN) NetworkXError)complete_graph cycle_graph empty_graph path_graphc.tfd}|S)a( A decorator which inspects the `create_using` argument and raises a NetworkX exception when `create_using` is a DiGraph (class or instance) for graph generators that do not support directed outputs. `create_using` may be a keyword argument or the first positional argument. c|r|dn|jd}|1tj|}|jr t d|i|S)Nr create_usingr#Directed Graph not supported)getnxr is_directedr)argskwargsr#Gfuncs _/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/networkx/generators/small.pywrapperz#_raise_on_directed..wrapper5sR"&tAwFJJ~,F  #L9A}}#$BCCT$V$$r)r,r.s` r-_raise_on_directedr0,s" 4[%% Nr/T)graphs returns_graphcP|dkr td|St||}|jr tdd|_t |}|t |z}|dkr|St|D]8}||t |z}|||z} |||z|z} |j| | :|S)a Return the cubic graph specified in LCF notation. LCF (Lederberg-Coxeter-Fruchte) notation[1]_ is a compressed notation used in the generation of various cubic Hamiltonian graphs of high symmetry. See, for example, `dodecahedral_graph`, `desargues_graph`, `heawood_graph` and `pappus_graph`. Nodes are drawn from ``range(n)``. Each node ``n_i`` is connected with node ``n_i + shift % n`` where ``shift`` is given by cycling through the input `shift_list` `repeat` s times. Parameters ---------- n : int The starting graph is the `n`-cycle with nodes ``0, ..., n-1``. The null graph is returned if `n` < 1. shift_list : list A list of integer shifts mod `n`, ``[s1, s2, .., sk]`` repeats : int Integer specifying the number of times that shifts in `shift_list` are successively applied to each current node in the n-cycle to generate an edge between ``n_current`` and ``n_current + shift mod n``. Returns ------- G : Graph A graph instance created from the specified LCF notation. Examples -------- The utility graph $K_{3,3}$ >>> G = nx.LCF_graph(6, [3, -3], 3) >>> G.edges() EdgeView([(0, 1), (0, 5), (0, 3), (1, 2), (1, 4), (2, 3), (2, 5), (3, 4), (4, 5)]) The Heawood graph: >>> G = nx.LCF_graph(14, [5, -5], 7) >>> nx.is_isomorphic(G, nx.heawood_graph()) True References ---------- .. [1] https://en.wikipedia.org/wiki/LCF_notation rr%r) rrr(rnamesortedlenrangeadd_edge) n shift_listrepeatsr#r+nodes n_extra_edgesishiftv1v2s r-rrAsh Av1l++ A|$A}}:;; AF 1IEc*o-Mq = !1s:./ 1q5\ AI? # 2r  Hr/c^tjddggdgddgdgd|}d|_|S)a Returns the Bull Graph The Bull Graph has 5 nodes and 5 edges. It is a planar undirected graph in the form of a triangle with two disjoint pendant edges [1]_ The name comes from the triangle and pendant edges representing respectively the body and legs of a bull. Parameters ---------- create_using : NetworkX graph constructor, optional (default=nx.Graph) Graph type to create. If graph instance, then cleared before populated. Returns ------- G : networkx Graph A bull graph with 5 nodes References ---------- .. [1] https://en.wikipedia.org/wiki/Bull_graph. r4rrD)rr4rr4rDrFrGr$z Bull Graphr'from_dict_of_listsr5r#r+s r-rrs;4  FyYA3A3?! AAF Hr/c ~tjgdgdgdgdddgddgddgddgdgddgd | }d |_|S) u Returns the Chvátal Graph The Chvátal Graph is an undirected graph with 12 nodes and 24 edges [1]_. It has 370 distinct (directed) Hamiltonian cycles, giving a unique generalized LCF notation of order 4, two of order 6 , and 43 of order 1 [2]_. Parameters ---------- create_using : NetworkX graph constructor, optional (default=nx.Graph) Graph type to create. If graph instance, then cleared before populated. Returns ------- G : networkx Graph The Chvátal graph with 12 nodes and 24 edges References ---------- .. [1] https://en.wikipedia.org/wiki/Chv%C3%A1tal_graph .. [2] https://mathworld.wolfram.com/ChvatalGraph.html )r4rG rD)rFrM)rGrQrNrPrR rr4rDrFrGrPrMrQrRrNr$z Chvatal GraphrIrKs r-rrs`4 1vBxBx2wtBx " AAF Hr/c ttjgdgdgdgdgdgdgdgdd | }d |_|S) a Returns the 3-regular Platonic Cubical Graph The skeleton of the cube (the nodes and edges) form a graph, with 8 nodes, and 12 edges. It is a special case of the hypercube graph. It is one of 5 Platonic graphs, each a skeleton of its Platonic solid [1]_. Such graphs arise in parallel processing in computers. Parameters ---------- create_using : NetworkX graph constructor, optional (default=nx.Graph) Graph type to create. If graph instance, then cleared before populated. Returns ------- G : networkx Graph A cubical graph with 8 nodes and 12 edges References ---------- .. [1] https://en.wikipedia.org/wiki/Cube#Cubical_graph )r4rFrG)rrDrQr4rFrM)rrDrP)rrPrQ)rFrGrMrO)r4rGrM)rr4rDrFrGrPrMrQr$zPlatonic Cubical GraphrIrKs r-rrsD6  " A&AF Hr/c4tdgdd|}d|_|S)a Returns the Desargues Graph The Desargues Graph is a non-planar, distance-transitive cubic graph with 20 nodes and 30 edges [1]_. It is a symmetric graph. It can be represented in LCF notation as [5,-5,9,-9]^5 [2]_. Parameters ---------- create_using : NetworkX graph constructor, optional (default=nx.Graph) Graph type to create. If graph instance, then cleared before populated. Returns ------- G : networkx Graph Desargues Graph with 20 nodes and 30 edges References ---------- .. [1] https://en.wikipedia.org/wiki/Desargues_graph .. [2] https://mathworld.wolfram.com/DesarguesGraph.html )rPrNirPzDesargues Graphrr5rKs r-rr s 2 "na6A AF Hr/c\tjddggdgdddgd|}d|_|S)a2 Returns the Diamond graph The Diamond Graph is planar undirected graph with 4 nodes and 5 edges. It is also sometimes known as the double triangle graph or kite graph [1]_. Parameters ---------- create_using : NetworkX graph constructor, optional (default=nx.Graph) Graph type to create. If graph instance, then cleared before populated. Returns ------- G : networkx Graph Diamond Graph with 4 nodes and 5 edges References ---------- .. [1] https://mathworld.wolfram.com/DiamondGraph.html r4rDrE)rr4rF)rr4rDrFr$z Diamond GraphrIrKs r-rr+s8.  FyYAq6: AAF Hr/c4tdgdd|}d|_|S)a Returns the Platonic Dodecahedral graph. The dodecahedral graph has 20 nodes and 30 edges. The skeleton of the dodecahedron forms a graph. It is one of 5 Platonic graphs [1]_. It can be described in LCF notation as: ``[10, 7, 4, -4, -7, 10, -4, 7, -7, 4]^2`` [2]_. Parameters ---------- create_using : NetworkX graph constructor, optional (default=nx.Graph) Graph type to create. If graph instance, then cleared before populated. Returns ------- G : networkx Graph Dodecahedral Graph with 20 nodes and 30 edges References ---------- .. [1] https://en.wikipedia.org/wiki/Regular_dodecahedron#Dodecahedral_graph .. [2] https://mathworld.wolfram.com/DodecahedralGraph.html rY) rSrQrGrSr^rQr_rGrDzDodecahedral Graphr[rKs r-rrIs!4 ":A|LA !AF Hr/ctd|}|jddgddgddgddgddgd d gd d gdd gdd gddgd d gg d |_|S)a Returns the Frucht Graph. The Frucht Graph is the smallest cubical graph whose automorphism group consists only of the identity element [1]_. It has 12 nodes and 18 edges and no nontrivial symmetries. It is planar and Hamiltonian [2]_. Parameters ---------- create_using : NetworkX graph constructor, optional (default=nx.Graph) Graph type to create. If graph instance, then cleared before populated. Returns ------- G : networkx Graph Frucht Graph with 12 nodes and 18 edges References ---------- .. [1] https://en.wikipedia.org/wiki/Frucht_graph .. [2] https://mathworld.wolfram.com/FruchtGraph.html rQrr4rDrRrFrNrGrPrSrMrTz Frucht Graph)radd_edges_fromr5rKs r-r r hs~4 A|$A F F F F F G G G G F H  AF Hr/c4tdddgd|}d|_|S)an Returns the Heawood Graph, a (3,6) cage. The Heawood Graph is an undirected graph with 14 nodes and 21 edges, named after Percy John Heawood [1]_. It is cubic symmetric, nonplanar, Hamiltonian, and can be represented in LCF notation as ``[5,-5]^7`` [2]_. It is the unique (3,6)-cage: the regular cubic graph of girth 6 with minimal number of vertices [3]_. Parameters ---------- create_using : NetworkX graph constructor, optional (default=nx.Graph) Graph type to create. If graph instance, then cleared before populated. Returns ------- G : networkx Graph Heawood Graph with 14 nodes and 21 edges References ---------- .. [1] https://en.wikipedia.org/wiki/Heawood_graph .. [2] https://mathworld.wolfram.com/HeawoodGraph.html .. [3] https://www.win.tue.nl/~aeb/graphs/Heawood.html rPrZrQz Heawood Graphr[rKs r-r r s$: "q"gq,/A AF Hr/c tj}tdD]}tdD]}|jd||fd||dz dzf|jd||fd||dzdzf|jd||fd||dz dzf|jd||fd||dzdzftdD]#}|jd||fd|||z|zdzf%tj|}d|_|S)u Returns the Hoffman-Singleton Graph. The Hoffman–Singleton graph is a symmetrical undirected graph with 50 nodes and 175 edges. All indices lie in ``Z % 5``: that is, the integers mod 5 [1]_. It is the only regular graph of vertex degree 7, diameter 2, and girth 5. It is the unique (7,5)-cage graph and Moore graph, and contains many copies of the Petersen graph [2]_. Returns ------- G : networkx Graph Hoffman–Singleton Graph with 50 nodes and 175 edges Notes ----- Constructed from pentagon and pentagram as follows: Take five pentagons $P_h$ and five pentagrams $Q_i$ . Join vertex $j$ of $P_h$ to vertex $h·i+j$ of $Q_i$ [3]_. References ---------- .. [1] https://blogs.ams.org/visualinsight/2016/02/01/hoffman-singleton-graph/ .. [2] https://mathworld.wolfram.com/Hoffman-SingletonGraph.html .. [3] https://en.wikipedia.org/wiki/Hoffman%E2%80%93Singleton_graph rPpentagonr4 pentagramrDzHoffman-Singleton Graph)r'Graphr8r9convert_node_labels_to_integersr5)r+r?jks r-r r s$:  A 1XRq RA JJ Aq)JAEQ;+G H JJ Aq)JAEQ;+G H JJ Q*[!a!eq[,I J JJ Q*[!a!eq[,I J1X R J1- QQa/PQ R  RR **1-A &AF Hr/cbtjddgddggdgdddgd|}d |_|S) a Returns the House graph (square with triangle on top) The house graph is a simple undirected graph with 5 nodes and 6 edges [1]_. Parameters ---------- create_using : NetworkX graph constructor, optional (default=nx.Graph) Graph type to create. If graph instance, then cleared before populated. Returns ------- G : networkx Graph House graph in the form of a square with a triangle on top References ---------- .. [1] https://mathworld.wolfram.com/HouseGraph.html r4rDrrF)rrFrGr4rDrGrHr$z House GraphrIrKs r-r r s?.  F1v) q!fE! AAF Hr/cPt|}|jddgd|_|S)a Returns the House graph with a cross inside the house square. The House X-graph is the House graph plus the two edges connecting diagonally opposite vertices of the square base. It is also one of the two graphs obtained by removing two edges from the pentatope graph [1]_. Parameters ---------- create_using : NetworkX graph constructor, optional (default=nx.Graph) Graph type to create. If graph instance, then cleared before populated. Returns ------- G : networkx Graph House graph with diagonal vertices connected References ---------- .. [1] https://mathworld.wolfram.com/HouseGraph.html )rrF)r4rDzHouse-with-X-inside Graph)r rar5rKs r-r r s-0 L!Aff%& (AF Hr/c ztjgdgdgdgdgdddggdd gd gdgd | }d |_|S)ai Returns the Platonic Icosahedral graph. The icosahedral graph has 12 nodes and 30 edges. It is a Platonic graph whose nodes have the connectivity of the icosahedron. It is undirected, regular and Hamiltonian [1]_. Parameters ---------- create_using : NetworkX graph constructor, optional (default=nx.Graph) Graph type to create. If graph instance, then cleared before populated. Returns ------- G : networkx Graph Icosahedral graph with 12 nodes and 30 edges. References ---------- .. [1] https://mathworld.wolfram.com/IcosahedralGraph.html )r4rPrQrRrT)rDrPrMrR)rFrMrRrN)rGrMrNrS)rPrMrSrTrMrT)rRrNrSrTrNrS) rr4rDrFrGrPrQrRrNrSr$zPlatonic Icosahedral GraphrIrKs r-rr!sT0 2wst " A*AF Hr/c ~tjgdgdgdgdgdgdgdgdd d gd gd | }d|_|S)um Returns the Krackhardt Kite Social Network. A 10 actor social network introduced by David Krackhardt to illustrate different centrality measures [1]_. Parameters ---------- create_using : NetworkX graph constructor, optional (default=nx.Graph) Graph type to create. If graph instance, then cleared before populated. Returns ------- G : networkx Graph Krackhardt Kite graph with 10 nodes and 18 edges Notes ----- The traditional labeling is: Andre=1, Beverley=2, Carol=3, Diane=4, Ed=5, Fernando=6, Garth=7, Heather=8, Ike=9, Jane=10. References ---------- .. [1] Krackhardt, David. "Assessing the Political Landscape: Structure, Cognition, and Power in Organizations". Administrative Science Quarterly. 35 (2): 342–369. doi:10.2307/2393394. JSTOR 2393394. June 1990. )r4rDrFrP)rrFrGrM)rrFrP)rr4rDrGrPrMrW)rrDrFrMrQ)r4rFrGrPrQ)rPrMrRrQrNrRrUr$zKrackhardt Kite Social NetworkrIrKs r-rrLsQ@ !1vs " A.AF Hr/c4tdddgd|}d|_|S)uF Returns the Moebius-Kantor graph. The Möbius-Kantor graph is the cubic symmetric graph on 16 nodes. Its LCF notation is [5,-5]^8, and it is isomorphic to the generalized Petersen graph [1]_. Parameters ---------- create_using : NetworkX graph constructor, optional (default=nx.Graph) Graph type to create. If graph instance, then cleared before populated. Returns ------- G : networkx Graph Moebius-Kantor graph References ---------- .. [1] https://en.wikipedia.org/wiki/M%C3%B6bius%E2%80%93Kantor_graph rPrZrRzMoebius-Kantor Graphr[rKs r-rrs$0 "q"gq,/A #AF Hr/c`tjgdgdddgddgdgd|}d|_|S)a? Returns the Platonic Octahedral graph. The octahedral graph is the 6-node 12-edge Platonic graph having the connectivity of the octahedron [1]_. If 6 couples go to a party, and each person shakes hands with every person except his or her partner, then this graph describes the set of handshakes that take place; for this reason it is also called the cocktail party graph [2]_. Parameters ---------- create_using : NetworkX graph constructor, optional (default=nx.Graph) Graph type to create. If graph instance, then cleared before populated. Returns ------- G : networkx Graph Octahedral graph References ---------- .. [1] https://mathworld.wolfram.com/OctahedralGraph.html .. [2] https://en.wikipedia.org/wiki/Tur%C3%A1n_graph#Special_cases )r4rDrFrG)rDrFrPrGrPrHr$zPlatonic Octahedral GraphrIrKs r-rrs=8  YAq6q!f!E! A)AF Hr/c2tdgdd}d|_|S)ax Returns the Pappus graph. The Pappus graph is a cubic symmetric distance-regular graph with 18 nodes and 27 edges. It is Hamiltonian and can be represented in LCF notation as [5,7,-7,7,-7,-5]^3 [1]_. Returns ------- G : networkx Graph Pappus graph References ---------- .. [1] https://en.wikipedia.org/wiki/Pappus_graph )rPrQr_rQr_rZrFz Pappus Graphr[)r+s r-rrs$ "+Q/A AF Hr/c tjgdgdgdgdgdgdgdgdgd gd d | }d |_|S)a Returns the Petersen graph. The Peterson graph is a cubic, undirected graph with 10 nodes and 15 edges [1]_. Julius Petersen constructed the graph as the smallest counterexample against the claim that a connected bridgeless cubic graph has an edge colouring with three colours [2]_. Parameters ---------- create_using : NetworkX graph constructor, optional (default=nx.Graph) Graph type to create. If graph instance, then cleared before populated. Returns ------- G : networkx Graph Petersen graph References ---------- .. [1] https://en.wikipedia.org/wiki/Petersen_graph .. [2] https://www.win.tue.nl/~aeb/drg/graphs/Petersen.html )r4rGrP)rrDrM)r4rFrQ)rDrGrR)rFrrN)rrQrR)r4rRrN)rDrPrN)rFrPrM)rGrMrQrUr$zPetersen GraphrIrKs r-rrsJ4  " AAF Hr/c$td|}|jtd|jddgddgddgg|jddgddgg|jdd gddgg|jd dgd dgd dggd |_|S) a? Return a small maze with a cycle. This is the maze used in Sedgewick, 3rd Edition, Part 5, Graph Algorithms, Chapter 18, e.g. Figure 18.2 and following [1]_. Nodes are numbered 0,..,7 Parameters ---------- create_using : NetworkX graph constructor, optional (default=nx.Graph) Graph type to create. If graph instance, then cleared before populated. Returns ------- G : networkx Graph Small maze with a cycle References ---------- .. [1] Figure 18.2, Chapter 18, Graph Algorithms (3rd Ed), Sedgewick rrRrDrQrPr4rMrFrGzSedgewick Maze)radd_nodes_fromr8rar5rKs r-rrs. A|$AU1Xq!fq!fq!f-.q!fq!f%&q!fq!f%&q!fq!fq!f-. AF Hr/c,td|}d|_|S)aK Returns the 3-regular Platonic Tetrahedral graph. Tetrahedral graph has 4 nodes and 6 edges. It is a special case of the complete graph, K4, and wheel graph, W4. It is one of the 5 platonic graphs [1]_. Parameters ---------- create_using : NetworkX graph constructor, optional (default=nx.Graph) Graph type to create. If graph instance, then cleared before populated. Returns ------- G : networkx Graph Tetrahedral Graph References ---------- .. [1] https://en.wikipedia.org/wiki/Tetrahedron#Tetrahedral_graph rGzPlatonic Tetrahedral Graph)rr5rKs r-rr%s0 q,'A )AF Hr/c tjidgddddgdddgdd d gdd gd d d gd dd gdddgd dgdddgdddgddgddgdddgddgdddgd dd gdgdgdgdgdgdgd|}d|_|S)a Returns the skeleton of the truncated cube. The truncated cube is an Archimedean solid with 14 regular faces (6 octagonal and 8 triangular), 36 edges and 24 nodes [1]_. The truncated cube is created by truncating (cutting off) the tips of the cube one third of the way into each edge [2]_. Parameters ---------- create_using : NetworkX graph constructor, optional (default=nx.Graph) Graph type to create. If graph instance, then cleared before populated. Returns ------- G : networkx Graph Skeleton of the truncated cube References ---------- .. [1] https://en.wikipedia.org/wiki/Truncated_cube .. [2] https://www.coolmath.com/reference/polyhedra-truncated-cube rrlr4rTrcrDrFrGrMrRrPrqrtrQrS rNrY )r{rtrrYr}r~r$zTruncated Cube GraphrIrKs r-rrBsO6  y Bx  1v  1v  s  Bx   1v  Bx  s  Bx  R      R   R! " R# $/ 2"5 A8$AF Hr/cRtd|}|jgdd|_|S)a Returns the skeleton of the truncated Platonic tetrahedron. The truncated tetrahedron is an Archimedean solid with 4 regular hexagonal faces, 4 equilateral triangle faces, 12 nodes and 18 edges. It can be constructed by truncating all 4 vertices of a regular tetrahedron at one third of the original edge length [1]_. Parameters ---------- create_using : NetworkX graph constructor, optional (default=nx.Graph) Graph type to create. If graph instance, then cleared before populated. Returns ------- G : networkx Graph Skeleton of the truncated tetrahedron References ---------- .. [1] https://en.wikipedia.org/wiki/Truncated_tetrahedron rz))rrD)rrN)r4rM)rFrT)rGrT)rPrQ)rRrSzTruncated Tetrahedron Graph)r rar5rKs r-rr}s+0 2|$APQ *AF Hr/c tjidgddddgdddgd d d gdd d gd ddgdddgdddgdddgdddgddgdddgdddgdddgddgdddgddd gidd d!gd d"gd d#d"gd#d$d%gd$dd&gdd'gd&d(dgd(d)d*gd)dd+gdd gdd,gd,dd*gdd-gd-d+d gd+d*gdddgdd.gddgdgd%d gd/gd!d"gd gd0|1}d2|_|S)3a Returns the Tutte graph. The Tutte graph is a cubic polyhedral, non-Hamiltonian graph. It has 46 nodes and 69 edges. It is a counterexample to Tait's conjecture that every 3-regular polyhedron has a Hamiltonian cycle. It can be realized geometrically from a tetrahedron by multiply truncating three of its vertices [1]_. Parameters ---------- create_using : NetworkX graph constructor, optional (default=nx.Graph) Graph type to create. If graph instance, then cleared before populated. Returns ------- G : networkx Graph Tutte graph References ---------- .. [1] https://en.wikipedia.org/wiki/Tutte_graph r)r4rDrFr4rGrDrSrTrFrtrrP!rMrQrRrcrN&%'rzr|#r"rqr~r{,+-rYr})r( $*)rrrrrrr$z Tutte's GraphrIrKs r-rrsh6 ) y) 2w)  Bx)  Bx ) 2w ) 2w )  2w)  2w)  2w)  Bx)  )  R)  R)  R)  ) R!) " R#) $ R%) & ') ( R)) * R+) , R-) . /) 0 R1) 2 R3) 4 R5) 6 7) 8 9) : R;) < =) > R?) @ A) B RC) D E) FRRRQ) T"W, AZAF Hr/)N)&__doc____all__ functoolsrnetworkxr'networkx.exceptionrnetworkx.generators.classicrrrr r0 _dispatchablerrrrrrrr r r r r rrrrrrrrrrrr/r-rs  4,*T2H 3H `T2 3 @T2( 3( VT2' 3' TT2 3 :T2 3 8T2 3 <T2+ 3+ \T2 3 BT2' 3' TT2 3 :T2 3 8T2& 3& RT2. 3. bT2 3 8T2 3 DT2 3 ,T2( 3( VT2 3 @T2 3 8T26 36 rT2 3 :T2G 3G r/