Rewiring and loop edges

Bug #1065681 reported by Gábor Csárdi
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
igraph
Fix Released
Medium
Tamás Nepusz

Bug Description

Hi Dov,

I think this is simply a bug. He have this in the C code for rewire:

      if (!igraph_vector_search(neis[0], 0, d, NULL) &&
   !igraph_vector_search(neis[1], 0, b, NULL) &&
   b!=c && a!=d && a!=b && c!=d) {
           do the rewiring here
      }

So, yes, if a=b or a=d, or b=c or c=d, the rewiring is not performed, I am not sure why. I have submitted a bug report for this:
****

Thanks, Best,
Gabor

On Thu, Oct 11, 2012 at 3:29 PM, Dov Pechenick <*> wrote:
> Hello,
>
> I'm using igraph in R, and I'm trying to randomize the edges of directed
> graphs while preserving in- and out-degree distributions. Since my graphs
> are directed, I don't use degree.sequence.game(). Instead, I've been using
> rewire(). This function correctly preserves the degree distribution,
> however as far as I can tell it completely ignores self loop edges during
> the rewiring process. That is to say, every single self loop in my original
> network is also preserved in all my rewired networks. I did not expect this
> based on the documentation:
>
> "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"
>
> While true that self loops aren't explicitly mentioned, the most general
> form of the algorithm allows a==b and c==d. Thus, this algorithm should
> allow for the generation and destruction of self-loops. For example, a->a
> and b->b can be replaced with a->b and b->a if they don't yet exist. The
> reverse should also be a valid swap. I tested this on the following
> networks, just to be sure:
>
> a <- graph(c(0,0,1,1,2,2,3,3)) # 4 nodes, only self loops
> b <- graph(c(0,1,1,0,2,3,3,2,0,2,2,0,0,3,3,0,1,2,2,1,1,3,3,1)) # 4 node
> complete graph, no self loops
>
> Rewiring using rewire() does nothing to the above graphs. For a, self loops
> are never destroyed, and for b, they are never created. If I am missing
> something, please let me know. Otherwise, is there a way to rewire directed
> graphs that both preserves degree distribution and allows for the generation
> and destruction of self-loops? (Ideally it would be the same function, with
> an option to allow self-loops.)
>
> Thanks!
> Dov

Changed in igraph:
milestone: none → 0.6.1
Revision history for this message
Tamás Nepusz (ntamas) wrote :

This can only go in 0.7 because adding a "loops" option to 0.6.1 would break API compatibility. Alternatively, we could silently switch to allowing the creation of loops in igraph_rewire in 0.6.2, but I guess most of our users who rely on the (undocumented) feature of igraph_rewire not allowing loops would not be happy with this -- including me ;)

Changed in igraph:
milestone: 0.6.1 → 0.7
importance: Undecided → Medium
assignee: nobody → Tamás Nepusz (ntamas)
status: New → In Progress
Revision history for this message
Tamás Nepusz (ntamas) wrote :

Aah, hang on, we have an igraph_rewiring_t argument so we can simply add a new option there.

Changed in igraph:
milestone: 0.7 → 0.6.1
Revision history for this message
Tamás Nepusz (ntamas) wrote :

The latest revisions in the 0.6-main and 0.7-main branches now include an IGRAPH_REWIRING_SIMPLE_LOOPS option for igraph_rewiring_t that should just do the right thing.

Changed in igraph:
status: In Progress → Fix Committed
Changed in igraph:
status: Fix Committed → Fix Released
Revision history for this message
Gábor Csárdi (gabor.csardi) wrote : Continue on github

The development of igraph has moved to github, so please do not comment on this bug here. You are of course welcome to comment on github, here:
https://github.com/igraph/igraph/issues/240

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.