예제 #1
0
  @Override
  protected Individual select(EvolutionaryAlgorithm algorithm, List<Individual> individuals) {

    double random;
    double acum;
    int n = individuals.size();
    double min = 2 - this.max;
    double range = this.max - min;
    Individual individual;
    int i;

    // Se ordena la lista de individuos según el comparador en orden inverso:
    Collections.sort(individuals, algorithm.getComparator());
    Collections.reverse(individuals);

    // Ahora la posicion en la lista de cada individuo indica su rank:
    random = EAFRandom.nextDouble();

    acum = 0.0;

    i = 0;
    do {

      i++;
      acum += (1.0 / n) * (this.max - range * ((double) (i - 1.0) / (double) (n - 1.0)));

    } while (acum < random);

    individual = individuals.get(--i);

    return (Individual) individual.clone();
  }
예제 #2
0
  @Override
  public void update(Observable o, Object arg) {

    EvolutionaryAlgorithm algorithm = (EvolutionaryAlgorithm) o;
    BestIndividualSpecification bestSpec = new BestIndividualSpecification();
    Individual best;

    super.update(o, arg);

    if (algorithm.getState() == EvolutionaryAlgorithm.REPLACE_STATE && arg == null) {
      best = algorithm.getBestEverIndividual();
      super.getLog()
          .println(
              algorithm.getGenerations()
                  + " - "
                  + best.getFitness()
                  + " - "
                  + FitnessUtil.meanFitnessValue(algorithm.getPopulation().getIndividuals()));
    }
  }