1

I would like to generate a lattice with 100 nodes but would like to ensure that all nodes have the same number of neighbours.

However when I do:

d=graph.lattice(100,0,nei=10,directed=TRUE,circular=TRUE)
get.edgelist(d)

then I can see that many of the nodes do not have the same number of neighbours.

Is there any way to ensure that every node has the same number of connections assuming that the first column represents nodes and the second column connections?

4

2 回答 2

1

这是因为对于有向图来说,默认的边方向graph.lattice并不是最好的。您可以做的是创建一个无向图,然后将其转换为有向图:

d <- as.directed(graph.lattice(100, 0, nei=10, directed=FALSE, circular=TRUE))
unique(degree(d, mode="in"))
#  [1] 20 
unique(degree(d, mode="out"))
#  [1] 20

如果您想要非相互边缘,那么最简单(但可读性较差)的解决方案是

d <- graph(sapply(1:100, function(i) {
  rbind(i, ((i+1):(i+10)-1) %% 100 + 1)
}))
unique(degree(d, mode="in"))
# [1] 10 
unique(degree(d, mode="out"))
# [1] 10
于 2013-01-23T02:58:51.013 回答
1

您可以创建一个边缘列表并从中制作图表。在这种情况下,假设您只考虑链接到(定向)的邻居,那么您可以执行以下操作:

el <- do.call(rbind,
              lapply(1:100,
                     function(e) {cbind(rep(e,10),
                                        sample(setdiff(1:100, e),10))}))
d <- graph.edgelist(el)

这会选择 10 个随机节点(除了自身)来链接一个节点。

于 2013-01-22T22:29:58.790 回答