# NOT RUN {
##################################
## Optimizing the sphere function
# define sphere function as objective function
sphere <- function(x){
return(sum(x^2))
}
## Define parameter
Pm <- 0.1
Pc <- 0.8
numVar <- 5
rangeVar <- matrix(c(-10,10), nrow=2)
## calculate the optimum solution using Genetic Algorithm
resultGA <- GA(sphere, optimType="MIN", numVar, numPopulation=20,
maxIter=100, rangeVar, Pm, Pc)
## calculate the optimum value using sphere function
optimum.value <- sphere(resultGA)
# }
Run the code above in your browser using DataLab