3
$\begingroup$

Is it possible to import graphs generated by geng (a tool from the nauty suite) one by one, rather than all at once. If one could also specify not only the order but also the number of edges that would be great, but the main thing is to be able to get one at a time rather than dump them all in memory at once. Thanks

$\endgroup$

2 Answers 2

2
$\begingroup$

To see geng's options, just rung geng -h on the command line.

You can use something like this to e.g. generate connected graphs (-c) on 5 vertices (5) with 6 to 7 edges (6:7):

geng = StartProcess[{"/opt/local/bin/geng", "-c", "5" , "6:7"}]

This does generate all graphs without stopping. But we can read them into Mathematica one by one instead of reading them all at once. Example:

While[(line = ReadLine[geng]) =!= EndOfFile,
  Print@ImportString[line, "Graph6"]
]

Simple use ReadLine to read the output line-by-line (i.e. graph-by-graph) until it returns EndOfFile (i.e. there is no more data).

$\endgroup$
6
  • $\begingroup$ Thanks, this helps somewhat ... However, the output of geng is still completely dumped into an output file, right? I guess there is no way of avoiding this? The problem is that even for small graphs, the output of such calls to geng generate an enormous amount of graphs ... $\endgroup$
    – EGME
    Dec 12, 2019 at 21:50
  • $\begingroup$ Yes, the output of geng is still stored somewhere. I do not know where (memory, disk, a combination of the two, etc.) On the upside: the output of geng is an extremely efficient encoding of the graphs. It will take up much less space than what Mathematica's Graph expressions would. So this should still be a considerable saving. $\endgroup$
    – Szabolcs
    Dec 12, 2019 at 22:01
  • $\begingroup$ It appears that geng cannot be installed on Windows machines? $\endgroup$
    – EGME
    Dec 14, 2019 at 14:20
  • $\begingroup$ @EGME It should be possible to install it on Windows, but the author does not provide binaries. That means you need to compile it yourself. Unfortunately, on Windows that tends to be much less convenient than on Unix-like systems. I don't use Windows much, so I can't really offer advice here, except that if I had to do it, I would try msys2 first, which provides a Unix-style environment in which the original compilation instructions should work. $\endgroup$
    – Szabolcs
    Dec 14, 2019 at 21:10
  • $\begingroup$ Thanks, I will try that ... I take it the source to compile is also on the website you linked? $\endgroup$
    – EGME
    Dec 14, 2019 at 21:12
2
$\begingroup$

Here is a simple way to get part of the graphs using the format "GraphList".

Import["~/MMA/geng/simplegraphs/graph5.g6", {"GraphList", Range[10,15]}]

results

simple graphs from 10 to 15

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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