igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] Vertex id consistency in delete.vertices and subgraph


From: Tamas Nepusz
Subject: Re: [igraph] Vertex id consistency in delete.vertices and subgraph
Date: Mon, 22 Mar 2010 09:20:36 +0000

> From the documentation for the R version of igraph it is noted that after 
> manipulating a graph via the delete.vertices or subgraph functions, "The ids 
> of the vertices will change in the subgraph of course since these are always 
> consecutive."
> 
> I am curious as to the motivation for this implementation?
This is part of igraph's C heritage. The core of igraph is implemented in C, 
where the vertex and edge IDs are indices into a continuous chunk of memory 
(well, it's an oversimplification, but it catches the general idea), and thus 
they must always start from zero and must be continuous.

> Often, it is much more useful to keep vertex ID's consistent after these 
> operations, as these ID's are often meaningful to the particular analysis 
> being performed.  Is there a way to keep the IDs consistent after performing 
> these manipulations?
Use vertex attributes for that, i.e. forget about igraph's IDs and attach your 
IDs as a "name" vertex attribute. Of course you must still use the original 
igraph vertex IDs when calling delete.vertices() or subgraph(), but you can 
always find them by scanning V(g)$name. The R interface might even support 
referring to vertices directly by their "name" attributes, but I'm not sure 
about that (it has been added recently and I don't remember whether it made its 
way into 0.5.3 or only into 0.6).

-- 
Tamas





reply via email to

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