Permutation Mathematics

 Permutation Mathematics

library(igraph)
> g <- sample_gnm(20, 50)
> g2 <- permute(g, sample(vcount(g)))
> graph.isomorphic(g, g2)
[1] TRUE
> 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)))
> graph.isomorphic(g, g2)
[1] TRUE
> g2$name
[1] "Random graph, Gnm, 20, 50"
> V(g2)$name
 [1] "m" "q" "d" "c" "e" "t" "b" "p" "h"
[10] "n" "r" "i" "s" "k" "l" "o" "a" "j"
[19] "f" "g"
> E(g2)$weight
 [1] 5 2 4 1 4 1 5 4 3 1 5 3 5 1 3 2 4 5
[19] 3 1 2 5 1 2 4 4 1 4 5 1 1 4 2 2 3 5
[37] 1 4 2 3 5 5 5 1 3 3 3 5 3 3
> all(sort(E(g2)$weight) == sort(E(g)$weight))
[1] TRUE
> plot(g2)
Random graph

> plot(g)

Post a Comment

0 Comments