I need to implement a restricted tournament selection. This method consists of comparing each offspring individual with a random group of individuals. Select the one that most resembles the offspring individual and choose the best of the two to be inserted into the new population.
I have all the operators implemented but I don't know how to do that:
def reduccion(self, hijos):
for hijo in hijos:
torneo = random.sample(self.generacion, 5)
for i in range(0,len(torneo)):
distancia=self.levenshtein(hijo.fenotipo, torneo[i].fenotipo)
print(distancia)
self.generacion = actual population
self.levenshtein = is distance between two strings with different length