[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [igraph] Adding structure to empty graph
From: |
Gábor Csárdi |
Subject: |
Re: [igraph] Adding structure to empty graph |
Date: |
Tue, 3 Nov 2009 16:39:18 +0100 |
On Tue, Nov 3, 2009 at 4:12 PM, Andrew Conway <address@hidden> wrote:
> I would like to write a function that takes some edges data and adds it to a
> given graph, which starts as an graph.empty(). The edge data would be added
> iteratively, and at each iteration the edges are represented as a vector of
> characters, e.g. c('actor1','actor2'). These actors may or may not exist in
> the graph already.
igraph is in general not very good at this, since adding
vertices/edges are O(n+m) operations, but in terms of the total number
of vertices plus the total number of edges in the graph.
> I am having a hard time figuring out how to accomplish this in igraph. It
> seems that igraph wants to generate some fixed number of vertices for a
> graph, then add structure. Also, is it possible to add character vertices
> to graph objects, or does everything have to go through the V(g)$name
> attributions?
Internally igraph always uses numeric ids. If you want to use symbolic
ids, then you have to use attributes. It is not very hard, though. You
can easily write a function that check whether both vertices are in
the graph by calling match(newids, V(g)$name) and then add them if
they are not with add.vertices(..., attr=...). Then you just add the
edge with add.edges().
Best,
Gabor
> Any advice is greatly appreciated.
>
> ___________________________________
> Drew Conway
> Ph.D. Student
> Department of Politics, New York University
> address@hidden
> http://www.drewconway.com/zia
> @drewconway
>
> _______________________________________________
> igraph-help mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/igraph-help
>
>
--
Gabor Csardi <address@hidden> UNIL DGM