Created
December 4, 2014 13:03
-
-
Save felixlindemann/bb0e14582e30ff8ffbf1 to your computer and use it in GitHub Desktop.
Recombine Tours within a Genetic Algorithm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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