📄 crossoper.m
字号:
function geneCodCro=crossOper(geneCod,proCro)
% crossover operator
% syntax:geneCodCro=crossOper(geneCod,proCro)
%
% Output Arguments:
% geneCode ---- a matrix of chromosome codes
% Input Arguments:
% geneCodCro ---- a matrix of chromosome codes after crossover
% proCro ---- the probability of cross-gene
%
% Author:Yan Anxin
% ID number:081810
% Yax235 DreamWorks, SEE, SEU, 2# Sipailou Nanjing, 210096, P.R.China
[sizePop,sizeGene]=size(geneCod);
matPool=randperm(sizePop); %to form the mating pool
geneCodCro=geneCod;
for ik=1:(sizePop/2)
proRand=rand(1);
if proRand>proCro,continue;end %random selection
father=geneCod(matPool(ik),:);mother=geneCod(matPool(ik+sizePop/2),:);
crossPoint=unidrnd(sizeGene); %random cross-matching
child=father(crossPoint:sizeGene);
father(crossPoint:sizeGene)=mother(crossPoint:sizeGene);
mother(crossPoint:sizeGene)=child; %single cross
geneCodCro(matPool(ik),:)=father;
geneCodCro(matPool(ik+sizePop/2),:)=mother;
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -