f <- function(x){
return(-sum( (x-5)^2 ) )
}
# Increase popSize and maxiter for more precise solutions
myga <- GA::ga(type="real-valued", fitness = f, popSize = 100, maxiter = 200,
min = rep(-50,5), max = rep(50,5), crossover = byte_crossover,
mutation = byte_mutation_random_dynamic, pmutation = 0.20)
print(myga@solution)
Run the code above in your browser using DataLab