3
$\begingroup$

The answer must be obvious, but I can't come up with it. In the previous versions of Mathematica there was ListGraphs function from Combinatorica package which was able to take number of vertices and edges as arguments. The help page states that beggining from 10.0 version its functionality was implemented in built-in GraphData. When I tried to run GraphData[4,3] it returned me an error

GraphData::notdef: GraphData has no value associated with the specified argument(s).

What should I do now if I need a list of all non-isomorphic graphs with $n$ vertices and $m$ edges?

$\endgroup$
  • 1
    $\begingroup$ Select[GraphData[3], GraphData[#, "EdgeCount"] == 2 &] works but is extremely slow $\endgroup$ – Lukas Lang Sep 9 '17 at 11:50
  • 1
    $\begingroup$ As of version 11.2, it seems only GraphData[n] (which gives gives a list of named graphs with n vertices) is supported. Perhaps you can use something like Select[GraphData[4], GraphData[#, "EdgeCount"] == 3&]? $\endgroup$ – kglr Sep 9 '17 at 11:51
2
$\begingroup$

Keep in mind that GraphData is a database, not a graph generator. It cannot have all graphs. That said, as of version 11.2 it does seem to have all undirected graphs up to 7 vertices.

To get all graphs on 4 vertices and 3 edges, you could use

Pick[
 GraphData[4],
 GraphData[#, "EdgeCount"] & /@ GraphData[4],
 3
]

(* {"C3+K1", "ClawGraph", {"Path", 4}} *)

GraphData /@ %

Mathematica graphics

This method is not at all fast, but for interactive queries I find it entirely usable.

The first time you request a graph, Mathematica will need to download the corresponding part of its graph database. This will be slow. The next time you request it, evaluation will be much faster (until the database gets updated, at which point it will be re-downloaded).

$\endgroup$

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.