SBX(Simulated binary crossover)模拟二进制交叉算子和DE(differential evolution)差分进化算子

本文深入探讨了演化计算中的两种重要算子:SBX(Simulated Binary Crossover)模拟二进制交叉算子与DE(Differential Evolution)差分进化算子。通过解析其原理及提供Matlab与Java实现代码,帮助读者理解并掌握这两种算子在优化算法中的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一起来学演化计算-SBX(Simulated binary crossover)模拟二进制交叉算子和DE(differential evolution)差分进化算子

觉得有用的话,欢迎一起讨论相互学习~

我的微博我的github我的B站

参考文献
[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;
	}
### SBX (Simulated Binary Crossover) in Genetic Algorithms Implementation and Usage In the context of genetic algorithms, crossover operations play a crucial role in generating new offspring from parent solutions. For continuous search spaces, Simulated Binary Crossover (SBX), proposed by K. Deb and R. B. Agarwal, is widely used due to its effectiveness[^1]. This operator mimics traditional one-point or two-point crossovers but adapts them specifically for real-valued parameters. #### Definition and Characteristics The primary characteristic of SBX lies in how it creates children that are closer to their parents compared with other methods like uniform mutation. The probability distribution function ensures this behavior while allowing occasional distant jumps within feasible bounds. Such properties make SBX particularly suitable when dealing with multi-objective optimization problems where maintaining diversity among population members remains essential. #### Mathematical Formulation Given two parent individuals \( P_1 \) and \( P_2 \), let us denote child individual as \( Q_i \). To generate each component value of these children: If both parents have identical values at some position i.e., \( p_{xi} = p_{yi} \): \[ q_i = p_xi \] Otherwise, Let's define β based on whether we want more exploration (\( u < 0.5 \)) or exploitation (\( u >= 0.5 \)): For \(u<0.5\), \[ \beta_q=2u^{(\frac{1}{n_c+1})}\] And for \(u>=0.5\), \[ \beta_q=(\frac{(2*(1-u))}{((1-u)^{\frac{n_c+1}{nc}})})^{\frac{1}{nc+1}}\] Where nc controls the spread factor around better parent solution during reproduction process. Finally calculate qi using following equations depending upon which parent has smaller xi : When px<=py, If rand()<0.5 then qi=0.5*((px+(βq)*(py−px))) Else qi=0.5*((py-(βq)*(py-px))) This procedure repeats until all components get assigned appropriate values forming complete offspring vectors Qi. ```matlab function [child1, child2] = sbx(parent1, parent2, eta_c) % Implementing simulated binary crossover operation between two parents dim = length(parent1); for i = 1:dim if rand() <= 0.5 % Calculate beta according to given formulae if abs(parent1(i)-parent2(i)) > eps if rand() < 0.5 beta = (2*rand())^(1/(eta_c+1)); else beta = (1/(2*(1-rand())))^(1/(eta_c+1)); end child1(i) = 0.5 * ((1 + beta)*min([parent1(i); parent2(i)]) ... +(1-beta)*max([parent1(i); parent2(i)])); child2(i) = 0.5 * ((1 - beta)*min([parent1(i); parent2(i)]) ... +(1+beta)*max([parent1(i); parent2(i)])); else child1(i) = parent1(i); child2(i) = parent2(i); end else child1(i) = parent1(i); child2(i) = parent2(i); end end ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值