0

So I'm trying to generate a random directed graph such that each vertex has 3 in-nodes and 1 outnode. But graph tool seems to be getting stuck in the deg_sampler() function.

from graph_tool.all import *

def deg_sampler():
    return 1,2
g = random_graph(1000,deg_sampler,verbose=True)

I get this error after running the code

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
  • Were you trying to copy text somewhere? Hitting Ctrl-C kills whatever is running in Python. That would be why you see "`KeyboardInterrupt`" at the bottom there. – Cody Piersall Dec 03 '15 at 17:52
  • I mean I would quit the program after about 30 minutes. Should it take that long to generate the nodes? – Karmanya Aggarwal Dec 03 '15 at 19:09

1 Answers1

1

The degree sampler function should return the in- and out-degrees of the nodes. In your implementation, each node has an in-degree of 1 and out-degree of 2. It is, of course, impossible to construct a graph with this degree sequence, since the average in- and out-degrees must identical. This is why the algorithm gets stuck in the "fixing average degrees" phase.

Tiago Peixoto
  • 5,149
  • 2
  • 28
  • 28