named_graph#
- graph_tool.generation.named_graph(name, *params, **kwargs)[git][source]#
Return a named graph, or a member of a deterministic family of graphs.
- Parameters:
- name
str Name of the graph or family, as given in the table below. Upper and lower case, hyphens, spaces, and underscores are treated as equal.
- *params
Parameters of the family, in the order given in the table below.
- **kwargs
Optional parameters of the family, as given in the table below.
- name
- Returns:
- g
Graph The generated graph.
- g
See also
complete_graphComplete graph
circular_graphCircular graph
latticeSquare lattice
graph_tool.collection.dataEmpirical networks
Notes
The supported names are the following, where the optional parameters are shown with their default values, and \(N\) is always the number of vertices.
Name
Parameters
Description
"empty"N, directed=FalseGraph with \(N\) vertices and no edges.
"complete"N, self_loops=False, directed=FalseComplete graph \(K_N\) (see
complete_graph())."transitive_tournament"NDirected graph with edges \(i\to j\) for all \(j < i\), i.e. the full citation graph, which is the transitive tournament.
"complete_bipartite"N1, N2, mode="undirected"Complete bipartite graph \(K_{N_1,N_2}\), with the parts \(\{0,\dots,N_1-1\}\) and \(\{N_1,\dots,N_1+N_2-1\}\).
"complete_multipartite"N1, N2, ...Complete multipartite graph with parts of sizes \(N_1, N_2, \dots\), whose vertices are numbered consecutively part by part, and every pair of vertices of different parts is adjacent.
"turan"N, rTurán graph, the complete \(r\)-partite graph with \(N \bmod r\) parts of size \(\lfloor N/r\rfloor + 1\) followed by \(r - (N \bmod r)\) parts of size \(\lfloor N/r\rfloor\).
"path"N, directed=False, mutual=FalsePath graph \(P_N\), with the edges \((i, i+1)\) for \(i = 0,\dots,N-2\).
"cycle"N, directed=False, mutual=FalseCycle graph \(C_N\), with the edges \((i, i+1 \bmod N)\) for \(i = 0,\dots,N-1\).
"circular"N, k=1, self_loops=False, directed=FalseCycle with every vertex adjacent to its \(k\) nearest neighbors on each side (see
circular_graph())."circulant"N, offsetsCirculant graph, with vertex \(i\) adjacent to \(i \pm o \bmod N\) for every offset \(o\), without parallel edges, and with a self-loop at every vertex if an offset is a multiple of \(N\).
"extended_chordal_ring"N, W, directed=FalseCycle \(C_N\) with the chords \((i, i + W_{j,i \bmod p} \bmod N)\) for every row \(j\) of the matrix \(W\) with \(p\) columns, where \(p\) divides \(N\) (with parallel edges or self-loops if the chords coincide).
"star"N, mode="undirected"Star with a center (vertex 0) and \(N-1\) leaves.
"wheel"NWheel, the cycle \(1, 2, \dots, N-1\) with all its vertices adjacent to the center, vertex 0.
"ladder"nLadder, the cartesian product \(P_n \times P_2\): the paths \(0,\dots,n-1\) and \(n,\dots,2n-1\), with the rungs \((i, i+n)\).
"circular_ladder"nCircular ladder or prism graph \(C_n \times P_2\), i.e. \(GP(n,1)\).
"moebius_ladder"nMöbius ladder, the cycle \(C_{2n}\) with the edges \((i, i + n)\) for \(i = 0,\dots,n-1\) (without parallel edges, so that it is \(K_4\) for \(n=2\)).
"barbell"m1, m2Two complete graphs \(K_{m_1}\), on the vertices \(0,\dots,m_1-1\) and \(m_1+m_2,\dots,2m_1+m_2-1\), joined by the path \(m_1-1, m_1, \dots, m_1+m_2\), whose \(m_2\) inner vertices belong to no clique.
"lollipop"m, nLollipop graph: complete graph \(K_m\) on the vertices \(0,\dots,m-1\), joined to a path of \(n\) further vertices, as the path \(m-1, m, \dots, m+n-1\).
"tadpole"m, nTadpole graph: cycle \(C_m\) on the vertices \(0,\dots,m-1\), joined to a path of \(n\) further vertices, as the path \(m-1, m, \dots, m+n-1\).
"tree"N, k=2, mode="undirected"Tree in which the parent of vertex \(i \ge 1\) is \(\lfloor (i-1)/k\rfloor\), so that every vertex but the last ones has \(k\) children, numbered in breadth-first order.
"balanced_tree"r, h, mode="undirected"Complete \(r\)-ary tree (m-ary tree) of height \(h\), i.e. the
"tree"with \(N = \sum_{l=0}^hr^l\) and \(k = r\)."binomial_tree"n, mode="undirected"Binomial tree of order \(n\), with \(2^n\) vertices, where the parent of vertex \(i \ge 1\) is \(i\) with its lowest nonzero binary digit set to zero.
"symmetric_tree"branches, mode="undirected"Tree in which every vertex at distance \(d\) from the root has
branches[d]children, numbered in breadth-first order."regular_tree"h, k, mode="undirected"Tree of height \(h\) in which every vertex but the leaves has degree \(k\), i.e. a finite Bethe lattice: the
"symmetric_tree"withbranches=[k, k-1, ..., k-1](of length \(h\))."prefix_tree"paths, mode="undirected"Prefix tree (trie) of the sequences in
paths, with the root 0, and a vertex for every distinct prefix, adjacent to the vertex of the prefix one symbol shorter. The vertex property mapslabelandcounthold the last symbol of the prefix and the number of sequences equal to it."hypercube"n, directed=FalseHypercube graph \(Q_n\), with \(2^n\) vertices, where \(u\) and \(v\) are adjacent if their binary representations differ in a single digit.
"folded_cube"nFolded cube graph, \(Q_{n-1}\) with the edges \((v, v \oplus (2^{n-1}-1))\) between antipodal vertices, where \(\oplus\) is the bitwise exclusive or (without parallel edges, so that it is \(K_2\) for \(n=2\)).
"hamming"d, qHamming graph \(H(d,q)\), the words of length \(d\) over \(q\) letters, adjacent if they differ in one letter, where the vertex \(v\) is the word of the digits of \(v\) in base \(q\).
"kneser"n, kKneser graph \(K(n,k)\), the \(k\)-subsets of \(n\) elements, adjacent if they are disjoint.
"johnson"n, kJohnson graph \(J(n,k)\), the \(k\)-subsets of \(n\) elements, adjacent if their intersection has \(k-1\) elements.
"generalized_petersen"n, kGeneralized Petersen graph \(GP(n,k)\), with \(1 \le k \le (n-1)/2\): the outer cycle \((i, i+1 \bmod n)\), the spokes \((i, n+i)\), and the inner edges \((n+i, n + (i+k \bmod n))\), for \(i = 0,\dots,n-1\).
"lcf"N, shifts, repeats=1Cubic Hamiltonian graph in LCF notation \([\text{shifts}]^\text{repeats}\) [frucht-canonical-1977]: the cycle \(C_N\) with the chords \((i \bmod N, i + s_{i \bmod L} \bmod N)\) for \(i = 0,\dots,L\,\text{repeats}-1\), where \(s\) are the \(L\) shifts, without parallel edges and self-loops.
"lattice"shape, periodic=FalseSquare lattice of any dimension (see
lattice())."triangular_lattice"m, n, periodic=FalseTriangular lattice with \(m\) rows and \(n\) columns of triangles.
"hexagonal_lattice"m, n, periodic=FalseHexagonal lattice with \(m\) rows and \(n\) columns of hexagons.
"dorogovtsev_goltsev_mendes"nPseudofractal scale-free graph of generation \(n\) [dorogovtsev-pseudofractal-2002]: starting from the edge \((0, 1)\), every generation adds, for every edge, a new vertex adjacent to both of its endpoints.
"mycielski"nMycielski graph of order \(n\), the \((n-2)\)-th Mycielskian of \(K_2\) (see
mycielskian()), or \(K_1\) for \(n=1\) [mycielski-coloriage-1955]."hkn_harary"k, nHarary graph \(H_{k,n}\), the \(k\)-connected graph with \(n\) vertices and the fewest edges [harary-maximum-1962]: the path \(P_n\) for \(k=1\), and otherwise the circulant graph with the offsets \(1,\dots,\lfloor k/2\rfloor\), plus, for odd \(k\), the edges \((i, i + \lfloor n/2\rfloor \bmod n)\) for \(i = 0,\dots,\lceil n/2\rceil - 1\).
"hnm_harary"n, mHarary graph with \(n\) vertices and \(m\) edges and the largest connectivity [harary-maximum-1962]. With \(d = \lfloor 2m/n\rfloor\) and \(o = \lfloor d/2\rfloor\), it is the circulant graph with the offsets \(1,\dots,o\), plus, if \(n\) or \(d\) is even, the edges \((i, i + n/2)\) for \(i < n/2\) if \(d\) is odd, and \((i, i + o + 1 \bmod n)\) for \(i < \lfloor (2m \bmod n)/2\rfloor\), and otherwise the edges \((i, i + \lfloor n/2\rfloor \bmod n)\) for \(i < m - no\), all without parallel edges.
"margulis_gabber_galil"nMargulis–Gabber–Galil 8-regular expander multigraph on \(\mathbb{Z}_n^2\) [gabber-explicit-1981], with the four edges from every \((x, y)\) to \((x + 2y, y)\), \((x + 2y + 1, y)\), \((x, y + 2x)\), and \((x, y + 2x + 1)\), modulo \(n\).
"chordal_cycle"p3-regular expander on \(\mathbb{Z}_p\), for a prime \(p\), with \(x\) adjacent to \(x\pm 1\) and \(x^{-1}\) (with \(0^{-1} = 0\)), as the multigraph with the three edges \((x, x-1)\), \((x, x+1)\), and \((x, x^{-1})\) for every \(x\), so that every edge between distinct vertices appears twice, and the vertices with \(x = x^{-1}\) have a self-loop.
"paley"pPaley graph of an odd prime \(p\), with \(x\to y\) if \(y-x\) is a nonzero square modulo \(p\), undirected if \(p \equiv 1 \pmod 4\), and a tournament otherwise.
"de_bruijn"m, nDirected de Bruijn graph of the words of length \(n\) over \(m\) letters, where the vertex \(v\) is the word of its digits in base \(m\), with the edges \(v \to (mv + a) \bmod m^n\) for every letter \(a\), i.e. from every word to its shifts by one letter, including self-loops.
"kautz"m, nDirected Kautz graph of the words \(s_0s_1\cdots s_n\) of length \(n+1\) over \(m+1\) letters, without equal consecutive letters, with the edges \(s_0s_1\cdots s_n \to s_1\cdots s_na\) for every letter \(a \ne s_n\).
"sudoku"n=3Sudoku graph of an \(n^2\times n^2\) grid, with cells adjacent if they share a row, column, or \(n\times n\) box, where the cell in row \(r\) and column \(c\) has the index \(rn^2 + c\).
"caveman"l, k\(l\) disjoint complete graphs \(K_k\), the \(c\)-th on the vertices \(ck,\dots,ck+k-1\) [watts-networks-1999].
"connected_caveman"l, kCaveman graph in which the edge \((ck, ck+1)\) of every complete graph \(c\) is replaced by \((ck, ck - 1 \bmod lk)\), which connects it to the last vertex of the previous one [watts-networks-1999].
"ring_of_cliques"n, k\(n\) complete graphs \(K_k\), the \(c\)-th on the vertices \(ck,\dots,ck+k-1\), joined in a ring by the edges \((ck + 1, (c+1 \bmod n)k)\).
"windmill"n, kWindmill graph: \(n\) complete graphs \(K_k\) sharing the single vertex 0, the \(a\)-th on the vertices 0 and \(a(k-1)+1,\dots,a(k-1)+k-1\).
"triad"nameDirected graph of 3 vertices with the given triad type, from
"003"to"300"[holland-method-1970]."tetrahedral"Graph of the tetrahedron, \(K_4\).
"cubical"Graph of the cube, \(Q_3\).
"octahedral"Graph of the octahedron, \(K_{2,2,2}\).
"dodecahedral"Graph of the dodecahedron, \(GP(10,2)\).
"icosahedral"Graph of the icosahedron.
"truncated_tetrahedron"Graph of the truncated tetrahedron.
"truncated_cube"Graph of the truncated cube.
"petersen"Petersen graph, \(GP(5,2)\), and the Kneser graph \(K(5,2)\).
"durer"Dürer graph, \(GP(6,2)\).
"moebius_kantor"Möbius–Kantor graph, \(GP(8,3)\).
"desargues"Desargues graph, \(GP(10,3)\).
"nauru"Nauru graph, \(GP(12,5)\).
"franklin"Franklin graph, \([5,-5]^6\).
"frucht"Frucht graph, \([-5,-2,-4,2,5,-2,2,5,-2,-5,4,2]\).
"heawood"Heawood graph, the (3,6)-cage, \([5,-5]^7\).
"pappus"Pappus graph, \([5,7,-7,7,-7,-5]^3\).
"mcgee"McGee graph, the (3,7)-cage, \([12,7,-7]^8\).
"tutte_coxeter"Tutte–Coxeter graph or Levi graph, the (3,8)-cage, \([-13,-9,7,-7,9,13]^5\).
"coxeter"Coxeter graph, \(K(7,3)\) without the seven lines of a Fano plane [brouwer-distance-regular-1989].
"tutte"Tutte graph, three Tutte fragments joined to a vertex and in a ring [tutte-hamiltonian-1946].
"robertson"Robertson graph, the (4,5)-cage [robertson-smallest-1964].
"hoffman_singleton"Hoffman–Singleton graph, the (7,5)-cage [hoffman-moore-1960].
"shrikhande"Shrikhande graph, the Cayley graph of \(\mathbb{Z}_4^2\) with generators \(\pm(1,0)\), \(\pm(0,1)\), \(\pm(1,1)\).
"clebsch"Clebsch graph, the folded cube of dimension 5.
"chvatal"Chvátal graph, the smallest triangle-free 4-regular 4-chromatic graph [chvatal-smallest-1970].
"grotzsch"Grötzsch graph, the Mycielski graph of order 4.
"folkman"Folkman graph, the smallest semisymmetric graph [folkman-regular-1967].
"meredith"Meredith graph, 4-regular and 4-connected, but not Hamiltonian [meredith-regular-1973].
"herschel"Herschel graph, the graph of the enneahedron, the smallest non-Hamiltonian polyhedral graph.
"beineke"The nine minimal graphs that are not line graphs, as connected components [beineke-characterizations-1970].
"smallest_cyclic_group"The smallest graph whose automorphism group is cyclic, of order 3, with 9 vertices and 15 edges.
"bull"Bull graph, a triangle with two pendant vertices.
"diamond"Diamond graph, \(K_4\) without an edge.
"house"House graph, a square with a triangle on top.
"house_x"House graph with both diagonals of the square.
"krackhardt_kite"Krackhardt’s kite social network [krackhardt-assessing-1990].
"sedgewick_maze"Small maze with a cycle, from Sedgewick’s Algorithms in C.
The parameters
directedandmutualgive directed graphs with edges in the direction of increasing indices along the path or cycle, and in both directions ifmutual=True. The parametermodetakes the values"undirected","out"(edges from the center, the root, or the first part),"in"(edges in the opposite direction) and"mutual"(edges in both directions). Withdirected=True, the edges of"hypercube"point from lower to higher vertex indices.The graphs are constructed in C++ from their definitions, and the families are generated in time \(O(V + E)\), apart from a factor \(O(k)\) per edge for the Kneser and Johnson graphs, and a factor \(O(\log E)\) for the families whose parallel edges are removed by sorting the edge list. The numbering of the vertices follows the definitions, e.g. the vertex of a Kneser or Johnson graph with index \(i\) is the subset of rank \(i\) in colexicographic order, and the vertex \((x, y)\) of a Margulis–Gabber–Galil graph has index \(xn + y\). The multigraphs
"margulis_gabber_galil"and"chordal_cycle"contain parallel edges and self-loops, as their definitions require.References
[frucht-canonical-1977]R. Frucht, “A canonical representation of trivalent Hamiltonian graphs”, J. Graph Theory 1, 45-60 (1977). DOI: 10.1002/jgt.3190010111 [sci-hub, @tor]
[dorogovtsev-pseudofractal-2002]S. N. Dorogovtsev, A. V. Goltsev, and J. F. F. Mendes, “Pseudofractal scale-free web”, Phys. Rev. E 65, 066122 (2002). DOI: 10.1103/PhysRevE.65.066122 [sci-hub, @tor]
[mycielski-coloriage-1955]J. Mycielski, “Sur le coloriage des graphs”, Colloq. Math. 3, 161-162 (1955). DOI: 10.4064/cm-3-2-161-162 [sci-hub, @tor]
[harary-maximum-1962] (1,2)F. Harary, “The maximum connectivity of a graph”, Proc. Natl. Acad. Sci. USA 48, 1142-1146 (1962). DOI: 10.1073/pnas.48.7.1142 [sci-hub, @tor]
[gabber-explicit-1981]O. Gabber and Z. Galil, “Explicit constructions of linear-sized superconcentrators”, J. Comput. Syst. Sci. 22, 407-420 (1981). DOI: 10.1016/0022-0000(81)90040-4 [sci-hub, @tor]
[watts-networks-1999] (1,2)D. J. Watts, “Networks, dynamics, and the small-world phenomenon”, Am. J. Sociol. 105, 493-527 (1999). DOI: 10.1086/210318 [sci-hub, @tor]
[holland-method-1970]P. W. Holland and S. Leinhardt, “A method for detecting structure in sociometric data”, Am. J. Sociol. 76, 492-513 (1970). DOI: 10.1086/224954 [sci-hub, @tor]
[brouwer-distance-regular-1989]A. E. Brouwer, A. M. Cohen, and A. Neumaier, “Distance-Regular Graphs”, Springer (1989). DOI: 10.1007/978-3-642-74341-2 [sci-hub, @tor]
[tutte-hamiltonian-1946]W. T. Tutte, “On Hamiltonian circuits”, J. London Math. Soc. s1-21, 98-101 (1946). DOI: 10.1112/jlms/s1-21.2.98 [sci-hub, @tor]
[robertson-smallest-1964]N. Robertson, “The smallest graph of girth 5 and valency 4”, Bull. Amer. Math. Soc. 70, 824-825 (1964). DOI: 10.1090/S0002-9904-1964-11250-7 [sci-hub, @tor]
[hoffman-moore-1960]A. J. Hoffman and R. R. Singleton, “On Moore graphs with diameters 2 and 3”, IBM J. Res. Dev. 4, 497-504 (1960). DOI: 10.1147/rd.45.0497 [sci-hub, @tor]
[chvatal-smallest-1970]V. Chvátal, “The smallest triangle-free 4-chromatic 4-regular graph”, J. Combin. Theory 9, 93-94 (1970). DOI: 10.1016/S0021-9800(70)80057-6 [sci-hub, @tor]
[folkman-regular-1967]J. Folkman, “Regular line-symmetric graphs”, J. Combin. Theory 3, 215-232 (1967). DOI: 10.1016/S0021-9800(67)80069-3 [sci-hub, @tor]
[meredith-regular-1973]G. H. J. Meredith, “Regular n-valent n-connected nonHamiltonian non-n-edge-colorable graphs”, J. Combin. Theory B 14, 55-60 (1973). DOI: 10.1016/S0095-8956(73)80006-1 [sci-hub, @tor]
[beineke-characterizations-1970]L. W. Beineke, “Characterizations of derived graphs”, J. Combin. Theory 9, 129-135 (1970). DOI: 10.1016/S0021-9800(70)80019-9 [sci-hub, @tor]
[krackhardt-assessing-1990]D. Krackhardt, “Assessing the political landscape: Structure, cognition, and power in organizations”, Admin. Sci. Q. 35, 342-369 (1990). DOI: 10.2307/2393394 [sci-hub, @tor]
[wiki-gallery]Examples
>>> g = gt.named_graph("petersen") >>> print(g) <Graph object, undirected, with 10 vertices and 15 edges, at 0x...> >>> g = gt.named_graph("generalized_petersen", 7, 2) >>> print(g.num_vertices(), g.num_edges()) 14 21 >>> g = gt.named_graph("kneser", 7, 3) >>> print(g.num_vertices(), g.num_edges()) 35 70 >>> g = gt.named_graph("tree", 15, 2, mode="out") >>> print(g.vertex(0).out_degree(), g.vertex(14).in_degree()) 2 1 >>> g = gt.named_graph("hoffman_singleton") >>> pos = gt.sfdp_layout(g) >>> gt.graph_draw(g, pos=pos, output="hoffman_singleton.pdf") <...>
The Hoffman–Singleton graph.#
Several named graphs are drawn together as follows, as the components of a single graph:
>>> g = gt.Graph(directed=False) >>> for name in ["petersen", "heawood", "moebius_kantor", "grotzsch"]: ... g = gt.graph_union(g, gt.named_graph(name), vmap=None) >>> gt.graph_draw(g, pos=gt.sfdp_layout(g), ... output="named_graph-gallery.pdf") <...>
The Petersen, Heawood, Möbius–Kantor, and Grötzsch graphs, drawn as the components of a single graph.#