igraph-help
[Top][All Lists]

## Re: [igraph] about rewire fuction

 From: Tamás Nepusz Subject: Re: [igraph] about rewire fuction Date: Fri, 6 Sep 2013 20:24:03 +0200

```> In the manual it said "Simple rewiring algorithm which chooses two arbitrary
> edges in each step (namely (a,b) and (c,d)) and substitutes them with (a,d)
> and (c,b) if they don’t yet exist."
> How do you determine which node is "a" given an edge? "a" is always the node
> with smaller ID than "b"?
Take a look at the source code here:

https://github.com/igraph/igraph/blob/master/src/structural_properties.c#L1509

Basically, we generate two random numbers between 0 (inclusive) and m-1
(inclusive), where m is the number of edges. Then we take the edges with the
generated IDs and extract their endpoints into (a,b) and (c,d). In case of
directed graphs, there is nothing else to do -- a and c will be the sources of
the two edges while b and d will be the targets. In case of undirected graphs,
the call to igraph_edge returns (a,b) and (c,d) such that a<b and c<d, so we
swap c with d with probability 0.5. This way we perform one of two possible
rewirings with equal chance:

1. (a,b) and (c,d) becomes (a,d) and (c,b)
2. (a,b) and (d,c) becomes (a,c) and (d,b)

> Do you agree? And would you please tell me where can I find the source code
> of rewire function? I want to look at the details.
It starts here:

https://github.com/igraph/igraph/blob/master/src/structural_properties.c#L1464

Best,
Tamas

```

reply via email to