Graph Theory – Simple Algorithm to Generate Unlabeled Graphs

algorithmscombinatoricscomputer sciencegraph theory

While working on some other problem I realized I need to generate (not only enumerate!) all unlabeled graph (or exactly ONE representative from each equivalence class of labeled graphs) with a certain number of vertices or edges (vertices would be enough as I can group them by edges later).

Generating all labeled graphs and then choosing a representative from each class is NOT an option. This would take too long.

Something like "the orderly method" from this website http://www.cs.uc.edu/~andersr9/interests/enumeration-of-unlabeled-graphs/ would work for me, but I couldn't find the original source.

Remark: A description of a canonical way of labeling an unlabeled graph will probably be enough for me at this moment. I might be able to devise an algorithm from there. However, a more precise answer would be greatly appreciated.

Best Answer

I would suggest using Nauty by Brendan McKay. It is very quick for up to 10 vertices (and at this point the compressed list of graphs are about 100MB). More specifically, use geng 10 -l > v10.g6.txt to create the graphs on 10 vertices, canonically labelled. There are 12005168 (1.2e7) unlabeled graphs on 10 vertices found in 8 seconds. Brendan McKay's webpage has information on the canonical labelling and the generation algorithms used. The program is distributed as source code and is very widely used.