[Top][All Lists]

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

Re: [igraph] working with graphs without reindexing them

From: sergiu netotea
Subject: Re: [igraph] working with graphs without reindexing them
Date: Wed, 8 Sep 2010 15:12:25 +0200

Ty for the reply,

I decided it is best if I write my own graph loader. My graphs are directed, and ncol loader seems to be designed for undirected ones. My plan is to create an empty graph with igraph_create, then to add nodes, assign attributes to them, then to add edges specified by reindexed ids. Since I have the initial IDs as attributes I will not loose the identity of one node. What do you think?

To all this I see one problem though: in igraph I found no function that returns the node id that has a certain label. Of course I could write my own function for that as well, that loops through all nodes and returns the node id that has a certain label. But I am afraid it is not very optimized. It seems strange, there are so many functions to querry attributes of a node id, but no function to querry the node id (ids) that has(have) a certain attribute.


On Tue, Sep 7, 2010 at 5:55 PM, Tamas Nepusz <address@hidden> wrote:
Hi Sergiu,

> What is the best way to load a subgraph without reindexing the node labels?
Assuming that your graph is stored in a flat file with two numbers per
line (vertex1 and vertex2), load them using the NCOL loader
(igraph_read_graph_ncol). The numeric vertex IDs will be set up by
igraph arbitrarily, but the NCOL loader will set up a vertex attribute
named "name" that contains the *original* vertex IDs in the file (as
strings, since the NCOL format may contain string vertex IDs as well).
After that, you can set up a quick indexing array that tells you the
igraph vertex ID based on your original vertex ID and use that when
calling igraph functions (but of course you have to update the indexing
when you delete vertices orr add new ones).

In order to use this functionality of the NCOL reader, you must attach
the C attribute handler first, see more details here:


> Also, what happens if a node gets removed? The whole set of nodes gets
> reindexed?
Yes, they do, but the assigned vertex attributes are kept, so you can
still track your vertices using the vertex attributes.

> as I understood node labeling is not well supported in igraph, am I
> right?
Well, there is the above mentioned attribute handler in the C layer. It
is branded as "experimental" in the manual, but if you are working with
a recent igraph version (0.5.3) or the development branch (0.6), the
attribute handler should be pretty stable -- I'm using it myself without


igraph-help mailing list

reply via email to

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