protected void addToPopulation(Solution newSolution){
  List<Integer> dominates=new ArrayList<Integer>();
  boolean dominated=false;
  for (int i=0; i < population.size(); i++) {
    int flag=dominanceComparator.compare(newSolution,population.get(i));
    if (flag < 0) {
      dominates.add(i);
    }
 else     if (flag > 0) {
      dominated=true;
    }
  }
  if (!dominates.isEmpty()) {
    population.remove(dominates.get(PRNG.nextInt(dominates.size())));
    population.add(newSolution);
  }
 else   if (!dominated) {
    population.remove(PRNG.nextInt(population.size()));
    population.add(newSolution);
  }
}

protected void addToPopulation ( Solution newSolution ) { List < Integer > dominates = new ArrayList < Integer > ( ) ; boolean dominated = false ; for ( int i = 0 ; i < population . size ( ) ; i ++ ) { int flag = dominanceComparator . compare ( newSolution , population . get ( i ) ) ; if ( flag < 0 ) { dominates . add ( i ) ; } else if ( flag > 0 ) { dominated = true ; } } if ( ! dominates . isEmpty ( ) ) { population . remove ( dominates . get ( PRNG . nextInt ( dominates . size ( ) ) ) ) ; population . add ( newSolution ) ; } else if ( ! dominated ) { population . remove ( PRNG . nextInt ( population . size ( ) ) ) ; population . add ( newSolution ) ; } }
adds the new solution to the population if is non - dominated with the current population , removing either a randomly - selected dominated solution or a non - dominated solution .
