Пример #1
0
  /**
   * Compare the {@linkplain Entity} objects returning the desired ordering.
   *
   * @param e1 The first {@linkplain Entity} to be used in the comparison.
   * @param e2 The second {@linkplain Entity} to be used in the comparison.
   * @return -1 if e1 is less than e2; 0 if e1 and e2 are equal 1 if e2 is greater than e1
   */
  @Override
  public int compare(E e1, E e2) {
    Fitness f1 = e1.getFitness();
    Fitness f2 = e2.getFitness();

    return f1.compareTo(f2);
  }
Пример #2
0
  /*
   * Selects the best among a set of feasible solutions
   * @param iterable The set of feasible solutions
   * @return The best individual among the feasible solutions
   */
  protected E selectBestOfFeasible(Iterable<E> iterable) {
    E bestIndividual = iterable.iterator().next();

    for (E current : iterable) {
      if (current.getFitness().compareTo(bestIndividual.getBestFitness()) > 0) {
        bestIndividual = (E) current.getClone();
      }
    }

    return bestIndividual;
  }