Ejemplo n.º 1
0
  @Override
  public void update(Observable o, Object arg) {

    ParallelEvolutionaryAlgorithm pea = (ParallelEvolutionaryAlgorithm) o;

    if (pea.getCurrentObservable() instanceof EvolutionaryAlgorithm) {
      super.update(o, arg);
      EvolutionaryAlgorithm algorithm = (EvolutionaryAlgorithm) pea.getCurrentObservable();

      BestIndividualSpecification bestSpec = new BestIndividualSpecification();
      Individual best;
      int algorithm_fes;

      best =
          IndividualsProductTrader.get(
                  bestSpec, algorithm.getPopulation().getIndividuals(), 1, pea.getComparator())
              .get(0);

      if (algorithm.getState() == EvolutionaryAlgorithm.REPLACE_STATE) {
        algorithm_fes = algorithm.getFEs();

        if (num_prints < this.fes_prints.size()
            && algorithm_fes >= Integer.parseInt((String) this.fes_prints.get(fes_index))) {
          super.getLog().println(best);
          this.fes_index++;
          num_prints++;
        }
      }

      if (algorithm.getState() == EvolutionaryAlgorithm.FINAL_STATE) {
        while (num_prints < this.fes_prints.size()) {
          super.getLog().println(best);
          num_prints++;
        }
      }
    }
  }
Ejemplo n.º 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()));
    }
  }