Skip to content

Instantly share code, notes, and snippets.

@felixlindemann
Created December 4, 2014 13:53
Show Gist options
  • Save felixlindemann/d8eb6b89c630e33d4c5b to your computer and use it in GitHub Desktop.
Save felixlindemann/d8eb6b89c630e33d4c5b to your computer and use it in GitHub Desktop.
Mutation process with in a genetic algorithm
# mutation
mutate <- function(tour){
# suche zufällig einen Start knoten aus, der mit einem Endknoten verbunden wird.
# combine which stop o[1] with wich stop o[2]
o <- sample(1:length(tour), 2)
tour[o[1]] <- o[2] + 1 # 1 is depot
# mutated tour
#immediate Repair
tour <- repair1(tour)
tour <- repair2(tour)
tour <- repair3(tour)
return (tour) # mutated + repaired tour
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment