igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] Creating a bipartite graph


From: Tamas Nepusz
Subject: Re: [igraph] Creating a bipartite graph
Date: Mon, 2 Nov 2009 15:46:09 +0000
User-agent: Mutt/1.5.17 (2007-11-01)

> I'm trying to create a bipartite graph (one group is a numeric ids, and the
> other is a string) with the following command:
> 
> g <- graph.bipartite(rep(0:1,10),c('1','a','2','c','3','a',1,'c','4','d'))
Note that igraph works with numeric vertex IDs starting from zero, not
with string IDs. This applies to graph.bipartite() as well. Since you
are constructing a graph with 20 vertices, your vertices will have IDs
from zero to 19. Moreover, vertices 0, 2, 4, ..., 16, 18 will be of type 0,
while vertices 1, 3, 5, ..., 17 and 19 will be of type 1, according to the 
type vector you supplied. In the second argument, you will have to pass
something like this:

c(0, 5, 1, 6, 2, 7, 3, 8, 4, 9)

This means that the first edge will go from vertex 0 to vertex 5, the
second will go from vertex 1 to vertex 6 and so on:

> g <- graph.bipartite(rep(0:1, 10), c(0,5,1,6,2,7,3,8,4,9))
> g
Vertices: 20
Edges: 5
Directed: FALSE
Edges:

[0] 0 -- 5
[1] 1 -- 6
[2] 2 -- 7
[3] 3 -- 8
[4] 4 -- 9

Also note that from igraph's point of view, a bipartite graph is simply
a graph with a "type" attribute that describes the vertex types, and
igraph functions working with bipartite graphs only will check this
attribute. However, there's nothing that stops you from adding an edge
between two vertices of the same type using add.edges().

-- 
Tamas




reply via email to

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