一、鯨魚優化算法
鯨魚優化算法(Whale Optimization Algorithm,WOA)是模仿自然界中鯨魚捕食行為的新型群體智能優化算法。它通過對自然界中座頭鯨群體狩獵行為的模擬,通過鯨魚群體搜索、包圍、追捕和攻擊獵物等過程實現優時化搜索的目的。鯨魚優化算法的工作原理如下:
1、初始化:首先,在算法開始時,需要為每個鯨魚設定一個初始位置,并生成初始種群。
2、搜索:每個鯨魚都會按照一定的規則探索空間。這個過程可以模擬鯨魚包圍、追捕和攻擊獵物等過程。
3、評估:每當鯨魚移動的時候,都會對當前的鯨魚種群計算適應度值。如果當前的適應度值優于之前的適應度值,則將當前適應度值設為最優解。
4、更新:當所有的鯨魚都完成了移動和評估后,算法會更新所有鯨魚的位置,并重復以上步驟。
5、迭代:鯨魚優化算法可以進行多次迭代,直到找到最優解為止。
鯨魚優化算法的優勢在于操作簡單,調整的參數少以及跳出局部最優的能力強,它能夠快速找到最優解,并且對于各種類型的優化問題都能有效地工作。對于基礎的問題,它還具有很好的收斂性和穩定性。
鯨魚優化算法主要包括三個過程:1)包圍獵物;2)發泡網攻擊;3)搜索捕食。
鯨魚優化算法的流程圖如下圖所示:
二、代碼實戰
%_________________________________________________________________________%
% 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)]);