コード例 #1
0
ファイル: MOCCOState.java プロジェクト: openea/eva2
 /**
  * This method establishes a fitness cache to give the plot methods easier and faster access to
  * the data
  *
  * @param reevaluate
  */
 public void makeFitnessCache(boolean reevaluate) {
   InterfaceOptimizationObjective[] tmpObj = null;
   if (reevaluate) {
     // clear all archives, since problem dimension may have changed
     for (int i = 0; i < this.populationHistory.length; i++) {
       if (this.populationHistory[i].getArchive() != null) {
         this.populationHistory[i].addPopulation(this.populationHistory[i].getArchive());
         this.populationHistory[i].SetArchive(null);
       }
     }
     Population pop = this.optimizer.getPopulation();
     if (pop.getArchive() != null) {
       pop.addPopulation(pop.getArchive());
       pop.SetArchive(null);
     }
     this.currentProblem.evaluate(pop);
   }
   this.fitnessCache = new ArrayList();
   this.objectiveCache = null;
   this.constraintCache = new ArrayList();
   if (this.currentProblem instanceof InterfaceMultiObjectiveDeNovoProblem) {
     this.objectiveCache = new ArrayList();
     tmpObj = ((InterfaceMultiObjectiveDeNovoProblem) this.currentProblem).getProblemObjectives();
   }
   this.paretoFront = new Population();
   for (int i = 0; i < this.populationHistory.length; i++) {
     if (reevaluate) {
       ((AbstractMultiObjectiveOptimizationProblem) this.currentProblem).resetParetoFront();
       this.currentProblem.evaluate(this.populationHistory[i]);
     }
     this.paretoFront.addPopulation(this.populationHistory[i]);
     ArrayList fitness = new ArrayList();
     ArrayList objectives = new ArrayList();
     ArrayList constraint = new ArrayList();
     for (int j = 0; j < this.populationHistory[i].size(); j++) {
       if (tmpObj != null) {
         double[] tmoF = new double[tmpObj.length];
         for (int k = 0; k < tmpObj.length; k++) {
           if (this.populationHistory[i].get(j) == null) {
             System.out.println("Individual " + i + " == null!");
           }
           if (tmpObj[k] == null) {
             System.out.println("Objective " + k + " == null!");
           }
           if (this.populationHistory[i].get(j).getData(tmpObj[k].getIdentName()) == null) {
             System.out.println("User Data " + k + " " + tmpObj[k].getIdentName() + " == null!");
           }
           tmoF[k] = (Double) this.populationHistory[i].get(j).getData(tmpObj[k].getIdentName());
         }
         objectives.add(tmoF);
       }
       fitness.add(this.populationHistory[i].get(j).getFitness());
       constraint.add(this.populationHistory[i].get(j).getConstraintViolation());
     }
     if (this.objectiveCache != null) {
       this.objectiveCache.add(objectives);
     }
     this.fitnessCache.add(fitness);
     this.constraintCache.add(constraint);
   }
   ArchivingAllDominating arch = new ArchivingAllDominating();
   arch.addElementsToArchive(this.paretoFront);
   this.paretoFront = this.paretoFront.getArchive();
   this.paretoFront.SetArchive(null);
 }