amocell4.java

来自「这是多目标进化算法包」· Java 代码 · 共 135 行

JAVA
135
字号
/** * aMOCell.java * @author Juan J. Durillo * @version 1.0 * */package jmetal.metaheuristics.mocell;import jmetal.base.*;import java.util.Comparator;import jmetal.base.archive.CrowdingArchive;import jmetal.base.operator.comparator.*;import jmetal.util.*;/** * This class representing an asynchronous version of MOCell algorithm in  * which all neighbors are considered in the replace and the feedback * takes place through parent selection from the archive */public class aMOCell4 extends Algorithm{  /**   * Stores the problem to solve   */  private Problem problem_;          //The problem to solve          /**    * Constructor   * @param problem Problem to solve   */      public aMOCell4(Problem problem){    problem_ = problem;  } // aMOCell4  /**      * Runs of the aMOCell3 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 {    //Init the param    int populationSize, archiveSize, maxEvaluations, evaluations, feedBack;    Operator mutationOperator, crossoverOperator, selectionOperator;    SolutionSet currentSolutionSet;    CrowdingArchive archive;    SolutionSet [] neighbors;        Neighborhood neighborhood;    Comparator dominance = new DominanceComparator(),    crowding  = new CrowdingComparator();      Distance distance = new Distance();    //Read the params    populationSize    = ((Integer)getInputParameter("populationSize")).intValue();    archiveSize       = ((Integer)getInputParameter("archiveSize")).intValue();    maxEvaluations    = ((Integer)getInputParameter("maxEvaluations")).intValue();                                    //Read the operators    mutationOperator  = operators_.get("mutation");    crossoverOperator = operators_.get("crossover");    selectionOperator = operators_.get("selection");         //Initialize the variables    //initialize the population and the archive    currentSolutionSet  = new SolutionSet(populationSize);            archive            = new CrowdingArchive(archiveSize,problem_.getNumberOfObjectives());                    evaluations        = 0;                            neighborhood       = new Neighborhood(populationSize);    neighbors          = new SolutionSet[populationSize];    //Create the comparator for check dominance    dominance = new jmetal.base.operator.comparator.DominanceComparator();       //Create the initial population    for (int i = 0; i < populationSize; i++){      Solution solution = new Solution(problem_);      problem_.evaluate(solution);                 problem_.evaluateConstraints(solution);      currentSolutionSet.add(solution);      solution.setLocation(i);      evaluations++;    }    // Main loop    while (evaluations < maxEvaluations){                                       for (int ind = 0; ind < currentSolutionSet.size(); ind++){        Solution individual = new Solution(currentSolutionSet.get(ind));        Solution [] parents = new Solution[2];        Solution [] offSpring;        //neighbors[ind] = neighborhood.getFourNeighbors(currentSolutionSet,ind);        neighbors[ind] = neighborhood.getEightNeighbors(currentSolutionSet,ind);                                                                   neighbors[ind].add(individual);        //parents        parents[0] = (Solution)selectionOperator.execute(neighbors[ind]);        if (archive.size()>0) {          parents[1] = (Solution)selectionOperator.execute(archive);        } else {          parents[1] = (Solution)selectionOperator.execute(neighbors[ind]);        }        //Create a new solution, using genetic operators mutation and crossover        offSpring = (Solution [])crossoverOperator.execute(parents);                       mutationOperator.execute(offSpring[0]);        //->Evaluate solution and constraints        problem_.evaluate(offSpring[0]);        problem_.evaluateConstraints(offSpring[0]);        evaluations++;        int flag = dominance.compare(individual,offSpring[0]);                       neighbors[ind].add(offSpring[0]);                       offSpring[0].setLocation(-1);        Ranking rank = new Ranking(neighbors[ind]);        for (int j = 0; j < rank.getNumberOfSubfronts(); j++){          distance.crowdingDistanceAssignment(rank.getSubfront(j),problem_.getNumberOfObjectives());        }        neighbors[ind].sort(new CrowdingComparator());         Solution worst = neighbors[ind].get(neighbors[ind].size()-1);        if (worst.getLocation() == -1) { //The worst is the offspring          archive.add(new Solution(offSpring[0]));        } else {          offSpring[0].setLocation(worst.getLocation());          currentSolutionSet.replace(offSpring[0].getLocation(),offSpring[0]);          archive.add(new Solution(offSpring[0]));        }                                                }    }    return archive;  }  // execute      } // aMOCell4

⌨️ 快捷键说明

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