2013-11-28 2 views
0

제한된 토너먼트 선택을 구현해야합니다. 이 방법은 각 자손 개체를 임의의 개체 그룹과 비교하는 것으로 구성됩니다. 새끼 개체와 가장 유사한 개체를 선택하고 새 모집단에 삽입 할 두 개체 중 최상의 개체를 선택하십시오.제한된 토너먼트 선택

나는 모든 연산자는 구현하지만 난 그렇게하는 방법을 모른다 :

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 = 실제 인구

self.levenshtein = 길이가 다른 두 문자열 사이의 거리입니다

답변

0

따라서 distanciahijo과 특정 구성원의 거리를 제공합니다. 자손과 가장 유사한 개체는 가장 가까운 거리에있는 개체입니다. 이를 수행하는 가장 간단한 방법은 inner for-loop 전에 변수를 초기화하여 지금까지 본 것과 가장 유사한 것을 추적하는 것입니다. 그렇다면 가장 비슷한 개인의 적합도를 hijo의 적합성과 비교하고 다음 세대에 가장 적합하게 맞추면됩니다. 다음을 수행하기위한 몇 가지 의사 코드가 있습니다.

def reduccion(self, hijos): 

    for hijo in hijos: 
     torneo = random.sample(self.generacion, 5) 

     mostSimilar = torneo[0] #Initialize this to be the 
           #first population member in the tournament 
     lowestDistance = self.levenshtein(hijo.fenotipo, mostSimilar.fenotipo) 

     for i in range(1,len(torneo)): #now we've already looked at #1 
      distancia=self.levenshtein(hijo.fenotipo, torneo[i].fenotipo) 

      if distancia < lowestDistance: #see if this distance is lower 
       lowestDistance = distancia #than what we've seen before 
       mostSimilar = torneo[i] 

     if mostSimilar.fitness < hijo.fitness: #compare the fitnesses 
      add hijo to next generation 
     else: 
      add mostSimilar to next generation