def sortLogNondominated(individuals, k, first_front_only=False):
 if (k == 0):
  return []
 unique_fits = defaultdict(list)
 for (i, ind) in enumerate(individuals):
  unique_fits[ind.fitness.wvalues].append(ind)
 obj = (len(individuals[0].fitness.wvalues) - 1)
 fitnesses = unique_fits.keys()
 front = dict.fromkeys(fitnesses, 0)
 fitnesses.sort(reverse=True)
 sortNDHelperA(fitnesses, obj, front)
 nbfronts = (max(front.values()) + 1)
 pareto_fronts = [[] for i in range(nbfronts)]
 for fit in fitnesses:
  index = front[fit]
  pareto_fronts[index].extend(unique_fits[fit])
 if (not first_front_only):
  count = 0
  for (i, front) in enumerate(pareto_fronts):
   count += len(front)
   if (count >= k):
    return pareto_fronts[:(i + 1)]
  return pareto_fronts
 else:
  return pareto_fronts[0]

def sortLogNondominated ( individuals , k , first_front_only = False ) : if ( k == 0 ) : return [ ] unique_fits = defaultdict ( list ) for ( i , ind ) in enumerate ( individuals ) : unique_fits [ ind . fitness . wvalues ] . append ( ind ) obj = ( len ( individuals [ 0 ] . fitness . wvalues ) - 1 ) fitnesses = unique_fits . keys ( ) front = dict . fromkeys ( fitnesses , 0 ) fitnesses . sort ( reverse = True ) sortNDHelperA ( fitnesses , obj , front ) nbfronts = ( max ( front . values ( ) ) + 1 ) pareto_fronts = [ [ ] for i in range ( nbfronts ) ] for fit in fitnesses : index = front [ fit ] pareto_fronts [ index ] . extend ( unique_fits [ fit ] ) if ( not first_front_only ) : count = 0 for ( i , front ) in enumerate ( pareto_fronts ) : count += len ( front ) if ( count >= k ) : return pareto_fronts [ : ( i + 1 ) ] return pareto_fronts else : return pareto_fronts [ 0 ]
sort *individuals* in pareto non-dominated fronts using the generalized reduced run-time complexity non-dominated sorting algorithm presented by fortin et al .