?? select_gen.m
function newchrom=select_gen(criteria,chrom)% SELECT_GEN Selects best chromosomes for next generation based on the criteria.% Copyright (c) 1997-2000 Jiming Liu and Jianbing Wuglobal Genetic_Result;[pop bitlength]=size(chrom);fit=[];%calculate fitness[fit,fitot]=call_fitness(criteria,chrom); Genetic_Result=[Genetic_Result;fit];for chromnum=1:pop sval(chromnum)=sum(fit(1,1:chromnum));end%select according to fitness by probability% Remain a most optimal population.% if change it ,the loop variable should be i=1:pop[fit_max,Pos]=max(fit);parname=Pos;for i=1:pop-1 rval=fitot*rand; if rval<=sval(1) parname=[parname 1]; else for j=1:pop-1 sl=sval(j); % Left value for comparing su=sval(j+1); % Right value for comparing if (rval>sl) & (rval<=su) parname=[parname j+1]; break; end end end endnewchrom(1:pop,:)=chrom(parname,:);
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -