Swap an edge of a bipartite graph while maintaining the partition

swap_an_edge(gr, n1, n2, max_try = 100)

Arguments

gr

tidygraph graph object

n1, n2

vectors that indicate the grouping of the nodes (by index)

max_try

Number of times to try to find two edges to swap. If no edges are found, the program will crash with the message "Unable to swap edges"

Value

a tidygraph graph object with two edges swapped

Examples

set.seed(0) library(tidygraph) gr <- tidygraph::create_ring(6, directed = FALSE) %>% mutate(.idx = 1:n(), name = c("A", "b", "C", "d", "E", "f")) swaped_gr <- swap_an_edge(gr, c(1,3,5), c(2,4,6)) plot(bind_graphs(gr, swaped_gr))