Reputation: 41
I am attempting to reproduce algorithm 5 from the paper: http://vlado.fmf.uni-lj.si/pub/networks/doc/ms/rndgen.pdf
My code is the following:
import random
import numpy as np
from random import randrange
from random import randint
from networkx import empty_graph
def fast_generate_scale_free(n, d):
#input: number of vertices: n, int
#minimum degree d, int
#output: scale-free multigraph
G=empty_graph(n)
M=np.zeros(2 *n *d)
if d >=1:
for v in range(0,n):
for i in range(0, d):
v= M[int(2*(v*d+i))]
#draw r uniformly at random
r=randint(0, 2*(v*d+i))
M[int(2*(v*d+i)+1)]=M[r]
for i in range(0, (n*d)):
a=M[int(2*i)]
b=M[int(2*i+1)]
G.add_edge(a,b)
return G
Essentially I get an output of (0,0) for any choice of n and d, which I suspect is caused by my initialization of the M array.
I would appreciate any help and this is purely for my own understanding.
Upvotes: 1
Views: 110