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

📄 gas_nextpopu.m

📁 其中提到遺傳學的程式碼與應用提供給次淚相向的研究者參考下載
💻 M
字号:
function new_popu = GAs_nextpopu(object, popu, bit_n, xover_rate, mut_rate, elite, ranges, obj_fcn)
%% next_popu = GAs_nextpopu(object, popu, bit_n, xover_rate, mut_rate, elite, ranges, obj_fcn)
%%
%% do elite, linear ranking, selection, crossover, mutation functions
%% Modified on 2002-11-5, by PenChen Chou

%-----------------------------------------------------------
% Copy popu to new_popu.
%disp('******> In modified GAs_nextpopu under \WORK <******');
new_popu = popu;
popu_s = size(popu, 1);
string_leng = size(popu, 2);
var_n=string_leng/bit_n;
% Reset negative fitness value
I=find(object<=0);
if ~isempty(I), object(I)=0.0*ones(size(I)); end
%object=log10(object.^3);
%----------------------------------------------------------------
% Change objective to fitness with select_pressure of 1.2 to 2.
fitness=object;
if (rand>0.5)
   rand('state',sum(100*clock))
   fitness=GA_LinRank(fitness,min([2, max([1.2, 3*rand])]));
end

%----------------------------------------------------------------------
% ====== ELITISM: find the best two and keep them in index1 and index2
if elite==1
   tmp_fitness = fitness;
   [junk, index1] = max(tmp_fitness);	% find the best
   tmp_fitness(index1) = min(tmp_fitness);  % Change it to a small value for next max finding
   [junk, index2] = max(tmp_fitness);	% find the second best
   % Put the best 2 into new_popu for xover and mutation later
   %new_popu([1 2], :) = popu([index1 index2], :);  % Save the best two chromosomes for Elitism=1
end;

% ====== MUTATION (elites are not subject to this.)
mask = rand(popu_s, string_leng) < mut_rate;
new_popu = xor(new_popu, mask);

%======= Selection
new_popu = GA_gray2bin(new_popu, bit_n);  % APPENED on 2002-11-5
% Evaluate objective function for each individual
[new_fcn_value, new_popu_real, new_popu] = GAs_evalpopu(new_popu,...
           bit_n, ranges, obj_fcn);
       
[new_fcn_value, INX]=sort(new_fcn_value);
new_popu=new_popu(INX,:);
[fitnessx, INX]=sort(fitness);
popu=popu(INX,:);
new_popu(1:popu_s/2)=popu((popu_s/2+1):(popu_s));

%--------------------------------------------------------------------
% Apply linear fitness scaling
% After several trials, using LFS is no better than not using it.
%fitness=GA_linear_fit_scale(fitness,2);    % Assume cm=2 in all cases

%-----------------------------------------------------------------
% restore the elites if elite==1
if elite==1,
   new_popu([1:2], :) = popu([index1 index2], :); % Save the best only back to new_popu
end;
%--------------------END-----------------------------------------

⌨️ 快捷键说明

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