Created
December 4, 2014 13:48
-
-
Save felixlindemann/283c421b8082aa5f2094 to your computer and use it in GitHub Desktop.
Recursive function for a genetic algorithm to find short cycles
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
searchFor <- function(tour, index, start){ | |
#helper function für recursiven Aufruf | |
if(tour[index -1] == 1) # 1 == depot | |
{ | |
return(TRUE) | |
}else{ | |
if(tour[index -1] == start) # Kurzzyklus gefunden | |
{ | |
return(FALSE) | |
}else{ | |
return(searchFor(tour, tour[index -1], start)) # erneuter Rekursiver aufruf | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment