简体   繁体   中英

Bipartite Graphs in R's igraph Package

I'm trying to create a bipartite graph w/ R's igraph package, but having a devil of a time.

Can anyone tell me why this works:

g <- graph.bipartite( rep(0:1,length=10), c(0,1,2,3,4,5,6,7,8,9))

But this gives me an error:

g <- graph.bipartite( rep(0:1,length=10), c(10,11,12,13,14,15,16,17,18,19))
Error in graph.bipartite(rep(0:1, length = 10), c(10, 11, 12, 13, 14,  : 
  At bipartite.c:438 : Invalid (negative) vertex id, Invalid vertex id

With your graph.bipartite( rep(0:1, length=10), ...) you have told graph.bipartite that there are ten vertices in the graph, and it treats them as 0,1,2,...9.

You could have written

graph.bipartite( c(0,0,1,0), c(0,2,1,2,2,3))

with four vertices 0, 1, 2, and 3 (with 2 in one part and 0, 1 and 3 in the other) but not

graph.bipartite( c(0,0,1,0), c(0,2,1,2,2,4))

because there is no vertex 4, nor

graph.bipartite( c(0,0,1,0), c(0,2,1,2,1,3))

because the attempted edge (1,3) joins two vertices in the same part.

The first argument of graph.bipartite implicitly specifies the number of vertices. In both cases, you will have 10 vertices in your graph. However, since vertices have consecutive numeric IDs starting from zero in igraph, you cannot use 10, 11 etc as vertex IDs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM