luca-scr / GA

An R package for optimization using genetic algorithms
http://luca-scr.github.io/GA/
91 stars 29 forks source link

keepBest option not working #41

Closed danlvn closed 4 years ago

danlvn commented 4 years ago

Hello,

I am trying to save the best solution of each iteration, but can't get the option to work. Please can you help me with this?

########################################################### library(GA) packageDescription("GA")$Version packageDescription("GA")$Date # f <- function(x) (x^2+x)*cos(x) # -10 < x < 10 # monitor <- function(obj) { cat(paste("iteration =", obj@iter , "solution =" , obj@bestSol[[obj@iter]]), "\n") } # GA <- ga(type = "real-valued", fitness = f, lower = -10, upper = 10, keepBest = TRUE, monitor = monitor,maxiter = 10) # summary(GA)$bestSol
########################################################## output:

GA <- ga(type = "real-valued", fitness = f, lower = -10, upper = 10, keepBest = TRUE, monitor = monitor,maxiter = 10) iteration = 1 solution =
iteration = 2 solution =
iteration = 3 solution =
iteration = 4 solution =
iteration = 5 solution =
iteration = 6 solution =
iteration = 7 solution =
iteration = 8 solution =
iteration = 9 solution =
iteration = 10 solution =
summary(GA)$bestSol NULL

luca-scr commented 4 years ago

Please install and use the devel version from GitHub.