R - "maximum subgraphs" in the graph

I want to determine the maximum subgraphs in a given graph

for example, for this graph: enter image description here

and this code:

    library("igraph")        
    from <- c(1,2,3,3,6,6,8,9)
    to <- c(2,3,4,5,7,8,6,10)
    edges = data.frame(from,to)
    g<- graph_from_data_frame(edges,directed=FALSE)
    plot(g)

    clc <- max_cliques(g, min=3)
    clc

max cliques with min = 3 gives me an empty list ...

the result I want to get (with min = 3):

(1,2,3,4,5) (6,7,8)

+4
source share
1 answer

I think what you are looking for is not clicks, but connected components.

On your chart, clicks (full subgraphs) are 2 or less in size, so the function max_cliqueswill not return you anything if you set the minimum size to 3.

Alternatively, you can use the function clustersto find the largest related components of your chart.

cl <- clusters(g)
me <- which(cl$csize >= 3)
res <- split(names(cl$membership), cl$membership)[me]
res
$`1`
[1] "1" "2" "3" "4" "5"

$`2`
[1] "6" "8" "7"
+3

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


All Articles