R 的 igraph 包中的二分图
我正在尝试使用 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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
graph.bipartite 的第一个参数隐式指定顶点数。在这两种情况下,图形中都会有 10 个顶点。但是,由于 igraph 中顶点具有从零开始的连续数字 ID,因此不能使用 10、11 等作为顶点 ID。
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.通过您的
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) 连接同一部分中的两个顶点。
With your
graph.bipartite( rep(0:1, length=10), ...)
you have toldgraph.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.