You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.1 KiB

3 years ago
  1. source("ea_crossover.R")
  2. n_point_crossover <- function(p1, p2, mask_gen, iterations) {
  3. indivs <- c()
  4. for(i in 1:iterations) {
  5. children <- ea.crossover(p1, p2, mask_gen())
  6. p1 <- children[[1]]
  7. p2 <- children[[2]]
  8. indivs <- append(indivs, c(indiv2int(p1), indiv2int(p2)))
  9. }
  10. return(indivs)
  11. }
  12. experiment <- function() {
  13. p1 <- rand.individual(10)
  14. p2 <- rand.individual(10)
  15. iterations <- 10000
  16. tmp_indivs <- n_point_crossover(p1, p2, ea.n_point_mask(10, 1), iterations)
  17. df <- data.frame(i=1:iterations, individual=tmp_indivs)
  18. df["crossover"] <- "1 point"
  19. tmp_indivs <- n_point_crossover(p1, p2, ea.n_point_mask(10, 2), iterations)
  20. df <- rbind(df, data.frame(i=(iterations+1):(2*iterations)
  21. ,individual=tmp_indivs
  22. ,crossover="2 point"))
  23. tmp_indivs <- n_point_crossover(p1, p2, ea.uniform_mask(10), iterations)
  24. df <- rbind(df, data.frame(i=(2*iterations+1):(3*iterations)
  25. ,individual=tmp_indivs
  26. ,crossover="uniform"))
  27. return(df)
  28. }