igraph-help
[Top][All Lists]
Advanced

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

## Re: [igraph] accessing edge attributes via vertex indices?

 From: Gábor Csárdi Subject: Re: [igraph] accessing edge attributes via vertex indices? Date: Thu, 9 Jan 2014 09:53:29 -0500

Hi David,

To test if an edge exists, use graph[v, w]. graph[v, w, edges=TRUE] returns the edge id.

Btw. to sum up all weights, it is easier to say sum(E(graph)\$weight) than iterating over all vertex pairs....

G.

On Thu, Jan 9, 2014 at 9:35 AM, David Robinson wrote:
This is related to my previous question about combining vertex attributes (thanks Tamas for the insight in figuring that out), but relates to operations on edges.

I have an undirected graph gA, with no loops and no multiple edges. Each edge of the graph has a vector of attributes, e.g. E(gA)\$weight . I would like to be able to find the attributes of the edge that connects two specific vertices. Something similar would happen in the following very simplified R code snippet:

sum<-0
for (i in 1:vcount(gA) {
for (j in 1: vcount(gA) {
sum <- sum+ E(gA)[from(i) & to(j)]\$weight
}
}

A couple of issues arise: Ideally, I would like to only do this when an edge exists between i and j exist, but I cannot seem to find a logic statement that returns either TRUE/FALSE.  The second issue occurs when i=j where the result of E(gA)[from(i) & to(j)] is multiple values.

I think that the problem boils down to the question: given two vertices, can I determine if an edge exists between them and, if so, what is the index of the edge between them?

Thanks again for all the help,
David

_______________________________________________
igraph-help mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/igraph-help

reply via email to

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