专栏首页人工智能与演化计算成长与进阶一起来学演化计算-SBX模拟二进制交叉算子和DE差分进化算子

一起来学演化计算-SBX模拟二进制交叉算子和DE差分进化算子

参考文献

[1] https://blog.csdn.net/qq_36347331/article/details/96351162

[2] http://www.it1352.com/994287.html

[3] https://www.egr.msu.edu/~kdeb/

SBX

DE

SBX matlab版本实现

function object=crossover(object,p1,p2,cf)
          object.rnvec=0.5*((1+cf).*p1.rnvec + (1-cf).*p2.rnvec);
          % 截断范围
          object.rnvec(object.rnvec>1)=1;
          object.rnvec(object.rnvec<0)=0;
end
u = rand(1,D_multitask);
cf = zeros(1,D_multitask);
cf(u<=0.5)=(2*u(u<=0.5)).^(1/(mu+1));
cf(u>0.5)=(2*(1-u(u>0.5))).^(-1/(mu+1));
child(count) = crossover(child(count),population(p1),population(p2),cf);
child(count+1) = crossover(child(count+1),population(p2),population(p1),cf);

SBX java版本实现

/**
 * This class allows to apply a SBX crossover operator using two parent
 * solutions.
 * 关于此代码和Deb论文中代码不一致可以查看http://www.it1352.com/994287.html帖子或者查看Deb官方源码
 */
//  SBXCrossover.java
//
//  Author:
//       Antonio J. Nebro <antonio@lcc.uma.es>
//       Juan J. Durillo <durillo@lcc.uma.es>
//
//  Copyright (c) 2011 Antonio J. Nebro, Juan J. Durillo
//
//  This program is free software: you can redistribute it and/or modify
//  it under the terms of the GNU Lesser General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public License
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.*/
public Solution[] doCrossover(double probability, Solution parent1, Solution parent2) throws JMException {

  Solution[] offSpring = new Solution[2];
  /**
  *使用一个父代个体去生成新个体的原因在于可以将父代的属性传给子代
  *具体有:
   * public Solution(Solution solution) {
   *   problemSet_ = solution.problemSet_;
   *   type_ = solution.type_;
   *
   *   numberOfObjectives_ = solution.getNumberOfObjectives();
   *   objective_ = new double[numberOfObjectives_];
   *   for (int i = 0; i < objective_.length; i++) {
   *    objective_[i] = solution.getObjective(i);
   *                } // for
   *    // <-
   *
   *   variable_ = type_.copyVariables(solution.variable_);
   *   overallConstraintViolation_ = solution.getOverallConstraintViolation();
   *   numberOfViolatedConstraints_ = solution.getNumberOfViolatedConstraint();
   *   distanceToSolutionSet_ = solution.getDistanceToSolutionSet();
   *   crowdingDistance_ = solution.getCrowdingDistance();
   *   kDistance_ = solution.getKDistance();
   *   fitness_ = solution.getFitness();
   *   rank_ = solution.getRank();
   *   location_ = solution.getLocation();
   *
   *   skillFactor_ = solution.getSkillFactor();*  } // Solution
   * */
  offSpring[0] = new Solution(parent1);
  offSpring[1] = new Solution(parent2);

  int i;
  double rand;
  double y1, y2, yL, yu;
  double c1, c2;
  double alpha, beta, betaq;
  double valueX1, valueX2;
  XReal x1 = new XReal(parent1);
  XReal x2 = new XReal(parent2);
  XReal offs1 = new XReal(offSpring[0]);
  XReal offs2 = new XReal(offSpring[1]);

  int numberOfVariables = x1.getNumberOfDecisionVariables();

  if (PseudoRandom.randDouble() <= probability) {
   //只有随机生成的数小于自定义的交叉可能性时才进行交叉操作
   for (i = 0; i < numberOfVariables; i++) {
    valueX1 = x1.getValue(i);
    valueX2 = x2.getValue(i);
    if (PseudoRandom.randDouble() <= 0.5) {
     if (java.lang.Math.abs(valueX1 - valueX2) > EPS) {

      if (valueX1 < valueX2) {
       y1 = valueX1;
       y2 = valueX2;
      } else {
       y1 = valueX2;
       y2 = valueX1;
      } // if

      yL = x1.getLowerBound(i);
      yu = x1.getUpperBound(i);
      rand = PseudoRandom.randDouble();
      beta = 1.0 + (2.0 * (y1 - yL) / (y2 - y1));
      alpha = 2.0 - java.lang.Math.pow(beta, -(distributionIndex_ + 1.0));

      if (rand <= (1.0 / alpha)) {
       betaq = java.lang.Math.pow((rand * alpha), (1.0 / (distributionIndex_ + 1.0)));
      } else {
       betaq = java.lang.Math.pow((1.0 / (2.0 - rand * alpha)),
         (1.0 / (distributionIndex_ + 1.0)));
      } // if

      c1 = 0.5 * ((y1 + y2) - betaq * (y2 - y1));
      beta = 1.0 + (2.0 * (yu - y2) / (y2 - y1));
      alpha = 2.0 - java.lang.Math.pow(beta, -(distributionIndex_ + 1.0));

      if (rand <= (1.0 / alpha)) {
       betaq = java.lang.Math.pow((rand * alpha), (1.0 / (distributionIndex_ + 1.0)));
      } else {
       betaq = java.lang.Math.pow((1.0 / (2.0 - rand * alpha)),
         (1.0 / (distributionIndex_ + 1.0)));
      } // if

      c2 = 0.5 * ((y1 + y2) + betaq * (y2 - y1));

      if (c1 < yL)
       c1 = yL;

      if (c2 < yL)
       c2 = yL;

      if (c1 > yu)
       c1 = yu;

      if (c2 > yu)
       c2 = yu;

      if (PseudoRandom.randDouble() <= 0.5) {
       offs1.setValue(i, c2);
       offs2.setValue(i, c1);
      } else {
       offs1.setValue(i, c1);
       offs2.setValue(i, c2);
      } // if
     } else {
      offs1.setValue(i, valueX1);
      offs2.setValue(i, valueX2);
     } // if
    } else {
     offs1.setValue(i, valueX2);
     offs2.setValue(i, valueX1);
    } // if
   } // if
  } // if

  return offSpring;
 }

本文分享自微信公众号 - DrawSky(wustcsken),作者:CloudXu

原文出处及转载信息见文内详细说明,如有侵权,请联系 yunjia_community@tencent.com 删除。

原始发表时间:2020-06-29

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • Jmetal设置Solution Variables

    DrawSky
  • jzy3D从入门到弃坑_2 使用jzy3D0.9画2D散点图

    DrawSky
  • MTO Jmetal IGD计算BUG

    特别注意其中new solution 时候的方式Solution newSolution = new Solution(end - start + 1); ,以...

    DrawSky
  • CountDownLatch的原理

    上次大概说了CountDownLatch的使用,今天说下实现的原理,CountDownLatch的使用效果和Join差不多,实现起来也比较简单。

    付威
  • 蒂花之秀,他们究竟对古诗词做了什么?

    菜天哥哥
  • 终于让采集侠自动采集了

    用织梦采集侠一段时间了,觉得这个插件真的不错,尤其是新版本,可以结合DEDE自动的采集规则来进行采集。一下采集功能就非常强大了。

    用户1191760
  • python自学第三节课(笔记)

    被缩进的内容(print()函数)和if条件语句组成了一个代码块(一个整体),成为了if条件下的内部命令。

    小老鼠
  • php获取主机信息

    if(!empty($_SERVER['HTTP_USER_AGENT'])){

    botkenni
  • R语言写2048游戏

           2048 是一款益智游戏,只需要用方向键让两两相同的数字碰撞就会诞生一个翻倍的数字,初始数字由 2 或者 4 构成,直到游戏界面全部被填满,游戏结...

    用户1680321
  • R条件语句

    但如果你有一长串 if 语句,那么就要考虑重写了。重写的一种方法是使用 switch() 函数, 它先对第一个参数求值,然后按照名称或位置在后面的参数列表中匹...

    生信编程日常

扫码关注云+社区

领取腾讯云代金券