[Top][All Lists]

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

Re: [igraph] working with graphs without reindexing them

From: Gábor Csárdi
Subject: Re: [igraph] working with graphs without reindexing them
Date: Wed, 8 Sep 2010 15:21:18 +0200

On Wed, Sep 8, 2010 at 3:12 PM, sergiu netotea <address@hidden> wrote:
> 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?


I don't really know what is wrong with NCOL, it handles directed
graphs just as well.
You approach works as well (obviously it is a lot more work), but
don't add the vertices and edges one by one, because that will be slow
(quadratic). Add them together.

> 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.

igraph is mainly used from R and Python, especially the attribute
handling part. That is why the C attribute handler has not too many
features. You will need to write the search function for yourself.


> Sergiu
> 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:
>> http://igraph.sourceforge.net/doc/html/ch09s02.html
>> > 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
>> problems.
>> --
>> Tamas
>> _______________________________________________
>> igraph-help mailing list
>> address@hidden
>> http://lists.nongnu.org/mailman/listinfo/igraph-help
> _______________________________________________
> igraph-help mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/igraph-help

Gabor Csardi <address@hidden>     UNIL DGM

reply via email to

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