Ejemplo n.º 1
0
  /** This method will optimize */
  @Override
  public void optimize() {
    AbstractEAIndividual indy;
    Population original = (Population) this.population.clone();
    double[] fitness;

    for (int i = 0; i < this.population.size(); i++) {
      indy = this.population.get(i);
      double tmpD = indy.getMutationProbability();
      indy.setMutationProbability(1.0);
      indy.mutate();
      indy.setMutationProbability(tmpD);
    }
    this.optimizationProblem.evaluate(this.population);
    for (int i = 0; i < this.population.size(); i++) {
      fitness = this.population.get(i).getFitness();
      if (fitness[0] > this.currentFloodPeak) {
        this.population.remove(i);
        this.population.add(i, original.get(i));
      }
    }
    this.currentFloodPeak -= this.drainRate;
    this.population.incrGeneration();
    this.firePropertyChangedEvent(Population.NEXT_GENERATION_PERFORMED);
  }
Ejemplo n.º 2
0
  /**
   * This method allows an optimizer to register a change in the optimizer.
   *
   * @param source The source of the event.
   * @param name Could be used to indicate the nature of the event.
   */
  @Override
  public void registerPopulationStateChanged(Object source, String name) {
    if (name.equals(Population.NEXT_GENERATION_PERFORMED)) {
      Population population = ((InterfaceOptimizer) source).getPopulation();
      double x = 100 / this.multiRuns;
      if (this.optimizationParameters.getTerminator() instanceof EvaluationTerminator) {
        double y =
            x
                / (double)
                    ((EvaluationTerminator) this.optimizationParameters.getTerminator())
                        .getFitnessCalls();
        currentProgress = (int) (this.currentRun * x + population.getFunctionCalls() * y);
      } else {
        currentProgress = (int) (this.currentRun * x);
      }
      updateStatus(currentProgress);

      // data to be stored in file
      double tmpd = 0;
      StringBuilder tmpLine = new StringBuilder("");
      tmpLine.append(population.getFunctionCalls());
      tmpLine.append("\t");
      tmpLine.append(population.getBestEAIndividual().getFitness(0));
      tmpLine.append("\t");
      for (int i = 0; i < population.size(); i++) {
        tmpd += population.get(i).getFitness(0) / (double) population.size();
      }
      tmpLine.append("\t");
      tmpLine.append(tmpd);
      tmpLine.append("\t");
      tmpLine.append(population.getWorstEAIndividual().getFitness(0));
      // tmpLine.append("\t");
      // tmpLine.append(this.optimizationParameters.getProblem().getAdditionalDataValue(population));
      this.writeToFile(tmpLine.toString());

      Double[] tmpData = new Double[2];
      tmpData[0] = (double) population.getFunctionCalls();
      // instead of adding simply the best fitness value i'll ask the problem what to show
      tmpData[1] = this.optimizationParameters.getProblem().getDoublePlotValue(population);
      if (this.plot != null) {
        if (this.continueFlag) {
          this.plot.setConnectedPoint(
              tmpData[0] + this.recentFunctionCalls, tmpData[1], 1000 + this.currentRun);
        } else {
          this.plot.setConnectedPoint(tmpData[0], tmpData[1], 1000 + this.currentRun);
        }
      }
      this.tmpData.add(tmpData);
    }
  }
Ejemplo n.º 3
0
 /**
  * This method takes a population of individuals with an array of fitness values and calculates a
  * single fitness value to replace the former fitness array. Please note: The orignal fitness
  * values are lost this way, so please use the individual.setData() method if you still want to
  * access the original fitness values.
  *
  * @param pop The population to process.
  */
 @Override
 public void convertMultiObjective2SingleObjective(Population pop) {
   for (int i = 0; i < pop.size(); i++) {
     this.convertSingleIndividual(pop.get(i));
   }
 }