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
2
  • 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. Commented Dec 3, 2015 at 17:52
  • I mean I would quit the program after about 30 minutes. Should it take that long to generate the nodes? Commented Dec 3, 2015 at 19:09

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.