# Some random shortcuts shorten the distances on a lattice
g <- make_lattice(length = 100, dim = 1, nei = 5)
mean_distance(g)
g <- rewire(g, each_edge(prob = 0.05))
mean_distance(g)
# Rewiring the start of each directed edge preserves the in-degree distribution
# but not the out-degree distribution
g <- barabasi.game(1000)
g2 <- g %>% rewire(each_edge(mode="in", multiple=TRUE, prob=0.2))
degree(g, mode="in") == degree(g2, mode="in")
Run the code above in your browser using DataLab