0

I'm using graph-tool to try to generate random graphs with a sequence of degrees. For example, in a 3-node graph, I generated a random graph with all nodes with input degrees 1 and output degrees 1.

>>> import graph_tool.all as gt

>>> def deg_sampler():
...         return 1,1

>>> g = gt.random_graph(3,deg_sampler,parallel_edges=True, self_loops=False)

>>> gt.graph_draw(g)

Can I generate a random graph defining the input and output degrees of each node? For example, tree nodes with respectively the input degrees (1, 2, 0) and output degrees (1, 0, 2).

eyllanesc
  • 235,170
  • 19
  • 170
  • 241

1 Answers1

0

The degree sampler can take an optional parameter corresponding to the index of the vertex, which then you can use to return the specific degree:

kin = [1, 2, 0]
kout = [1, 0, 2]

g = random_graph(3, lambda i: (kin[i], kout[i]))
Tiago Peixoto
  • 5,149
  • 2
  • 28
  • 28