nsgaii_main.java

来自「关于多目标优化的代码」· Java 代码 · 共 143 行

JAVA
143
字号
/** * NSGAII_main.java * * @author Juan J. Durillo * @author Antonio J. Nebro * @version 1.0 *   This implementation of jMetal makes use of a QualityIndicator object *   to obtained the convergence speed of the algorithm. This version is used *   in the paper: *     A.J. Nebro, J.J. Durillo, C.A. Coello Coello, F. Luna, E. Alba  *     "A Study of Convergence Speed in Multi-Objective Metaheuristics."  *     To be presented in: PPSN'08. Dortmund. September 2008. */package jmetal.metaheuristics.nsgaII;import jmetal.base.*;import jmetal.base.operator.crossover.*   ;import jmetal.base.operator.mutation.*    ; import jmetal.base.operator.selection.*   ;import jmetal.problems.*                  ;import jmetal.problems.DTLZ.*;import jmetal.problems.ZDT.*;import jmetal.problems.WFG.*;import jmetal.problems.ZZJ07.*;import jmetal.problems.LZ07.* ;import jmetal.util.JMException;import java.io.IOException;import java.util.logging.FileHandler;import java.util.logging.Logger;import jmetal.qualityIndicator.QualityIndicator;public class NSGAII_main {  public static Logger      logger_ ;      // Logger object  public static FileHandler fileHandler_ ; // FileHandler object  /**   * @param args Command line arguments.   * @throws JMException    * @throws IOException    * @throws SecurityException    * Usage: three options   *      - jmetal.metaheuristics.nsgaII.NSGAII_main   *      - jmetal.metaheuristics.nsgaII.NSGAII_main problemName   *      - jmetal.metaheuristics.nsgaII.NSGAII_main problemName paretoFrontFile   */  public static void main(String [] args) throws                                   JMException, SecurityException, IOException {    Problem   problem   ;         // The problem to solve    Algorithm algorithm ;         // The algorithm to use    Operator  crossover ;         // Crossover operator    Operator  mutation  ;         // Mutation operator    Operator  selection ;         // Selection operator        QualityIndicator indicators ; // Object to get quality indicators    // Logger object and file to store log messages    logger_      = Configuration.logger_ ;    fileHandler_ = new FileHandler("NSGAII_main.log");     logger_.addHandler(fileHandler_) ;        indicators = null ;    if (args.length == 1) {      Object [] params = {"Real"};      problem = (new ProblemFactory()).getProblem(args[0],params);    } // if    else if (args.length == 2) {      Object [] params = {"Real"};      problem = (new ProblemFactory()).getProblem(args[0],params);      indicators = new QualityIndicator(problem, args[1]) ;    } // if    else { // Default problem      problem = new Kursawe(3, "Real");       //problem = new Kursawe(3,"BinaryReal");      //problem = new Water("Real");      //problem = new ZDT4(10, "Real");      //problem = new WFG1("Real");      //problem = new DTLZ1("Real");      //problem = new OKA2("Real") ;    } // else        algorithm = new NSGAII(problem);    // Algorithm parameters    algorithm.setInputParameter("populationSize",100);    algorithm.setInputParameter("maxEvaluations",25000);    // Mutation and Crossover for Real codification     crossover = CrossoverFactory.getCrossoverOperator("SBXCrossover");                       crossover.setParameter("probability",0.9);                       crossover.setParameter("distributionIndex",20.0);    mutation = MutationFactory.getMutationOperator("PolynomialMutation");                        mutation.setParameter("probability",1.0/problem.getNumberOfVariables());    mutation.setParameter("distributionIndex",20.0);        // Mutation and Crossover Binary codification    /*    crossover = CrossoverFactory.getCrossoverOperator("SinglePointCrossover");                       crossover.setParameter("probability",0.9);                       mutation = MutationFactory.getMutationOperator("BitFlipMutation");                        mutation.setParameter("probability",1.0/199);     */    // Selection Operator     selection = SelectionFactory.getSelectionOperator("BinaryTournament2") ;                               // Add the operators to the algorithm    algorithm.addOperator("crossover",crossover);    algorithm.addOperator("mutation",mutation);    algorithm.addOperator("selection",selection);    // Add the indicator object to the algorithm    algorithm.setInputParameter("indicators", indicators) ;        // Execute the Algorithm    long initTime = System.currentTimeMillis();    SolutionSet population = algorithm.execute();    long estimatedTime = System.currentTimeMillis() - initTime;        // Result messages     logger_.info("Total execution time: "+estimatedTime + "ms");    logger_.info("Variables values have been writen to file VAR");    population.printVariablesToFile("VAR");        logger_.info("Objectives values have been writen to file FUN");    population.printObjectivesToFile("FUN");      if (indicators != null) {      logger_.info("Quality indicators") ;      logger_.info("Hypervolume: " + indicators.getHypervolume(population)) ;      logger_.info("GD         : " + indicators.getGD(population)) ;      logger_.info("IGD        : " + indicators.getIGD(population)) ;      logger_.info("Spread     : " + indicators.getSpread(population)) ;      logger_.info("Epsilon    : " + indicators.getEpsilon(population)) ;             int evaluations = ((Integer)algorithm.getOutputParameter("evaluations")).intValue();      logger_.info("Speed      : " + evaluations + " evaluations") ;          } // if  } //main} // NSGAII_main

⌨️ 快捷键说明

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