Skip to content

Instantly share code, notes, and snippets.

@felixlindemann
Created December 4, 2014 13:03
Show Gist options
  • Save felixlindemann/bb0e14582e30ff8ffbf1 to your computer and use it in GitHub Desktop.
Save felixlindemann/bb0e14582e30ff8ffbf1 to your computer and use it in GitHub Desktop.
Recombine Tours within a Genetic Algorithm
recombine<- function(tours, f, m, recomb){
# tours = Genpool
# f = father index
# m = mother index
# recomb = Predefined Recombination vector
t.f <- tours[f,] #get tourplan father
t.m <- tours[m,] #get tourplan mother
t.c <- t.f # use father as template
# Recombing
for(i in 1:ncol(recomb)){
if(recomb[i] == 1) {
t.c[i] <- t.m[i]
}
}
# prepare Return
t.c <- matrix(t.c, nrow=1)
colnames(t.c) <- colnames(tours)
return (t.c)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment