⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gde3.java

📁 这是多目标进化算法包
💻 JAVA
字号:
/** * GDE3.java * @author Antonio J. Nebro * @version 1.0   */package jmetal.metaheuristics.gde3;import java.util.Comparator;import jmetal.base.*;import jmetal.util.*;/** * This class implements the NSGA-II algorithm.  */public class GDE3 extends Algorithm {    /**   * stores the problem  to solve   */  private Problem  problem_;            /**  * Constructor  * @param problem Problem to solve  */  public GDE3(Problem problem){    this.problem_ = problem;                          } // NSGAII    /**     * Runs of the NSGA-II algorithm.  * @return a <code>SolutionSet</code> that is a set of non dominated solutions  * as a result of the algorithm execution     * @throws JMException   */    public SolutionSet execute() throws JMException {    int populationSize ;    int maxIterations  ;    int evaluations    ;    int iterations     ;        SolutionSet population          ;    SolutionSet offspringPopulation ;    SolutionSet union               ;        Distance   distance  ;    Comparator dominance ;        distance  = new Distance()  ;                   dominance = new jmetal.base.operator.comparator.DominanceComparator();         // Differential evolution parameters    int r1    ;    int r2    ;    int r3    ;    int jrand ;    double CR ;    double F  ;        //Read the parameters    populationSize = ((Integer)this.getInputParameter("populationSize")).intValue();    maxIterations  = ((Integer)this.getInputParameter("maxIterations")).intValue();                    CR             = ((Double)this.getInputParameter("CR")).doubleValue();                    F              = ((Double)this.getInputParameter("F")).doubleValue();                       //Initialize the variables    population  = new SolutionSet(populationSize);            evaluations = 0;                    iterations  = 0 ;    // Create the initial solutionSet    Solution newSolution;    for (int i = 0; i < populationSize; i++) {      newSolution = new Solution(problem_);                          problem_.evaluate(newSolution);                  problem_.evaluateConstraints(newSolution);      evaluations++;      population.add(newSolution);    } //for             // Generations ...    while (iterations < maxIterations) {          // Create the offSpring solutionSet            offspringPopulation  = new SolutionSet(populationSize * 2);              for (int i = 0; i < (populationSize); i++){           //obtain parents        do {           r1 = (int)(PseudoRandom.randInt(0,populationSize-1));        } while( r1==i );        do {           r2 = (int)(PseudoRandom.randInt(0,populationSize-1));        } while( r2==i || r2==r1);        do {           r3 = (int)(PseudoRandom.randInt(0,populationSize-1));        } while( r3==i || r3==r1 || r3==r2 );                jrand = (int)(PseudoRandom.randInt(0, problem_.getNumberOfVariables())-1) ;                Solution child = new Solution(problem_) ;        for (int j=0; j < problem_.getNumberOfVariables(); j++) {           if (PseudoRandom.randInt(0, 1) < CR || j == jrand) {             double value ;             value = population.get(r3).getDecisionVariables().variables_[j].getValue()  +                     F * (population.get(r1).getDecisionVariables().variables_[j].getValue() -                          population.get(r2).getDecisionVariables().variables_[j].getValue()) ;                          if (value < child.getDecisionVariables().variables_[j].getLowerBound())               value =  child.getDecisionVariables().variables_[j].getLowerBound() ;             if (value > child.getDecisionVariables().variables_[j].getUpperBound())               value = child.getDecisionVariables().variables_[j].getUpperBound() ;                            child.getDecisionVariables().variables_[j].setValue(value) ;           }           else {             double value ;             value = population.get(i).getDecisionVariables().variables_[j].getValue();             child.getDecisionVariables().variables_[j].setValue(value) ;           } // else        }                problem_.evaluate(child) ;        evaluations++ ;                // dominance test        int result  ;        result = dominance.compare(population.get(i), child) ;        if (result == -1) { // Solution i dominates child          offspringPopulation.add(population.get(i)) ;        } // if        else if (result == 1) { // child dominates          offspringPopulation.add(child) ;        } // else if        else { // the two solutions are non-dominated          offspringPopulation.add(child) ;          offspringPopulation.add(population.get(i)) ;        } // else      } // for                 // Ranking the offspring population      Ranking ranking = new Ranking(offspringPopulation);                              int remain = populationSize;      int index  = 0;      SolutionSet front = null;      population.clear();      // Obtain the next front      front = ranking.getSubfront(index);      while ((remain > 0) && (remain >= front.size())){                        //Assign crowding distance to individuals        distance.crowdingDistanceAssignment(front,problem_.getNumberOfObjectives());                        //Add the individuals of this front        for (int k = 0; k < front.size(); k++ ) {          population.add(front.get(k));        } // for        //Decrement remain        remain = remain - front.size();        //Obtain the next front        index++;        if (remain > 0) {          front = ranking.getSubfront(index);        } // if              } // while            // remain is less than front(index).size, insert only the best one      if (remain > 0) {  // front contains individuals to insert                                distance.crowdingDistanceAssignment(front,problem_.getNumberOfObjectives());        front.sort(new jmetal.base.operator.comparator.CrowdingComparator());        for (int k = 0; k < remain; k++) {          population.add(front.get(k));        } // for                remain = 0;       } // if                               iterations ++ ;    } // while        // Return the first non-dominated front    Ranking ranking = new Ranking(population);            return ranking.getSubfront(0);  } // execute} // GDE3-II

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -