电子说
一、鲸鱼优化算法
鲸鱼优化算法(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)]);