格子に順序
# 1辺のノード数 n <- 4 # 次元 d <- 3 a <- array(1:(n^d),rep(n,d)) N <- 1:n Na <- 1:(n-1) Nb <- 2:n tmp.list <- rep(list(N),d-1) tmp.list[[d]] <- Na tmpa <- expand.grid(tmp.list)-1 tmp.list[[d]] <- Nb tmpb <- expand.grid(tmp.list)-1 Amat <- matrix(0,0,2) for(i in 1:d){ tmp <- 1:d tmp[i] <- d tmp[d] <- i u <- n^(0:(d-1)) Amat <- rbind(Amat,cbind(a[apply(t(tmpa[,tmp]) * u,2,sum)+1],a[apply(t(tmpb[,tmp]) * u,2,sum)+1])) } Amat library(igraph) g <- graph.edgelist(Amat) plot(g)