?? roulette.m
字號:
function[newPop] = roulette(oldPop,options)%roulette is the traditional selection function with the probability of%surviving equal to the fittness of i / sum of the fittness of all individuals%%function[newPop] = roulette(oldPop,options)%newPop - the new population selected from the oldPop%oldPop - the current population%options - options [gen]%Get the parameters of the populationnumVars = size(oldPop,2);numSols = size(oldPop,1);%Generate the relative probabilites of selectiontotalFit = sum(oldPop(:,numVars));prob=oldPop(:,numVars) / totalFit; prob=cumsum(prob);rNums=sort(rand(numSols,1)); %Generate random numbers%Select individuals from the oldPop to the newfitIn=1;newIn=1;while newIn<=numSols if(rNums(newIn)<prob(fitIn)) newPop(newIn,:) = oldPop(fitIn,:); newIn = newIn+1; else fitIn = fitIn + 1; endend
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -