ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

jMetal官方文档汉化八:Operator类

2021-12-22 21:35:32  阅读:159  来源: 互联网

标签:crossoverProbability jMetal double distributionIndex 文档 solutions 算子 Operator pu


Operator 接口

启发式算法的基础是通过应用不同的算子,从现有的个体solution中修改或生成新的个体solution。例如,EAs使用交叉、变异和选择操算子修改解决方案。在jMetal中,任何改变或生成solution(或solution集合)的操作都会实现或扩展Operator接口:

package org.uma.jmetal.operator;

/**
 * Interface representing an operator
 *
 * @author Antonio J. Nebro <antonio@lcc.uma.es>
 * @version 0.1
 * @param <Source> Source Class of the object to be operated with
 * @param <Result> Result Class of the result obtained after applying the operator
 */
public interface Operator<Source, Result> {
  /**
   * @param source The data to process
   */
  public Result execute(Source source) ;
}

本接口中的泛型用于指示算子将被应用于Source并且将结果以Result类型返回

框架已经引入了一系列的算子,他们可以被分为四类

  • 交叉算子:表示启发式算法中使用的复合或交叉运算符。下文实例中的算子分别可以模拟二进制(SBX)交叉以及实数和二进制编码的单点交叉。
  • 变异算子:表示启发式算法中所使用的变异算子。包含实数编码的多项式变异以及二进制编码的位反转变异等
  • 选择算子. 在许多启发式算法中,这种算子用于执行选择过程。选择算子的一个示例是二进制竞赛。
  • 本地搜索算子. 此类用于表示本地搜索过程。它包含一种方法,用于咨询应用后执行了多少次评估。

下面就来叙述这些算子的接口和实现类

交叉算子

CrossoverOperator 接口可以作为 jMetal 5中交叉算子的代表:

package org.uma.jmetal.operator;

/**
 * Interface representing crossover operators. They will receive a list of solutions and return
 * another list of solutions
 *
 * @author Antonio J. Nebro <antonio@lcc.uma.es>
 *
 * @param <S> The class of the solutions
 */
public interface CrossoverOperator<S extends Solution<?>> extends Operator<List<S>,List<S>> {
}

这个接口简单地说明了交叉点有一个solution对象的列表作为源,并返回另一个solution对象的列表作为结果。让我们看一下这个接口的两个实现,一个用于实数类型,另一个用于二进制类型。
模拟二进制交叉(SBX)是许多多目标进化算法(如NSGA-II、SPEA2、SMS-EMOA、MOCell等)中的默认交叉算子。SBXCrossover类的方案如下所示:

package org.uma.jmetal.operator.impl.crossover;

/**
 * This class allows to apply a SBX crossover operator using two parent solutions (Double encoding).
 * A {@link RepairDoubleSolution} object is used to decide the strategy to apply when a value is out
 * of range.
 *
 * The implementation is based on the NSGA-II code available in
 * <a href="http://www.iitk.ac.in/kangal/codes.shtml">http://www.iitk.ac.in/kangal/codes.shtml</a>
 *
 * @author Antonio J. Nebro <antonio@lcc.uma.es>
 * @author Juan J. Durillo
 */
public class SBXCrossover implements CrossoverOperator<DoubleSolution> {
  /** EPS defines the minimum difference allowed between real values */
  private static final double EPS = 1.0e-14;

  private double distributionIndex ;
  private double crossoverProbability  ;
  private RepairDoubleSolution solutionRepair ;

  private JMetalRandom randomGenerator ;

  /** Constructor */
  public SBXCrossover(double crossoverProbability, double distributionIndex) {
    this (crossoverProbability, distributionIndex, new RepairDoubleSolutionAtBounds()) ;
  }

  /** Constructor */
  public SBXCrossover(double crossoverProbability, double distributionIndex, RepairDoubleSolution solutionRepair) {
    if (crossoverProbability < 0) {
      throw new JMetalException("Crossover probability is negative: " + crossoverProbability) ;
    } else if (distributionIndex < 0) {
      throw new JMetalException("Distribution index is negative: " + distributionIndex);
    }

    this.crossoverProbability = crossoverProbability ;
    this.distributionIndex = distributionIndex ;
    this.solutionRepair = solutionRepair ;

    randomGenerator = JMetalRandom.getInstance() ;
  }

  /** Execute() method */
  @Override
  public List<DoubleSolution> execute(List<DoubleSolution> solutions) {
    if (null == solutions) {
      throw new JMetalException("Null parameter") ;
    } else if (solutions.size() != 2) {
      throw new JMetalException("There must be two parents instead of " + solutions.size()) ;
    }

    return doCrossover(crossoverProbability, solutions.get(0), solutions.get(1)) ;
  }
  
  ...

未完待续????

标签:crossoverProbability,jMetal,double,distributionIndex,文档,solutions,算子,Operator,pu
来源: https://blog.csdn.net/Mactavish_Cui/article/details/122095262

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有