基于鯨魚算法結(jié)合蟻群算法求解函數(shù)極值問題含Matlab代碼
?作者簡介:熱愛科研的
開發(fā)者,修心和技術(shù)同步精進(jìn),matlab項目合作可私信。??個人主頁:
??個人信條:格物致知。
更多Matlab仿真內(nèi)容點擊??
? ? ?
? ? ? ?
1 內(nèi)容介紹
蟻群算法是繼模擬退火、遺傳算法、禁忌搜索等之后的又一啟發(fā)式智能優(yōu)化算法,它是由意大利學(xué)者M(jìn).Dorigo等人首次提出,并廣泛應(yīng)用于求解一系列組合優(yōu)化問題,如:旅行商問題,二次分配問題,車輛路徑問題和圖著色問題等,這些應(yīng)用充分顯示了它在解決復(fù)雜離散優(yōu)化問題方面的優(yōu)越性。連續(xù)空間函數(shù)優(yōu)化問題也是蟻群算法的研究課題之一,多峰函數(shù)優(yōu)化又是函數(shù)優(yōu)化的一個重要方面,但目前蟻群算法對該問題的研究主要是集中在求解函數(shù)的最大(小)值,對求解函數(shù)所有極值方面的研究卻很少。
2 部分代碼
clear
close all
clc
% Set ABC Control Parameters
ABCOpts = struct( 'ColonySize',? 100, ...? ?% Number of Employed Bees+ Number of Onlooker Bees 種群規(guī)模
? ? 'MaxCycles', 500,...? ?% Maximum cycle number in order to terminate the algorithm 循環(huán)次數(shù),即全部螞蟻走幾遍
? ? 'ErrGoal',? ?1e-20, ...? % Error goal in order to terminate the algorithm (not used in the code in current version)
? ? 'Dim',? ? ? ?20 , ... % Number of parameters of the objective function 維數(shù)
? ? 'Limit',? ?100, ... % Control paramter in order to abandone the food source 放棄食物源的閾值
? ? 'lb',? -5.12, ... % Lower bound of the parameters to be optimized 函數(shù)值下限
? ? 'ub',? 5.12, ... %Upper bound of the parameters to be optimized 函數(shù)值上限
? ? 'ObjFun' , 'rastrigin', ... %Write the name of the objective function you want to minimize 選擇函數(shù)
? ? 'RunTime',3); % Number of the runs 迭代次數(shù)
GlobalMins=zeros(ABCOpts.RunTime,ABCOpts.MaxCycles);
GlobalMins_WABC=zeros(ABCOpts.RunTime,ABCOpts.MaxCycles);
for r=1:ABCOpts.RunTime
? ??
? ? % Initialise population
? ? Range = repmat((ABCOpts.ub-ABCOpts.lb),[ABCOpts.ColonySize ABCOpts.Dim]);
? ? Lower = repmat(ABCOpts.lb, [ABCOpts.ColonySize ABCOpts.Dim]);
? ? Colony = rand(ABCOpts.ColonySize,ABCOpts.Dim) .* Range + Lower;
? ??
? ? Employed=Colony(1:(ABCOpts.ColonySize/2),:);
? ? GlobalMins(r,:) = ABCbee(ABCOpts,Employed);? % ABC算法
? ?GlobalMins_WABC(r,:) = WABCbee(ABCOpts,Employed);? % WABC-ABC算法
end; %end of runs
%----------------------------- 畫圖、記錄最優(yōu)均值和方差 --------------------------
dd=ABCOpts.MaxCycles;
if ABCOpts.RunTime==1
? ? semilogy((1:10:dd),GlobalMins(1:10:end));
? ? hold on
? ? semilogy((1:10:dd),GlobalMins_WABC(1:10:end),'-*g');
else
? ? semilogy((1:10:dd),mean(GlobalMins(:,1:10:end)));%若多次執(zhí)行,求均值
? ? hold on
? ? semilogy((1:10:dd),mean(GlobalMins_WABC(:,1:10:end)),'-*g');%若多次執(zhí)行,求均值
end
grid on
title('Mean of Best function values');
xlabel('cycles');
ylabel('fitness');
legend('ABC','WABC');
fprintf('Mean =%g Std=%g\n',mean(GlobalMins(:,end)),std(GlobalMins(:,end)));
fprintf('Mean =%g Std=%g\n',mean(GlobalMins_WABC(:,end)),std(GlobalMins_WABC(:,end)));
3 運行結(jié)果

4 參考文獻(xiàn)
[1]劉卉. 應(yīng)用蟻群算法求解函數(shù)所有極值[D]. 四川師范大學(xué), 2011.
博主簡介:擅長
、 、 、 、 、 、 、 、 等多種領(lǐng)域的Matlab仿真,相關(guān)matlab代碼問題可私信交流。部分理論引用網(wǎng)絡(luò)文獻(xiàn),若有侵權(quán)聯(lián)系博主刪除。
?