[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [igraph] Contracting two vertices into one in Igraph - error
From: |
Tamás Nepusz |
Subject: |
Re: [igraph] Contracting two vertices into one in Igraph - error |
Date: |
Thu, 8 Nov 2012 10:29:25 +0100 |
> And after I pick two nodes, say 25, 26, which have multiple edges between
> them, I'm trying to merge them into a single vertex:
The right contraction vector in this case is:
c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,25)
The reason is as follows. In the contraction vector, the i-th element must
contain the _new_ ID of vertex i of the _old_ graph (making sure that the new
IDs are in a continuous range from 1 to the desired number of vertices in the
new graph). This is to allow making several contractions and permutations in a
single step. Since the _new_ ID of every vertex except your vertex 26 must stay
the same, the first 25 elements of the vector are 1:25. The 26th element must
be 25 because you want the new ID of vertex 26 to become 25 (since you merged
that into vertex 25).
In general, if you want to merge vertex v into vertex u (assuming that v > u),
you will need a contraction vector as follows:
vec <- c(1:(v-1), u, v:(vcount(g)-1))
If v < u, just swap u and v and do the same thing.
Best,
Tamas