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

source("ea_crossover.R")
n_point_crossover <- function(p1, p2, mask_gen, iterations) {
indivs <- c()
for(i in 1:iterations) {
children <- ea.crossover(p1, p2, mask_gen())
p1 <- children[[1]]
p2 <- children[[2]]
indivs <- append(indivs, c(indiv2int(p1), indiv2int(p2)))
}
return(indivs)
}
experiment <- function() {
p1 <- rand.individual(10)
p2 <- rand.individual(10)
iterations <- 10000
tmp_indivs <- n_point_crossover(p1, p2, ea.n_point_mask(10, 1), iterations)
df <- data.frame(i=1:iterations, individual=tmp_indivs)
df["crossover"] <- "1 point"
tmp_indivs <- n_point_crossover(p1, p2, ea.n_point_mask(10, 2), iterations)
df <- rbind(df, data.frame(i=(iterations+1):(2*iterations)
,individual=tmp_indivs
,crossover="2 point"))
tmp_indivs <- n_point_crossover(p1, p2, ea.uniform_mask(10), iterations)
df <- rbind(df, data.frame(i=(2*iterations+1):(3*iterations)
,individual=tmp_indivs
,crossover="uniform"))
return(df)
}