Skip to content

Instantly share code, notes, and snippets.

@felixlindemann
Created December 4, 2014 14:02
Show Gist options
  • Save felixlindemann/ad50954c984c2c61ed98 to your computer and use it in GitHub Desktop.
Save felixlindemann/ad50954c984c2c61ed98 to your computer and use it in GitHub Desktop.
calculate fitnes of a tourplan in a genetic algorithm
calcTourplan <- function(cij, tour){
F <- 0
# Speichere die Orte, die keinen Vorgänger haben --> Also vom Depot aus angesteuert werden
hasPreDecessor <- rep(FALSE, nrow(locations))
for(i in 1:ncol(tour)){
F<- F + cij[i+1, tour[i]]
hasPreDecessor[tour[i]] <- TRUE
}
I <- which(hasPreDecessor==FALSE)
# Welche knoten sind mit dem Depot verbunden?
if(length(I)>0){
for(i in I){
F<- F + cij[1, i] # i = 1 is depot
}
}
return (F)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment