⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 crossoper.m

📁 基本遗传算法的matlab源程序
💻 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 + -