[igraph] An elementary question

1 view
Skip to first unread message

Moses Boudourides

unread,
Jun 28, 2011, 11:12:57 AM6/28/11
to Help for igraph users
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)?

(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

Chris Wj

unread,
Jun 28, 2011, 2:01:26 PM6/28/11
to Help for igraph users
R, Python, or C?

Moses Boudourides

unread,
Jun 28, 2011, 2:20:33 PM6/28/11
to Help for igraph users
Hi Chris,

Mainly I'm using R (but I could survive in Python too).

--Moses

Yiorgos Adamopoulos

unread,
Jun 29, 2011, 5:08:34 PM6/29/11
to Help for igraph users
On Tue, Jun 28, 2011 at 6:12 PM, Moses Boudourides
<moses.bo...@gmail.com> wrote:
> 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.

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

Gábor Csárdi

unread,
Jun 30, 2011, 3:31:35 PM6/30/11
to Help for igraph users
Moses,

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

Moses Boudourides

unread,
Jun 30, 2011, 3:42:20 PM6/30/11
to Help for igraph users
Thanks, Gabor. I'll try to do it next week on the boat from Italy to
Greece because tomorrow morning I'm leaving from Paris. --M
Reply all
Reply to author
Forward
0 new messages