Roulette Selection in Genetic Algorithms

后端 未结 14 1010
庸人自扰
庸人自扰 2020-11-27 12:19

Can anyone provide some pseudo code for a roulette selection function? How would I implement this:

14条回答
  •  误落风尘
    2020-11-27 12:57

    Roulette Wheel Selection in MatLab:

    TotalFitness=sum(Fitness);
        ProbSelection=zeros(PopLength,1);
        CumProb=zeros(PopLength,1);
    
        for i=1:PopLength
            ProbSelection(i)=Fitness(i)/TotalFitness;
            if i==1
                CumProb(i)=ProbSelection(i);
            else
                CumProb(i)=CumProb(i-1)+ProbSelection(i);
            end
        end
    
        SelectInd=rand(PopLength,1);
    
        for i=1:PopLength
            flag=0;
            for j=1:PopLength
                if(CumProb(j)=SelectInd(i))
                    SelectedPop(i,1:IndLength)=CurrentPop(j+1,1:IndLength);
                    flag=1;
                    break;
                end
            end
            if(flag==0)
                SelectedPop(i,1:IndLength)=CurrentPop(1,1:IndLength);
            end
        end
    

提交回复
热议问题