# Importing graphs from geng incrementally

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

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).

• 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 ...
– EGME
Dec 12, 2019 at 21:50
• 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. Dec 12, 2019 at 22:01
• It appears that geng cannot be installed on Windows machines?
– EGME
Dec 14, 2019 at 14:20
• @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. Dec 14, 2019 at 21:10
• Thanks, I will try that ... I take it the source to compile is also on the website you linked?
– EGME
Dec 14, 2019 at 21:12

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