資源簡介
該代碼本人詳細注釋了,還包含參考資料,具體理論解析參考博客(https://blog.csdn.net/weixin_43935696/article/details/107045716)

代碼片段和文件信息
%?script?布谷鳥算法,求解函數最小值
%?@author?zhaoyuqiang?
%#ok<*SAGROW>?Remove?hints?of?syntax
%#ok<*CLALL>
%#ok<*FNDSB>
clear?all?;?
close?all?;
clc?;
N?=?25;?% 鳥巢的數量Number?of?nests(The?scale?of?solution)
D?=?10?;?%?問題的維度?Dimensionality?of?solution
T?=500?;?%迭代次數的上限?Number?of?iterations
Xmax?=?pi?;
Xmin?=?-pi?;
Pa?=?0.25?;?%?Probability?of?building?a?new?nest(After?host?bird?find?exotic?bird?eggs)
%繪圖
%fv?=?@(a)?cumsum(a.^22);%11*sin(6*a)?+?7*cos(5*a);
x?=?0:10;
fv?=?cumsum(x.^22);
plot(x?fv);
hold?on
h?=?plot(00‘*‘);
nestPop?=?rand(ND)*(Xmax-Xmin)+Xmin?;??%?初始化寄主的鳥巢Random?initial?solutions
for?t=1:T
????levy_nestPop?=??func_levy(nestPopXmaxXmin)?;?%?通過levy飛行產生一個解Generate?new?solutions?by?Levy?flights
????nestPop?=?func_bestNestPop(nestPoplevy_nestPop);??%?與上一代比較,更新適應度較優的鳥窩Choose?a?best?nest?among??new?and?old?nests?????
????rand_nestPop?=?func_newBuildNest(nestPopPaXmaxXmin);?%?舍棄最糟糕的鳥巢并建立一個新鳥巢Abandon(Pa)?worse?nests?and?build?new?nests?by?(Preference?random?walk?)
????nestPop?=?func_bestNestPop(nestPoprand_nestPop)?;?%列出當前最佳的鳥巢?Choose?a?best?nest?among??new?and?old?nests
????[~index]?=?max(func_fitness(nestPop))?;?%?Best?nests更新當代最優鳥巢的位置
????trace(t)?=?func_objValue(nestPop(index:))?;
????%trace(t)?=?func_objValue(nestPop(index))?;
????%fval?=?func_objValue(nestPop(index:));
???%?h?=?plot(nestPop(index:)func_objValue(nestPop(index:))‘*‘);
????fprintf(“%f-----%f\n“nestPop(index:)func_objValue(nestPop(index:)));
????
end
h?=?plot(nestPop(index:)func_objValue(nestPop(index:))‘*‘);
figure?
plot(trace);
xlabel(‘迭代次數‘)?;
ylabel(‘適應度值‘)?;
title(‘適應度進化曲線‘)?;
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2020-07-08?22:10??CSCode\
?????目錄???????????0??2020-07-06?00:56??CSCode\Book\
?????文件??????629677??2020-07-05?10:08??CSCode\Book\布谷鳥搜索算法綜述.pdf
?????目錄???????????0??2020-07-08?22:08??CSCode\CSTofunction\
?????文件????????3138??2020-07-04?21:38??CSCode\CSTofunction\CS.zip
?????文件????????1833??2020-07-07?20:38??CSCode\CSTofunction\CSMain.m
?????文件?????????351??2020-07-05?12:52??CSCode\CSTofunction\func_bestNestPop.m
?????文件?????????224??2018-06-26?16:15??CSCode\CSTofunction\func_fitness.m
?????文件?????????797??2020-07-05?10:24??CSCode\CSTofunction\func_levy.m
?????文件?????????551??2020-07-05?10:46??CSCode\CSTofunction\func_newBuildNest.m
?????文件?????????205??2020-07-05?13:02??CSCode\CSTofunction\func_objValue.m
評論
共有 條評論