Skip to content

Instantly share code, notes, and snippets.

@felixlindemann
Created December 4, 2014 13:38
Show Gist options
  • Save felixlindemann/3f1194710fff356718de to your computer and use it in GitHub Desktop.
Save felixlindemann/3f1194710fff356718de to your computer and use it in GitHub Desktop.
Repair child according to cond 1&2 in a #Genetic Algortihm
repair1 <- function(tour){
#cond 1/2 once arrive/leave
#substitute multiple indices by 0(1) --> ALL!
#getunique stops
y<-unique(tour)
y<- y[y!=1] # 1 --> 0 # elminate Depot-Stops
#iterate over potentail multiple Stop indices
for(i in y){
# which stops have this index?
x <- which(tour == i)
if(length(x)>1){
# if i is multiple stop
tour[x] <- 1 # return to depot
}
}
# Return
return (tour)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment