Skip to content

Instantly share code, notes, and snippets.

@felixlindemann
Created December 4, 2014 13:48
Show Gist options
  • Save felixlindemann/283c421b8082aa5f2094 to your computer and use it in GitHub Desktop.
Save felixlindemann/283c421b8082aa5f2094 to your computer and use it in GitHub Desktop.
Recursive function for a genetic algorithm to find short cycles
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