Random graph with degree sequence.

Hi,

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.

My code:

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).

Thanks,

Alvaro

Yes. 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]))

Best,
Tiago

Hi Thiago. Thanks for the answer.

Can I allow parallel edges? I tried this code, but it didn't work:

import graph_tool.all as gt
kin = [11, 22, 0]
kout = [11, 0, 22]
g = gt.random_graph(3, lambda i: (kin[i], kout[i]),parallel_edges=True,
self_loops=False)
gt.graph_draw(g)

Thanks again!

Alvaro