f <- function(x){
return(-sum( (x-5)^2 ) )
}
myga <- GA::ga(type="real-valued", fitness = f, popSize = 100, maxiter = 200,
lower = rep(-50,5), upper = rep(50,5), crossover = byte_crossover,
mutation = byte_mutation)
print(myga@solution)
Run the code above in your browser using DataLab