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

📄 selectoper.m

📁 基本遗传算法的matlab源程序
💻 M
字号:
function  [geneCodSel,indivSel,evalSel]=selectOper(geneCod,indiv,eval,bounds)
%  selection operator by roulette
%  syntax:[geneCodSel,indivSel,evalSel]=selectOper(geneCod,indiv,eval)
%
%  Output Arguments:
%      geneCode     ---- a matrix of chromosome codes
%      indiv        ---- a matrix of all individual in form of actual value
%      eval         ---- a matrix of all fitness value
%  Input Arguments:
%      geneCodSel   ---- a matrix of chromosome codes after selection
%      indiv        ---- a matrix of all individual after selection
%      eval         ---- a matrix of all fitness value after selection
%      bounds     ---- a matrix of upper and lower bounds on the variables
%
%  Author:Yan Anxin
%  ID number:081810
%  Yax235 DreamWorks, SEE, SEU, 2# Sipailou Nanjing, 210096, P.R.China 

sizePop=length(eval);[varSize,]=size(bounds);
fitSum=sum(eval);            %the sum of fitness value
selePro=eval/fitSum;         %the probability of selection
cumuPro=cumsum(selePro);     %cumulative probability
wheel=[0;cumuPro];           %to generate roulette

geneCodSel=geneCod;indivSel=indiv;evalSel=eval;       %selection operator
sizeloop=1;
while sizeloop~=sizePop
    pro=rand(1);outflag=0;
    for jk=1:sizePop
        if(pro>wheel(jk))&&(pro<=wheel(jk+1))
            geneCodSel(sizeloop,:)=geneCod(jk,:);
            indivSel(sizeloop,:)=indiv(jk,:);
            evalSel(sizeloop)=eval(jk);
            break
        end       
    end
    for jk=1:varSize        %to prevent cross-border
        if (indivSel(sizeloop,jk)<bounds(jk,1))||(indivSel(sizeloop,jk)>bounds(jk,2))
            outflag=1;break;
        end
    end
    if outflag==0,sizeloop=sizeloop+1;end
end

indivSel=indivSel';evalSel=evalSel';

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -