I'm sorry to bother you with such a trivial question but it would save
me some time searching through manuals if you were able to give me
directly the answer.
Say I have a graph G and all vertices are associated to a binary
attribute which takes the values 1 and 0, i.e., for each vertex the
attribute is either 1 or 0.
How would I get in igraph the following two graphs:
(1) G1 which is what it remains from G if we DELETE ALL LINKS
connecting vertices with attribute 0 (but of course keeping in G1 all
vertices of G, although some of them now might turn out to be
isolated)?
(2) G0 which is what it remains from G if we delete all links
connecting vertices with attribute 1 (but of course keeping all
vertices of G)?
Best,
--Moses
_______________________________________________
igraph-help mailing list
igrap...@nongnu.org
https://lists.nongnu.org/mailman/listinfo/igraph-help
Mainly I'm using R (but I could survive in Python too).
--Moses
With my 1 month experience on igraph, I do not find your question a trivial one.
> Say I have a graph G and all vertices are associated to a binary
> attribute which takes the values 1 and 0, i.e., for each vertex the
> attribute is either 1 or 0.
Since I am not accustomed to igraph's attribute interface, I
constructed an array containing values of 0 and 1. I am indexing the
array using the vertex id.
> (1) G1 which is what it remains from G if we DELETE ALL LINKS
> connecting vertices with attribute 0 (but of course keeping in G1 all
> vertices of G, although some of them now might turn out to be
> isolated)?
Here is what I did. I constructed an Erdos-Renyi G(n,p) graph. From
this graph I got its adjacency matrix (m) which I copied to two other
matrices (m1 and m0).
I iterated through the vertices of the graph. If the attribute was 0,
then I zeroed the respective line and column in the new adjacency
matrix.
Some drawbacks in my approach that are seen immediately:
1- Isolated vertices are "lost". They can be restored by either
keeping them in a list, inserting a self-loop or some other hack.
2- It is written in C
3- It does not read a CSV. If the list can recommend a parser that
goes from CSV files to an igraph_t maybe this hack I did can improve.
--
http://gr.linkedin.com/in/yiorgos
On Tue, Jun 28, 2011 at 11:12 AM, Moses Boudourides
<moses.bo...@gmail.com> wrote:
> Hello,
>
> I'm sorry to bother you with such a trivial question but it would save
> me some time searching through manuals if you were able to give me
> directly the answer.
>
> Say I have a graph G and all vertices are associated to a binary
> attribute which takes the values 1 and 0, i.e., for each vertex the
> attribute is either 1 or 0.
>
> How would I get in igraph the following two graphs:
>
> (1) G1 which is what it remains from G if we DELETE ALL LINKS
> connecting vertices with attribute 0 (but of course keeping in G1 all
> vertices of G, although some of them now might turn out to be
> isolated)?
delete.edges(g, E(g)[ V(g)[attr == 0] %--% V(g)[attr == 0] ])
'g' is the graph, 'attr' is the name of the attribute. This might not
be the fastest to run, but it should work. (Tell me if it does not.)
> (2) G0 which is what it remains from G if we delete all links
> connecting vertices with attribute 1 (but of course keeping all
> vertices of G)?
Similarly,
delete.edges(g, E(g)[ V(g)[attr == 1] %--% V(g)[attr == 1] ])
G.
> Best,
>
> --Moses
>
> _______________________________________________
> igraph-help mailing list
> igrap...@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/igraph-help
>
--
Gabor Csardi <csa...@rmki.kfki.hu> MTA KFKI RMKI