reproduc.m

来自「基本遗传算法程序包」· M 代码 · 共 23 行

M
23
字号
function [new_gen,selected] = reproduc(old_gen,fitness)%REPRODUC selects individuals proportional to their fitness.%	[NEW_GEN,SELECTED] = MATE(OLD_GEN,FITNESS) selects %       individuals from OLD_GEN proportional to their FITNESS%       NEW_GEN will have the same number of individuals as OLD_GEN.%       SELECTED contains the indices (rows) of the selected%       individuals (ie: NEW_GEN=OLD_GEN(SELECTED,:)).%%	Copyright (c) 1993 by the MathWorks, Inc.%	Andrew Potvin 1-10-93.norm_fit = fitness/sum(fitness);selected = rand(size(fitness));sum_fit = 0;for i=1:length(fitness),   sum_fit = sum_fit + norm_fit(i);   index = find(selected<sum_fit);   selected(index) = i*ones(size(index));endnew_gen = old_gen(selected,:);% end reproduc

⌨️ 快捷键说明

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