protected Population truncate(Population offspring,int size){
  Population survivors=new Population();
  Iterator<Solution> iterator=offspring.iterator();
  while (iterator.hasNext()) {
    Solution solution=iterator.next();
    double fitness=(Double)solution.getAttribute(FitnessEvaluator.FITNESS_ATTRIBUTE);
    if (fitness < 1.0) {
      survivors.add(solution);
      iterator.remove();
    }
  }
  if (survivors.size() < size) {
    offspring.sort(fitnessComparator);
    while (survivors.size() < size) {
      survivors.add(offspring.get(0));
      offspring.remove(0);
    }
  }
 else   if (survivors.size() > size) {
    MutableDistanceMap map=new MutableDistanceMap(computeDistanceMatrix(survivors));
    while (survivors.size() > size) {
      int index=map.findMostCrowdedPoint();
      map.removePoint(index);
      survivors.remove(index);
    }
  }
  return survivors;
}

protected Population truncate ( Population offspring , int size ) { Population survivors = new Population ( ) ; Iterator < Solution > iterator = offspring . iterator ( ) ; while ( iterator . hasNext ( ) ) { Solution solution = iterator . next ( ) ; double fitness = ( Double ) solution . getAttribute ( FitnessEvaluator . FITNESS_ATTRIBUTE ) ; if ( fitness < 1.0 ) { survivors . add ( solution ) ; iterator . remove ( ) ; } } if ( survivors . size ( ) < size ) { offspring . sort ( fitnessComparator ) ; while ( survivors . size ( ) < size ) { survivors . add ( offspring . get ( 0 ) ) ; offspring . remove ( 0 ) ; } } else if ( survivors . size ( ) > size ) { MutableDistanceMap map = new MutableDistanceMap ( computeDistanceMatrix ( survivors ) ) ; while ( survivors . size ( ) > size ) { int index = map . findMostCrowdedPoint ( ) ; map . removePoint ( index ) ; survivors . remove ( index ) ; } } return survivors ; }
returns the population of solutions that survive to the next generation .
