一、鯨魚優(yōu)化算法
鯨魚優(yōu)化算法(Whale Optimization Algorithm,WOA)是模仿自然界中鯨魚捕食行為的新型群體智能優(yōu)化算法。它通過對(duì)自然界中座頭鯨群體狩獵行為的模擬,通過鯨魚群體搜索、包圍、追捕和攻擊獵物等過程實(shí)現(xiàn)優(yōu)時(shí)化搜索的目的。鯨魚優(yōu)化算法的工作原理如下:
1、初始化:首先,在算法開始時(shí),需要為每個(gè)鯨魚設(shè)定一個(gè)初始位置,并生成初始種群。
2、搜索:每個(gè)鯨魚都會(huì)按照一定的規(guī)則探索空間。這個(gè)過程可以模擬鯨魚包圍、追捕和攻擊獵物等過程。
3、評(píng)估:每當(dāng)鯨魚移動(dòng)的時(shí)候,都會(huì)對(duì)當(dāng)前的鯨魚種群計(jì)算適應(yīng)度值。如果當(dāng)前的適應(yīng)度值優(yōu)于之前的適應(yīng)度值,則將當(dāng)前適應(yīng)度值設(shè)為最優(yōu)解。
4、更新:當(dāng)所有的鯨魚都完成了移動(dòng)和評(píng)估后,算法會(huì)更新所有鯨魚的位置,并重復(fù)以上步驟。
5、迭代:鯨魚優(yōu)化算法可以進(jìn)行多次迭代,直到找到最優(yōu)解為止。
鯨魚優(yōu)化算法的優(yōu)勢(shì)在于操作簡(jiǎn)單,調(diào)整的參數(shù)少以及跳出局部最優(yōu)的能力強(qiáng),它能夠快速找到最優(yōu)解,并且對(duì)于各種類型的優(yōu)化問題都能有效地工作。對(duì)于基礎(chǔ)的問題,它還具有很好的收斂性和穩(wěn)定性。
鯨魚優(yōu)化算法主要包括三個(gè)過程:1)包圍獵物;2)發(fā)泡網(wǎng)攻擊;3)搜索捕食。
鯨魚優(yōu)化算法的流程圖如下圖所示:
二、代碼實(shí)戰(zhàn)
%_________________________________________________________________________%
% Whale Optimization Algorithm (WOA) source codes demo 1.0 %
% %
% Developed in MATLAB R2011b(7.13) %
% %
% Author and programmer: Seyedali Mirjalili %
% %
% e-Mail: ali.mirjalili@gmail.com %
% seyedali.mirjalili@griffithuni.edu.au %
% %
% Homepage: http://www.alimirjalili.com %
% %
% Main paper: S. Mirjalili, A. Lewis %
% The Whale Optimization Algorithm, %
% Advances in Engineering Software , in press, %
% DOI: http://dx.doi.org/10.1016/j.advengsoft.2016.01.008 %
% %
%_________________________________________________________________________%
% You can simply define your cost in a seperate file and load its handle to fobj
% The initial parameters that you need are:
%__________________________________________
% fobj = @YourCostFunction
% dim = number of your variables
% Max_iteration = maximum number of generations
% SearchAgents_no = number of search agents
% lb=[lb1,lb2,...,lbn] where lbn is the lower bound of variable n
% ub=[ub1,ub2,...,ubn] where ubn is the upper bound of variable n
% If all the variables have equal lower bound you can just
% define lb and ub as two single number numbers
% To run WOA: [Best_score,Best_pos,WOA_cg_curve]=WOA(SearchAgents_no,Max_iteration,lb,ub,dim,fobj)
%__________________________________________
clear all
clc
SearchAgents_no=30; % Number of search agents
Function_name='F1'; % Name of the test function that can be from F1 to F23 (Table 1,2,3 in the paper)
Max_iteration=500; % Maximum numbef of iterations
% Load details of the selected benchmark function
[lb,ub,dim,fobj]=Get_Functions_details(Function_name);
[Best_score,Best_pos,WOA_cg_curve]=WOA(SearchAgents_no,Max_iteration,lb,ub,dim,fobj);
figure('Position',[269 240 660 290])
%Draw search space
subplot(1,2,1);
func_plot(Function_name);
title('Parameter space')
xlabel('x_1');
ylabel('x_2');
zlabel([Function_name,'( x_1 , x_2 )'])
%Draw objective space
subplot(1,2,2);
semilogy(WOA_cg_curve,'Color','r')
title('Objective space')
xlabel('Iteration');
ylabel('Best score obtained so far');
axis tight
grid on
box on
legend('WOA')
display(['The best solution obtained by WOA is : ', num2str(Best_pos)]);
display(['The best optimal value of the objective funciton found by WOA is : ', num2str(Best_score)]);