[英]Generating incorrect graphs from adjacency matrices using graph-tool on Python
[英]Python, Generating Random Graphs with Graph-tool
因此,我尝试生成一个随机的有向图,以使每个顶点具有3个节点和1个节点。 但是图形工具似乎卡在deg_sampler()函数中。
from graph_tool.all import *
def deg_sampler():
return 1,2
g = random_graph(1000,deg_sampler,verbose=True)
运行代码后出现此错误
adding vertices: 1000 of 1000 (100%)
fixing average degrees. Total degree difference: 1000^CTraceback (most recent call last):
File "code.py", line 6, in <module>
g = random_graph(1000,deg_sampler,verbose=True)
File "/usr/lib/python2.7/dist-packages/graph_tool/generation/__init__.py", line 384, in random_graph
_get_rng(), verbose, True)
File "/usr/lib/python2.7/dist-packages/graph_tool/generation/__init__.py", line 379, in <lambda>
sampler = lambda i: deg_sampler()
KeyboardInterrupt
度采样器函数应返回节点的进度和出度。 在您的实现中,每个节点的入度为1,出度为2。当然,用此度数序列构造图是不可能的,因为平均入度和出度必须相同。 这就是为什么算法陷入“固定平均度”阶段的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.