igraph-help
[Top][All Lists]

## Re: [igraph] Generating scale-free networks with different exponents

 From: Gábor Csárdi Subject: Re: [igraph] Generating scale-free networks with different exponents Date: Tue, 8 Nov 2011 11:06:57 -0500

```On Tue, Nov 8, 2011 at 10:44 AM, Narges Zarrabi <address@hidden> wrote:
> Hi,
> I am using the following code to generate scale-free networks with different
> exponents, taken from
> (http://127.0.0.1:20410/library/igraph/html/degree.sequence.game.html).
> n<-1000
> scale<-1.9
> degs <- sample(1:n, n, replace=TRUE, prob=(1:n)^(-scale))
> if (sum(degs) %% 2 != 0) { degs[1] <- degs[1] + 1 }
> g <- degree.sequence.game(degs, method="vl")
> all(degree(g) == degs)
> The code works sometimes, but most of the times I receive the following
> error:
> Error in degree.sequence.game(degs, method = "vl") :
>   At gengraph_mr-connected.cpp:139 : Cannot realize the given degree
> sequence as an undirected, simple graph, Invalid value

Depending on your exponent, it is possible that the generated degree
sequence cannot be realized as a graph. Practical solution: just
continue generating graphs until you have enough and ignore the
errors. (See ?try for ignoring the errors.)

> Also I don't understand what is the reason having the last line in the
> code: all(degree(g) == degs)

It's a check to show you that the generated graph indeed has the
prescribed degree sequence.

Best,
Gabor

> Any comments that can help? Many thanks
> Narcis
> _______________________________________________
> igraph-help mailing list
> https://lists.nongnu.org/mailman/listinfo/igraph-help
>
>

--
Gabor Csardi <address@hidden>     MTA KFKI RMKI

```