igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] will igraph re-number vertices?


From: Csardi Gabor
Subject: Re: [igraph] will igraph re-number vertices?
Date: Wed, 24 Oct 2007 21:57:18 +0200
User-agent: Mutt/1.5.9i

Hi Matt!

On Wed, Oct 24, 2007 at 02:01:28PM -0400, Matt Bonner wrote:
> Heya,
>
> Will igraph ever silently renumber vertices/change their vertex ID's
> as a result of another operation?

Yes, it does do that.

> For example, suppose I use decompose to eventually pull out the the
> largest component. Presuming the largest component and the full graph
> each have a vertex with ID 6, does vertex 6 in the component refer to
> the same vertex in the full graph? 

No, vertex 6 may be different in the subgraph.

> Is the behavior the same for the R
> functions and the C functions?

Yes, the R functions just call the C routines.

> In simple tests with things like centrality measures, it seems like
> igraph doesn't ever renumber vertices in this way. However, it would
> be nice to KNOW that igraph isn't doing this for a given function, or
> for any function.

The thing is the following. In igraph the vertex ids go from zero
to N-1, N is the number of vertices. This implies that if you create 
another graph with eg. subgraph or decompose.graph then the vertex 
ids might change since the number of vertices changes.

In the R package it is true that igraph never changes a graph
which was supplied as an argument, but creates and returns the 
new graph if needed. Eg.

subgraph(g, v)

never changes "g" but creates a new graph with vertices v only 
and returns it. The vertex ids in the new graph might be different
than the ones in "g" though.

Or to put it another way, only objects on the left hand side of "<-"
change.

If you want to keep track of the vertices then assign a vertex attribute
to the graph, these are (usually) kept when creating a new graph:

g <- graph.ring(10)
V(g)$name <- letters[1:10]
g

subgraph(g, 1:7)

or even

subgraph(g, V(g)[name %in% c("b","c","d","e")])

Some functions like as.undirected drop vertex attributes,
this is a bug and we're working on it.

Hope it is clear now,
Gabor

PS. it is ok if you're not a member of the list, but please consider
that your messages might be delayed, even for days if i'm offline.

> Thanks,
>
> --Matt
>
>
> _______________________________________________
> igraph-help mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/igraph-help

-- 
Csardi Gabor <address@hidden>    MTA RMKI, ELTE TTK




reply via email to

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