0

我正在尝试创建一个带有 R 的 igraph 包的二分图,但有一段时间的魔鬼。

谁能告诉我为什么会这样:

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

但这给了我一个错误:

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
4

2 回答 2

1

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.

于 2011-04-07T19:18:45.727 回答
1

graph.bipartite( rep(0:1, length=10), ...)已经告诉你graph.bipartite图中有十个顶点,它将它们视为 0,1,2,...9。

你可以写

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

有四个顶点 0、1、2 和 3(一个部分有 2,另一部分有 0、1 和 3),但没有

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

因为没有顶点 4,也没有

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

因为尝试的边 (1,3) 连接了同一部分的两个顶点。

于 2011-04-07T18:48:57.143 回答