geneticAlgorithm is a function executing the genetic algorithm and its modifications for identifying the community structure of a network via modularity maximization
geneticAlgorithm(adjacency, numRandom = 0, initial = c("general", "cluster", "own"), p, g, mutRat = 0.5, crossOver = 0.2, beta = 0.1, alpha = 0.4, n_l = 4, local = FALSE)Default is 0.5
Default is 0.2
Default is 0.1
cluster. Default is 0.4. Ignored if initial is not cluster.
Default is 4. Ignored if local is FALSE
TRUE, local search operator is applied at the end of each iteration in the genetic algorithm.
numRandom>0
numRandom>0
numRandom>0
The initial partition used in the genetic algorithm can either be the generic one where all vertices are put in their own community (initial=general) or the initial partition can be identified by randomly picking a vertex $\alpha$$n$ times and assigning its cluster to all its neighbours (initial=cluster) or the initial partition can be given by the user (initial=own). In this case, the user needs to add a last column to the adjacency matrix indicating the initial partition. Hence, the adjacency matrix has to have one column more than the network has vertices.
Li, S., Chen, Y., Du, H., and Feldman, M. W. A genetic algorithm with local search strategy for improved detection of community structure. Complexity, 15(4):53-60, 2010.
#unweighted network
randomgraph <- erdos.renyi.game(10, 0.3, type="gnp",directed = FALSE, loops = FALSE)
#to ensure that the graph is connected
vertices <- which(clusters(randomgraph)$membership==1)
graph <- induced.subgraph(randomgraph,vertices)
adj <- get.adjacency(graph)
result <- geneticAlgorithm(adj, p=4, g=6)
Run the code above in your browser using DataLab