igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[igraph] correction to rewire for undirected graphs


From: Vincent Matossian
Subject: [igraph] correction to rewire for undirected graphs
Date: Fri, 15 Jun 2007 10:49:46 -0400


  Hi, I noticed that igraph_rewire works well for directed graphs but returned an error for undirected ones. The source revealed that the neighbors view is updated only in the case of directed edges, and that was causing the igraph_get_eid to fail finding a random edge, after making a correction such as the one below the problem appears to be gone.

As usual, I might have missed something as the edge selector concept isn't very clear to me at this point.

Best,

Vincent



--- structural_properties_modified.c      2007-06-15 10:37: 52.093750000 -0400
+++ structural_properties.c     2007-06-15 10:32:58.906250000 -0400
@@ -1825,7 +1825,7 @@
   long int no_of_nodes=igraph_vcount(graph);
   long int i, a, b, c, d;
   igraph_i_adjlist_t allneis;
-  igraph_vector_t *neis[4], edgevec;
+  igraph_vector_t *neis[2], edgevec;
   igraph_es_t es;

   if (mode == IGRAPH_REWIRING_SIMPLE && no_of_nodes<4)
@@ -1863,8 +1862,6 @@
       i=igraph_vector_size(neis[1]);
       if (i==0) d=a;
       else d=VECTOR(*neis[1])[RNG_INTEGER(0, i-1)];
-      neis[2]=igraph_i_adjlist_get(&allneis, b);
-      neis[3]=igraph_i_adjlist_get(&allneis, d);

       /* Okay, we have two edges. Can they be rewired?
        * neis[0] mustn't contain d and neis[1] mustn't contain b
@@ -1878,7 +1875,7 @@
        VECTOR(edgevec)[0]=a; VECTOR(edgevec)[1]=b;
        VECTOR(edgevec)[2]=c; VECTOR(edgevec)[3]=d;
        /*printf("Deleting: %d -> %d, %d -> %d\n", a, b, c, d);*/
-       IGRAPH_CHECK(igraph_es_pairs(&es, &edgevec, igraph_is_directed(graph)));

+       IGRAPH_CHECK(igraph_es_pairs(&es, &edgevec, IGRAPH_DIRECTED));
        IGRAPH_FINALLY(igraph_es_destroy, &es);
        IGRAPH_CHECK(igraph_delete_edges(graph, es));
        igraph_es_destroy(&es);
@@ -1894,13 +1890,6 @@
          if (VECTOR(*neis[0])[i]==b) { VECTOR(*neis[0])[i]=d; break; }
        for (i=igraph_vector_size(neis[1])-1; i>=0; i--)
          if (VECTOR(*neis[1])[i]==d) { VECTOR(*neis[1])[i]=b; break; }
-
-       if(!igraph_is_directed(graph)){
-       for (i=igraph_vector_size(neis[2])-1; i>=0; i--)
-         if (VECTOR(*neis[2])[i]==a) { VECTOR(*neis[2])[i]=c; break; }
-       for (i=igraph_vector_size(neis[3])-1; i>=0; i--)
-         if (VECTOR(*neis[3])[i]==c) { VECTOR(*neis[3])[i]=a; break; }
-       }
       }
       break;
     default:

reply via email to

[Prev in Thread] Current Thread [Next in Thread]