Created
December 4, 2014 13:49
-
-
Save felixlindemann/dad3d0e1af2855487c12 to your computer and use it in GitHub Desktop.
Repair short cycles in 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
repair2 <- function(tour){ | |
#repair short cycles (DFJc) | |
# iteriere über jeden Stop im Tourenplan | |
for(i in 1:length(tour)){ | |
# wenn der Nachfolger nicht das Depot ist (hier index = 1) | |
# dann kann es Kurzzyklen geben | |
if(tour[i]>1){ # not returning to depot | |
# finde sukzezzive jeden nachfolger in der Tour --> Rekursiv | |
r<-searchFor(tour, tour[i], i+1) #recursive call | |
# Ein kurzzyklus liegt vor, wenn der Startknoten wieder erreicht wird. | |
# in diesem Fall ist r = FALSE | |
if(r == FALSE){ #if shortcycle found, return current node to depot | |
tour[i] <- 1 | |
} | |
} | |
} | |
#elimiate cycles | |
return (tour) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment