图个数的计数-SageMath

本博客我主要是自己储存一些自己常用的笔记和心得,分享倒不是主要的,以免误人子弟。所以质量有好有不好,为了区别,后面的未完成的文章均采用Vip文章如果有熟悉的人可以联系我,我会定期去开放一部分。

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:

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,
,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!
答案:

The 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 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")

算好几个3到7之间的连通图个数,下面代码错误了,虽然看起来非常正确。

for n in range(3,7):
     count = 0
     for g in graphs.nauty_geng("n -c"):
         count += 1
     print (n,count)

我们改造如下:

for n in range(3,7):
    count = 0
    for g in graphs.nauty_geng("{0} -c".format(n)):
        count += 1
    print (n,count)

在这里插入图片描述
https://ask.sagemath.org/question/11026/using-nauty_geng-with-variable-number-of-vertices/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值