# Enumerating labeled graphs on n vertices

I'm trying to enumerate the labeled graphs on $$n$$ vertices having at most $$e$$ edges. I thought GraphData /@ GraphData[n] and then filtering by edge count would do the trick (albeit slowlt) but this seems to only return some named graphs and it also only has one graph per isomorphism class, which is not what I want.

• You can compute the max edge number mmax = Binomial[n,2] for n vertices, and select all m-element subsets of Range[mmax]. Then create arrays where these positions are set to 1, the rest to 0. Finally use the values in the arrays to fill the upper triangular part of an adjacency matrix. TakeList will be helpful for partitioning the array, PadLeft for turning it into a matrix. Finally, symmetrix the matrix and convert to a graph with AdjacencyGraph. I'm sorry, I don't have time to write ready to use code for this. Commented Feb 28, 2022 at 20:16

The idea suggested by @Szabolics in the comment is easily realized by Subsets[ ]:

gen[n_, e_] := Module[{alledges},
alledges = Subsets[Range[n], {2}];
Table[Graph[Range[n], UndirectedEdge @@@ edges,
VertexLabels -> "Name", VertexCoordinates -> CirclePoints[n],
ImageSize -> 50], {edges, Subsets[alledges, e]}]];

gen[5,3]


• Nice solution, +1! I'll use this approach from now on when I need to generate labelled graphs. You have a small mistake where you wrote vc instead of vcoord. This could be made even simpler by using VertexCoordinates -> CirclePoints[n]. Commented Jul 25 at 10:22
• @Szabolcs Thank you very much :-) Following your comment, I revised my answer. Commented Jul 25 at 10:31