ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 17 Feb 2014 08:57:20 -0600Using nauty_geng with variable number of verticeshttp://ask.sagemath.org/question/11026/using-nauty_geng-with-variable-number-of-vertices/I am trying to use the nauty graph generator to count the number of non-isomorphic graphs with specified properties, but I am hindered by the fact that it seems nauty_geng only allows a fixed number of vertices.
For example, the following code counts the number of (non-isomorphic) connected graphs on 5 vertices:
count = 0
for g in graphs.nauty_geng("5 -c"):
count += 1
print count
The Sage output is: 21.
However, if I try to count the number of connected graphs on *n* vertices for *n* in a certain range, say *n*=3,4,5,6, as with the following code,
for n in range(3,7):
count = 0
for g in graphs.nauty_geng("n -c"):
count += 1
print (n,count)
,the count remains equal to zero for each *n*, and the situation is the same for all similar codes I have tried. The result is that in order to see what happens for multiple values of *n*, I must manually change all occurrences of *n* in the code.
1. Is this the meaning of "At a minimum, you must pass the number of vertices you desire," a statement in the help box?
2. Is there any way around this?
Thanks for any help with this!Wed, 12 Feb 2014 06:39:09 -0600http://ask.sagemath.org/question/11026/using-nauty_geng-with-variable-number-of-vertices/Answer by fidbc for <p>I am trying to use the nauty graph generator to count the number of non-isomorphic graphs with specified properties, but I am hindered by the fact that it seems nauty_geng only allows a fixed number of vertices.</p>
<p>For example, the following code counts the number of (non-isomorphic) connected graphs on 5 vertices:</p>
<pre><code>count = 0
for g in graphs.nauty_geng("5 -c"):
count += 1
print count
</code></pre>
<p>The Sage output is: 21.</p>
<p>However, if I try to count the number of connected graphs on <em>n</em> vertices for <em>n</em> in a certain range, say <em>n</em>=3,4,5,6, as with the following code, </p>
<pre><code>for n in range(3,7):
count = 0
for g in graphs.nauty_geng("n -c"):
count += 1
print (n,count)
</code></pre>
<p>,the count remains equal to zero for each <em>n</em>, and the situation is the same for all similar codes I have tried. The result is that in order to see what happens for multiple values of <em>n</em>, I must manually change all occurrences of <em>n</em> in the code.</p>
<ol>
<li><p>Is this the meaning of "At a minimum, you must pass the number of vertices you desire," a statement in the help box?</p></li>
<li><p>Is there any way around this?</p></li>
</ol>
<p>Thanks for any help with this!</p>
http://ask.sagemath.org/question/11026/using-nauty_geng-with-variable-number-of-vertices/?answer=16036#post-id-16036The issue above is that `geng` is being called with the arguments
n -c
each time. The value of `n` should be substituted in the string. Here is a working version of the for loop you have.
for n in range(3,7):
count = 0
for g in graphs.nauty_geng("{0} -c".format(n)):
count += 1
print (n,count)
See [here](http://docs.python.org/2/library/stdtypes.html#str.format) for more details on the `format` function.
Other possible variations on the call to `geng` above could also be:
graphs.nauty_geng("%d -c"%(n))
or
graphs.nauty_geng(str(n)+" -c")Wed, 12 Feb 2014 14:46:22 -0600http://ask.sagemath.org/question/11026/using-nauty_geng-with-variable-number-of-vertices/?answer=16036#post-id-16036Comment by Emperor's_New_Clothes for <p>The issue above is that <code>geng</code> is being called with the arguments</p>
<p>n -c</p>
<p>each time. The value of <code>n</code> should be substituted in the string. Here is a working version of the for loop you have.</p>
<pre><code>for n in range(3,7):
count = 0
for g in graphs.nauty_geng("{0} -c".format(n)):
count += 1
print (n,count)
</code></pre>
<p>See <a href="http://docs.python.org/2/library/stdtypes.html#str.format">here</a> for more details on the <code>format</code> function.</p>
<p>Other possible variations on the call to <code>geng</code> above could also be:</p>
<pre><code>graphs.nauty_geng("%d -c"%(n))
</code></pre>
<p>or</p>
<pre><code>graphs.nauty_geng(str(n)+" -c")
</code></pre>
http://ask.sagemath.org/question/11026/using-nauty_geng-with-variable-number-of-vertices/?comment=16242#post-id-16242Thank you! This is very helpful!Mon, 17 Feb 2014 08:57:20 -0600http://ask.sagemath.org/question/11026/using-nauty_geng-with-variable-number-of-vertices/?comment=16242#post-id-16242