📄 ga_rwheel.m
字号:
function new_popu=GA_Rwheel(fit,popu);
%%new_popu=GA_Rwheel(fit,popu);
%% fit is the fitness values
%% popu is the total popu in real numbers
%% new_popu is a new population derived from Roulette wheel selection
%%
%% For example
%popu=10*rand(10,2);fit=popu(:,1).*popu(:,2);
%new_popu=GA_Rwheel(fit,popu);
%[popu fit new_popu]
% PenChen Chou. 2005-3-9
rand('state',sum(100*clock));
% No negative fit
Y=min(fit);
if Y<0, fit=fit-Y; end
% Cumulative sum
fit=fit/sum(fit);
fit=cumsum(fit);
N=length(fit);
new_popu=[];
% Create new popu
for i=1:N
I=find(fit<rand);
if isempty(I)
inx=1;
else
inx=I(end)+1;
end
new_popu=[new_popu; popu(inx,:)];
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -