[igraph] 回复: 回复: how to find disconnected components

72 views
Skip to first unread message

四正(红砖)

unread,
Jun 21, 2013, 2:05:15 AM6/21/13
to Help for igraph users

I found the example about it:

>>> from igraph import Graph
>>> g = Graph.Ring(20)
>>> mc = g.mincut()
>>> print mc.value
2.0
>>> print min(map(len, mc))
1
>>> mc.es["color"] = "red"
i don't understand why it's 2...

------------------ 原始邮件 ------------------
发件人: "Gábor Csár"<csardi...@gmail.com>;
发送时间: 2013年6月21日(星期五) 中午1:43
收件人: "Help for igraph users"<igrap...@nongnu.org>;
主题: Re: [igraph]回复: how to find disconnected components

Then I think graph.mincut() does what you want.

Gabor


On Fri, Jun 21, 2013 at 1:36 AM, 四正(红砖) <sizhe...@qq.com> wrote:

Hi Gabor,

i'm not sure whether clusters() is my want.

i try to make it more clear:

g1 and g2 are two connected graphs, and i also can put them together as G, which contains 2 disconnected components.

in addition, in g1 and g2, several connecting components may be found by some functions.

what i want is to return 2 but not more disconnected components.

Gang

------------------ 原始邮件 ------------------
发件人: "Gábor Csár"<csardi...@gmail.com>;
发送时间: 2013年6月21日(星期五) 中午1:25
收件人: "Help for igraph users"<igrap...@nongnu.org>;
主题: Re: [igraph] how to find disconnected components

I am not sure that I get what you want, but isn't just clusters() what you are looking for? If not, then can you give an example?

Gabor


On Fri, Jun 21, 2013 at 1:22 AM, 四正(红砖) <sizhe...@qq.com> wrote:
Hi all,

for a disconnected graph, how to find all the disconnected components, pls?

i checked the functions about components and blocks, but i'm afraid of returning connected components as well.

Thanks.
Gang

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



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


Tamás Nepusz

unread,
Jun 21, 2013, 3:44:27 AM6/21/13
to Help for igraph users
> I found the example about it:
>
> >>> from igraph import Graph
> >>> g = Graph.Ring(20)
> >>> mc = g.mincut()
> >>> print mc.value
> 2.0
> i don't understand why it's 2...
Because you have to remove at least two edges from a ring graph to make it fall apart into two components.

--
T.

四正(红砖)

unread,
Jun 21, 2013, 10:02:56 AM6/21/13
to Help for igraph users

Thanks Tamas.

well, so if i have a graph with disconnected components, it will return 0? my graph is large, it is still running...

in fact, i have some big/large graphs, which return FALSE if i call is_connected(). 
I just want to know if they are disconnected, how many disconnected components do they have.

------------------ Original ------------------
From:  "Tamás Nepusz"<nta...@gmail.com>;
Date:  Fri, Jun 21, 2013 03:44 PM
To:  "Help for igraph users"<igrap...@nongnu.org>;
Subject:  Re: [igraph]回复: 回复: how to find disconnected components
.

Tamás Nepusz

unread,
Jun 21, 2013, 10:07:33 AM6/21/13
to Help for igraph users
> in fact, i have some big/large graphs, which return FALSE if i call is_connected().
> I just want to know if they are disconnected, how many disconnected components do they have.
Gabor has suggested using components() in a previous email, what's wrong with that? components() will give you a VertexClustering object where each cluster corresponds to a connected component of a vertex. You can then call len() on the VertexClustering object to get the number of components:

>>> g = Graph.Full(4) * 5
>>> len(g.components())
5

You can also index the result of g.components() as if it were a list to get the indices of the vertices in each of the components:

>>> comp = g.components()
>>> comp[0]
[0, 1, 2, 3]

Gábor Csárdi

unread,
Jun 21, 2013, 10:09:45 AM6/21/13
to Help for igraph users
Actually, I still don't understand what is the goal here. Can you give a simple example? SAy a graph with ten vertices, from 'A' to 'J', and some set of edges. 

How would the desired output look for a given input?

Gabor

四正(红砖)

unread,
Jun 21, 2013, 10:41:37 AM6/21/13
to Help for igraph users

OK, I see. components() works well.

Thank you very much~

------------------ Original ------------------
From:  "Gábor Csár"<csardi...@gmail.com>;
Date:  Fri, Jun 21, 2013 10:09 PM
To:  "Help for igraph users"<igrap...@nongnu.org>;
Subject:  Re: [igraph]回复: 回复: how to find disconnected components

Narayanan, Manikandan (NIH/NIAID) [E]

unread,
Jun 21, 2013, 3:32:27 PM6/21/13
to Help for igraph users

Hi,

  Vertex IDs used to start at 0 (as described here: http://igraph.wikidot.com/r-traps ). In latest version (R igraph 0.6.5), I see them starting from 1 as shown in code below.

 

  Could you please confirm if this change is intentional?

 

 

#Code

> g <- graph.atlas(1000)

> V(g)[0]

 

# Output in igraph_0.5.5-4

Vertex sequence:

[1] 0

 

# Output in igraph_0.6.5-1

Vertex sequence:

numeric(0)

 

 

  I tried looking in the release notes but couldn’t find anything about this. If this change is not intentional, I would like to debug what is going on with my installation of the latest version.

 

 

Thanks,

Mani

Tamás Nepusz

unread,
Jun 21, 2013, 3:44:27 PM6/21/13
to Help for igraph users
> Could you please confirm if this change is intentional?
Yes, this is intentional.

> I tried looking in the release notes but couldn’t find anything about this. If this change is not intentional, I would like to debug what is going on with my installation of the latest version.
You would have had to go back all the way to version 0.6 to find the relevant entry:

http://igraph.sourceforge.net/relnotes-0.6.html

(See the "Numbering from 1 in R" section)

If you have lots of old code that relied on vertices being indexed from zero and you do not have time to re-write them, you can install the "igraph0" package which uses zero-based indexing, but note that this is not going to be updated any more.

All the best,
Tamas

Narayanan, Manikandan (NIH/NIAID) [E]

unread,
Jun 21, 2013, 3:55:02 PM6/21/13
to Help for igraph users
Thank you very much Tamas! I am sorry, I should've looked more carefully - I was looking at the NEWS file all the way till 0.6.4 but should've gone one version below that as you've noted.

Yes, igraph0 would work well with my old codes.


Cheers,
Mani


-----Original Message-----
From: Tamás Nepusz [mailto:nta...@gmail.com]
Sent: Friday, June 21, 2013 3:44 PM
To: Help for igraph users
Reply all
Reply to author
Forward
0 new messages