跳到内容

通过置换顶点 ID 创建新图。

用法

permute(graph, permutation)

参数

graph

输入的图,可以是有向图或无向图。

permutation

一个数值向量,给出要应用的置换。第一个元素是顶点 1 的新 ID,依此类推。一到 vcount(graph) 之间的每个数字必须恰好出现一次。

一个新的图对象。

详细信息

此函数通过根据指定的映射置换其顶点,从输入图创建一个新图。使用 canonical_permutation() 的输出调用此函数,以创建图的规范形式。

permute() 保留图的所有图、顶点和边的属性。

作者

Gabor Csardi csardi.gabor@gmail.com

permute_vertices().

示例


# Random permutation of a random graph
g <- sample_gnm(20, 50)
g2 <- permute(g, sample(vcount(g)))
isomorphic(g, g2)
#> [1] TRUE

# Permutation keeps all attributes
g$name <- "Random graph, Gnm, 20, 50"
V(g)$name <- letters[1:vcount(g)]
E(g)$weight <- sample(1:5, ecount(g), replace = TRUE)
g2 <- permute(g, sample(vcount(g)))
isomorphic(g, g2)
#> [1] TRUE
g2$name
#> [1] "Random graph, Gnm, 20, 50"
V(g2)$name
#>  [1] "l" "p" "a" "b" "j" "r" "g" "f" "q" "h" "i" "k" "c" "d" "m" "o" "t" "e" "n"
#> [20] "s"
E(g2)$weight
#>  [1] 4 1 1 5 4 4 4 5 4 4 3 3 2 3 3 2 5 3 1 3 4 4 4 5 3 1 5 1 2 2 2 4 4 5 4 2 1 5
#> [39] 1 1 5 3 1 4 4 3 1 1 1 3
all(sort(E(g2)$weight) == sort(E(g)$weight))
#> [1] TRUE