Finding the size of biconce components in R

I analyze an undirected graph in R. I try (in the end) to write a function to get the ratio of the size (number of vertices) of the largest connected component to the size of the largest biconfection component - from any random graph. I was able to extract the size of the largest related component, but I had problems with the size of the largest component with binoculars. I started using the igraph biconnected_components function on g chart:

bicomponent_list <- biconnected_components(g)
bicomponent_list$components # lists all of the components, including size and vertex names
length(bicomponent_list$components[[1]]) # returns number of vertices of first bicomponent

Then my half-baked idea was to sort this list somehow while decreasing the number of vertices so that I could always call length (bicomponent_components $ components [[1]]), and this would be the largest binary-connected component. But I do not know how to sort it correctly. Maybe I need to convert it to a vector? But I also don’t know how to indicate that I want the number of vertices in the vector. Does anyone know or have a better way to do this? Many thanks!

library(igraph)

# generating sample graph
g1 <- barabasi.game(100, 1, 5)
V(g1)$name <- as.character(1:100)

g2 <- erdos.renyi.game(50, graph.density(g1), directed = TRUE)
V(g2)$name <- as.character(101:200)

g3 <- graph.union(g1, g2, byname = TRUE)

# analyzing the bicomponents
bicomponent_list <- biconnected_components(g3)
bi_list <- as.list(bicomponent_list$components)
bi_list <- lapply(bi_list, length) # lists the sizes of all of the components that I want to reorder

My desired result will be arranged bi_listin such a way that it length(bicomponent_list$components[[1]])returns the two-component with the highest number of vertices.

+4
source share
1 answer

components - , .

sapply(bicomponent_list$components, length)

, max()

max(sapply(bicomponent_list$components, length))
+1

Source: https://habr.com/ru/post/1617800/


All Articles