def nsga2select(population, fitnesses, survivors, allowequality=True):
 fronts = const_non_dominated_sort(population, key=(lambda x: fitnesses[x]), allowequality=allowequality)
 individuals = set()
 for front in fronts:
  remaining = (survivors - len(individuals))
  if (not (remaining > 0)):
   break
  if (len(front) > remaining):
   crowd_dist = const_crowding_distance(front, fitnesses)
   front = sorted(front, key=(lambda x: crowd_dist[x]), reverse=True)
   front = set(front[:remaining])
  individuals |= front
 return list(individuals)

def nsga2select ( population , fitnesses , survivors , allowequality = True ) : fronts = const_non_dominated_sort ( population , key = ( lambda x : fitnesses [ x ] ) , allowequality = allowequality ) individuals = set ( ) for front in fronts : remaining = ( survivors - len ( individuals ) ) if ( not ( remaining > 0 ) ) : break if ( len ( front ) > remaining ) : crowd_dist = const_crowding_distance ( front , fitnesses ) front = sorted ( front , key = ( lambda x : crowd_dist [ x ] ) , reverse = True ) front = set ( front [ : remaining ] ) individuals |= front return list ( individuals )
the nsga-ii selection strategy .